import React, { useState } from 'react'; import { StoryFn, Meta, StoryObj } from '@storybook/react-webpack5'; import Dropdown, { DropdownItem } from '@/components/Dropdown'; import { Box, SelectChangeEvent } from '@mui/material'; export default { title: 'Components/Dropdown', component: Dropdown, args: { size: 'medium', select: 'single', error: false, disabled: false, }, 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 BasicDropdownTemplate: StoryFn = (args, context) => { const classNameFromGlobal = context.globals.theme; // In a single select, selectedValue can be used as a string type instead of an array. // In the current Storybook Template, we use selectedValue as a string[] in order to also use it as multiple depending on the control selection. const [selectedValue, setSelectedValue] = useState(['test1']); const handleSelectedValueChange = (event: SelectChangeEvent) => { const { target: { value }, } = event; setSelectedValue( // On autofill we get a stringified value. typeof value === 'string' ? value.split(',') : (value as string[]), ); }; return ( Conquer cancer through AI test item 2 test item 3 ); }; export const BasicDropdown: StoryObj = { render: BasicDropdownTemplate, parameters: { chromatic: { disableSnapshot: true }, }, }; const SizeTemplate: StoryFn = (args, context) => { const classNameFromGlobal = context.globals.theme; // In a single select, selectedValue can be used as a string type instead of an array. // In the current Storybook Template, we use selectedValue as a string[] in order to also use it as multiple depending on the control selection. const [selectedValue, setSelectedValue] = useState(['test1']); const handleSelectedValueChange = (event: SelectChangeEvent) => { const { target: { value }, } = event; setSelectedValue( // On autofill we get a stringified value. typeof value === 'string' ? value.split(',') : (value as string[]), ); }; return ( Small item 1 Small item 2 Small item 3 Medium item 1 Medium item 2 Medium item 3 Large item 1 Large item 2 Large item 3 ); }; export const Size: StoryObj = { render: SizeTemplate, parameters: { chromatic: { disableSnapshot: true }, }, argTypes: { size: { control: false, }, }, }; const SelectTypeTemplate: StoryFn = (args, context) => { const classNameFromGlobal = context.globals.theme; const [selectedValue, setSelectedValue] = useState('single1'); const handleSelectedValueChange = (event: SelectChangeEvent) => { const { target: { value }, } = event; setSelectedValue(value as string); }; const [selectedValue2, setSelectedValue2] = useState(['multiple1']); const handleSelectedValueChange2 = (event: SelectChangeEvent) => { const { target: { value }, } = event; setSelectedValue2( // On autofill we get a stringified value. typeof value === 'string' ? value.split(',') : (value as string[]), ); }; return ( Single item 1 Single item 2 Single item 3 Multiple item 1 Multiple item 2 Multiple item 3 ); }; export const SelectType: StoryObj = { render: SelectTypeTemplate, parameters: { chromatic: { disableSnapshot: true }, }, argTypes: { select: { control: false, }, }, }; const ErrorTemplate: StoryFn = (args, context) => { const classNameFromGlobal = context.globals.theme; // In a single select, selectedValue can be used as a string type instead of an array. // In the current Storybook Template, we use selectedValue as a string[] in order to also use it as multiple depending on the control selection. const [selectedValue, setSelectedValue] = useState(['test1']); const handleSelectedValueChange = (event: SelectChangeEvent) => { const { target: { value }, } = event; setSelectedValue( // On autofill we get a stringified value. typeof value === 'string' ? value.split(',') : (value as string[]), ); }; return ( Small item 1 Small item 2 Small item 3 ); }; export const Error: StoryObj = { render: ErrorTemplate, parameters: { chromatic: { disableSnapshot: true }, }, argTypes: { error: { control: false, }, }, }; const DisabledTemplate: StoryFn = (args, context) => { const classNameFromGlobal = context.globals.theme; // In a single select, selectedValue can be used as a string type instead of an array. // In the current Storybook Template, we use selectedValue as a string[] in order to also use it as multiple depending on the control selection. const [selectedValue, setSelectedValue] = useState(['test1']); const handleSelectedValueChange = (event: SelectChangeEvent) => { const { target: { value }, } = event; setSelectedValue( // On autofill we get a stringified value. typeof value === 'string' ? value.split(',') : (value as string[]), ); }; return ( Small item 1 Small item 2 Small item 3 ); }; export const Disabled: StoryObj = { render: DisabledTemplate, parameters: { chromatic: { disableSnapshot: true }, }, argTypes: { disabled: { control: false, }, }, };