Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An example of how to use storybook-addon-info with real source files and readme support
const storyFiles = require.context('../src', true, /__stories__\/.+\.js$/)
const sources = require.context('!!raw-loader!../src', true,
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
const group = storiesOf(baseName, module)
group.addWithInfo(storyName, md, story, {inline: true, source: false, propTables: false})
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
You can’t perform that action at this time.