Skip to content

Latest commit

 

History

History
95 lines (72 loc) · 3.12 KB

10-storybook.md

File metadata and controls

95 lines (72 loc) · 3.12 KB

Storybook

By default, muban includes @muban/storybook and @muban/storybook-addon-source to bring most of the existing Storybook experience to Muban.

It allows you to write your stories using the new Args format, and you can customize the rendered template using inline an hbs template, and optionally manipulate the passed data that is passed to your template.

The source addon will allow you to preview the source of your component files (template, styles, script and data) in the Storybook panels for reference.

Running

You can run the following commands

yarn storybook          # start the storybook app on port 6006
yarn build-storybook    # create a storybook build in /dist/storybook

Any of the normal storybook cli params apply here.

Setup

Some things to keep in mind when working with storybook:

Example

Just create a MyComponent.stories.ts file in your component folder.

You can have a look at the existing stories for the default preview components in this repo.

import { Meta } from '@muban/storybook/dist/client/preview/types-6-0';

// Most things are just normal storybook configuration
export default {
  title: 'My Component',
  component: require('./my-component'), // require your hbs file here, omitting the .hbs extension
  argTypes: {
    title: { control: 'text' },
    content: { control: 'text' },
  },
  parameters: {
    source: {
      data: require('./data/data.yaml'), // this is for your muban source addon
    },
    docs: {
      description: {
        component: 'Some additional docs description',
      },
    },
  },
} as Meta;


export const Default = () => ({
  // this template is optional, if you omit it, this is how it will be used by default
  template: `<hbs>
      {{> my-component @root }}
    </hbs>`,
});
Default.args = require('./data/data.yaml');


// reuse the above template and data, just configuring different args
export const Simple = Default.bind({});
Simple.args = require('./data/data-simple');


// do more custom things
export const Custom = (args) => ({
  // use any hbs syntax to create your custom story template
  template: `<hbs>
      <div style="width: 300px; margin: 0 auto;">
        {{> my-component @root }}
      </div>
    </hbs>`,
  // optionally return custom data, you can use the passed args here to modify/etc.
  data: {
    ...args,
    foo: 'bar'
  }
});