Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon-docs: Fix MDX IDs from CSF imports #12154

Merged
merged 1 commit into from
Aug 20, 2020
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
23 changes: 8 additions & 15 deletions addons/docs/src/mdx/__testfixtures__/csf-imports.output.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function MDXContent({ components, ...props }) {
<MDXLayout {...layoutProps} {...props} components={components} mdxType=\\"MDXLayout\\">
<Meta title=\\"MDX/CSF imports\\" mdxType=\\"Meta\\" />
<h1>{\`Stories from CSF imports\`}</h1>
<Story story={MyStories.Basic} name=\\"BasicStory\\" mdxType=\\"Story\\" />
<Story story={MyStories.Basic} name=\\"_Basic_\\" mdxType=\\"Story\\" />
<Canvas mdxType=\\"Canvas\\">
<Story story={Other} name=\\"OtherStory\\" mdxType=\\"Story\\" />
<Story story={Other} name=\\"_Other_\\" mdxType=\\"Story\\" />
</Canvas>
<Story name=\\"renamed\\" story={MyStories.Foo} mdxType=\\"Story\\" />
</MDXLayout>
Expand All @@ -37,23 +37,16 @@ function MDXContent({ components, ...props }) {

MDXContent.isMDXComponent = true;

export const BasicStory = MyStories.Basic;
export const _Basic_ = MyStories.Basic;

export const OtherStory = Other;
export const _Other_ = Other;

export const FooStory = MyStories.Foo;
FooStory.storyName = 'renamed';
export const _Foo_ = MyStories.Foo;
_Foo_.storyName = 'renamed';

const componentMeta = {
title: 'MDX/CSF imports',
includeStories: ['BasicStory', 'OtherStory', 'FooStory'],
};
const componentMeta = { title: 'MDX/CSF imports', includeStories: ['_Basic_', '_Other_', '_Foo_'] };

const mdxStoryNameToKey = {
BasicStory: 'BasicStory',
OtherStory: 'OtherStory',
renamed: 'FooStory',
};
const mdxStoryNameToKey = { _Basic_: '_Basic_', _Other_: '_Other_', renamed: '_Foo_' };

componentMeta.parameters = componentMeta.parameters || {};
componentMeta.parameters.docs = {
Expand Down
2 changes: 1 addition & 1 deletion addons/docs/src/mdx/mdx-compiler-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function genAttribute(key, element) {
function genImportStory(ast, storyDef, storyName, context) {
const { code: story } = generate(storyDef.expression, {});

const storyKey = `${story.split('.').pop()}Story`;
const storyKey = `_${story.split('.').pop()}_`;

const statements = [`export const ${storyKey} = ${story};`];
if (storyName) {
Expand Down