[14/n][Storybook] SegmentedControls update argTypes and use typed themes (#51)

This commit is contained in:
Vivian Phung 2024-05-14 17:41:29 -04:00 committed by GitHub
commit 19545c48bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 9 deletions

View File

@ -1,2 +1,3 @@
export * from './SegmentedControlItem'; export * from './SegmentedControlItem';
export * from './SegmentedControls'; export * from './SegmentedControls';
export * from './SegmentedControls.theme';

View File

@ -1,6 +1,24 @@
import { StoryObj, Meta } from '@storybook/react'; import { StoryObj, Meta } from '@storybook/react';
import { SegmentedControls } from 'components/shared/SegmentedControls'; import {
SegmentedControls,
SegmentedControlsVariants,
SegmentedControlsOption,
} from 'components/shared/SegmentedControls';
const segmentedControlsTypes: SegmentedControlsVariants['type'][] = [
'fixed-width',
'full-width',
];
const segmentedControlsSizes: SegmentedControlsVariants['size'][] = [
'sm',
'md',
];
const segmentedControlsOptions: SegmentedControlsOption[] = [
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' },
{ label: 'Option 3', value: '3' },
];
const meta: Meta<typeof SegmentedControls> = { const meta: Meta<typeof SegmentedControls> = {
title: 'Components/SegmentedControls', title: 'Components/SegmentedControls',
@ -14,8 +32,21 @@ const meta: Meta<typeof SegmentedControls> = {
control: 'text', control: 'text',
}, },
onChange: { onChange: {
action: 'onChange', action: 'change',
}, },
type: {
control: 'select',
options: segmentedControlsTypes,
},
size: {
control: 'select',
options: segmentedControlsSizes,
},
},
args: {
options: segmentedControlsOptions,
value: '1',
size: 'md',
}, },
}; };
@ -24,15 +55,16 @@ export default meta;
type Story = StoryObj<typeof SegmentedControls>; type Story = StoryObj<typeof SegmentedControls>;
export const Default: Story = { export const Default: Story = {
render: ({ options, value, onChange }) => ( render: ({ options, value, onChange, ...args }) => (
<SegmentedControls options={options} value={value} onChange={onChange} /> <SegmentedControls
options={options}
value={value}
onChange={onChange}
{...args}
/>
), ),
args: { args: {
options: [ options: segmentedControlsOptions,
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' },
{ label: 'Option 3', value: '3' },
],
value: '1', value: '1',
}, },
}; };