Git Product home page Git Product logo

addon-smart-knobs's Introduction

Smart knobs addon for Storybook

This Storybook plugin uses @storybook/addon-knobs but creates the knobs automatically based on PropTypes, Flow and Typescript.

Installation:

npm i storybook-addon-smart-knobs --save-dev

Usage:

import React from 'react'
import PropTypes from 'prop-types'
import { storiesOf } from '@storybook/react'
import { withKnobs } from '@storybook/addon-knobs'
import { withSmartKnobs } from 'storybook-addon-smart-knobs'

const Button = ({ children, onClick }) => (
  <button onClick={ onClick }>{ children }</button>
)

Button.propTypes = {
  children: PropTypes.node,
  onClick: PropTypes.func
}

storiesOf('Button')
  .addDecorator(withSmartKnobs(options))
  .addDecorator(withKnobs)
  .add('simple', () => <Button>Smart knobed button</Button>)

Options

  • ignoreProps

    Type: Array

    Will not automatically create knobs for props whose name is in this array. Example:

      .withSmartKnobs({ ignoreProps: ['numberProp'] })
      .add('example', () => <div numberProp={date('date', date)} />) 

Configuration:

This plugin has a peer dependency on babel-plugin-react-docgen . As a result, babel-plugin-react-docgen needs to be added to your Storybook Babel configuration.

For a standard Storybook configuration, add react-docgen to your plugins in an appropriate .babelrc file.

If you have created a webpack.config.js file for Storybook, you may need to configure the plugin in there.

module.exports = (baseConfig, env, defaultConfig) => {
  defaultConfig.module.rules[0].use[0].options.plugins = [
    require.resolve('babel-plugin-react-docgen'),
  ]

  return defaultConfig
}

Typescript:

Use react-docgen-typescript-loader to generate docgen info from Typescript types. This docgen info will be used to automatically create knobs.

addon-smart-knobs's People

Contributors

bhoomit avatar bhoomitt avatar chaopan avatar chrisjaure avatar chriszarate avatar dependabot[bot] avatar evless avatar flipace avatar ganapativs avatar gongreg avatar lucasconstantino avatar mei33 avatar ndelangen avatar nekitk avatar patrickdevivo avatar petermikitsh avatar rpellerin avatar shilman avatar strothj avatar thompsonsj avatar tkh44 avatar weslleyaraujo avatar whythat 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.