Created
January 12, 2022 11:40
-
-
Save lightsound/fdd7ec6719923ca1db123ca68c76d333 to your computer and use it in GitHub Desktop.
Storybookのテンプレートを削減するためのファクトリー関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AnyFramework, ComponentTitle, StoryAnnotations } from '@storybook/csf' | |
import { ComponentMeta, ComponentStory } from '@storybook/react' | |
import { VFC } from 'react' | |
export const createStorybookFactory = <P extends object>(Component: VFC<P>) => { | |
const Template = ((args) => <Component {...args} />) as ComponentStory< | |
typeof Component | |
> | |
const Default = Template.bind({}) | |
Default.storyName = Component.displayName | |
return { | |
Default, | |
createStory: (options?: StoryAnnotations<AnyFramework, P>) => { | |
const story = Template.bind({}) | |
return options ? { ...story, ...options } : story | |
}, | |
createMeta: ( | |
title: ComponentTitle, | |
options?: Omit<ComponentMeta<typeof Component>, 'title' | 'component'> | |
) => { | |
return { | |
...options, | |
parameters: { | |
controls: { hideNoControlsWarning: true }, | |
...options?.parameters, | |
}, | |
title: `${title}/${Component.displayName}`, | |
component: Component, | |
} | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
例えばこんな感じで使えます