Skip to content

Commit

Permalink
feat(types): add CSF3 typings
Browse files Browse the repository at this point in the history
- Support object notation
- Render function
- Play function
  • Loading branch information
yannbf committed Jul 12, 2021
1 parent 9ab0618 commit 8040589
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 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 can be executed after the story is rendered.
*/
play?: Function;
}

export interface Annotations<Args, StoryFnReturnType>
Expand Down Expand Up @@ -263,11 +271,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;
};

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

0 comments on commit 8040589

Please sign in to comment.