mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-28 05:10:17 +08:00
Add ComponentMeta React convenience type
This commit is contained in:
parent
2d715c725d
commit
51aec158f7
@ -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:
|
||||
*
|
||||
|
@ -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} />;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user