1.4.2 • Published 4 years ago

storybook-addon-vue-info v1.4.2

Weekly downloads
19,697
License
MIT
Repository
github
Last release
4 years ago

Want to automatically generate beautiful docs or write stories in docs? Try Storybook Docs!

Docs Mode (docs-addon) is a successor of info-addon, and supports many frameworks/libraries, include Vue.js!


Build Status npm version Monthly download GitHub license code style: prettier

storybook-addon-vue-info

A Storybook addon that shows Vue component's information.

Requirements

  • @storybook/vue>=4.0.0

Getting started

First, install the addon.

npm install --save-dev storybook-addon-vue-info

# yarn add -D storybook-addon-vue-info

Then register in addons.js.

// .storybook/addons.js

// Don't forget "/lib/" !!
import 'storybook-addon-vue-info/lib/register'

And setup a webpack loader in order to extract component information with vue-docgen-api.

npm install --save-dev vue-docgen-loader vue-docgen-api

# yarn add -D vue-docgen-loader vue-docgen-api
// .storybook/webpack.config.js

// This example uses "Full control mode + default".
// If you are using other mode, add payload of `config.module.rules.push` to rules list.
module.exports = ({ config }) => {
  config.module.rules.push({
    test: /\.vue$/,
    loader: 'vue-docgen-loader',
    enforce: 'post'
  })

  return config
}

Usage

Add withInfo decorator then set info options to the story.

NOTE: info option is required for the addon. If you omit it, the addon does nothing.

import { storiesOf } from '@storybook/vue'

import { withInfo } from 'storybook-addon-vue-info'

storiesOf('MyComponent', module)
  .addDecorator(withInfo)
  .add(
    'foo',
    () => ({
      components: { MyAwesomeComponent },
      template: '<my-awesome-component/>'
    }),
    {
      info: {
        summary: 'Summary for MyComponent'
      }
    }
  )

You can set the addon as global decorator.

// config.js
import { addDecorator } from '@storybook/vue'

import { withInfo } from 'storybook-addon-vue-info'

addDecorator(withInfo)

To set default options, use setDefaults.

// .storybook/config.js
import { setDefaults } from 'storybook-addon-vue-info'

setDefaults({
  header: false
})

For more details, see live examples.

Options

NameData typeDefault valueDescription
headerbooleantrueWhether to show header or not.
sourcebooleantrueWhether to show source(usage) or not.
wrapperComponentComponentdefault wrapperOverride inline docs component.
previewClassNamestringundefinedClass name passed down to preview container.
previewStyleStyle objectundefinedStyle passed down to preview container.
summarystring''Summary for the story. Accepts Markdown.
components{ [name: string]: Component }\|nullnullDisplay info for these components. Same type as component's components property.
docsInPanelbooleantrueWhether to show docs in addon panel.
useDocgenbooleantrueWhether to use result of vue-docgen-api.
casing"kebab" \| "camel" \| "pascal" \| undefinedundefinedWhich case to use. For detailed usage, see below.

Valid casing options

{
  // Don't convert names
  casing: undefined
}

{
  // Show names in kebab-case
  casing 'kebab'
}

{
  // Show prop names in camelCase and
  // Show component names in PascalCase
  casing: 'camel' // or 'pascal'
}

{
  // Show prop names in camelCase and
  // Show component names in kebab-case
  casing: {
    props: 'camel',
    component: 'kebab'
  }
}

In addition to addon options, we have a component option.

Set descriptions manually

With vue-docgen-api, the addon automatically shows descriptions and types extracted by docgen (see example in vue-docgen-api README). However, if you want to explicitly specify desciprion for component props, events or slots, add description option for your story component.

Assume <my-awesome-component> have props label and visible.

storiesOf('MyComponent', module)
  .addDecorator(withInfo)
  .add(
    'foo',
    () => ({
      components: { MyAwesomeComponent },
      template: '<my-awesome-component/>',
      description: {
        MyAwesomeComponent: {
          props: {
            // These description will appear in `description` column in props table
            label: 'A label for my awesome component',
            visible: 'Whether component is visible or not'
          },
          events: {
            click: 'Event for user clicking the component'
          },
          slots: {
            default: 'Place text or icon here'
          }
        }
      }
    }),
    {
      info: true
    }
  )

For more detail, please take a look at live example.

Example

For real example, see example directory.

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.1

5 years ago

1.0.0-beta.0

5 years ago

1.0.0-alpha.9

5 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha.0

5 years ago

0.7.1

5 years ago

0.7.0

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago