mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 03:41:06 +08:00
Merge pull request #20765 from storybookjs/allow-no-of-in-story
Docs: Allow `<Story/>` to reference the first story
This commit is contained in:
commit
b108c285fa
@ -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,
|
||||
|
@ -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>(
|
||||
|
Loading…
x
Reference in New Issue
Block a user