Skip to content

Instantly share code, notes, and snippets.

@pbt001
Forked from lencioni/story.js
Created May 28, 2020 20:04
Show Gist options
  • Save pbt001/1cedabe86a820bd8e36f48bc7e1a7e70 to your computer and use it in GitHub Desktop.
Save pbt001/1cedabe86a820bd8e36f48bc7e1a7e70 to your computer and use it in GitHub Desktop.
Building Storybook stories with allExamples.js
import { storiesOf, action } from '@kadira/storybook';
import { browserDLSExamples } from '../examples/allExamples';
import fixtures from '../examples/fixtures';
const { DLSExamples, DLSComponents } = browserDLSExamples();
Object.entries(DLSExamples).forEach(([name, examplesFunc]) => {
let story = storiesOf(name, module);
const {
component,
examples,
isPrivate,
tags,
usage,
isDeprecated: isStoryDeprecated,
} = examplesFunc(DLSComponents, { action, fixtures });
examples.forEach(({
render,
description,
noStory,
isDeprecated,
}) => {
if (noStory) return null;
if (tags) {
story = story.withTags(...tags);
}
if (isPrivate) {
story = story.private();
}
if (usage) {
story = story.usage(usage);
}
// setDeprecated needs to be called on every story to prevent leaking state
// between examples. Otherwise every example following a deprecated one will
// also show as deprecated.
story = story.setDeprecated({
isDeprecated: isStoryDeprecated || isDeprecated,
isExample: !isStoryDeprecated,
});
return story.addWithSource(
description,
render,
component || DLSComponents[name],
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment