@storybook/addons#BaseStory TypeScript Examples

The following examples show how to use @storybook/addons#BaseStory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: story.tsx    From joplin-utils with MIT License 6 votes vote down vote up
/**
 * Create a typed story of a given component
 *
 * @example
 * const { meta, of } = story(Button)
 * export default meta({})
 * export const story1 = of({})
 * export const story2 = of({})
 */
export function story<T>(Component: React.ComponentType<T>) {
  return {
    meta(meta: Meta<T>): Meta<T> {
      return { ...meta, component: Component }
    },
    of(
      annotations: Annotations<T, StoryFnReactReturnType> &
        Pick<BaseStory<any, any>, 'storyName'> = {},
    ) {
      const copy: Story<T> = (props: T) => <Component {...props} />
      Object.assign(copy, annotations)
      return copy
    },
  }
}