Skip to content

Commit

Permalink
Merge pull request #1545 from storybooks/regExpStringify
Browse files Browse the repository at this point in the history
Add RegExp option for hierarchySeparator
  • Loading branch information
usulpro committed Jul 30, 2017
2 parents 7ecadce + 4cad0b0 commit b02fec0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
13 changes: 12 additions & 1 deletion addons/options/src/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ export function init() {
// NOTE nothing to do here
}

function regExpStringify(exp) {
if (typeof exp === 'string') return exp;
if (Object.prototype.toString.call(exp) === '[object RegExp]') return exp.source;
return null;
}

// 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(options) {
export function setOptions(newOptions) {
const channel = addons.getChannel();
if (!channel) {
throw new Error(
'Failed to find addon channel. This may be due to https://github.com/storybooks/storybook/issues/1192.'
);
}
const options = {
...newOptions,
hierarchySeparator: regExpStringify(newOptions.hierarchySeparator),
};

channel.emit(EVENT_ID, { options });
}
2 changes: 1 addition & 1 deletion examples/cra-kitchen-sink/.storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ setOptions({
showSearchBox: false,
downPanelInRight: true,
sortStoriesByKind: false,
hierarchySeparator: '\\/|\\.|¯\\\\_\\(ツ\\)_\\/¯'
hierarchySeparator: /\/|\./,
});

setAddon(infoAddon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1605,31 +1605,31 @@ exports[`Storyshots Cells/Molecules with text 1`] = `
</button>
`;

exports[`Storyshots Cells/Molecules/Atoms.more with some emoji2 1`] = `
exports[`Storyshots Cells/Molecules.Atoms/simple with some emoji 1`] = `
<button
className="css-1yjiefr"
>
😀 😎 👍 💯
</button>
`;

exports[`Storyshots Cells/Molecules/Atoms.more with text2 1`] = `
exports[`Storyshots Cells/Molecules.Atoms/simple with text 1`] = `
<button
className="css-1yjiefr"
>
Hello Button
</button>
`;

exports[`Storyshots Cells¯\\_(ツ)_/¯Molecules.Atoms/simple with some emoji 1`] = `
exports[`Storyshots Cells/Molecules/Atoms.more with some emoji2 1`] = `
<button
className="css-1yjiefr"
>
😀 😎 👍 💯
</button>
`;

exports[`Storyshots Cells¯\\_(ツ)_/¯Molecules.Atoms/simple with text 1`] = `
exports[`Storyshots Cells/Molecules/Atoms.more with text2 1`] = `
<button
className="css-1yjiefr"
>
Expand Down
2 changes: 1 addition & 1 deletion examples/cra-kitchen-sink/src/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ storiesOf('component.Button', module)

// Atomic

storiesOf('Cells¯\\_(ツ)_/¯Molecules.Atoms/simple', module)
storiesOf('Cells/Molecules.Atoms/simple', module)
.addDecorator(withKnobs)
.add('with text', () =>
<Button>
Expand Down

0 comments on commit b02fec0

Please sign in to comment.