import type { Meta, StoryObj } from '@storybook/react' import React from 'react' import { createSizeDecorator } from '../../utils/decorators' import { Typography } from '../Typography' import { Checkbox } from './Checkbox' import { CheckboxList } from './CheckboxList' import { LabeledCheckbox } from './LabeledCheckbox' const meta: Meta = { title: 'Form/Checkbox', component: Checkbox, decorators: [createSizeDecorator('XS')], argTypes: { disabled: { control: 'boolean', defaultValue: false, description: 'Disables the checkbox if set to true.', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'false' }, }, }, error: { control: 'boolean', defaultValue: false, description: 'Displays an error border.', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'false' }, }, }, checked: { control: { type: 'select' }, options: [true, false, 'indeterminate'], defaultValue: undefined, description: 'Checked state of the checkbox', table: { type: { summary: 'boolean | "indeterminate"' }, defaultValue: { summary: undefined }, }, }, className: { control: 'text', description: 'Additional CSS classes for the checkbox.', defaultValue: '', }, }, } export default meta type Story = StoryObj export const Default: Story = {} export const CheckboxWithLabel: Story = { render: (_args) => Unchecked, } export const AllStates: Story = { render: (_args) => ( Unchecked Checked Indeterminate Disabled Disabled Checked Disabled Indeterminate Error Label with a link ), } const ControlledCheckboxList = (_args: Story['args']) => { const [selected, setSelected] = React.useState([]) const handleCheckedChange = (id: string, isChecked: boolean) => { setSelected((prev) => isChecked ? [...prev, id] : prev.filter((item) => item !== id), ) } return ( handleCheckedChange('option1', !!c)} > Option 1 handleCheckedChange('option2', !!c)} > Option 2 handleCheckedChange('option3', !!c)} > Option 3 ) } export const Controlled: Story = { render: () => , }