-
-
Save 9oelM/c50c043f04bb0f6b3cb2639ac397010a to your computer and use it in GitHub Desktop.
React Storybook - Kitchen Sink
This file contains 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 { configure } from '@kadira/storybook' | |
import 'lib/semantic-ui/semantic-ui.global.less' | |
// Our project follows the convention of co-locating components with their stories. For example: | |
// Component/ | |
// Component.js | |
// Component.spec.js | |
// Component.stories.js | |
// index.js | |
const req = require.context('../src', true, /.stories.js$/) | |
/** | |
* @returns {void} | |
*/ | |
function loadStories () { | |
// Load all stories | |
req.keys().forEach(req) | |
// Load the "Kitchen Sink" story | |
require('./KitchenSink.stories.js') | |
} | |
configure(loadStories, module) |
This file contains 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
// This is using Semantic-UI-React for a grid system but the rendering can be handled however you want. | |
import { getStorybook, storiesOf } from '@kadira/storybook' | |
import { Grid, Header } from 'semantic-ui-react' | |
// Avoid infinite loop | |
const KITCHEN_SINK_TITLE = 'Kitchen Sink' | |
const renderStory = (story) => ( | |
<Grid.Row key={story.name} style={{ marginBottom: '1rem' }}> | |
<Grid.Column> | |
<Header as='h2' content={story.name} /> | |
{story.render()} | |
</Grid.Column> | |
</Grid.Row> | |
) | |
const renderStoryGroup = (group) => (group.kind !== KITCHEN_SINK_TITLE && | |
<Grid.Column key={group.kind}> | |
<Header as='h1' content={group.kind} /> | |
{group.stories.map(renderStory)} | |
</Grid.Column> | |
) | |
storiesOf('Kitchen Sink', module) | |
.add('everything', () => ( | |
<Grid padded columns={1}> | |
{getStorybook().map(renderStoryGroup)} | |
</Grid> | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment