import React, { useState } from 'react'; import { StoryFn, Meta } from '@storybook/react-webpack5'; import Toggle from '@/components/Toggle/Toggle'; import { Box, Table, TableBody, TableCell, TableHead, TableRow, TextField } from '@mui/material'; import FormLabel from '@/components/FormLabel'; import { action } from 'storybook/actions'; export default { title: 'Components/Toggle', component: Toggle, argTypes: { checked: { control: { type: 'select', }, options: [true, false, undefined], description: "If `true`, the component is checked. Indeterminate state doesn't supported `checked` prop.", }, onChange: { control: { type: 'select', }, options: ['function', undefined], mapping: { function: action('onChange'), undefined: undefined, }, description: '(() => void)', }, disabled: { control: { type: 'boolean', }, description: 'If `true`, the component is disabled.', options: [true, false], }, }, args: { size: 'small', indeterminate: false, disabled: false, }, parameters: { controls: { include: ['disabled', 'checked', 'size', 'indeterminate', 'onChange'], }, docs: { description: { component: `Switches toggle the state of a single setting on or off. see [Material-UI Switch](https://mui.com/material-ui/react-switch/). \nIn order to use Button, [checked] value have to be undefined`, }, }, }, } as Meta; const BaseTemplate: StoryFn = (args) => { const [checked, setChecked] = useState(Boolean(args.checked)); return ( DEFAULT setChecked(!checked)} />
); }; const Template: StoryFn = (args) => ( ON Indeterminate OFF SMALL DEFAULT SMALL FOCUS LARGE DEFAULT LARGE FOCUS
); const DisabledTemplate: StoryFn = (args) => ( ON Indeterminate OFF SMALL DEFAULT LARGE DEFAULT
); const TemplateWithLabel: StoryFn = (args) => ( ON Indeterminate OFF SMALL DEFAULT } /> } control={} /> } control={} /> SMALL FOCUS } /> } control={} /> } control={} /> LARGE DEFAULT } /> } control={} /> } control={} /> LARGE FOCUS } /> } control={} /> } control={} />
); const IndeterminateTemplate: StoryFn = () => { const [checked, setChecked] = useState([true, false, false]); const handleChange1 = () => { const result = !(checked[0] && checked[1]); setChecked([result, result, result]); }; const handleChange2 = (event: React.ChangeEvent) => { setChecked([event.target.checked, checked[1], checked[2]]); }; const handleChange3 = (event: React.ChangeEvent) => { setChecked([checked[0], event.target.checked, checked[2]]); }; const handleChange4 = (event: React.ChangeEvent) => { setChecked([checked[0], checked[1], event.target.checked]); }; return ( SMALL LARGE } /> } /> } /> } /> } /> } /> } /> } />
); }; export const ToggleBase = { render: BaseTemplate, }; export const ToggleEnabled = { render: Template, }; export const ToggleDisabled = { render: DisabledTemplate, args: { disabled: true, }, }; export const ToggleWithLabel = { render: TemplateWithLabel, }; export const ToggleWithLabelAndIndeterminate = { render: IndeterminateTemplate, parameters: { docs: { description: { story: 'Usage is same with Toggle', }, }, }, };