Created
November 1, 2016 17:03
-
-
Save jeffcarbs/ef81004e53fc755bbb84a23146fb3a24 to your computer and use it in GitHub Desktop.
React Storybook - Kitchen Sink
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 { 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 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
// 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
This looks interesting , can you suggest how to use this with angular SB , as i am stuck with how to render in angular
i can't wrap my head around how angular renders in this case