UNPKG

5.71 kBMarkdownView Raw
1<h1>Storybook Docs for Ember</h1>
2
3> migration guide: This page documents the method to configure storybook introduced recently in 5.3.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.
4
5Storybook Docs transforms your Storybook stories into world-class component documentation. Storybook Docs for Ember supports [DocsPage](../docs/docspage.md) for auto-generated docs, and [MDX](../docs/mdx.md) for rich long-form docs.
6
7To learn more about Storybook Docs, read the [general documentation](../README.md). To learn the Ember specifics, read on!
8
9- [Installation](#installation)
10- [DocsPage](#docspage)
11- [Props tables](#props-tables)
12- [MDX](#mdx)
13- [IFrame height](#iframe-height)
14- [More resources](#more-resources)
15
16## Installation
17
18First add the package. Make sure that the versions for your `@storybook/*` packages match:
19
20```sh
21yarn add -D @storybook/addon-docs@next
22```
23
24Then add the following to your `.storybook/main.js` addons:
25
26```js
27module.exports = {
28 addons: ['@storybook/addon-docs'],
29};
30```
31
32## DocsPage
33
34When you [install docs](#installation) you should get basic [DocsPage](../docs/docspage.md) documentation automagically for all your stories, available in the `Docs` tab of the Storybook UI.
35
36## Props tables
37
38Getting [Props tables](../docs/props-tables.md) for your components requires a few more steps. Docs for Ember relies on [@storybook/ember-cli-storybook addon](https://github.com/storybookjs/ember-cli-storybook), to extract documentation comments from your component source files. If you're using Storybook with Ember, you should already have this addon installed, you will just need to enable it by adding the following config block in your `ember-cli-build.js` file:
39
40```js
41let app = new EmberApp(defaults, {
42 'ember-cli-storybook': {
43 enableAddonDocsIntegration: true,
44 },
45});
46```
47
48Now, running the ember-cli server will generate a JSON documentation file at `/storybook-docgen/index.json`. Since generation of this file is tied into the ember-cli build, it will get regenerated everytime component files are saved. For details on documenting your components, check out the examples in the addon that powers the generation [ember-cli-addon-docs-yuidoc](https://github.com/ember-learn/ember-cli-addon-docs-yuidoc#documenting-components).
49
50Next, add the following to your `.storybook/preview.js` to load the generated json file:
51
52```js
53import { setJSONDoc } from '@storybook/addon-docs/ember';
54import docJson from '../storybook-docgen/index.json';
55setJSONDoc(docJson);
56```
57
58Finally, be sure to fill in the `component` field in your story metadata. This should be a string that matches the name of the `@class` used in your souce comments:
59
60```ts
61export default {
62 title: 'App Component',
63 component: 'AppComponent',
64};
65```
66
67If you haven't upgraded from `storiesOf`, you can use a parameter to do the same thing:
68
69```ts
70import { storiesOf } from '@storybook/angular';
71
72storiesOf('App Component', module)
73 .addParameters({ component: 'AppComponent' })
74 .add( ... );
75```
76
77## MDX
78
79[MDX](../docs/mdx.md) is a convenient way to document your components in Markdown and embed documentation components, such as stories and props tables, inline.
80
81Docs has peer dependencies on `react`. If you want to write stories in MDX, you may need to add this dependency as well:
82
83```sh
84yarn add -D react
85```
86
87Then update your `.storybook/main.js` to make sure you load MDX files:
88
89```js
90module.exports = {
91 stories: ['../src/stories/**/*.stories.@(js|mdx)'],
92};
93```
94
95Finally, you can create MDX files like this:
96
97```md
98import { Meta, Story, ArgsTable } from '@storybook/addon-docs';
99import { hbs } from 'ember-cli-htmlbars';
100
101<Meta title='App Component' component='AppComponent' />
102
103# App Component
104
105Some **markdown** description, or whatever you want.
106
107<Story name='basic' height='400px'>{{
108 template: hbs`<AppComponent @title={{title}} />`,
109context: { title: "Title" },
110}}</Story>
111
112## ArgsTable
113
114<ArgsTable of='AppComponent' />
115```
116
117Yes, it's redundant to declare `component` twice. [Coming soon](https://github.com/storybookjs/storybook/issues/8673).
118
119Also, to use the `Props` doc block, you need to set up documentation generation, [as described above](#docspage).
120
121## IFrame height
122
123Storybook Docs renders all Ember stories inside `iframe`s, with a default height of `60px`. You can update this default globally, or modify the `iframe` height locally per story in `DocsPage` and `MDX`.
124
125To update the global default, modify `.storybook/preview.js`:
126
127```ts
128import { addParameters } from '@storybook/ember';
129
130addParameters({ docs: { iframeHeight: 400 } });
131```
132
133For `DocsPage`, you need to update the parameter locally in a story:
134
135```ts
136export const basic = () => ...
137basic.parameters = {
138 docs: { iframeHeight: 400 }
139}
140```
141
142And for `MDX` you can modify it as an attribute on the `Story` element:
143
144```md
145<Story name='basic' height='400px'>{...}</Story>
146```
147
148## More resources
149
150Want to learn more? Here are some more articles on Storybook Docs:
151
152- References: [DocsPage](../docs/docspage.md) / [MDX](../docs/mdx.md) / [FAQ](../docs/faq.md) / [Recipes](../docs/recipes.md) / [Theming](../docs/theming.md) / [Props](../docs/props-tables.md)
153- 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)
154- Example: [Storybook Design System](https://github.com/storybookjs/design-system)