Skip to content

Latest commit

 

History

History
 
 

ember

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Storybook Docs for Ember

migration guide: This page documents the method to configure storybook introduced recently in 5.3.0, consult the migration guide if you want to migrate to this format of configuring storybook.

Storybook Docs transforms your Storybook stories into world-class component documentation. Storybook Docs for Ember supports DocsPage for auto-generated docs, and MDX for rich long-form docs.

To learn more about Storybook Docs, read the general documentation. To learn the Ember specifics, read on!

Installation

First add the package. Make sure that the versions for your @storybook/* packages match:

yarn add -D @storybook/addon-docs@next

Then add the following to your .storybook/main.js addons:

module.exports = {
  addons: ['@storybook/addon-docs'],
};

DocsPage

When you install docs you should get basic DocsPage documentation automagically for all your stories, available in the Docs tab of the Storybook UI.

Props tables for your components requires a few more steps. Docs for Ember relies on @storybook/ember-cli-storybook addon, 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:

let app = new EmberApp(defaults, {
  'ember-cli-storybook': {
    enableAddonDocsIntegration: true,
  },
});

Now, 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.

Next, add the following to your .storybook/preview.js to load the generated json file:

import { setJSONDoc } from '@storybook/addon-docs/ember';
import docJson from '../storybook-docgen/index.json';
setJSONDoc(docJson);

Finally, 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:

export default {
  title: 'App Component',
  component: 'AppComponent',
};

If you haven't upgraded from storiesOf, you can use a parameter to do the same thing:

import { storiesOf } from '@storybook/angular';

storiesOf('App Component', module)
  .addParameters({ component: 'AppComponent' })
  .add( ... );

MDX

MDX is a convenient way to document your components in Markdown and embed documentation components, such as stories and props tables, inline.

Docs has peer dependencies on react, react-is, and babel-loader. If you want to write stories in MDX, you'll need to add these dependencies as well:

yarn add -D react react-is babel-loader

Then update your .storybook/main.js to make sure you load MDX files:

module.exports = {
  stories: ['../src/stories/**/*.stories.(js|mdx)'],
};

Finally, you can create MDX files like this:

import { Meta, Story, Props } from '@storybook/addon-docs/blocks';
import { hbs } from 'ember-cli-htmlbars';

<Meta title='App Component' component='AppComponent' />

# App Component

Some **markdown** description, or whatever you want.

<Story name='basic' height='400px'>{{
  template: hbs`<AppComponent @title={{title}} />`,
context: { title: "Title" },
}}</Story>

## Props

<Props of='AppComponent' />

Yes, it's redundant to declare component twice. Coming soon.

Also, to use the Props doc block, you need to set up documentation generation, as described above.

IFrame height

Storybook Docs renders all Ember stories inside iframes, with a default height of 60px. You can update this default globally, or modify the iframe height locally per story in DocsPage and MDX.

To update the global default, modify .storybook/preview.js:

import { addParameters } from '@storybook/ember';

addParameters({ docs: { iframeHeight: 400 } });

For DocsPage, you need to update the parameter locally in a story:

export const basic = () => ...
basic.story = {
  parameters: { docs: { iframeHeight: 400 } }
}

And for MDX you can modify it as an attribute on the Story element:

<Story name='basic' height='400px'>{...}</Story>

More resources

Want to learn more? Here are some more articles on Storybook Docs: