Merge pull request #20765 from storybookjs/allow-no-of-in-story

Docs: Allow `<Story/>` to reference the first story
This commit is contained in:
Jeppe Reinhold 2023-01-24 13:04:36 +01:00 committed by GitHub
commit b108c285fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 13 deletions

View File

@ -15,6 +15,8 @@ export default meta;
type Story = StoryObj<typeof meta>;
export const DefaultAttached: Story = {};
export const Of: Story = {
args: {
of: ButtonStories.Primary,
@ -28,6 +30,14 @@ export const OfWithMeta: Story = {
},
};
export const OfWithMetaUnattached: Story = {
parameters: { attached: false },
args: {
of: ButtonStories.Secondary,
meta: ButtonStories.default,
},
};
export const Inline: Story = {
args: {
of: StoryParametersStories.NoParameters,

View File

@ -93,6 +93,15 @@ export const getStoryId = (props: StoryProps, context: DocsContextProps): StoryI
deprecate(dedent`Referencing stories by \`id\` is deprecated, please use \`of\` instead.
Please refer to the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#story-block'`);
return id;
}
const { name } = props as StoryDefProps;
if (name) {
deprecate(dedent`Referencing stories by \`name\` is deprecated, please use \`of\` instead.
Please refer to the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#story-block'`);
return context.storyIdByName(name);
}
// The `story={moduleExports}` prop is a legacy prop for stories defined in CSF files, but
@ -106,19 +115,9 @@ export const getStoryId = (props: StoryProps, context: DocsContextProps): StoryI
Please refer to the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#story-block'`);
}
if (of || story) {
if (meta) context.referenceMeta(meta, false);
const resolved = context.resolveOf(of || story, ['story']);
return resolved.story.id;
}
const { name } = props as StoryDefProps;
if (name) {
deprecate(dedent`Referencing stories by \`name\` is deprecated, please use \`of\` instead.
Please refer to the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#story-block'`);
}
return id || context.storyIdByName(name);
if (meta) context.referenceMeta(meta, false);
const resolved = context.resolveOf(of || story || 'story', ['story']);
return resolved.story.id;
};
export const getStoryProps = <TFramework extends Renderer>(