Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

storybook-addon-vue-info

pocka9.6kMIT1.4.2TypeScript support: included

Storybook addon that shows Vue component information

vue, storybook

readme

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!


logo

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

Name Data type Default value Description
header boolean true Whether to show header or not.
source boolean true Whether to show source(usage) or not.
wrapperComponent Component default wrapper Override inline docs component.
previewClassName string undefined Class name passed down to preview container.
previewStyle Style object undefined Style passed down to preview container.
summary string '' Summary for the story. Accepts Markdown.
components { [name: string]: Component }|null null Display info for these components. Same type as component's components property.
docsInPanel boolean true Whether to show docs in addon panel.
useDocgen boolean true Whether to use result of vue-docgen-api.
casing "kebab" | "camel" | "pascal" | undefined undefined Which 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.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

[1.4.2] - 2020-02-24

Fixed

  • Stringify function props' default value. (Issue: #126, PR: #127)

[1.4.1] - 2019-12-19

Fixed

  • Fix incorrect component detection.

[1.4.0] - 2019-12-11

Added

  • Add casing option. (Issue: #122, PR: #123)

[1.3.4] - 2019-11-15

Fixed

  • Fix compatibility issue with vue-docgen-api@4.

[1.3.3] - 2019-11-14

Deprecated

  • Deprecate the custom loader in favor of vue-docgen-loader. (PR: #121)

[1.3.2] - 2019-09-24

Fixed

  • Do not reset preview style with all: initial. (Issue: #21, PR: #115)

[1.3.1] - 2019-09-07

Fixed

  • Ignore story decorators. (Issue: #50, PR: #113)

[1.3.0] - 2019-08-26

Added

  • Add description story option, which supports descriptions for props, events and slots.

Deprecated

  • Deprecate propsDescription in favor of description.

[1.2.3] - 2019-08-15

Security

  • Bump marked from 0.6.2 to 0.7.0. (Issue: #110, Vulnerability detail: npm)

[1.2.2] - 2019-07-26

Fixed

  • Get default value only if prop is specified as an object. (Issue: #107, PR: #108)

[1.2.1] - 2019-06-06

Fixed

  • Styling problems in props table on narrow screen/addon-panel (PR: #103)

[1.2.0] - 2019-05-11

Added

  • previewClassName and previewStyle option (Issue: #93, PR: #98)

[1.1.2] - 2019-05-11

Fixed

  • Show any for prop type when the prop has no type field (Issue: #95, PR: #97)

[1.1.1] - 2019-04-20

Fixed

  • Use dedent-tabs, which is a fork of dedent, to support tab dedenting. (Issue: #79, PR: #90)

[1.1.0] - 2019-04-20

Added

  • Allow passing options for vue-docgen-api (PR: #86).
  • Show error message if vue-docgen-api fails to parse component (PR: #85).

Fixed

  • Remove global affecting highlight.js' CSS (PR: #87).

[1.0.1] - 2019-03-21

Fixed

  • Fix re-render issue (only when using docsInPanel = true).

[1.0.0] - 2019-03-06

Changed

  • BREAKING: Adapt to the latest decorator API. You need to specify the info parameters for each story (can omit by setting default).
  • BREAKING: propTables option changed to components.
  • BREAKING: propsDescription now takes the components' name as a key.
  • Massive changes to UI.

Removed

  • BREAKING: Support for SB3.
  • propTablesExclude option.

Added

  • Support for SB4&5.
  • docsInPanel option to show the info in an addon panel (enabled by default)
  • Added a webpack loader parsing Vue components with vue-docgen-api. Thanks to this feature, you can see info for events and slots, and show info exists in mixins or inherited components.

[0.7.1] - 2019-01-23

Fixed

  • Display class name when prop type is class (PR: #64)