[12/n][Storybook] Select argTypes and typed variants

This commit is contained in:
Vivian Phung 2024-05-14 16:39:29 -04:00 committed by Vivian Phung
parent 19545c48bd
commit d76db4fb96
2 changed files with 130 additions and 49 deletions

View File

@ -1,2 +1,3 @@
export * from './Select'; export * from './Select';
export * from './SelectItem'; export * from './SelectItem';
export * from './Select.theme';

View File

@ -1,6 +1,21 @@
import { StoryObj, Meta } from '@storybook/react'; import { StoryObj, Meta } from '@storybook/react';
import { PlusIcon } from 'components/shared/CustomIcon';
import { Select } from 'components/shared/Select'; import { Select, SelectOption, SelectTheme } from 'components/shared/Select';
const selectOrientation: SelectTheme['orientation'][] = [
'horizontal',
'vertical',
];
const selectVariants: SelectTheme['variant'][] = ['default', 'danger'];
const selectSizes: SelectTheme['size'][] = ['sm', 'md'];
const selectError: SelectTheme['error'][] = [true, false];
const selectIsOpen: SelectTheme['isOpen'][] = [true, false];
const selectOptions: SelectOption[] = [
{ label: 'Option 1', value: 'option1' },
{ label: 'Option 2', value: 'option2' },
{ label: 'Option 3', value: 'option3' },
];
const meta: Meta<typeof Select> = { const meta: Meta<typeof Select> = {
title: 'Components/Select', title: 'Components/Select',
@ -17,13 +32,13 @@ const meta: Meta<typeof Select> = {
control: 'text', control: 'text',
}, },
multiple: { multiple: {
control: 'boolean', type: 'boolean',
}, },
searchable: { searchable: {
control: 'boolean', type: 'boolean',
}, },
clearable: { clearable: {
control: 'boolean', type: 'boolean',
}, },
leftIcon: { leftIcon: {
control: 'text', control: 'text',
@ -35,7 +50,7 @@ const meta: Meta<typeof Select> = {
control: 'text', control: 'text',
}, },
hideValues: { hideValues: {
control: 'boolean', type: 'boolean',
}, },
value: { value: {
control: 'object', control: 'object',
@ -46,6 +61,29 @@ const meta: Meta<typeof Select> = {
onChange: { onChange: {
action: 'change', action: 'change',
}, },
orientation: {
control: 'radio',
options: selectOrientation,
},
placeholder: {
control: 'text',
},
variant: {
control: 'select',
options: selectVariants,
},
size: {
control: 'select',
options: selectSizes,
},
error: {
control: 'radio',
options: selectError,
},
isOpen: {
control: 'radio',
options: selectIsOpen,
},
}, },
}; };
@ -54,52 +92,94 @@ export default meta;
type Story = StoryObj<typeof Select>; type Story = StoryObj<typeof Select>;
export const Default: Story = { export const Default: Story = {
render: ({
options,
label,
description,
multiple,
searchable,
clearable,
leftIcon,
rightIcon,
helperText,
hideValues,
value,
onClear,
onChange,
}) => (
<Select
options={options}
label={label}
description={description}
multiple={multiple}
searchable={searchable}
clearable={clearable}
leftIcon={leftIcon}
rightIcon={rightIcon}
helperText={helperText}
hideValues={hideValues}
value={value}
onClear={onClear}
onChange={onChange}
/>
),
args: { args: {
options: [ options: selectOptions,
{ label: 'Option 1', value: 'option1' },
{ label: 'Option 2', value: 'option2' },
{ label: 'Option 3', value: 'option3' },
],
label: 'Select', label: 'Select',
description: 'Select an option', description: 'Select an option',
multiple: false, },
searchable: false, };
clearable: false,
leftIcon: '', export const Multiple: Story = {
rightIcon: '', args: {
helperText: '', ...Default.args,
hideValues: false, multiple: true,
value: { label: 'Option 1', value: 'option1' }, },
};
export const Searchable: Story = {
args: {
...Default.args,
searchable: true,
},
};
export const Clearable: Story = {
args: {
...Default.args,
clearable: true,
},
};
export const LeftIcon: Story = {
args: {
...Default.args,
leftIcon: <PlusIcon />,
},
};
export const RightIcon: Story = {
args: {
...Default.args,
rightIcon: <PlusIcon />,
},
};
export const HelperText: Story = {
args: {
...Default.args,
helperText: 'Helper text',
},
};
export const HideValues: Story = {
args: {
...Default.args,
hideValues: true,
},
};
export const Error: Story = {
args: {
...Default.args,
error: true,
},
};
export const IsOpen: Story = {
args: {
...Default.args,
isOpen: true,
},
};
export const WithValue: Story = {
args: {
...Default.args,
value: selectOptions[0],
},
};
export const WithPlaceholder: Story = {
args: {
...Default.args,
placeholder: 'Select an option',
},
};
// TODO: fix Select danger variant
export const WithVariantDanger: Story = {
args: {
...Default.args,
variant: 'danger',
}, },
}; };