NOTE: This README only for version ^5.0.0
. For older versions README_V4.md
All previous api should work correctly at ^5.0.0
and above. But vue users will need to change their import path, as vue commands have been moved to their own folder.
This addon is compatible with:
- Storybook for React (React example storybook)
- Storybook for Vue (Vue example storybook)
Features:
- Automatically generate props table (Only for React)
- Does not affect on story function. So Storybook Info works correctly now.
- 100% markdown support
- Code highlighting
- Accept multiple README (useful for hoc component - add component's and original component's README)
- Looks like Github's README
- Supports
<docs/>
tags for vue components (example-vue/components/MyButton/MyButton.vue).
Also it very useful because most projects and components already have README.md files. Now it is easy to add them into your Storybook.
Stories will be added with .addWithInfo method if Storybook Info Addon is installed.
npm install --save-dev storybook-readme
or
yarn add --dev storybook-readme
Nothing to do :)
Only if using Single File Components and want to use <docs>
tag at storybook documentation.
module.exports = storybookBaseConfig => {
storybookBaseConfig.module.rules.push({
resourceQuery: /blockType=docs/,
use: ['storybook-readme/vue/docs-loader', 'html-loader', 'markdown-loader'],
});
};
Define <docs>
tag inside vue module:
<docs>
Docs inside vue module
</docs>
<template>
<button class="button">
<slot></slot>
</button>
</template>
Use it to define docs at story:
import MyButton from '../components/MyButton/MyButton.vue';
storiesOf('Vue <docs>', module).addParameters({
readme: {
content: MyButton.__docs,
},
});
Register addon at .storybook/addons.js
import 'storybook-readme/register';
NOTE: It is possible to set addon's panel title
import registerWithPanelTitle from 'storybook-readme/registerWithPanelTitle';
registerWithPanelTitle('Docs');
Add decorator at .storybook/config.js
import { addDecorator, configure } from '@storybook/react';
import { addReadme } from 'storybook-readme';
addDecorator(addReadme);
function loadStories() {
require('../stories/index.js');
}
configure(loadStories, module);
Important 5.0 change: the core commands of this addon are now imported from different locations depending on the framework you're using. React, for example, will import its commands from the main folder, seen above, just as it was in
v4.0
. Vue, on the other hand, now has a vue specific import location. See below:
import { addDecorator, configure } from '@storybook/vue';
import { addReadme } from 'storybook-readme/vue'; // <---- Vue subpackage
addDecorator(addReadme);
function loadStories() {
require('../stories/index.js');
}
configure(loadStories, module);
Hope it is very simple.
import React from 'react';
import { storiesOf } from '@storybook/react';
import Button from '../components/Button';
import ButtonReadme from '../components/Button/README.md';
storiesOf('Buttons', module)
.addDecorator(withKnobs)
.addParameters({
readme: {
// Show readme before story
content: ButtonReadme,
// Show readme at the addons panel
sidebar: ButtonReadme,
},
})
.add('Button', () => <Button />);
It is possible to override docs for story
import React from 'react';
import { storiesOf } from '@storybook/react';
import Button from '../components/Button';
import ButtonReadme from '../components/Button/README.md';
storiesOf('Buttons', module)
.addDecorator(withKnobs)
.addParameters({
readme: {
content: ButtonReadme,
sidebar: ButtonReadme,
},
})
.add('Button', () => <Button />)
.add('Button', () => <Button />)
.add('Button', () => <Button />, {
readme: {
// override docs
content: CustomButtonReadme,
sidebar: CustomButtonReadme,
},
});
Will be applied for series of stories.
.addParameters({
readme: {
/**
* Accepts string (markdown) or array of strings
* string | Array<string>
*/
content: Readme,
/**
* Accepts string (markdown) or array of strings
* string | Array<string>
*/
sidebar: Readme,
/**
* Override theme values
*
* All theme values https://github.com/tuchk4/storybook-readme/blob/master/packages/storybook-readme/src/styles/githubMarkdownCss.js#L436
*/
theme: {},
/**
* Prism code theme
* Full list of theme https://github.com/PrismJS/prism-themes
* To be used with storybook-readme, naming of the code theme should be used in one of these styles. https://github.com/tuchk4/storybook-readme/tree/master/packages/storybook-readme/src/styles/prismCodeThemes
*/
codeTheme: 'github',
/**
* Wrapper for story. Usually used to set some styles
* NOTE: will be applied only for content docs (docs around the story)
*
* React: React.ReactNode
* Vue: Vue component
*/
StoryPreview: ({ children}) => <div>{children}</div>
/**
* Wrapper for hedaer docs. Usually used to set some styles
* NOTE: will be applied only for content docs (docs around the story)
*
* React: React.ReactNode
* Vue: Vue component
*/
HeaderPreview: ({ children}) => <div>{children}</div>
/**
* Wrapper for footer docs. Usually used to set some styles
* NOTE: will be applied only for content docs (docs around the story)
*
* React: React.ReactNode
* Vue: Vue component
*/
FooterPreview: ({ children}) => <div>{children}</div>
/**
* Wrapper for content and sidebar docs. Usually used to set some styles
* NOTE: will be applied only for content docs (docs around the story)
*
* React: React.ReactNode
* Vue: Vue component
*/
DocPreview: ({ children}) => <div>{children}</div>
},
})
Will be applied for all stories.
NOTE: that global configuration
is applied only for content docs (docs around the story).
import { addParameters } from '@storybook/react'; // or @storybook/vue for vuejs
import { configureReadme } from 'storybook-readme';
configureReadme({
/**
* Wrapper for story. Usually used to set some styles
* React: React.ReactNode
* Vue: Vue component
*/
StoryPreview: ({ children }) => <div>{children}</div>,
/**
* Wrapper for content and sidebar docs. Usually used to set some styles
* React: React.ReactNode
* Vue: Vue component
*/
DocPreview: ({ children }) => (
<div style={{ background: '#000' }}> {children}</div>
),
/**
* Wrapper for hedaer docs. Usually used to set some styles
* React: React.ReactNode
* Vue: Vue component
*/
HeaderPreview: ({ children }) => (
<div style={{ background: 'red' }}>{children}</div>
),
/**
* Wrapper for footer docs. Usually used to set some styles
* React: React.ReactNode
* Vue: Vue component
*/
FooterPreview: ({ children }) => <div>{children}</div>,
/**
* Header docs in markdown format
*/
header: '',
/**
* Footer docs in markdown format
*/
footer: '',
});
addParameters({
readme: {
// You can set a code theme globally.
codeTheme: 'github',
},
});
<!-- STORY -->
placeholder for story<!-- PROPS -->
placeholder for props table. There are some issue with props parsing. Clarification issue#137<!-- STORY HIDE START -->
,<!-- STORY HIDE END -->
content enclosed by the tags won't be shown in stories
Button variants could be imported separately.
\`\`\`js import { OutlinedButton, ContainedButton, TextButton } from 'Button'; \`\`\`
<!-- PROPS -->
Example:
<!-- STORY -->
<!-- STORY HIDE START -->
content here won't be shown in stories
<!-- STORY HIDE END -->
Some docs after story
Use shortcodes between colon to insert emoji into the docs. For example
Here is rocket π
Here is rocket π
List of all shortcodes could be found at Emojipedia or at Gist/rxaviers
- π
- π
- π
Feel free to suggest new features or report bugs :)
Full docs for previous api are at README_V4.md
TL;DR:
Accepts README or array of README in markdown format. Multiple README is useful when you develop higher order components and want to add multiple READMEs along with the original component docs.
Renders README at the addons panel.
import { withReadme } from 'storybook-readme';
import withReadme from 'storybook-readme/with-readme';
// as HigherOrder Component
storiesOf('Button', module).add(
'Default',
withReadme(ButtonReadme, () => <Button />),
);
// as Decorator
storiesOf('Button', module)
.addDecorator(withReadme(ButtonReadme))
.add('Default', () => <Button />);
Renders README around the story.
import { withDocs } from 'storybook-readme';
import withDocs from 'storybook-readme/with-docs';
// as HigherOrder Component
storiesOf('Button', module).add(
'Default',
withDocs(ButtonReadme, () => <Button />),
);
// as Decorator
storiesOf('Button', module)
.addDecorator(withDocs(ButtonReadme))
.add('Default', () => <Button />);
Renders README in main frame without story.
import { docs } from 'storybook-readme';
storiesOf('Button', module).add('Default', () => docs(ButtonReadme));