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) => (
{variant}
Open: {value.length ? value.join(', ') : 'none'}