diff --git a/src/story.test.ts b/src/story.test.ts index baedcfd..3860d86 100644 --- a/src/story.test.ts +++ b/src/story.test.ts @@ -33,6 +33,7 @@ const Button = (props: ButtonArgs) => 'Button'; const simple: XMeta = { title: 'simple', component: Button, + tags: ['foo', 'bar'], decorators: [(storyFn, context) => `withDecorator(${storyFn(context)})`], parameters: { a: () => null, b: NaN, c: Symbol('symbol') }, loaders: [() => Promise.resolve({ d: '3' })], @@ -43,6 +44,7 @@ const simple: XMeta = { const strict: XMeta = { title: 'simple', component: Button, + tags: ['foo', 'bar'], decorators: [(storyFn, context) => `withDecorator(${storyFn(context)})`], parameters: { a: () => null, b: NaN, c: Symbol('symbol') }, loaders: [() => Promise.resolve({ d: '3' })], @@ -56,7 +58,8 @@ const Simple: XStory = () => 'Simple'; const CSF1Story: XStory = () => 'Named Story'; CSF1Story.story = { name: 'Another name for story', - decorators: [(storyFn) => `Wrapped(${storyFn()}`], + tags: ['foo', 'bar'], + decorators: [storyFn => `Wrapped(${storyFn()}`], parameters: { a: [1, '2', {}], b: undefined, c: Button }, loaders: [() => Promise.resolve({ d: '3' })], args: { a: 1 }, @@ -64,24 +67,27 @@ CSF1Story.story = { const CSF2Story: XStory = () => 'Named Story'; CSF2Story.storyName = 'Another name for story'; -CSF2Story.decorators = [(storyFn) => `Wrapped(${storyFn()}`]; +CSF2Story.tags = ['foo', 'bar']; +CSF2Story.decorators = [storyFn => `Wrapped(${storyFn()}`]; CSF2Story.parameters = { a: [1, '2', {}], b: undefined, c: Button }; CSF2Story.loaders = [() => Promise.resolve({ d: '3' })]; CSF2Story.args = { a: 1 }; const CSF3Story: XStory = { - render: (args) => 'Named Story', + render: args => 'Named Story', name: 'Another name for story', - decorators: [(storyFn) => `Wrapped(${storyFn()}`], + tags: ['foo', 'bar'], + decorators: [storyFn => `Wrapped(${storyFn()}`], parameters: { a: [1, '2', {}], b: undefined, c: Button }, loaders: [() => Promise.resolve({ d: '3' })], args: { a: 1 }, }; const CSF3StoryStrict: XStory = { - render: (args) => 'Named Story', + render: args => 'Named Story', name: 'Another name for story', - decorators: [(storyFn) => `Wrapped(${storyFn()}`], + tags: ['foo', 'bar'], + decorators: [storyFn => `Wrapped(${storyFn()}`], parameters: { a: [1, '2', {}], b: undefined, c: Button }, loaders: [() => Promise.resolve({ d: '3' })], args: { x: '1' }, @@ -113,7 +119,7 @@ test('ArgsFromMeta will infer correct args from render/loader/decorators', () => loader2: `${args.loaderArg2}`, }); - const renderer: ArgsStoryFn = (args) => `${args.theme}`; + const renderer: ArgsStoryFn = args => `${args.theme}`; const meta = { component: Button, diff --git a/src/story.ts b/src/story.ts index ee9bb3a..2da4f8d 100644 --- a/src/story.ts +++ b/src/story.ts @@ -11,6 +11,8 @@ export type StoryName = string; /** @deprecated */ export type StoryKind = ComponentTitle; +export type Tag = string; + export interface StoryIdentifier { componentId: ComponentId; title: ComponentTitle; @@ -21,6 +23,8 @@ export interface StoryIdentifier { name: StoryName; /** @deprecated */ story: StoryName; + + tags: Tag[]; } export type Parameters = { [name: string]: any }; @@ -290,12 +294,17 @@ export interface ComponentAnnotations; - + /** * Function that is executed after the story is rendered. */ play?: PlayFunction; -}; + + /** + * Named tags for a story, used to filter stories in different contexts. + */ + tags?: Tag[]; +} export type StoryAnnotations< TFramework extends AnyFramework = AnyFramework, @@ -317,6 +326,11 @@ export type StoryAnnotations< */ play?: PlayFunction; + /** + * Named tags for a story, used to filter stories in different contexts. + */ + tags?: Tag[]; + /** @deprecated */ story?: Omit, 'story'>; } & ({} extends TRequiredArgs ? { args?: TRequiredArgs } : { args: TRequiredArgs });