Skip to content

Instantly share code, notes, and snippets.

@lencioni
Created May 18, 2017 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lencioni/98e5c5f4b013fc340142ab1b7cd54ec9 to your computer and use it in GitHub Desktop.
Save lencioni/98e5c5f4b013fc340142ab1b7cd54ec9 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