Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@9oelM
Forked from jeffcarbs/KitchenSink.stories.js
Created October 29, 2020 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9oelM/c50c043f04bb0f6b3cb2639ac397010a to your computer and use it in GitHub Desktop.
Save 9oelM/c50c043f04bb0f6b3cb2639ac397010a to your computer and use it in GitHub Desktop.
React Storybook - Kitchen Sink
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 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