Skip to content

Commit

Permalink
Merge pull request #14780 from storybookjs/feat/react-component-story
Browse files Browse the repository at this point in the history
React: Add ComponentStory convenience type
  • Loading branch information
shilman committed May 10, 2021
2 parents 6fe7f9c + 99ddea0 commit 5853ff7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/react/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export {
forceReRender,
} from './preview';

export * from './preview/types-6-0';
export * from './preview/types-6-3';

if (module && module.hot && module.hot.decline) {
module.hot.decline();
Expand Down
26 changes: 26 additions & 0 deletions app/react/src/client/preview/types-6-3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ComponentProps, JSXElementConstructor } from 'react';
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:
*
* ```tsx
* const Template: ComponentStory<typeof Button> = (args) => <Button {...args} />
* ```
*/
export type ComponentStory<
T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>
> = Story<ComponentProps<T>>;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ComponentProps } from 'react';
import { Meta, Story } from '@storybook/react';
import React from 'react';
import { ComponentMeta, Story, ComponentStory } from '@storybook/react';
import TsButton from '../../components/TsButton';

export default {
Expand All @@ -12,7 +12,7 @@ export default {
</>
),
],
} as Meta;
} as ComponentMeta<typeof TsButton>;

const Template: Story = (args) => <TsButton {...args} />;

Expand All @@ -22,8 +22,7 @@ Basic.args = {
children: 'basic',
};

type ButtonProps = ComponentProps<typeof TsButton>;
const TypedTemplate: Story<ButtonProps> = (args) => <TsButton {...args} />;
const TypedTemplate: ComponentStory<typeof TsButton> = (args) => <TsButton {...args} />;

export const Typed = TypedTemplate.bind({});
Typed.args = {
Expand Down

0 comments on commit 5853ff7

Please sign in to comment.