import React, { useState } from 'react'; import { action } from 'storybook/actions'; import { Table, TableHead, TableRow, TableBody, TableCell, Box } from '@mui/material'; import Bell from '@lunit/design-system-icons/Bell'; import ToggleButton from '@/components/ToggleButton'; import type { StoryFn, Meta } from '@storybook/react-webpack5'; import type { ButtonProps } from '@/components/Button/Button.types'; type ButtonSizeType = Pick; type SizeValues = ButtonSizeType[keyof ButtonSizeType]; const sizeList: SizeValues[] = ['small', 'medium', 'large']; export default { title: 'Components/ToggleButton', component: ToggleButton, args: { children: 'Text', kind: 'contained', color: 'primary', selectedColor: 'primary', size: 'small', disabled: false, }, argTypes: { icon: { control: false, description: `Use this prop when you want to add icon. \n It is added to the left of the text criteria`, table: { defaultValue: { summary: 'undefined' }, type: { summary: 'React.ReactNode' }, }, }, value: { control: false, table: { type: { summary: 'any' } }, }, children: { type: 'string', }, selected: { control: false, table: { defaultValue: { summary: 'false' }, }, }, selectedColor: { control: { type: 'radio', }, options: ['primary', 'secondary'], description: 'The color of the button when it is in an select state. It has nothing to do with active button', table: { defaultValue: { summary: 'primary' }, }, }, kind: { control: { type: 'radio', }, options: ['contained', 'outlined', 'ghost'], description: 'Button has three Kinds Contained, Outlined, Ghost', table: { defaultValue: { summary: 'contained' }, }, }, color: { control: { type: 'radio', }, options: ['primary', 'secondary'], table: { defaultValue: { summary: 'primary' }, }, }, disabled: { control: { type: 'boolean', }, table: { defaultValue: { summary: 'false' }, }, }, size: { options: ['small', 'medium', 'large'], table: { defaultValue: { summary: 'small' }, }, }, onChange: { type: 'function', control: false, options: ['function', undefined], mapping: { function: action('onChange'), undefined: undefined, }, }, onClick: { type: 'function', control: false, options: ['function', undefined], mapping: { function: action('onClick'), undefined: undefined, }, description: 'It is a callback function that is called when the button is clicked.', }, }, parameters: { controls: { include: [ 'onChange', 'onClick', 'children', 'disabled', 'size', 'kind', 'color', 'selectedColor', 'selected', 'value', 'icon', ], }, docs: { description: { component: `A Toggle Button can be used to group related options. please see [Material-UI Toggle Button](https://mui.com/material-ui/react-toggle-button/).`, }, }, }, } as Meta; const BasicToggleButtonTemplate: StoryFn = (arg) => { const [selected, setSelected] = useState(Boolean(arg.selected)); return ( setSelected(!selected)}> {arg.children} ); }; export const BasicToggleButton = { render: BasicToggleButtonTemplate, name: 'Basic ToggleButton', parameters: { chromatic: { disableSnapshot: true }, }, }; const SizeTemplate: StoryFn = (args) => { const [selectedButtons, setSelectedButtons] = React.useState<{ [key: string]: boolean; }>({}); const handleToggle = (buttonId: string) => { setSelectedButtons((prev) => ({ ...prev, [buttonId]: !prev[buttonId], })); }; return ( Size Small Medium Large {sizeList.map((size) => { if (size) { return ( } size={size} value={`${size}-1`} selected={selectedButtons[`${size}-1`]} onChange={() => handleToggle(`${size}-1`)} /> handleToggle(`${size}-2`)} > {args.children} } size={size} value={`${size}-3`} selected={selectedButtons[`${size}-3`]} onChange={() => handleToggle(`${size}-3`)} > {args.children} ); } })}
); }; export const Size = { render: SizeTemplate, argTypes: { size: { control: false, }, }, }; const SizeDocsTemplate: StoryFn = (args) => { const [selectedButtons, setSelectedButtons] = React.useState<{ [key: string]: boolean; }>({}); const handleToggle = (buttonId: string) => { setSelectedButtons((prev) => ({ ...prev, [buttonId]: !prev[buttonId], })); }; return ( handleToggle('contained-small')} > Small handleToggle('contained-medium')} > Medium handleToggle('contained-large')} > Large handleToggle('outlined-small')} > Small handleToggle('outlined-medium')} > Medium handleToggle('outlined-large')} > Large handleToggle('ghost-small')} > Small handleToggle('ghost-medium')} > Medium handleToggle('ghost-large')} > Large ); }; export const SizeDocs = { render: SizeDocsTemplate, argTypes: { size: { control: false, }, }, parameters: { chromatic: { disableSnapshot: true }, }, }; const ColorTemplate: StoryFn = (args) => { const [selectedButtons, setSelectedButtons] = React.useState<{ [key: string]: boolean; }>({}); const handleToggle = (buttonId: string) => { setSelectedButtons((prev) => ({ ...prev, [buttonId]: !prev[buttonId], })); }; return ( handleToggle('contained-primary')} > Primary handleToggle('contained-secondary')} > Secondary handleToggle('outlined-primary')} > Primary handleToggle('ghost-primary')} > Primary handleToggle('ghost-secondary')} > Secondary ); }; export const Color = { render: ColorTemplate, argTypes: { size: { control: false, }, }, parameters: { chromatic: { disableSnapshot: true }, }, }; const SelectedColorTemplate: StoryFn = (arg) => { const [selected1, setSelected1] = useState(true); const [selected2, setSelected2] = useState(true); return ( Selected color Primary Secondary Selected setSelected1(!selected1)} > {arg.children} setSelected2(!selected2)} > {arg.children}
); }; export const SelectedColor = { render: SelectedColorTemplate, argTypes: { selectedColor: { control: false, }, }, args: { selected: true, }, }; const SelectedColorDocsTemplate: StoryFn = (args) => { const { ...restProps } = args; return ( Primary Secondary ); }; export const SelectedColorDocs = { render: SelectedColorDocsTemplate, argTypes: { selectedColor: { control: false, }, }, args: { selected: true, }, parameters: { chromatic: { disableSnapshot: true }, }, }; const SelectedDocsTemplate: StoryFn = (args) => { const { ...restProps } = args; return ( Not Selected Selected ); }; export const SelectedDocs = { render: SelectedDocsTemplate, argTypes: { selectedColor: { control: false, }, }, parameters: { chromatic: { disableSnapshot: true }, include: ['color', 'size', 'disabled', 'selected', 'kind'], }, }; const DisabledTemplate: StoryFn = (args) => { return ( Text Text Text ); }; export const DisabledDocs = { render: DisabledTemplate, argTypes: { selectedColor: { control: false, }, }, args: { selected: false, }, parameters: { chromatic: { disableSnapshot: true }, }, };