Restructure the repo into npm workspaces so the component kit publishes as its own package, like MUI and shadcn/ui: - packages/ui: @openkhalix/tansy-ui (published), with components, stories, tests, tokens and the library build - packages/brand: private logo and catalogue data shared by both apps - apps/site: the landing page - apps/docs: Storybook The package: - MIT licence (copyright OpenKhalix) - per-component ES modules and type declarations - "use client" on component modules so they import into Next.js Server Components; helpers stay server-safe - tokens.css for Tailwind v4 apps, and a prebuilt styles.css for apps without Tailwind - lucide-react 1.x, whose types compile against current React 19 types The apps resolve the package through a "source" export condition, so they hot-reload component edits, while outside users get dist/. scripts/test-package.mjs packs the package and installs the tarball into Vite + Tailwind (strict types), plain React and Next.js apps; each must build and render correctly. Gitea workflows run CI on push and publish to npm when a vX.Y.Z tag matching the package version is pushed.
186 lines
6.6 KiB
TypeScript
186 lines
6.6 KiB
TypeScript
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<typeof Avatar>
|
|
|
|
export default meta
|
|
type Story = StoryObj<typeof meta>
|
|
|
|
export const Playground: Story = {}
|
|
|
|
export const Sizes: Story = {
|
|
render: (args) => (
|
|
<div className="grid gap-4">
|
|
<div className="flex items-end gap-4">
|
|
{AVATAR_SIZES_LIST.map((size) => (
|
|
<Avatar key={size} {...args} size={size} />
|
|
))}
|
|
</div>
|
|
<div className="flex items-end gap-4">
|
|
{AVATAR_SIZES_LIST.map((size) => (
|
|
<Avatar key={size} {...args} src={undefined} size={size} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
),
|
|
}
|
|
|
|
export const Shapes: Story = {
|
|
render: (args) => (
|
|
<div className="flex items-center gap-4">
|
|
{AVATAR_SHAPES.map((shape) => (
|
|
<Avatar key={shape} {...args} shape={shape} />
|
|
))}
|
|
{AVATAR_SHAPES.map((shape) => (
|
|
<Avatar key={`${shape}-fallback`} {...args} src={undefined} name="Acme Corporation" shape={shape} />
|
|
))}
|
|
</div>
|
|
),
|
|
}
|
|
|
|
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) => (
|
|
<div className="flex flex-wrap items-center gap-3">
|
|
{['Jane Doe', 'John Smith', 'Maya Chen', 'Carlos Mendez', 'Aiko Tanaka', 'Samuel Okafor', 'Lena Fischer', 'Acme'].map(
|
|
(name) => (
|
|
<Avatar key={name} size={args.size} shape={args.shape} name={name} />
|
|
),
|
|
)}
|
|
<Avatar size={args.size} shape={args.shape} alt="Unknown user" />
|
|
<Avatar size={args.size} shape={args.shape} name="Marcus Reed" src="data:image/png;base64,broken" />
|
|
</div>
|
|
),
|
|
}
|
|
|
|
export const WithStatus: Story = {
|
|
render: (args) => (
|
|
<div className="grid gap-5">
|
|
<div className="flex flex-wrap items-center gap-5">
|
|
{AVATAR_STATUSES.map((status) => (
|
|
<div key={status} className="flex flex-col items-center gap-2">
|
|
<Avatar {...args} status={status} />
|
|
<span className="text-xs capitalize text-fg-muted">{status}</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
<div className="flex flex-wrap items-end gap-4">
|
|
{AVATAR_SIZES_LIST.map((size) => (
|
|
<Avatar key={size} name="John Smith" src={PORTRAITS.john} size={size} status="online" />
|
|
))}
|
|
{AVATAR_SIZES_LIST.map((size) => (
|
|
<Avatar key={`sq-${size}`} name="Maya Chen" shape="square" size={size} status="busy" />
|
|
))}
|
|
</div>
|
|
</div>
|
|
),
|
|
}
|
|
|
|
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: () => (
|
|
<div className="grid gap-6">
|
|
{(['sm', 'md', 'lg'] as const).map((size) => (
|
|
<AvatarGroup key={size} size={size} max={4} aria-label="Project members">
|
|
<Avatar name="Jane Doe" src={PORTRAITS.jane} />
|
|
<Avatar name="John Smith" src={PORTRAITS.john} />
|
|
<Avatar name="Maya Chen" src={PORTRAITS.maya} />
|
|
<Avatar name="Carlos Mendez" />
|
|
<Avatar name="Aiko Tanaka" src={PORTRAITS.aiko} />
|
|
<Avatar name="Samuel Okafor" />
|
|
<Avatar name="Lena Fischer" />
|
|
</AvatarGroup>
|
|
))}
|
|
<AvatarGroup size="md" shape="square" max={3} aria-label="Reviewers">
|
|
<Avatar name="Acme Corporation" />
|
|
<Avatar name="Jane Doe" src={PORTRAITS.jane} />
|
|
<Avatar name="Marcus Reed" />
|
|
<Avatar name="Lena Fischer" />
|
|
<Avatar name="Samuel Okafor" />
|
|
</AvatarGroup>
|
|
</div>
|
|
),
|
|
}
|
|
|
|
export const InContext: Story = {
|
|
render: () => (
|
|
<div className="flex w-full max-w-sm items-center gap-3 rounded-xl border border-border bg-surface p-4">
|
|
<Avatar name="Jane Doe" src={PORTRAITS.jane} size="lg" status="online" />
|
|
<div className="min-w-0 flex-1">
|
|
<p className="truncate text-sm font-semibold text-fg">Jane Doe</p>
|
|
<p className="truncate text-sm text-fg-muted">jane.doe@example.com</p>
|
|
</div>
|
|
<AvatarGroup size="xs" max={2} aria-label="Shared with">
|
|
<Avatar name="John Smith" src={PORTRAITS.john} />
|
|
<Avatar name="Maya Chen" src={PORTRAITS.maya} />
|
|
<Avatar name="Carlos Mendez" />
|
|
<Avatar name="Aiko Tanaka" />
|
|
</AvatarGroup>
|
|
</div>
|
|
),
|
|
}
|
|
|
|
export const GroupPlayground: StoryObj<typeof AvatarGroup> = {
|
|
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) => (
|
|
<AvatarGroup {...args}>
|
|
<Avatar name="Jane Doe" src={PORTRAITS.jane} />
|
|
<Avatar name="John Smith" src={PORTRAITS.john} />
|
|
<Avatar name="Maya Chen" src={PORTRAITS.maya} />
|
|
<Avatar name="Carlos Mendez" />
|
|
<Avatar name="Aiko Tanaka" src={PORTRAITS.aiko} />
|
|
<Avatar name="Samuel Okafor" />
|
|
</AvatarGroup>
|
|
),
|
|
}
|