GithubHelp home page GithubHelp logo

spartez / storybook-addon-vue-info Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pocka/storybook-addon-vue-info

0.0 5.0 0.0 1.38 MB

Info addon for Vue components

Home Page: https://storybook-addon-vue-info.netlify.com/?path=/story/examples-basic-usage--simple-example

License: MIT License

JavaScript 32.50% Vue 21.83% CSS 6.51% TypeScript 39.16%

storybook-addon-vue-info's Introduction

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 custom webpack loader in order to extract component information with 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: 'storybook-addon-vue-info/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.

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

propsDescription

If you want to explicitly specify desciprion for component props, add propsDescription 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/>',
      propsDescription: {
        MyAwesomeComponent: {
          // These description will appear in `description` column in props table
          label: 'A label for my awesome component',
          visible: 'Whether component is visible or not'
        }
      }
    }),
    {
      info: true
    }
  )

Loader options

You can pass options for vue-docgen-api through loader options (e.g. module alias).

// .storybook/webpack.config.js

module.exports = ({ config }) => {
  config.module.rules.push({
    test: /\.vue$/,
    loader: 'storybook-addon-vue-info/loader',
    options: {
      docgenOptions: {
        // options for vue-docgen-api...
      }
    },
    enforce: 'post'
  })

  return config
}

Example

For real example, see example directory.

storybook-addon-vue-info's People

Contributors

adrianjost avatar dartist21 avatar devcrossnet avatar pocka avatar the1975 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.