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 Addons|a11y Default 1`] = ``; -exports[`Storyshots Addon a11y Disabled 1`] = ` +exports[`Storyshots Addons|a11y Disabled 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`] = `