Skip to content
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
18 changes: 18 additions & 0 deletions code/core/src/csf/story.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type ButtonArgs = {

const Button = (props: ButtonArgs) => 'Button';

const ButtonIcon = ({ icon }: { icon: string }) => `ButtonIcon ${icon}`;

let a = 1;
async function doSomething() {
a = 2;
Expand Down Expand Up @@ -119,6 +121,22 @@ CSF1Story.story = {
args: { a: 1 },
};

const simpleWithSubComponents: 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' })],
async beforeEach() {
await doSomething();
return cleanup;
},
args: { x: '1' },
argTypes: { x: { type: { name: 'string' } } },
subcomponents: { ButtonIcon }, // the fact that this line does not cause a Typescript compilation error itself means that the type is correct
};

const CSF2Story: XStory = () => 'Named Story';
CSF2Story.storyName = 'Another name for story';
CSF2Story.tags = ['foo', 'bar'];
Expand Down
2 changes: 1 addition & 1 deletion code/core/src/csf/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TAr
*
* By defining them each component will have its tab in the args table.
*/
subcomponents?: Record<string, TRenderer['component']>;
subcomponents?: Record<string, (TRenderer & { T: any })['component']>;

/** Function that is executed after the story is rendered. */
play?: PlayFunction<TRenderer, TArgs>;
Expand Down
Loading