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'], } satisfies Meta; export default meta; type Story = StoryObj; 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))) } />
))}
); }, };