import { useState, useEffect } from 'react';
import { fn } from 'storybook/test';
import { Meta, StoryObj } from '@storybook/react-webpack5';
import { storySourceWithoutNoise } from '../../.storybook/helpers';
import CheckboxButton, { type CheckboxButtonProps } from './CheckboxButton';
import { Label } from '../label/Label';
/**
* Use Checkbox component instead when pairing with a label. Only use CheckboxButton when you need a standalone checkbox (e.g. settings matrix) and provide an `aria-label`.
*
* **Design guidance**: wise.design/components/checkbox
*/
export default {
component: CheckboxButton,
title: 'Actions/CheckboxButton',
args: {
'aria-label': 'Toggle checkbox',
checked: true,
disabled: false,
indeterminate: false,
onBlur: fn(),
onChange: fn(),
onClick: fn(),
onFocus: fn(),
},
argTypes: {
'aria-label': {
description: 'Provides the accessible name when the control has no visible text label.',
},
checked: {
description: 'Controls whether the checkbox is checked.',
},
disabled: {
description: 'Toggles the disabled state.',
},
name: {
description: 'Name submitted with the form when the checkbox is checked.',
},
value: {
description: 'Value submitted with the form when the checkbox is checked.',
},
onChange: {
description: 'Called when the checked state changes.',
},
indeterminate: {
description:
'Sets the native mixed state — used when some (not all) child items are selected. Clicking resolves to checked; clear `indeterminate` in `onChange` to reflect the transition.',
},
defaultChecked: { table: { category: 'Common' } },
id: { table: { category: 'Common' } },
className: { table: { category: 'Common' } },
onBlur: { table: { category: 'Common' } },
onClick: { table: { category: 'Common' } },
onFocus: { table: { category: 'Common' } },
},
parameters: {
docs: { toc: true },
},
} satisfies Meta;
type Story = StoryObj;
const withColumnLayout = (Story: () => JSX.Element) => (
);
/** Interactive single checkbox — use the Controls panel to toggle `disabled` and `indeterminate`. */
export const Playground: Story = storySourceWithoutNoise({
render: function Render(args: CheckboxButtonProps) {
const [checked, setChecked] = useState(args.checked ?? true);
useEffect(() => {
setChecked(args.checked ?? true);
}, [args.checked]);
return (
{
setChecked(e.currentTarget.checked);
args.onChange?.(e);
}}
/>
);
},
});
/** Disabled state — checked and unchecked. */
export const Disabled: Story = {
decorators: [withColumnLayout],
render: (args) => (
<>
{}}
/>
{}}
/>
>
),
};
/** Indeterminate state — checked and unchecked. */
export const Indeterminate: Story = {
decorators: [withColumnLayout],
render: (args) => (
<>