UNPKG

7.86 kBMarkdownView Raw
1<center>
2 <img src="https://raw.githubusercontent.com/storybookjs/storybook/next/code/addons/docs/docs/media/hero.png" width="100%" />
3</center>
4
5# Storybook Docs
6
7> migration guide: This page documents the method to configure Storybook introduced recently in 7.0.0, consult the [migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) if you want to migrate to this format of configuring Storybook.
8
9Storybook Docs transforms your Storybook stories into world-class component documentation.
10
11**DocsPage.** Out of the box, all your stories get a `DocsPage`. `DocsPage` is a zero-config aggregation of your component stories, text descriptions, docgen comments, props tables, and code examples into clean, readable pages.
12
13**MDX.** If you want more control, `MDX` allows you to write long-form markdown documentation and include stories in one file. You can also use it to write pure documentation pages and embed them inside your Storybook alongside your stories.
14
15Just like Storybook, Docs supports every major view layer including React, Vue, Angular, HTML, Web components, Svelte, and many more.
16
17Read on to learn more:
18
19- [Storybook Docs](#storybook-docs)
20 - [DocsPage](#docspage)
21 - [MDX](#mdx)
22 - [Framework support](#framework-support)
23 - [Installation](#installation)
24 - [Be sure to check framework specific installation needs](#be-sure-to-check-framework-specific-installation-needs)
25 - [Preset options](#preset-options)
26 - [TypeScript configuration](#typescript-configuration)
27 - [More resources](#more-resources)
28
29## DocsPage
30
31When you [install Docs](#installation), every story gets a `DocsPage`. `DocsPage` pulls information from your stories, components, source code, and story metadata to construct a sensible, zero-config default.
32
33Click on the `Docs` tab to see it:
34
35<center>
36 <img src="https://raw.githubusercontent.com/storybookjs/storybook/next/code/addons/docs/docs/media/docs-tab.png" width="100%" />
37</center>
38
39For more information on how it works, see the [`DocsPage` reference](https://github.com/storybookjs/storybook/blob/next/code/addons/docs/docs/docspage.md).
40
41## MDX
42
43`MDX` is a syntax for writing long-form documentation with stories side-by-side in the same file. In contrast to `DocsPage`, which provides smart documentation out of the box, `MDX` gives you full control over your component documentation.
44
45Here's an example file:
46
47<!-- prettier-ignore-start -->
48
49```md
50import { Meta, Story, Canvas } from '@storybook/blocks';
51import * as CheckboxStories from './Checkbox.stories';
52
53<Meta title="MDX/Checkbox" of={CheckboxStories} />
54
55# Checkbox
56
57With `MDX` we can include a story for `Checkbox` right in the middle of our
58markdown documentation.
59
60<Canvas>
61 <Story of={CheckboxStories.Unchecked} />
62</Canvas>
63```
64
65<!-- prettier-ignore-end -->
66
67And here's how that's rendered in Storybook:
68
69<center>
70 <img src="https://raw.githubusercontent.com/storybookjs/storybook/next/code/addons/docs/docs/media/mdx-simple.png" width="100%" />
71</center>
72
73For more information on `MDX`, see the [`MDX` reference](https://github.com/storybookjs/storybook/blob/next/code/addons/docs/docs/mdx.md).
74
75## Framework support
76
77Storybook Docs supports all view layers that Storybook supports except for React Native (currently). There are some framework-specific features as well, such as props tables and inline story rendering. The following page captures the current state of support:
78
79[Framework Support](https://storybook.js.org/docs/react/api/frameworks-feature-support)
80
81**Note:** `#` = WIP support
82
83Want to add enhanced features to your favorite framework? Check out this [dev guide](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/multiframework.md)
84
85## Installation
86
87First add the package. Make sure that the versions for your `@storybook/*` packages match:
88
89```sh
90yarn add -D @storybook/addon-docs
91```
92
93Docs has peer dependencies on `react`. If you want to write stories in MDX, you may need to add this dependency as well:
94
95```sh
96yarn add -D react
97```
98
99Then add the following to your `.storybook/main.js`:
100
101```js
102export default {
103 stories: [
104 '../src/**/*.mdx', // 👈 Add this, to match your project's structure
105 '../src/**/*.stories.@(js|jsx|ts|tsx)',
106 ],
107 addons: [
108 '@storybook/addon-docs', // 👈 Also add this
109 ],
110};
111```
112
113If using in conjunction with the [storyshots add-on](https://github.com/storybookjs/storybook/blob/next/code/addons/storyshots-core/README.md), you will need to
114configure Jest to transform MDX stories into something Storyshots can understand:
115
116Add the following to your Jest configuration:
117
118```json
119{
120 "transform": {
121 "^.+\\.[tj]sx?$": "babel-jest",
122 "^.+\\.mdx$": "@storybook/addon-docs/jest-transform-mdx"
123 }
124}
125```
126
127### Be sure to check framework specific installation needs
128
129- [React](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/react) (covered here)
130- [Vue](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/vue)
131- [Angular](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/angular)
132- [Ember](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/ember)
133- [Web Components](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/web-components)
134- [Common setup (all other frameworks)](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/common)
135
136## Preset options
137
138The `addon-docs` preset has a few configuration options that can be used to configure its babel/webpack loading behavior. Here's an example of how to use the preset with options:
139
140```js
141export default {
142 addons: [
143 {
144 name: '@storybook/addon-docs',
145 options: {
146 jsxOptions: {},
147 csfPluginOptions: null,
148 mdxPluginOptions: {},
149 transcludeMarkdown: true,
150 },
151 },
152 ],
153};
154```
155
156`jsxOptions` are options that will be passed to `@babel/preset-react` for `.md` and `.mdx` files.
157
158`csfPluginOptions` is an object for configuring `@storybook/csf-plugin`. When set to `null` it tells docs not to run the `csf-plugin` at all, which can be used as an optimization, or if you're already using `csf-plugin` in your `main.js`.
159
160The `transcludeMarkdown` option enables mdx files to import `.md` files and render them as a component.
161
162```mdx
163import { Meta } from '@storybook/addon-docs';
164import Changelog from '../CHANGELOG.md';
165
166<Meta title="Changelog" />
167
168<Changelog />
169```
170
171## TypeScript configuration
172
173As of SB6 [TypeScript is zero-config](https://storybook.js.org/docs/react/configure/typescript) and should work with SB Docs out of the box. For advanced configuration options, refer to the [Props documentation](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/props-tables.md).
174
175## More resources
176
177Want to learn more? Here are some more articles on Storybook Docs:
178
179- References: [DocsPage](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/docspage.md) / [MDX](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/mdx.md) / [FAQ](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/faq.md) / [Recipes](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/recipes.md) / [Theming](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/theming.md) / [Props](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/props-tables.md)
180- Announcements: [Vision](https://medium.com/storybookjs/storybook-docs-sneak-peak-5be78445094a) / [DocsPage](https://medium.com/storybookjs/storybook-docspage-e185bc3622bf) / [MDX](https://medium.com/storybookjs/rich-docs-with-storybook-mdx-61bc145ae7bc) / [Framework support](https://medium.com/storybookjs/storybook-docs-for-new-frameworks-b1f6090ee0ea)
181- Example: [Storybook Design System](https://github.com/storybookjs/design-system)