Last active
February 18, 2019 10:39
-
-
Save gnarf/ea9bd0f76e36516b6f1f38e4aba542a3 to your computer and use it in GitHub Desktop.
An example of how to use storybook-addon-info with real source files and readme support
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
const storyFiles = require.context('../src', true, /__stories__\/.+\.js$/) | |
const sources = require.context('!!raw-loader!../src', true, | |
/__stories__\/.+\.js$/) | |
const readme = require.context('!!raw-loader!../src', true, /README\.md$/) | |
const READMES = readme.keys().reduce((memo, key) => { | |
const [,baseName] = key.match(/^\.\/([^\/]+)\//) | |
memo[baseName] = readme(key) | |
return memo | |
}, {}) | |
const generateStories = storyFiles.keys() | |
generateStories.forEach(jsSource => { | |
const source = sources(jsSource) | |
const story = storyFiles(jsSource).default | |
// take the folder name | |
const [,baseName,storyName] = jsSource.match(/^\.\/([^\/]+)\/__stories__\/(.+)\.js$/) | |
const readmemd = READMES[baseName] ? `## README | |
${READMES[baseName]}` : '' | |
const md = `${readmemd} | |
## Story Source: | |
\`\`\` javascript | |
${source} | |
\`\`\` | |
` | |
const group = storiesOf(baseName, module) | |
group.addWithInfo(storyName, md, story, {inline: true, source: false, propTables: false}) | |
}) |
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 React from 'react' | |
import Button from '../Button' | |
import { action } from '@kadira/storybook' | |
export default () => <Button onClick={action('clicked')}>Button</Button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment