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

Add RegExp option for hierarchySeparator #1545

Merged
merged 4 commits into from
Jul 30, 2017
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
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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen if null will be passed here ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be ignored

};

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢 ok..

.addDecorator(withKnobs)
.add('with text', () =>
<Button>
Expand Down