Skip to content

Commit

Permalink
Merge pull request #20255 from storybookjs/shilman/19965-fix-mdx-loca…
Browse files Browse the repository at this point in the history
…l-vars-handling

Csf-tools: Fix local vars handling in MDX-generated CSF
  • Loading branch information
shilman authored Dec 14, 2022
2 parents fa5051f + 8617bf5 commit 7d5f90c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
30 changes: 30 additions & 0 deletions code/lib/csf-tools/src/CsfFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,36 @@ describe('CsfFile', () => {
`);
});

it('docs-only story with local vars', () => {
expect(
parse(
dedent`
export const TestControl = () => _jsx("p", {
children: "Hello"
});
export default { title: 'foo/bar', tags: ['mdx'], includeStories: ["__page"] };
export const __page = () => {};
__page.parameters = { docsOnly: true };
`,
true
)
).toMatchInlineSnapshot(`
meta:
title: foo/bar
tags:
- mdx
includeStories:
- __page
stories:
- id: foo-bar--page
name: Page
parameters:
__isArgsStory: false
__id: foo-bar--page
docsOnly: true
`);
});

it('title variable', () => {
expect(
parse(
Expand Down
6 changes: 5 additions & 1 deletion code/lib/csf-tools/src/CsfFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,11 @@ export class CsfFile {
if (isExportStory(key, self._meta)) {
const id = toId(self._meta.id || self._meta.title, storyNameFromExport(key));
const parameters: Record<string, any> = { ...story.parameters, __id: id };
if (entries.length === 1 && key === '__page') {
const { includeStories } = self._meta || {};
if (
key === '__page' &&
(entries.length === 1 || (Array.isArray(includeStories) && includeStories.length === 1))
) {
parameters.docsOnly = true;
}
acc[key] = { ...story, id, parameters };
Expand Down

0 comments on commit 7d5f90c

Please sign in to comment.