import * as React from 'react'; import type { Meta, StoryObj } from '@storybook/react-vite'; import { Checkbox } from './checkbox'; import { Label } from '../label/label'; const meta = { title: 'Components/Checkbox', component: Checkbox, parameters: { layout: 'centered', docs: { description: { component: 'Binary toggle for a form. Use it when the choice takes effect on save; use Switch when it applies immediately.', }, }, }, tags: ['autodocs'], argTypes: { size: { control: 'inline-radio', options: ['xs', 'sm', 'md', 'lg'] }, colorPalette: { control: 'select', options: ['primary', 'secondary', 'tertiary', 'black', 'red', 'green', 'yellow'], }, }, } satisfies Meta; export default meta; type Story = StoryObj; export const Sizes: Story = { render: () => (
{(['xs', 'sm', 'md', 'lg'] as const).map((size) => ( ))}
), }; /** The checked fill takes whichever palette it is given. */ export const Palettes: Story = { render: () => (
{(['primary', 'secondary', 'tertiary', 'black', 'red', 'green'] as const).map((palette) => ( ))}
), }; export const Default: Story = { render: () => (
), }; export const States: Story = { render: () => (
), }; /** * A parent checkbox is `indeterminate` when only some children are selected — * that third state is what stops it from lying about the group. */ export const ParentChild: Story = { render: function ParentChildStory() { const [items, setItems] = React.useState([true, false, false]); const allChecked = items.every(Boolean); const someChecked = items.some(Boolean); return (
setItems(items.map(() => next === true))} />
{items.map((checked, index) => (
setItems(items.map((v, i) => (i === index ? next === true : v))) } />
))}
); }, };