Add ComponentMeta React convenience type

This commit is contained in:
Michael Shilman 2021-05-07 15:53:52 +08:00
parent 2d715c725d
commit 51aec158f7
2 changed files with 14 additions and 3 deletions

View File

@ -1,8 +1,19 @@
import { ComponentProps, JSXElementConstructor } from 'react';
import type { Story } from './types-6-0';
import type { Story, Meta } from './types-6-0';
export * from './types-6-0';
/**
* For the common case where a component's stories are simple components that receives args as props:
*
* ```tsx
* export default { ... } as ComponentMeta<typeof Button>;
* ```
*/
export type ComponentMeta<
T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>
> = Meta<ComponentProps<T>>;
/**
* For the common case where a story is a simple component that receives args as props:
*

View File

@ -1,5 +1,5 @@
import React from 'react';
import { Meta, Story, ComponentStory } from '@storybook/react';
import { ComponentMeta, Story, ComponentStory } from '@storybook/react';
import TsButton from '../../components/TsButton';
export default {
@ -12,7 +12,7 @@ export default {
</>
),
],
} as Meta;
} as ComponentMeta<typeof TsButton>;
const Template: Story = (args) => <TsButton {...args} />;