|
| 1 | +import { |
| 2 | + Canvas, |
| 3 | + ColorItem, |
| 4 | + ColorPalette, |
| 5 | + Controls, |
| 6 | + Meta, |
| 7 | + Subtitle, |
| 8 | + Title, |
| 9 | +} from '@storybook/addon-docs/blocks' |
| 10 | + |
| 11 | +import * as AvatarStories from './avatar.stories' |
| 12 | + |
| 13 | +<Meta of={AvatarStories} /> |
| 14 | + |
| 15 | +<Title /> |
| 16 | + |
| 17 | +<Subtitle>Image, initials, and empty-state avatar primitive.</Subtitle> |
| 18 | + |
| 19 | +## Basic usage |
| 20 | + |
| 21 | +Use `Avatar` for people by default. Pass `size`, `name`, and an optional |
| 22 | +`image`; `name` supplies the default accessible label, the initials fallback, |
| 23 | +and the deterministic meta color used when initials render. |
| 24 | + |
| 25 | +<Canvas of={AvatarStories.Default} /> |
| 26 | + |
| 27 | +## Initials fallback |
| 28 | + |
| 29 | +When `image` is not supplied, cannot be resolved, or every responsive image |
| 30 | +candidate fails, Avatar falls back to initials derived from `name`. Names are |
| 31 | +normalized before initials are generated. |
| 32 | + |
| 33 | +<Canvas of={AvatarStories.InitialsFallback} /> |
| 34 | + |
| 35 | +## Workspace avatars |
| 36 | + |
| 37 | +Use `shape="rounded"` for workspace-like entities. Product code can wrap |
| 38 | +Avatar with a small convention component when a surface always represents the |
| 39 | +same kind of entity. |
| 40 | + |
| 41 | +<Canvas of={AvatarStories.WorkspaceAvatar} /> |
| 42 | + |
| 43 | +## Image sources |
| 44 | + |
| 45 | +Pass a string for a single image URL, or a source map keyed by intrinsic image |
| 46 | +width. Source maps render native `srcSet` width descriptors and a `sizes` hint |
| 47 | +based on the selected avatar size. |
| 48 | + |
| 49 | +<Canvas of={AvatarStories.ImageSources} /> |
| 50 | + |
| 51 | +## Sizes |
| 52 | + |
| 53 | +Avatar supports a fixed set of CSS pixel sizes. Use one of the supported |
| 54 | +numeric values instead of styling the avatar dimensions from the outside. |
| 55 | + |
| 56 | +<Canvas of={AvatarStories.Sizes} /> |
| 57 | + |
| 58 | +## Accessibility |
| 59 | + |
| 60 | +Images default to `name` for alt text. Pass `alt` when the visual needs a more |
| 61 | +specific label, and pass `alt=""` when the avatar is decorative. |
| 62 | + |
| 63 | +<Canvas of={AvatarStories.Accessibility} /> |
| 64 | + |
| 65 | +## Playground |
| 66 | + |
| 67 | +Use the controls to inspect the component API and common image/name |
| 68 | +combinations. |
| 69 | + |
| 70 | +<Canvas of={AvatarStories.Playground} /> |
| 71 | + |
| 72 | +### API |
| 73 | + |
| 74 | +<Controls of={AvatarStories.Playground} /> |
| 75 | + |
| 76 | +## Custom properties |
| 77 | + |
| 78 | +The following CSS custom properties are available to customize the avatar |
| 79 | +component appearance. The values shown below are the default values. |
| 80 | + |
| 81 | +<Canvas of={AvatarStories.MetaColors} /> |
| 82 | + |
| 83 | +### Customizable properties |
| 84 | + |
| 85 | +#### Avatar colors |
| 86 | + |
| 87 | +<ColorPalette> |
| 88 | + <ColorItem title="--reactist-avatar-initials-color" colors={['#ffffff']} /> |
| 89 | + <ColorItem title="--reactist-avatar-border-tint" colors={['#0000001a']} /> |
| 90 | + <ColorItem title="--reactist-avatar-empty-fill" colors={['var(--reactist-framework-fill-crest)']} /> |
| 91 | +</ColorPalette> |
| 92 | + |
| 93 | +#### Avatar meta fills |
| 94 | + |
| 95 | +<ColorPalette> |
| 96 | + <ColorItem title="--reactist-avatar-meta-fill-0" colors={['#b8255f']} /> |
| 97 | + <ColorItem title="--reactist-avatar-meta-fill-1" colors={['#dc4c3e']} /> |
| 98 | + <ColorItem title="--reactist-avatar-meta-fill-2" colors={['#f48318']} /> |
| 99 | + <ColorItem title="--reactist-avatar-meta-fill-3" colors={['#fecf05']} /> |
| 100 | + <ColorItem title="--reactist-avatar-meta-fill-4" colors={['#aeb83a']} /> |
| 101 | + <ColorItem title="--reactist-avatar-meta-fill-5" colors={['#7ecc48']} /> |
| 102 | + <ColorItem title="--reactist-avatar-meta-fill-6" colors={['#369307']} /> |
| 103 | + <ColorItem title="--reactist-avatar-meta-fill-7" colors={['#52ccb8']} /> |
| 104 | + <ColorItem title="--reactist-avatar-meta-fill-8" colors={['#148fad']} /> |
| 105 | + <ColorItem title="--reactist-avatar-meta-fill-9" colors={['#3ab9e2']} /> |
| 106 | + <ColorItem title="--reactist-avatar-meta-fill-10" colors={['#96c3eb']} /> |
| 107 | + <ColorItem title="--reactist-avatar-meta-fill-11" colors={['#2a67e2']} /> |
| 108 | + <ColorItem title="--reactist-avatar-meta-fill-12" colors={['#692ec2']} /> |
| 109 | + <ColorItem title="--reactist-avatar-meta-fill-13" colors={['#ac30cc']} /> |
| 110 | + <ColorItem title="--reactist-avatar-meta-fill-14" colors={['#eb96c8']} /> |
| 111 | + <ColorItem title="--reactist-avatar-meta-fill-15" colors={['#e05095']} /> |
| 112 | + <ColorItem title="--reactist-avatar-meta-fill-16" colors={['#c9766f']} /> |
| 113 | + <ColorItem title="--reactist-avatar-meta-fill-17" colors={['#808080']} /> |
| 114 | + <ColorItem title="--reactist-avatar-meta-fill-18" colors={['#999999']} /> |
| 115 | + <ColorItem title="--reactist-avatar-meta-fill-19" colors={['#ccae96']} /> |
| 116 | +</ColorPalette> |
| 117 | + |
| 118 | +### Component-owned variables |
| 119 | + |
| 120 | +Avatar sets these variables at render time from the `size`, `shape`, and |
| 121 | +`name` props. They are listed for completeness, but consumers should prefer |
| 122 | +the component props instead of overriding them directly. |
| 123 | + |
| 124 | +```css |
| 125 | +.avatar { |
| 126 | + --reactist-avatar-size: 36px; |
| 127 | + --reactist-avatar-rounded-radius: 5px; |
| 128 | + --reactist-avatar-meta-fill: var(--reactist-avatar-meta-fill-0); |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +## What the consumer owns |
| 133 | + |
| 134 | +- **Identity data** — choose the `name`, `image`, and any custom `alt` text. |
| 135 | +- **Source selection** — provide either one URL or a width-keyed source map. |
| 136 | +- **Entity convention** — choose `shape="circle"` for people and |
| 137 | + `shape="rounded"` for workspace-like entities. |
| 138 | +- **Decorative usage** — pass `alt=""` when surrounding UI already names the |
| 139 | + represented entity. |
| 140 | +- **Persistence and fetching** — Avatar does not load, cache, or persist remote |
| 141 | + user/workspace data. |
| 142 | + |
| 143 | +## Accessibility |
| 144 | + |
| 145 | +- `name` becomes the default image `alt` text and initials `aria-label`. |
| 146 | +- `alt` overrides the accessible label for both image and initials rendering. |
| 147 | +- `alt=""` marks image and initials avatars as decorative. |
| 148 | +- An avatar with no `name` and no `image` renders as an empty decorative visual. |
0 commit comments