import React, { useState } from 'react'; import { Box, Table, TableHead, TableRow, TableBody, TableCell } from '@mui/material'; import { action } from 'storybook/actions'; import ToggleButton from '@/components/ToggleButton'; import type { StoryFn, Meta } from '@storybook/react-webpack5'; export default { title: 'Components/ToggleButton', component: ToggleButton, args: { children: 'Text', kind: 'contained', color: 'primary', selectedColor: 'primary', size: 'small', disabled: false, }, argTypes: { value: { control: false, table: { type: { summary: 'any' } }, }, selected: { control: false, table: { defaultValue: { summary: 'false' }, }, }, children: { type: 'string', }, disabled: { control: { type: 'boolean', }, table: { defaultValue: { summary: 'false' }, }, }, size: { control: { type: 'radio', }, options: ['small', 'medium', 'large'], table: { defaultValue: { summary: 'small' }, }, }, 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' }, }, }, onChange: { type: 'function', control: false, options: ['function', undefined], mapping: { function: action('onChange'), undefined: undefined, }, }, onClick: { type: 'function', control: { type: 'radio', }, options: ['function', undefined], mapping: { function: action('onClick'), undefined: undefined, }, description: 'It is a callback function that is called when the button is clicked.', }, color: { options: ['primary', 'secondary'], table: { defaultValue: { summary: 'primary' }, }, }, kind: { control: false, options: ['contained', 'outlined', 'ghost'], description: 'Button has three Kinds Contained, Outlined, Ghost', table: { defaultValue: { summary: 'contained' }, }, }, }, parameters: { controls: { include: [ 'value', 'kind', 'selectedColor', 'onClick', 'children', 'disabled', 'size', 'selected', 'color', 'onChange', ], }, 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/).`, }, }, pseudo: { hover: ['#hover1', '#hover2', '#hover3'], }, }, } as Meta; const ButtonTemplate: StoryFn = (args) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars const { color, children, kind, ...restArgs } = args; const [values, setValues] = useState({ contained: false, outlined: false, ghost: false, }); const handleChange = (value: keyof typeof values) => { setValues({ ...values, [value]: !values[value] }); }; return ( <> Kind Contained(default) Outlined Ghost handleChange('contained')} selected={values.contained} > {children} handleChange('outlined')} selected={values.outlined} > {children} handleChange('ghost')} selected={values.ghost} > {children}


); }; export const Kind = { render: ButtonTemplate, argTypes: { color: { control: { type: 'radio', }, }, }, }; const ToggleButtonDocsTemplate: StoryFn = (args) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars const { color, children, kind, ...restArgs } = args; const [values, setValues] = useState({ contained: false, outlined: false, ghost: false, }); const handleChange = (value: keyof typeof values) => { setValues({ ...values, [value]: !values[value] }); }; return ( handleChange('contained')} selected={values.contained} > {children} handleChange('outlined')} selected={values.outlined} > {children} handleChange('ghost')} selected={values.ghost} > {children} ); }; export const KindDocs = { render: ToggleButtonDocsTemplate, parameters: { chromatic: { disableSnapshot: true }, }, }; const ContainedTemplate: StoryFn = (args) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars const { color: _, ...restArgs } = args; const [values, setValues] = useState({ primary: { enable: false, hover: false, focus: false, }, secondary: { enable: false, hover: false, focus: false, }, }); const handleChange = ( color: keyof typeof values, value: keyof (typeof values)[keyof typeof values], ) => { setValues({ ...values, [color]: { ...values[color], [value]: !values[color][value], }, }); }; return ( Contained Primary Contained Secondary Enable handleChange('primary', 'enable')} selected={values.primary.enable} > {args.children} handleChange('secondary', 'enable')} selected={values.secondary.enable} > {args.children} Hover handleChange('primary', 'hover')} selected={values.primary.hover} > {args.children} handleChange('secondary', 'hover')} selected={values.secondary.hover} > {args.children} Focus handleChange('primary', 'focus')} selected={values.primary.focus} > {args.children} handleChange('secondary', 'focus')} selected={values.secondary.focus} > {args.children} Disabled {args.children} {args.children}
); }; export const KindContained = { render: ContainedTemplate, name: 'Kind: Contained', argTypes: { color: { control: false, }, }, }; const GhostTemplate: StoryFn = (args) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars const { color: _, ...restArgs } = args; const [values, setValues] = useState({ primary: { enable: false, hover: false, focus: false, }, secondary: { enable: false, hover: false, focus: false, }, }); const handleChange = ( color: keyof typeof values, value: keyof (typeof values)[keyof typeof values], ) => { setValues({ ...values, [color]: { ...values[color], [value]: !values[color][value], }, }); }; return ( <> Ghost Primary Ghost Secondary Enable handleChange('primary', 'enable')} selected={values.primary.enable} > {args.children} handleChange('secondary', 'enable')} selected={values.secondary.enable} > {args.children} Hover handleChange('primary', 'hover')} selected={values.primary.hover} > {args.children} handleChange('secondary', 'hover')} selected={values.secondary.hover} > {args.children} Focus handleChange('primary', 'focus')} selected={values.primary.focus} > {args.children} handleChange('secondary', 'focus')} selected={values.secondary.focus} > {args.children} Disabled {args.children} {args.children}


); }; export const KindGhost = { render: GhostTemplate, name: 'Kind: Ghost', argTypes: { color: { control: false, }, }, }; const OutlinedTemplate: StoryFn = (args) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars const { color, ...restProps } = args; const [values, setValues] = useState({ primary: { enable: false, hover: false, focus: false, }, }); const handleChange = ( color: keyof typeof values, value: keyof (typeof values)[keyof typeof values], ) => { setValues({ ...values, [color]: { ...values[color], [value]: !values[color][value], }, }); }; return ( <> Outlined Primary Enable handleChange('primary', 'enable')} selected={values.primary.enable} > Text Hover handleChange('primary', 'hover')} selected={values.primary.hover} > Text Focus handleChange('primary', 'focus')} selected={values.primary.focus} > Text Disabled Text
); }; export const KindOutlined = { render: OutlinedTemplate, name: 'Kind: Outlined', argTypes: { color: { control: false, }, }, };