[16/n][Storybook] Steps argTypes and typed variants (#53)

This commit is contained in:
Vivian Phung 2024-05-14 17:48:38 -04:00 committed by GitHub
commit 6fdbcf6f46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 41 deletions

View File

@ -2,7 +2,7 @@ import { Fragment, ComponentPropsWithoutRef } from 'react';
import { stepsTheme, StepsTheme } from './Steps.theme'; import { stepsTheme, StepsTheme } from './Steps.theme';
import { Step, StepProps, StepTheme } from './Step'; import { Step, StepProps, StepTheme } from './Step';
interface StepsProps export interface StepsProps
extends ComponentPropsWithoutRef<'ul'>, extends ComponentPropsWithoutRef<'ul'>,
StepsTheme, StepsTheme,
Pick<StepTheme, 'orientation'> { Pick<StepTheme, 'orientation'> {

View File

@ -1,2 +1,3 @@
export * from './Steps'; export * from './Steps';
export * from './Steps.theme'; export * from './Steps.theme';
export * from './Step';

View File

@ -1,6 +1,22 @@
import { StoryObj, Meta } from '@storybook/react'; import { StoryObj, Meta } from '@storybook/react';
import { Steps } from 'components/shared/Steps'; import { Steps, StepsTheme, StepProps } from 'components/shared/Steps';
const stepsOrientations: StepsTheme['orientation'][] = [
'horizontal',
'vertical',
];
const stepsOptions: Pick<StepProps, 'label'>[] = [
{
label: 'Create repository',
},
{
label: 'Deploy',
},
{
label: `What's next?`,
},
];
const meta: Meta<typeof Steps> = { const meta: Meta<typeof Steps> = {
title: 'Components/Steps', title: 'Components/Steps',
@ -9,7 +25,7 @@ const meta: Meta<typeof Steps> = {
argTypes: { argTypes: {
orientation: { orientation: {
control: 'radio', control: 'radio',
options: ['horizontal', 'vertical'], options: stepsOrientations,
}, },
currentIndex: { currentIndex: {
control: 'number', control: 'number',
@ -25,50 +41,23 @@ export default meta;
type Story = StoryObj<typeof Steps>; type Story = StoryObj<typeof Steps>;
export const Default: Story = { export const Default: Story = {
render: ({ orientation, currentIndex, steps }) => (
<Steps
currentIndex={currentIndex}
steps={steps}
orientation={orientation}
/>
),
args: { args: {
currentIndex: 0, orientation: 'vertical',
steps: [ currentIndex: 1,
{ steps: stepsOptions,
label: 'Create repository',
},
{
label: 'Deploy',
},
{
label: `What's next?`,
},
],
}, },
}; };
export const Horizontal: Story = { export const Horizontal: Story = {
render: ({ orientation, currentIndex, steps }) => (
<Steps
currentIndex={currentIndex}
steps={steps}
orientation={orientation}
/>
),
args: { args: {
currentIndex: 0, ...Default.args,
steps: [
{
label: 'Create repository',
},
{
label: 'Deploy',
},
{
label: `What's next?`,
},
],
orientation: 'horizontal', orientation: 'horizontal',
}, },
}; };
export const Past: Story = {
args: {
...Default.args,
currentIndex: 2,
},
};