Every component is rebuilt on @base-ui/react with a single prop API, token-only colours and dark mode, and 28 new components are added. Components - New: Field, FeaturedTextArea, NumberInput, Combobox, CheckboxGroup, Slider, ToggleGroup/Toggle, IconButton, Dialog/Modal, AlertDialog, Drawer/Sheet, Popover, InfoTip, DropdownMenu, Tabs, Breadcrumb, Pagination, Toast (Toaster, useToast), Progress, Meter, Skeleton, CountBadge, Avatar/AvatarGroup, Kbd, Separator, Table - Rewritten: Button, Input, FeaturedInput, TextArea, Select, FeaturedSelect (real ARIA combobox), NativeSelect, Checkbox, Radio, Switch, Tooltip, Accordion, Alert, Spinner, Badge, Card - Removed TextField (use Input) and sonner (use Toast) Foundations - Semantic tokens (surfaces, text, borders, status ramps) in src/styles/tokens.css, with class-based dark mode - Visible focus rings, linked labels/descriptions/errors, alert roles by severity, keyboard support from Base UI - Fixed the Classic Blue ramp; Emerald, Amber and Teal 500 steps now carry white text at AA - Library build (per-component ES modules, types, tokens.css, exports) Quality - Vitest, Testing Library and axe tests for every component (289 tests) - scripts/check-stories.mjs renders every story in Chrome and fails on errors or axe violations, including contrast; all 423 stories pass in light and dark mode and in all seven palettes - Storybook: controls for every prop, open states for every popup, light/dark toolbar, Introduction guides, docs/CONVENTIONS.md BREAKING CHANGE: component props changed across the kit; see CHANGELOG.md.
135 lines
4.8 KiB
TypeScript
135 lines
4.8 KiB
TypeScript
import { useState } from 'react'
|
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
import { fn } from 'storybook/test'
|
|
import { Accordion, type AccordionItem } from './Accordion'
|
|
import { ACCORDION_VARIANTS } from './accordion.tokens'
|
|
|
|
const FAQ: AccordionItem[] = [
|
|
{
|
|
value: 'billing',
|
|
title: 'When will I be charged?',
|
|
content: 'Plans are billed monthly on the date you subscribed. Annual plans are billed once a year and include two months free.',
|
|
},
|
|
{
|
|
value: 'cancel',
|
|
title: 'Can I cancel at any time?',
|
|
content: 'Yes. Cancel from Settings → Billing and you keep access until the end of the current period. No questions asked.',
|
|
},
|
|
{
|
|
value: 'seats',
|
|
title: 'How do seats work?',
|
|
content: 'Each member of your workspace uses one seat. Guests with view-only access are free, and you can add seats whenever you need them.',
|
|
},
|
|
{
|
|
value: 'sso',
|
|
title: 'Do you support single sign-on?',
|
|
content: 'SAML single sign-on is available on the Enterprise plan.',
|
|
disabled: true,
|
|
},
|
|
]
|
|
|
|
const meta = {
|
|
title: 'Navigation/Accordion',
|
|
component: Accordion,
|
|
tags: ['autodocs'],
|
|
parameters: {
|
|
docs: {
|
|
description: {
|
|
component:
|
|
'A stack of collapsible sections, built on Base UI Accordion. Each trigger is a button inside a heading (`headingLevel`, default 3) whose `aria-controls` points at its panel. Closed panels stay in the DOM as `hidden="until-found"`, so find-in-page opens them. Set `multiple` to let several sections stay open.',
|
|
},
|
|
},
|
|
},
|
|
argTypes: {
|
|
items: { control: false },
|
|
multiple: { control: 'boolean' },
|
|
variant: { control: 'inline-radio', options: ACCORDION_VARIANTS, table: { defaultValue: { summary: 'bordered' } } },
|
|
headingLevel: { control: 'inline-radio', options: [2, 3, 4, 5, 6], table: { defaultValue: { summary: '3' } } },
|
|
disabled: { control: 'boolean' },
|
|
value: { control: 'object' },
|
|
defaultValue: { control: 'object' },
|
|
onValueChange: { control: false },
|
|
},
|
|
args: {
|
|
items: FAQ,
|
|
multiple: false,
|
|
variant: 'bordered',
|
|
headingLevel: 3,
|
|
disabled: false,
|
|
defaultValue: ['billing'],
|
|
onValueChange: fn(),
|
|
},
|
|
decorators: [
|
|
(Story) => (
|
|
<div className="max-w-2xl">
|
|
<Story />
|
|
</div>
|
|
),
|
|
],
|
|
} satisfies Meta<typeof Accordion>
|
|
|
|
export default meta
|
|
type Story = StoryObj<typeof meta>
|
|
|
|
export const Playground: Story = {}
|
|
|
|
const ACCOUNT: AccordionItem[] = [
|
|
{ value: 'email', title: 'How do I change my email address?', content: 'Go to Settings → Profile, enter the new address and confirm it from the email we send to [email protected].' },
|
|
{ value: 'export', title: 'Can I export my data?', content: 'Yes. Settings → Data lets you download everything as CSV or JSON.' },
|
|
{ value: 'delete', title: 'How do I delete my account?', content: 'Workspace owners can delete the account from Settings → Danger zone. This cannot be undone.' },
|
|
]
|
|
|
|
const SECURITY: AccordionItem[] = [
|
|
{ value: '2fa', title: 'Is two-factor authentication available?', content: 'Every plan supports authenticator apps and security keys.' },
|
|
{ value: 'encryption', title: 'Is my data encrypted?', content: 'Data is encrypted in transit with TLS 1.3 and at rest with AES-256.' },
|
|
{ value: 'audit', title: 'Do you keep an audit log?', content: 'Business and Enterprise plans keep a searchable audit log for 12 months.' },
|
|
]
|
|
|
|
const GROUPS = { bordered: FAQ, separated: ACCOUNT, ghost: SECURITY }
|
|
|
|
export const Variants: Story = {
|
|
parameters: { docs: { description: { story: 'The three variants, each with its own questions.' } } },
|
|
render: (args) => (
|
|
<div className="grid gap-10">
|
|
{ACCORDION_VARIANTS.map((variant) => (
|
|
<div key={variant} className="grid gap-2">
|
|
<p className="text-xs font-medium uppercase tracking-wide text-fg-muted">{variant}</p>
|
|
<Accordion {...args} variant={variant} items={GROUPS[variant]} defaultValue={[GROUPS[variant][0].value]} />
|
|
</div>
|
|
))}
|
|
</div>
|
|
),
|
|
}
|
|
|
|
export const Separated: Story = { args: { variant: 'separated', defaultValue: ['cancel'] } }
|
|
|
|
export const Ghost: Story = { args: { variant: 'ghost' } }
|
|
|
|
export const Multiple: Story = {
|
|
args: { multiple: true, defaultValue: ['billing', 'seats'] },
|
|
}
|
|
|
|
export const AllClosed: Story = { args: { defaultValue: [] } }
|
|
|
|
export const Controlled: Story = {
|
|
render: function Render(args) {
|
|
const [value, setValue] = useState<string[]>(['seats'])
|
|
return (
|
|
<div className="grid gap-3">
|
|
<Accordion
|
|
{...args}
|
|
multiple
|
|
value={value}
|
|
onValueChange={(next) => {
|
|
setValue(next)
|
|
args.onValueChange?.(next)
|
|
}}
|
|
/>
|
|
<p className="text-sm text-fg-muted">
|
|
Open: <code className="text-fg">{value.length ? value.join(', ') : 'none'}</code>
|
|
</p>
|
|
</div>
|
|
)
|
|
},
|
|
}
|