import type { Meta, StoryObj } from '@storybook/react-vite' import { Avatar, AvatarGroup } from './Avatar' import { AVATAR_SHAPES, AVATAR_SIZES_LIST, AVATAR_STATUSES } from './avatar.tokens' import { PORTRAITS } from './display.fixtures' const meta = { title: 'Display/Avatar', component: Avatar, subcomponents: { AvatarGroup }, tags: ['autodocs'], parameters: { docs: { description: { component: "A person's picture, built on Base UI Avatar. While the image loads, or if it fails, the avatar shows the initials of `name` on a colour derived from the name (so a person keeps their colour everywhere), or a generic icon. `status` adds a presence dot with an accessible label. `AvatarGroup` stacks avatars with a \"+N\" overflow.", }, }, }, argTypes: { src: { control: 'text' }, alt: { control: 'text' }, name: { control: 'text' }, size: { control: 'inline-radio', options: AVATAR_SIZES_LIST, table: { defaultValue: { summary: 'md' } } }, shape: { control: 'inline-radio', options: AVATAR_SHAPES, table: { defaultValue: { summary: 'circle' } } }, status: { control: 'inline-radio', options: [undefined, ...AVATAR_STATUSES] }, statusLabel: { control: 'text' }, }, args: { name: 'Jane Doe', src: PORTRAITS.jane, size: 'lg', shape: 'circle', }, } satisfies Meta export default meta type Story = StoryObj export const Playground: Story = {} export const Sizes: Story = { render: (args) => (
{AVATAR_SIZES_LIST.map((size) => ( ))}
{AVATAR_SIZES_LIST.map((size) => ( ))}
), } export const Shapes: Story = { render: (args) => (
{AVATAR_SHAPES.map((shape) => ( ))} {AVATAR_SHAPES.map((shape) => ( ))}
), } export const Fallbacks: Story = { parameters: { docs: { description: { story: 'Initials come from the first and last word of `name`, on a colour picked from the name. With no name, a generic icon. A broken `src` falls back the same way.', }, }, }, render: (args) => (
{['Jane Doe', 'John Smith', 'Maya Chen', 'Carlos Mendez', 'Aiko Tanaka', 'Samuel Okafor', 'Lena Fischer', 'Acme'].map( (name) => ( ), )}
), } export const WithStatus: Story = { render: (args) => (
{AVATAR_STATUSES.map((status) => (
{status}
))}
{AVATAR_SIZES_LIST.map((size) => ( ))} {AVATAR_SIZES_LIST.map((size) => ( ))}
), } export const Group: Story = { parameters: { docs: { description: { story: '`AvatarGroup` overlaps its avatars with a ring in the surface colour and collapses the rest into "+N".', }, }, }, render: () => (
{(['sm', 'md', 'lg'] as const).map((size) => ( ))}
), } export const InContext: Story = { render: () => (

Jane Doe

jane.doe@example.com

), } export const GroupPlayground: StoryObj = { name: 'Group playground', argTypes: { max: { control: { type: 'number', min: 0, max: 8 }, table: { defaultValue: { summary: '4' } } }, size: { control: 'inline-radio', options: AVATAR_SIZES_LIST, table: { defaultValue: { summary: 'md' } } }, shape: { control: 'inline-radio', options: AVATAR_SHAPES, table: { defaultValue: { summary: 'circle' } } }, children: { control: false }, }, args: { max: 4, size: 'md', shape: 'circle', 'aria-label': 'Team members' }, render: (args) => ( ), }