diff --git a/addons/options/README.md b/addons/options/README.md index e19aa601ecda..92dcb099570b 100644 --- a/addons/options/README.md +++ b/addons/options/README.md @@ -90,13 +90,19 @@ setOptions({ * @type {Regex} */ hierarchySeparator: null, - + /** + * regex for finding the hierarchy root separator + * @example: + * null - turn off mulitple hierarchy roots + * /\|/ - split by `|` + * @type {Regex} + */ + hierarchyRootSeparator: null, /** * sidebar tree animations * @type {Boolean} */ sidebarAnimations: true, - /** * id to select an addon panel * @type {String} diff --git a/addons/options/src/preview/index.js b/addons/options/src/preview/index.js index c97b594824ac..b4eb3d67fab4 100644 --- a/addons/options/src/preview/index.js +++ b/addons/options/src/preview/index.js @@ -13,6 +13,14 @@ function regExpStringify(exp) { return null; } +function hasOwnProp(object, propName) { + return Object.prototype.hasOwnProperty.call(object, propName); +} + +function withRegexProp(object, propName) { + return hasOwnProp(object, propName) ? { [propName]: regExpStringify(object[propName]) } : {}; +} + // setOptions function will send Storybook UI options when the channel is // ready. If called before, options will be cached until it can be sent. export function setOptions(newOptions) { @@ -23,16 +31,13 @@ export function setOptions(newOptions) { ); } - let options = newOptions; - // since 'undefined' and 'null' are the valid values we don't want to - // override the hierarchySeparator if the prop is missing - if (Object.prototype.hasOwnProperty.call(newOptions, 'hierarchySeparator')) { - options = { - ...newOptions, - hierarchySeparator: regExpStringify(newOptions.hierarchySeparator), - }; - } + // override the hierarchySeparator or hierarchyRootSeparator if the prop is missing + const options = { + ...newOptions, + ...withRegexProp(newOptions, 'hierarchySeparator'), + ...withRegexProp(newOptions, 'hierarchyRootSeparator'), + }; channel.emit(EVENT_ID, { options }); } diff --git a/examples/cra-kitchen-sink/.storybook/config.js b/examples/cra-kitchen-sink/.storybook/config.js index 631e70c75c1f..3ee683d25cdd 100644 --- a/examples/cra-kitchen-sink/.storybook/config.js +++ b/examples/cra-kitchen-sink/.storybook/config.js @@ -13,7 +13,8 @@ setOptions({ showSearchBox: false, addonPanelInRight: true, sortStoriesByKind: false, - hierarchySeparator: /\/|\./, + hierarchySeparator: /\./, + hierarchyRootSeparator: /\|/, }); // deprecated usage of infoAddon diff --git a/examples/official-storybook/config.js b/examples/official-storybook/config.js index 8eb7037ca68b..b013ea08ee2c 100644 --- a/examples/official-storybook/config.js +++ b/examples/official-storybook/config.js @@ -1,7 +1,13 @@ /* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */ import { configure } from '@storybook/react'; +import { setOptions } from '@storybook/addon-options'; import 'react-chromatic/storybook-addon'; +setOptions({ + hierarchySeparator: /\/|\./, + hierarchyRootSeparator: /\|/, +}); + function loadStories() { let req; req = require.context('../../lib/ui/src', true, /\.stories\.js$/); diff --git a/examples/official-storybook/stories/__snapshots__/addon-a11y.stories.storyshot b/examples/official-storybook/stories/__snapshots__/addon-a11y.stories.storyshot index d85b387dd973..40a2739f4999 100644 --- a/examples/official-storybook/stories/__snapshots__/addon-a11y.stories.storyshot +++ b/examples/official-storybook/stories/__snapshots__/addon-a11y.stories.storyshot @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Storyshots Addon a11y Default 1`] = ` `; -exports[`Storyshots Addon a11y Invalid contrast 1`] = ` +exports[`Storyshots Addons|a11y Invalid contrast 1`] = ` `; -exports[`Storyshots Addon a11y Label 1`] = ` +exports[`Storyshots Addons|a11y Label 1`] = ` diff --git a/examples/official-storybook/stories/__snapshots__/addon-actions.stories.storyshot b/examples/official-storybook/stories/__snapshots__/addon-actions.stories.storyshot index d245eb9a062c..14d27e909bd3 100644 --- a/examples/official-storybook/stories/__snapshots__/addon-actions.stories.storyshot +++ b/examples/official-storybook/stories/__snapshots__/addon-actions.stories.storyshot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Storyshots Addon Actions All types 1`] = ` +exports[`Storyshots Addons|Actions All types 1`] = `
`; -exports[`Storyshots Addon Actions Decorated Action 1`] = ` +exports[`Storyshots Addons|Actions Decorated Action 1`] = ` `; -exports[`Storyshots Addon Actions Function Name 1`] = ` +exports[`Storyshots Addons|Actions Function Name 1`] = ` `; -exports[`Storyshots Addon Actions Hello World 1`] = ` +exports[`Storyshots Addons|Actions Hello World 1`] = ` `; -exports[`Storyshots Addon Actions Reserved keyword as name 1`] = ` +exports[`Storyshots Addons|Actions Reserved keyword as name 1`] = ` `; -exports[`Storyshots Addon Links.Button Second 1`] = ` +exports[`Storyshots Addons|Links.Button Second 1`] = ` `; -exports[`Storyshots Addon Links.Href log 1`] = ` +exports[`Storyshots Addons|Links.Href log 1`] = ` See action logger `; -exports[`Storyshots Addon Links.Link First 1`] = ` +exports[`Storyshots Addons|Links.Link First 1`] = ` @@ -26,7 +26,7 @@ exports[`Storyshots Addon Links.Link First 1`] = ` `; -exports[`Storyshots Addon Links.Link Second 1`] = ` +exports[`Storyshots Addons|Links.Link Second 1`] = ` @@ -34,7 +34,7 @@ exports[`Storyshots Addon Links.Link Second 1`] = ` `; -exports[`Storyshots Addon Links.Select First 1`] = ` +exports[`Storyshots Addons|Links.Select First 1`] = ` @@ -42,7 +42,7 @@ exports[`Storyshots Addon Links.Select First 1`] = ` `; -exports[`Storyshots Addon Links.Select Index 1`] = ` +exports[`Storyshots Addons|Links.Select Index 1`] = ` ); const TextArea = hoc(({ children }) => ); -storiesOf('Addon Info.GitHub issues', module).add( +storiesOf('Addons|Info.GitHub issues', module).add( '#1814', withInfo('Allow Duplicate DisplayNames for HOC #1814')(() => (
diff --git a/examples/official-storybook/stories/addon-jest.stories.js b/examples/official-storybook/stories/addon-jest.stories.js index a53ba301a683..3cb6f9135907 100644 --- a/examples/official-storybook/stories/addon-jest.stories.js +++ b/examples/official-storybook/stories/addon-jest.stories.js @@ -8,7 +8,7 @@ const withTestsFiles = withTests({ results, }); -storiesOf('Addon jest', module) +storiesOf('Addons|jest', module) .addDecorator(withTestsFiles('addon-jest')) .add('withTests', () => (
diff --git a/examples/official-storybook/stories/addon-knobs.stories.js b/examples/official-storybook/stories/addon-knobs.stories.js index c009a428cf18..d5ddfd0e7a55 100644 --- a/examples/official-storybook/stories/addon-knobs.stories.js +++ b/examples/official-storybook/stories/addon-knobs.stories.js @@ -45,7 +45,7 @@ class AsyncItemLoader extends React.Component { } } -storiesOf('Addon Knobs.withKnobs', module) +storiesOf('Addons|Knobs.withKnobs', module) .addDecorator(withKnobs) .add('tweaks static values', () => { const name = text('Name', 'Storyteller'); @@ -97,7 +97,7 @@ storiesOf('Addon Knobs.withKnobs', module)
)); -storiesOf('Addon Knobs.withKnobsOptions', module) +storiesOf('Addons|Knobs.withKnobsOptions', module) .addDecorator( withKnobsOptions({ debounce: { wait: 100, leading: boolean }, // Same as lodash debounce. diff --git a/examples/official-storybook/stories/addon-links.stories.js b/examples/official-storybook/stories/addon-links.stories.js index fada321e6a72..884cdfd58596 100644 --- a/examples/official-storybook/stories/addon-links.stories.js +++ b/examples/official-storybook/stories/addon-links.stories.js @@ -4,11 +4,11 @@ import { linkTo, hrefTo } from '@storybook/addon-links'; import LinkTo from '@storybook/addon-links/react'; import { action } from '@storybook/addon-actions'; -storiesOf('Addon Links.Link', module) +storiesOf('Addons|Links.Link', module) .add('First', () => Go to Second) .add('Second', () => Go to First); -storiesOf('Addon Links.Button', module) +storiesOf('Addons|Links.Button', module) .add('First', () => ( )) @@ -16,7 +16,7 @@ storiesOf('Addon Links.Button', module) )); -storiesOf('Addon Links.Select', module) +storiesOf('Addons|Links.Select', module) .add('Index', () => (