|
| 1 | +import { ArgTypes, Canvas, Description, Meta, Subtitle, Title } from '@storybook/addon-docs/blocks' |
| 2 | + |
| 3 | +import { Avatar } from './avatar' |
| 4 | + |
| 5 | +import * as AvatarStories from './avatar.stories' |
| 6 | + |
| 7 | +<Meta of={AvatarStories} /> |
| 8 | + |
| 9 | +<Title /> |
| 10 | + |
| 11 | +<Subtitle>Image, initials, and empty-state avatar primitive.</Subtitle> |
| 12 | + |
| 13 | +## Basic usage |
| 14 | + |
| 15 | +Use `Avatar` for people by default. Pass `size`, `name`, and an optional |
| 16 | +`image`; `name` supplies the default accessible label, the initials fallback, |
| 17 | +and the deterministic meta color used when initials render. |
| 18 | + |
| 19 | +<Canvas of={AvatarStories.Default} /> |
| 20 | + |
| 21 | +## Initials fallback |
| 22 | + |
| 23 | +When `image` is not supplied, cannot be resolved, or every responsive image |
| 24 | +candidate fails, Avatar falls back to initials derived from `name`. Names are |
| 25 | +normalized before initials are generated. |
| 26 | + |
| 27 | +<Canvas of={AvatarStories.InitialsFallback} /> |
| 28 | + |
| 29 | +## Workspace avatars |
| 30 | + |
| 31 | +Use `shape="rounded"` for workspace-like entities. Product code can wrap |
| 32 | +Avatar with a small convention component when a surface always represents the |
| 33 | +same kind of entity. |
| 34 | + |
| 35 | +<Canvas of={AvatarStories.WorkspaceAvatar} /> |
| 36 | + |
| 37 | +## Image sources |
| 38 | + |
| 39 | +Pass a string for a single image URL, or a source map keyed by intrinsic image |
| 40 | +width. Source maps render native `srcSet` width descriptors and a `sizes` hint |
| 41 | +based on the selected avatar size. |
| 42 | + |
| 43 | +<Canvas of={AvatarStories.ImageSources} /> |
| 44 | + |
| 45 | +## Sizes |
| 46 | + |
| 47 | +Avatar supports a fixed set of CSS pixel sizes. Use one of the supported |
| 48 | +numeric values instead of styling the avatar dimensions from the outside. |
| 49 | + |
| 50 | +<Canvas of={AvatarStories.Sizes} /> |
| 51 | + |
| 52 | +## Accessibility |
| 53 | + |
| 54 | +Images default to `name` for alt text. Pass `alt` when the visual needs a more |
| 55 | +specific label, and pass `alt=""` when the avatar is decorative. |
| 56 | + |
| 57 | +<Canvas of={AvatarStories.Accessibility} /> |
| 58 | + |
| 59 | +## Playground |
| 60 | + |
| 61 | +Use the controls to inspect the component API and common image/name |
| 62 | +combinations. |
| 63 | + |
| 64 | +<Canvas of={AvatarStories.Playground} /> |
| 65 | + |
| 66 | +## API |
| 67 | + |
| 68 | +### `<Avatar />` |
| 69 | + |
| 70 | +<Description of={Avatar} /> |
| 71 | +<ArgTypes of={Avatar} /> |
| 72 | + |
| 73 | +## What the consumer owns |
| 74 | + |
| 75 | +- **Identity data** — choose the `name`, `image`, and any custom `alt` text. |
| 76 | +- **Source selection** — provide either one URL or a width-keyed source map. |
| 77 | +- **Entity convention** — choose `shape="circle"` for people and |
| 78 | + `shape="rounded"` for workspace-like entities. |
| 79 | +- **Decorative usage** — pass `alt=""` when surrounding UI already names the |
| 80 | + represented entity. |
| 81 | +- **Persistence and fetching** — Avatar does not load, cache, or persist remote |
| 82 | + user/workspace data. |
| 83 | + |
| 84 | +## Accessibility |
| 85 | + |
| 86 | +- `name` becomes the default image `alt` text and initials `aria-label`. |
| 87 | +- `alt` overrides the accessible label for both image and initials rendering. |
| 88 | +- `alt=""` marks image and initials avatars as decorative. |
| 89 | +- An avatar with no `name` and no `image` renders as an empty decorative visual. |
0 commit comments