From ab9f3bc1d6cd0cb1cd5001c4f5e49e3fe1513c46 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Mon, 6 Dec 2021 17:13:21 +1100 Subject: [PATCH 1/3] Only make `TArgs` parameterize `args` and `argTypes` in our default annotations. --- src/story.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/story.ts b/src/story.ts index 1219d85..3dcc1c8 100644 --- a/src/story.ts +++ b/src/story.ts @@ -144,7 +144,7 @@ export type BaseAnnotations[]; + decorators?: DecoratorFunction[]; /** * Custom metadata for a story. @@ -168,28 +168,28 @@ export type BaseAnnotations[]; + loaders?: LoaderFunction[]; /** * Define a custom render function for the story(ies). If not passed, a default render function by the framework will be used. */ - render?: ArgsStoryFn; + render?: ArgsStoryFn; /** * Function that is executed after the story is rendered. */ - play?: PlayFunction; + play?: PlayFunction; }; export type ProjectAnnotations< TFramework extends AnyFramework = AnyFramework, TArgs = Args > = BaseAnnotations & { - argsEnhancers?: ArgsEnhancer[]; - argTypesEnhancers?: ArgTypesEnhancer[]; + argsEnhancers?: ArgsEnhancer[]; + argTypesEnhancers?: ArgTypesEnhancer[]; globals?: Globals; globalTypes?: GlobalTypes; - applyDecorators?: DecoratorApplicator; + applyDecorators?: DecoratorApplicator; }; type StoryDescriptor = string[] | RegExp; @@ -289,7 +289,7 @@ export type StoryAnnotations< export type LegacyAnnotatedStoryFn< TFramework extends AnyFramework = AnyFramework, TArgs = Args -> = StoryFn & StoryAnnotations; +> = StoryFn & StoryAnnotations; export type LegacyStoryAnnotationsOrFn< TFramework extends AnyFramework = AnyFramework, @@ -299,7 +299,7 @@ export type LegacyStoryAnnotationsOrFn< export type AnnotatedStoryFn< TFramework extends AnyFramework = AnyFramework, TArgs = Args -> = ArgsStoryFn & StoryAnnotations; +> = ArgsStoryFn & StoryAnnotations; export type StoryAnnotationsOrFn = | AnnotatedStoryFn From c2c5bfe17e7f70739b850c714a81083cb8cbd824 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Wed, 8 Dec 2021 16:10:45 +1100 Subject: [PATCH 2/3] Tighten up types again. --- src/story.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/story.ts b/src/story.ts index 3dcc1c8..2eea160 100644 --- a/src/story.ts +++ b/src/story.ts @@ -174,11 +174,6 @@ export type BaseAnnotations; - - /** - * Function that is executed after the story is rendered. - */ - play?: PlayFunction; }; export type ProjectAnnotations< @@ -265,7 +260,14 @@ export type ComponentAnnotations< * * By defining them each component will have its tab in the args table. */ - subcomponents?: Record; + subcomponents?: Record; + + + + /** + * Function that is executed after the story is rendered. + */ + play?: PlayFunction; }; export type StoryAnnotations< @@ -281,6 +283,11 @@ export type StoryAnnotations< * Override the display name in the UI (CSF v2) */ storyName?: StoryName; + + /** + * Function that is executed after the story is rendered. + */ + play?: PlayFunction; /** @deprecated */ story?: Omit, 'story'>; @@ -289,7 +296,7 @@ export type StoryAnnotations< export type LegacyAnnotatedStoryFn< TFramework extends AnyFramework = AnyFramework, TArgs = Args -> = StoryFn & StoryAnnotations; +> = StoryFn & StoryAnnotations; export type LegacyStoryAnnotationsOrFn< TFramework extends AnyFramework = AnyFramework, @@ -299,7 +306,7 @@ export type LegacyStoryAnnotationsOrFn< export type AnnotatedStoryFn< TFramework extends AnyFramework = AnyFramework, TArgs = Args -> = ArgsStoryFn & StoryAnnotations; +> = ArgsStoryFn & StoryAnnotations; export type StoryAnnotationsOrFn = | AnnotatedStoryFn From 85efd3c2c619bd84cc876123b56662982cc6c3ed Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Wed, 8 Dec 2021 16:13:16 +1100 Subject: [PATCH 3/3] Play function can only be set at the story level cf https://github.com/storybookjs/storybook/blob/35d0096a772c29bdafac80065232f7728d483b1e/lib/store/src/prepareStory.ts#L196 --- src/story.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/story.ts b/src/story.ts index 2eea160..86b60cd 100644 --- a/src/story.ts +++ b/src/story.ts @@ -261,13 +261,6 @@ export type ComponentAnnotations< * By defining them each component will have its tab in the args table. */ subcomponents?: Record; - - - - /** - * Function that is executed after the story is rendered. - */ - play?: PlayFunction; }; export type StoryAnnotations<