-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(web): Introduce UNSTABLE_Avatar component #DS-1323
- Loading branch information
1 parent
d35239a
commit b9e0254
Showing
9 changed files
with
313 additions
and
1 deletion.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
packages/web/src/scss/components/UNSTABLE_Avatar/README.md
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,101 @@ | ||
# UNSTABLE Avatar | ||
|
||
⚠️ This component is UNSTABLE. It may significantly change at any point in the future. | ||
Please use it with caution. | ||
|
||
The `UNSTABLE_Avatar` component is used to represent a user or entity. | ||
|
||
It can be a circle or a square (with rounded corners, using `radius-100` token) and | ||
can have different sizes. | ||
|
||
## Example | ||
|
||
```html | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--medium" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</div> | ||
|
||
<a href="#" class="UNSTABLE_Avatar UNSTABLE_Avatar--xsmall" aria-label="Profile of Jiří Bárta"> | ||
<img src="https://picsum.photos/id/823/162/162" alt="Jiří Bárta" aria-hidden="true" /> | ||
</a> | ||
``` | ||
|
||
## Square | ||
|
||
Add `UNSTABLE_Avatar--square` modifier to make the avatar a square. | ||
|
||
```html | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--medium UNSTABLE_Avatar--square" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</div> | ||
``` | ||
|
||
## Sizes | ||
|
||
The Avatar component supports `xsmall`, `small`, `medium`, `large`, and `xlarge` sizes. | ||
|
||
```html | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--xsmall" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</div> | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--small" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</div> | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--medium" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</div> | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--large" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</div> | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--xlarge" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</div> | ||
``` | ||
|
||
## Content | ||
|
||
The content of the `UNSTABLE_Avatar` component can be an image, an icon, or a text string. | ||
|
||
### Icon | ||
|
||
Add an icon with correct size. | ||
|
||
```html | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--medium" aria-label="Profile of Jiří Bárta"> | ||
<svg width="24" height="24" aria-hidden="true"> | ||
<use xlink:href="/assets/icons/svg/sprite.svg#profile" /> | ||
</svg> | ||
</div> | ||
``` | ||
|
||
ℹ️ Don't forget to add the `aria-label` attribute for accessible title. | ||
|
||
### Image | ||
|
||
Add an image, it will be resized to fit the avatar. | ||
|
||
```html | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--medium" aria-label="Profile of Jiří Bárta"> | ||
<img src="https://picsum.photos/id/823/162/162" alt="Jiří Bárta" aria-hidden="true" /> | ||
</div> | ||
``` | ||
|
||
ℹ️ Don't forget to add the `aria-label` attribute for accessible title. | ||
The image should have an `alt` attribute set and can be aria-hidden, because the `aria-label` | ||
attribute is set on the container. | ||
|
||
### Text | ||
|
||
It is possible to use text as the content of the `UNSTABLE_Avatar` component. | ||
This is useful when you want to display the initials of a user. You need to | ||
take care of the text length and case. The rest is handled by the component. | ||
|
||
```html | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--medium" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</div> | ||
``` | ||
|
||
ℹ️ Don't forget to add the `aria-label` attribute for accessible title, especially when | ||
using an abbreviation. The `aria-hidden` attribute is set on the text span, because the `aria-label` | ||
attribute is set on the container and the abbreviation is not useful for screen readers. |
37 changes: 37 additions & 0 deletions
37
packages/web/src/scss/components/UNSTABLE_Avatar/_UNSTABLE_Avatar.scss
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,37 @@ | ||
@use 'theme'; | ||
@use '../../tools/dictionaries'; | ||
|
||
.UNSTABLE_Avatar { | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
overflow: hidden; | ||
text-decoration: none; | ||
color: theme.$color; | ||
border-width: theme.$border-width; | ||
border-style: theme.$border-style; | ||
border-color: theme.$border-color; | ||
border-radius: theme.$border-radius; | ||
background-color: theme.$background-color; | ||
user-select: none; | ||
|
||
@media (hover: hover) { | ||
&:hover { | ||
text-decoration: none; | ||
color: theme.$color; | ||
} | ||
} | ||
} | ||
|
||
.UNSTABLE_Avatar--square { | ||
border-radius: theme.$border-radius-square; | ||
} | ||
|
||
.UNSTABLE_Avatar > img { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
} | ||
|
||
@include dictionaries.generate-sizes('UNSTABLE_Avatar', theme.$sizes); |
38 changes: 38 additions & 0 deletions
38
packages/web/src/scss/components/UNSTABLE_Avatar/_theme.scss
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,38 @@ | ||
@use '@tokens' as tokens; | ||
@use '../../settings/dictionaries'; | ||
|
||
$color: tokens.$text-secondary-default; | ||
$border-width: tokens.$border-width-100; | ||
$border-style: tokens.$border-style-100; | ||
$border-color: tokens.$border-secondary-default; | ||
$border-radius: 50%; | ||
$border-radius-square: tokens.$radius-100; | ||
$background-color: tokens.$background-cover; | ||
|
||
$sizes: ( | ||
xsmall: ( | ||
width: tokens.$space-700, | ||
height: tokens.$space-700, | ||
typography: tokens.$body-xsmall-text-bold, | ||
), | ||
small: ( | ||
width: tokens.$space-800, | ||
height: tokens.$space-800, | ||
typography: tokens.$body-small-text-bold, | ||
), | ||
medium: ( | ||
width: tokens.$space-900, | ||
height: tokens.$space-900, | ||
typography: tokens.$body-medium-text-bold, | ||
), | ||
large: ( | ||
width: tokens.$space-1000, | ||
height: tokens.$space-1000, | ||
typography: tokens.$body-large-text-bold, | ||
), | ||
xlarge: ( | ||
width: tokens.$space-1100, | ||
height: tokens.$space-1100, | ||
typography: tokens.$body-xlarge-text-bold, | ||
), | ||
); |
120 changes: 120 additions & 0 deletions
120
packages/web/src/scss/components/UNSTABLE_Avatar/index.html
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,120 @@ | ||
{{#> web/layout/plain }} {{setVar "sizes" "xsmall" "small" "medium" "large" "xlarge" }} | ||
|
||
<section class="docs-Section"> | ||
<h2 class="docs-Heading">Icon</h2> | ||
|
||
<div class="docs-Stack docs-Stack--start"> | ||
<div class="d-flex" style="gap: var(--spirit-space-400)"> | ||
|
||
{{#each @root.sizes as |size|}} | ||
{{setVar "iconSize" "24"}} | ||
{{#if (eq size "xsmall")}} | ||
{{setVar "iconSize" "16"}} | ||
{{/if}} | ||
{{#if (eq size "small")}} | ||
{{setVar "iconSize" "20"}} | ||
{{/if}} | ||
{{#if (eq size "large")}} | ||
{{setVar "iconSize" "28"}} | ||
{{/if}} | ||
{{#if (eq size "xlarge")}} | ||
{{setVar "iconSize" "32"}} | ||
{{/if}} | ||
|
||
<a href="#" class="UNSTABLE_Avatar UNSTABLE_Avatar--{{size}}" aria-label="Profile of Jiří Bárta"> | ||
<svg width="{{@root.iconSize}}" height="{{@root.iconSize}}" aria-hidden="true"> | ||
<use xlink:href="/assets/icons/svg/sprite.svg#profile" /> | ||
</svg> | ||
</a> | ||
|
||
{{/each}} | ||
|
||
</div> | ||
<div class="d-flex" style="gap: var(--spirit-space-400)"> | ||
|
||
{{#each @root.sizes as |size|}} | ||
{{setVar "iconSize" "24"}} | ||
{{#if (eq size "xsmall")}} | ||
{{setVar "iconSize" "16"}} | ||
{{/if}} | ||
{{#if (eq size "small")}} | ||
{{setVar "iconSize" "20"}} | ||
{{/if}} | ||
{{#if (eq size "large")}} | ||
{{setVar "iconSize" "28"}} | ||
{{/if}} | ||
{{#if (eq size "xlarge")}} | ||
{{setVar "iconSize" "32"}} | ||
{{/if}} | ||
|
||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--square UNSTABLE_Avatar--{{size}}" aria-label="Profile of Jiří Bárta"> | ||
<svg width="{{@root.iconSize}}" height="{{@root.iconSize}}" aria-hidden="true"> | ||
<use xlink:href="/assets/icons/svg/sprite.svg#profile" /> | ||
</svg> | ||
</div> | ||
|
||
{{/each}} | ||
|
||
</div> | ||
</div> | ||
</section> | ||
|
||
<section class="docs-Section"> | ||
<h2 class="docs-Heading">Text</h2> | ||
|
||
<div class="docs-Stack docs-Stack--start"> | ||
<div class="d-flex" style="gap: var(--spirit-space-400)"> | ||
|
||
{{#each @root.sizes as |size|}} | ||
|
||
<a href="#" class="UNSTABLE_Avatar UNSTABLE_Avatar--{{size}}" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</a> | ||
|
||
{{/each}} | ||
|
||
</div> | ||
<div class="d-flex" style="gap: var(--spirit-space-400)"> | ||
|
||
{{#each @root.sizes as |size|}} | ||
|
||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--square UNSTABLE_Avatar--{{size}}" aria-label="Profile of Jiří Bárta"> | ||
<span aria-hidden="true">JB</span> | ||
</div> | ||
|
||
{{/each}} | ||
|
||
</div> | ||
</div> | ||
</section> | ||
|
||
<section class="docs-Section"> | ||
<h2 class="docs-Heading">Image</h2> | ||
|
||
<div class="docs-Stack docs-Stack--start"> | ||
<div class="d-flex" style="gap: var(--spirit-space-400)"> | ||
|
||
{{#each @root.sizes as |size|}} | ||
|
||
<a href="#" class="UNSTABLE_Avatar UNSTABLE_Avatar--{{size}}" aria-label="Profile of Jiří Bárta"> | ||
<img src="https://picsum.photos/id/823/162/162" alt="Jiří Bárta" aria-hidden="true" /> | ||
</a> | ||
|
||
{{/each}} | ||
|
||
</div> | ||
<div class="d-flex" style="gap: var(--spirit-space-400)"> | ||
|
||
{{#each @root.sizes as |size|}} | ||
|
||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--square UNSTABLE_Avatar--{{size}}" aria-label="Profile of Jiří Bárta"> | ||
<img src="https://picsum.photos/id/823/162/162" alt="Jiří Bárta" aria-hidden="true" /> | ||
</div> | ||
|
||
{{/each}} | ||
|
||
</div> | ||
</div> | ||
</section> | ||
|
||
{{/ web/layout/plain }} |
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 @@ | ||
@forward 'UNSTABLE_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
Binary file added
BIN
+69.7 KB
...2e/demo-components-compare.spec.ts-snapshots/unstable-avatar-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.