Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSF: Add CSF3 typings #15558

Merged
merged 5 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/react-ts/src/AccountForm.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { ComponentMeta } from '@storybook/react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { screen } from '@testing-library/dom';
import userEvent from '@testing-library/user-event';
import { AccountForm, AccountFormProps } from './AccountForm';
Expand All @@ -14,7 +14,7 @@ export default {
// export const Standard = (args: AccountFormProps) => <AccountForm {...args} />;
// Standard.args = { passwordVerification: false };

export const Standard = {
export const Standard: ComponentStory<typeof AccountForm> = {
// render: (args: AccountFormProps) => <AccountForm {...args} />,
args: { passwordVerification: false },
};
Expand Down Expand Up @@ -51,7 +51,7 @@ export const StandardFailHover = {
},
};

export const Verification = {
export const Verification: ComponentStory<typeof AccountForm> = {
args: { passwordVerification: true },
};

Expand Down
26 changes: 21 additions & 5 deletions lib/addons/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ export interface BaseAnnotations<Args, StoryFnReturnType> {
* @see [Decorators](https://storybook.js.org/docs/addons/introduction/#1-decorators)
*/
decorators?: BaseDecorators<StoryFnReturnType>;
/**
* Define a custom render function for the story(ies). If not passed, a default render function by the framework will be used.
*/
render?: (args: Args, context: StoryContext) => StoryFnReturnType;
/**
* Function that is executed after the story is rendered.
*/
play?: Function;
}

export interface Annotations<Args, StoryFnReturnType>
Expand Down Expand Up @@ -228,6 +236,8 @@ export interface BaseMeta<ComponentType> {
*
* Stories can be organized in a nested structure using "/" as a separator.
*
* Since CSF 3.0 this property is optional.
*
* @example
* export default {
* ...
Expand All @@ -236,7 +246,7 @@ export interface BaseMeta<ComponentType> {
*
* @see [Story Hierarchy](https://storybook.js.org/docs/basics/writing-stories/#story-hierarchy)
*/
title: string;
title?: string;

/**
* The primary component for your story.
Expand All @@ -263,11 +273,17 @@ export interface BaseMeta<ComponentType> {
subcomponents?: Record<string, ComponentType>;
}

export interface BaseStory<Args, StoryFnReturnType> {
(args: Args, context: StoryContext): StoryFnReturnType;

type BaseStoryObject<Args, StoryFnReturnType> = {
/**
* Override the display name in the UI
*/
storyName?: string;
}
};

type BaseStoryFn<Args, StoryFnReturnType> = {
(args: Args, context: StoryContext): StoryFnReturnType;
} & BaseStoryObject<Args, StoryFnReturnType>;

export type BaseStory<Args, StoryFnReturnType> =
| BaseStoryFn<Args, StoryFnReturnType>
| BaseStoryObject<Args, StoryFnReturnType>;