import SelectAdd, { Props as SelectAddProps } from '.'; import React from 'react'; import CanvasContainer from '@techytools/ui/.storybook/components/CanvasContainer'; import CanvasStoryPadding from '@techytools/ui/.storybook/components/CanvasStoryPadding'; import useShowStorybookCode from '@techytools/ui/hooks/useShowStorybookCode'; const style = { margin: '0 0.875rem 0.875rem 0', minWidth: '10rem', width: '45%', }; const DemoOne = (props: SelectAddProps) => { const [values, setValues] = React.useState(props.values); const [value, setValue] = React.useState(props.value); const handleValuesRemove = (value: string) => { setValues(values.filter((v) => v !== value)); }; const handleValuesAdd = (value: string) => { setValues([...values, value]); }; const handleValueSelect = (value: string) => { setValue(value); }; return ( { handleValueSelect(value); }} onAdd={(value) => { handleValuesAdd(value); }} onRemove={(value) => { handleValuesRemove(value); }} {...props} values={values} value={value} style={style} /> ); }; export default (props) => { useShowStorybookCode(); return ( ); }; export const code = `import SelectAdd, { Props as SelectAddProps } from '@techytools/ui/components/SelectAdd'; const [values, setValues] = React.useState(['Jack', 'Lucy', 'Tom']); const [value, setValue] = React.useState(undefined); const handleValuesRemove = (value: string) => { setValues(values.filter((v) => v !== value)); }; const handleValuesAdd = (value: string) => { setValues([...values, value]); }; const handleValueSelect = (value: string) => { setValue(value); }; { handleValueSelect(value); }} onAdd={(value) => { handleValuesAdd(value); }} onRemove={(value) => { handleValuesRemove(value); }} />`;