-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core/avatar): add avatar component (#598)
Co-authored-by: Daniel Leroux <daniel.leroux@siemens.com>
- Loading branch information
1 parent
4c385e5
commit 6bcda4f
Showing
33 changed files
with
636 additions
and
38 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/angular-test-app/src/preview-examples/avatar-image.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
template: ` | ||
<ix-avatar image="https://ui-avatars.com/api/?name=John+Doe"></ix-avatar> | ||
`, | ||
}) | ||
export default class AvatarImage {} |
16 changes: 16 additions & 0 deletions
16
packages/angular-test-app/src/preview-examples/avatar-initials.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
template: ` <ix-avatar initials="JD"></ix-avatar> `, | ||
}) | ||
export default class AvatarInitials {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
template: ` <ix-avatar></ix-avatar> `, | ||
}) | ||
export default class Avatar {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
@import 'common-variables'; | ||
@import 'mixins/text-truncation'; | ||
@import 'mixins/hover'; | ||
|
||
:host { | ||
display: flex; | ||
position: relative; | ||
width: fit-content; | ||
|
||
.avatar { | ||
display: flex; | ||
align-items: center; | ||
|
||
> .avatar-image { | ||
height: 2rem; | ||
width: 2rem; | ||
min-height: 2rem; | ||
min-width: 2rem; | ||
border-radius: 100px; | ||
} | ||
|
||
> .avatar-initials { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 2rem; | ||
width: 2rem; | ||
min-height: 2rem; | ||
min-width: 2rem; | ||
border-radius: 100px; | ||
background-color: var(--theme-color-component-3); | ||
} | ||
|
||
#avatar-path-background { | ||
fill: var(--theme-avatar--background); | ||
} | ||
|
||
#avatar-path-person { | ||
fill: var(--theme-color-4); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
function DefaultAvatar(props: { initials?: string }) { | ||
const { initials } = props; | ||
|
||
if (initials) { | ||
return <div class={'avatar-initials'}>{initials}</div>; | ||
} | ||
|
||
return ( | ||
<svg | ||
class={'avatar-image'} | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="32" | ||
height="32" | ||
viewBox="0 0 32 32" | ||
> | ||
<g fill="none" fill-rule="evenodd"> | ||
<path | ||
id="avatar-path-background" | ||
d="M16 0C7.163 0 0 7.163 0 16s7.163 16 16 16 16-7.163 | ||
16-16c0-4.243-1.686-8.313-4.686-11.314C24.314 1.686 20.244 0 16 0z" | ||
/> | ||
<path | ||
id="avatar-path-person" | ||
d="M17.897 17.91c3.8-.018 7.358 1.875 9.485 5.046-2.417 3.999-6.734 6.434-11.382 | ||
6.42-4.648.014-8.965-2.421-11.382-6.42 2.127-3.171 5.685-5.064 | ||
9.485-5.045h3.794zM15.821 2.129c3.682 0 6.667 2.984 6.667 6.666 0 3.682-2.985 | ||
6.667-6.667 6.667s-6.667-2.985-6.667-6.667 2.985-6.666 6.667-6.666z" | ||
/> | ||
</g> | ||
</svg> | ||
); | ||
} | ||
|
||
import { Component, Element, h, Host, Prop } from '@stencil/core'; | ||
|
||
/** | ||
* @since 2.0.0 | ||
*/ | ||
@Component({ | ||
tag: 'ix-avatar', | ||
styleUrl: 'avatar.scss', | ||
shadow: true, | ||
}) | ||
export class Avatar { | ||
@Element() hostElement: HTMLIxAvatarElement; | ||
|
||
/** | ||
* Display a avatar image | ||
* | ||
*/ | ||
@Prop() image: string; | ||
|
||
/** | ||
* Display the initials of the user. Will be overwritten by image | ||
* | ||
*/ | ||
@Prop() initials: string; | ||
|
||
render() { | ||
return ( | ||
<Host> | ||
<li class="avatar"> | ||
{this.image ? ( | ||
<img src={this.image} class="avatar-image"></img> | ||
) : ( | ||
<DefaultAvatar initials={this.initials} /> | ||
)} | ||
</li> | ||
</Host> | ||
); | ||
} | ||
} |
Oops, something went wrong.