diff --git a/addons/docs/src/mdx/__snapshots__/mdx-compiler-plugin.test.js.snap b/addons/docs/src/mdx/__snapshots__/mdx-compiler-plugin.test.js.snap index ce77eb70ec47..0d148f136aac 100644 --- a/addons/docs/src/mdx/__snapshots__/mdx-compiler-plugin.test.js.snap +++ b/addons/docs/src/mdx/__snapshots__/mdx-compiler-plugin.test.js.snap @@ -53,6 +53,7 @@ MDXContent.isMDXComponent = true; export const one = () => ; one.story = {}; +one.story.name = 'one'; one.story.parameters = { mdxSource: '' }; one.story.decorators = [storyFn =>
{storyFn()}
]; @@ -181,6 +182,7 @@ MDXContent.isMDXComponent = true; export const one = () => ; one.story = {}; +one.story.name = 'one'; one.story.parameters = { mdxSource: '' }; export const helloStory = () => ; @@ -342,6 +344,7 @@ helloButton.story.parameters = { mdxSource: '' }; export const two = () => ; two.story = {}; +two.story.name = 'two'; two.story.parameters = { mdxSource: '' }; const componentMeta = { @@ -443,6 +446,7 @@ MDXContent.isMDXComponent = true; export const text = () => 'Plain text'; text.story = {}; +text.story.name = 'text'; text.story.parameters = { mdxSource: \\"'Plain text'\\" }; const componentMeta = { title: 'Text', includeStories: ['text'] }; @@ -501,6 +505,7 @@ MDXContent.isMDXComponent = true; export const one = () => ; one.story = {}; +one.story.name = 'one'; one.story.parameters = { mdxSource: '' }; export const helloStory = () => ; diff --git a/addons/docs/src/mdx/mdx-compiler-plugin.js b/addons/docs/src/mdx/mdx-compiler-plugin.js index 096b1edeca77..d66890e62620 100644 --- a/addons/docs/src/mdx/mdx-compiler-plugin.js +++ b/addons/docs/src/mdx/mdx-compiler-plugin.js @@ -72,9 +72,8 @@ function genStoryExport(ast, counter) { } statements.push(`${storyKey}.story = {};`); - if (storyName !== storyKey) { - statements.push(`${storyKey}.story.name = '${storyName}';`); - } + // always preserve the name, since CSF exports can get modified by displayName + statements.push(`${storyKey}.story.name = '${storyName}';`); let parameters = getAttr(ast.openingElement, 'parameters'); parameters = parameters && parameters.expression; diff --git a/docs/src/pages/configurations/options-parameter/index.md b/docs/src/pages/configurations/options-parameter/index.md index a4586badd353..2adaaee66b15 100644 --- a/docs/src/pages/configurations/options-parameter/index.md +++ b/docs/src/pages/configurations/options-parameter/index.md @@ -82,6 +82,14 @@ addParameters({ * @type {Function} */ storySort: undefined + + /** + * Function to transform Component Story Format named exports (typically camel-case + * variables) into display names. If the story specifies a `story.name` option, that + * will not be transformed and will always take precedence over a named export. + * @type {Function} + */ + makeDisplayName: lodash.startCase }, }); ``` diff --git a/examples/html-kitchen-sink/tests/__snapshots__/htmlshots.test.js.snap b/examples/html-kitchen-sink/tests/__snapshots__/htmlshots.test.js.snap index f4a8859c0f4e..ca0e2dec3aa7 100644 --- a/examples/html-kitchen-sink/tests/__snapshots__/htmlshots.test.js.snap +++ b/examples/html-kitchen-sink/tests/__snapshots__/htmlshots.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Storyshots Addons|Actions Decorated actions + config 1`] = ` +exports[`Storyshots Addons|Actions story1 1`] = ` `; -exports[`Storyshots Addons|Actions Decorated actions 1`] = ` +exports[`Storyshots Addons|Actions story2 1`] = ` `; -exports[`Storyshots Addons|Actions Hello World 1`] = ` +exports[`Storyshots Addons|Actions story3 1`] = ` `; -exports[`Storyshots Addons|Actions Multiple actions + config 1`] = ` +exports[`Storyshots Addons|Actions story4 1`] = ` `; -exports[`Storyshots Addons|Actions Multiple actions 1`] = ` +exports[`Storyshots Addons|Actions story5 1`] = ` + + +`; + +exports[`Storyshots Addons|Actions story6 1`] = ` `; -exports[`Storyshots Addons|Actions Multiple actions, object + config 1`] = ` +exports[`Storyshots Addons|Actions story7 1`] = ` `; -exports[`Storyshots Addons|Actions Multiple actions, object 1`] = ` +exports[`Storyshots Addons|Actions story8 1`] = ` `; -exports[`Storyshots Addons|Actions Multiple actions, selector 1`] = ` - - -`; - -exports[`Storyshots Addons|Backgrounds story 1 1`] = ` +exports[`Storyshots Addons|Backgrounds story1 1`] = ` @@ -69,7 +69,7 @@ exports[`Storyshots Addons|Backgrounds story 1 1`] = ` `; -exports[`Storyshots Addons|Backgrounds story 2 1`] = ` +exports[`Storyshots Addons|Backgrounds story2 1`] = ` @@ -77,7 +77,7 @@ exports[`Storyshots Addons|Backgrounds story 2 1`] = ` `; -exports[`Storyshots Addons|Centered button in center 1`] = ` +exports[`Storyshots Addons|Centered story1 1`] = `
+ John Doe +

+`; + +exports[`Storyshots Addons|Knobs Simple 1`] = ` +
+ I am John Doe and I'm 44 years old. +
+`; + +exports[`Storyshots Addons|Knobs story3 1`] = ` +

+ John Doe +

+`; + +exports[`Storyshots Addons|Knobs story4 1`] = `
@@ -147,29 +167,9 @@ exports[`Storyshots Addons|Knobs All knobs 1`] = `
`; -exports[`Storyshots Addons|Knobs CSS transitions 1`] = ` -

- John Doe -

-`; - -exports[`Storyshots Addons|Knobs DOM 1`] = ` -

- John Doe -

-`; - -exports[`Storyshots Addons|Knobs Simple 1`] = ` -
- I am John Doe and I'm 44 years old. -
-`; - -exports[`Storyshots Addons|Knobs XSS safety 1`] = `<img src=x onerror="alert('XSS Attack')" >`; +exports[`Storyshots Addons|Knobs story5 1`] = `<img src=x onerror="alert('XSS Attack')" >`; -exports[`Storyshots Addons|Notes Simple note 1`] = ` +exports[`Storyshots Addons|Notes story1 1`] = `

@@ -185,8 +185,6 @@ exports[`Storyshots Addons|Notes Simple note 1`] = ` exports[`Storyshots Addons|a11y Default 1`] = ` `; -exports[`Storyshots Addons|a11y Label 1`] = ` - `; +exports[`Storyshots Addons|a11y story5 1`] = `

`; + exports[`Storyshots Demo button 1`] = ` `; -exports[`Storyshots Addons|Backgrounds Example 2 1`] = ` +exports[`Storyshots Addons|Backgrounds example2 1`] = ` `; -exports[`Storyshots Addons|Centered Button 1`] = ` +exports[`Storyshots Addons|Centered button 1`] = `
`; -exports[`Storyshots Addons|Contexts Simple CSS Theming 1`] = ` +exports[`Storyshots Addons|Contexts simpleCssTheming 1`] = `
`; -exports[`Storyshots Addons|Knobs All knobs 1`] = ` +exports[`Storyshots Addons|Knobs Simple 1`] = ` +
+ I am John Doe and I'm 44 years old. +
+`; + +exports[`Storyshots Addons|Knobs allKnobs 1`] = `
@@ -136,13 +142,7 @@ exports[`Storyshots Addons|Knobs All knobs 1`] = `
`; -exports[`Storyshots Addons|Knobs Simple 1`] = ` -
- I am John Doe and I'm 44 years old. -
-`; - -exports[`Storyshots Addons|Links Go to welcome 1`] = ` +exports[`Storyshots Addons|Links goToWelcome 1`] = ` `; -exports[`Storyshots Addon|Backgrounds story 2 1`] = ` +exports[`Storyshots Addon|Backgrounds story2 1`] = ` @@ -77,7 +77,7 @@ exports[`Storyshots Addon|Contexts Languages 1`] = `
`; -exports[`Storyshots Addon|Contexts Simple CSS Theming 1`] = ` +exports[`Storyshots Addon|Contexts simpleCssTheming 1`] = `
@@ -87,7 +87,13 @@ exports[`Storyshots Addon|Contexts Simple CSS Theming 1`] = `
`; -exports[`Storyshots Addon|Knobs All knobs 1`] = ` +exports[`Storyshots Addon|Knobs Simple 1`] = ` +
+ I am John Doe and I'm 40 years old. +
+`; + +exports[`Storyshots Addon|Knobs allKnobs 1`] = `
@@ -125,19 +131,13 @@ exports[`Storyshots Addon|Knobs All knobs 1`] = `
`; -exports[`Storyshots Addon|Knobs Simple 1`] = ` -
- I am John Doe and I'm 40 years old. -
-`; - -exports[`Storyshots Addon|Knobs XSS safety 1`] = ` +exports[`Storyshots Addon|Knobs xssSafety 1`] = `
<img src=x onerror="alert('XSS Attack')" >
`; -exports[`Storyshots Addon|Links Go to welcome 1`] = ` +exports[`Storyshots Addon|Links goToWelcome 1`] = ` `; -exports[`Storyshots Core|Parameters passed to story 1`] = ` +exports[`Storyshots Core|Parameters passedToStory 1`] = `
- Parameters are {"options":{"hierarchyRootSeparator":{},"hierarchySeparator":{}},"docs":{"iframeHeight":"60px"},"globalParameter":"globalParameter","framework":"vue","chapterParameter":"chapterParameter","storyParameter":"storyParameter"} + Parameters are {"options":{"hierarchyRootSeparator":{},"hierarchySeparator":{}},"docs":{"iframeHeight":"60px"},"globalParameter":"globalParameter","framework":"vue","chapterParameter":"chapterParameter","storyParameter":"storyParameter","displayName":"passed to story"}
`; -exports[`Storyshots Core|Template string only 1`] = ` +exports[`Storyshots Core|Template stringOnly 1`] = `