-
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
Showing
10 changed files
with
292 additions
and
1 deletion.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
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,81 @@ | ||
# 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" title="Jiří Bárta">JB</div> | ||
|
||
<a href="#" class="UNSTABLE_Avatar UNSTABLE_Avatar--xsmall" title="Jiří Bárta"> | ||
<img src="https://picsum.photos/id/823/162/162" alt="" /> | ||
</a> | ||
``` | ||
|
||
## Circle | ||
|
||
Add `UNSTABLE_Avatar--circle` modifier to make the avatar a circle. | ||
|
||
```html | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--medium UNSTABLE_Avatar--circle" title="Jiří Bárta">JB</div> | ||
``` | ||
|
||
## Sizes | ||
|
||
The Avatar component supports `xsmall`, `small`, `medium`, `large`, and `xlarge` sizes. | ||
|
||
```html | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--xsmall" title="Jiří Bárta">JB</div> | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--small" title="Jiří Bárta">JB</div> | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--medium" title="Jiří Bárta">JB</div> | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--large" title="Jiří Bárta">JB</div> | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--xlarge" title="Jiří Bárta">JB</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" title="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 `title` attribute for accessibility. | ||
|
||
### Image | ||
|
||
Add an image, it will be resized to fit the avatar. | ||
|
||
```html | ||
<div class="UNSTABLE_Avatar UNSTABLE_Avatar--medium" title="Jiří Bárta"> | ||
<img src="https://picsum.photos/id/823/162/162" alt="" /> | ||
</div> | ||
``` | ||
|
||
ℹ️ Don't forget to add the `title` attribute for accessibility. The `alt` then can be empty. | ||
|
||
### 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" title="Jiří Bárta">JB</div> | ||
``` | ||
|
||
ℹ️ Don't forget to add the `title` attribute for accessibility, especially when using an abbreviation. |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
@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; | ||
|
||
@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}}" title="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}}" title="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}}" title="Jiří Bárta"> | ||
JB | ||
</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}}" title="Jiří Bárta"> | ||
JB | ||
</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}}" title="Jiří Bárta"> | ||
<img src="https://picsum.photos/id/823/162/162" alt="" /> | ||
</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}}" title="Jiří Bárta"> | ||
<img src="https://picsum.photos/id/823/162/162" alt="" /> | ||
</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.
Binary file modified
BIN
+744 Bytes
(100%)
tests/e2e/demo-homepages.spec.ts-snapshots/web-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.