Created
May 18, 2017 20:17
-
-
Save lencioni/98e5c5f4b013fc340142ab1b7cd54ec9 to your computer and use it in GitHub Desktop.
Building Storybook stories with allExamples.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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