import React, { useState } from 'react'; import { StoryFn, Meta, StoryObj } from '@storybook/react-webpack5'; import Dropdown, { DropdownItem } from '@/components/Dropdown'; import { Box, SelectChangeEvent, Table, TableBody, TableCell, TableHead, TableRow, } from '@mui/material'; import Button from '@/components/Button'; export default { title: 'Components/Dropdown', component: Dropdown, argTypes: { size: { control: { type: 'radio', }, options: ['small', 'medium', 'large'], description: 'The size of the dropdown. Default is medium.', }, select: { control: { type: 'radio', }, options: ['single', 'multiple'], description: 'The select type of the dropdown. Default is single.', }, error: { control: { type: 'radio', }, options: [true, false], description: 'The error prop toggles the error state.', }, disabled: { control: { type: 'radio', }, options: [true, false], description: 'If true, the text field will be disabled.', }, }, } as Meta; const dropdownContent = { test1: 'Conquer cancer through AI', test2: 'test item 2', test3: 'test item 3', }; const DropdownExampleTemplate: StoryFn = (args, context) => { const classNameFromGlobal = context.globals.theme; const [ex1selectedValue, setEx1SelectedValue] = useState(''); const handleEx1SelectedValueChange = (event: SelectChangeEvent) => { const { target: { value }, } = event; setEx1SelectedValue(value as string); }; const [ex2selectedValue, setEx2SelectedValue] = useState([]); const handleEx2SelectedValueChange = (event: SelectChangeEvent) => { const { target: { value }, } = event; setEx2SelectedValue( // On autofill we get a stringified value. typeof value === 'string' ? value.split(',') : (value as string[]), ); }; const [ex3selectedValue, setEx3SelectedValue] = useState('test1'); const handleEx3SelectedValueChange = (event: SelectChangeEvent) => { const { target: { value }, } = event; setEx3SelectedValue(value as string); }; const [open, setOpen] = useState(false); const handleClose = () => { setOpen(false); }; const handleOpen = () => { setOpen(true); }; return ( Using placeholder Example Dropdown with Button Example {/* This placeholder examples are referenced from MUI demo https://v5.mui.com/material-ui/react-select/#placeholder */} {/* Example 1 (Placeholder with Single select) */} { if (!selected) { return ( theme.palette.lunit_token.core.text_light, }} > Placeholder Single ); } return dropdownContent[selected as keyof typeof dropdownContent]; }} > {Object.entries(dropdownContent).map(([key, text]) => ( {text} ))}    {/* Example 2 (Placeholder with Multiple select) */} { if ((selected as string[]).length === 0) { return ( theme.palette.lunit_token.core.text_light, }} > Placeholder multiple ); } return (selected as string[]) .map((value) => dropdownContent[value as keyof typeof dropdownContent]) .join(', '); }} > {Object.entries(dropdownContent).map(([key, text]) => ( {text} ))} {/* Example 3 (Button dropdown) */} {Object.entries(dropdownContent).map(([key, text]) => ( {text} ))}
); }; export const DropdownExamples: StoryObj = { render: DropdownExampleTemplate, parameters: { controls: { include: [], }, chromatic: { disableSnapshot: true }, }, };