All Projects → storybookjs → Babel Plugin React Docgen

storybookjs / Babel Plugin React Docgen

Licence: mit
📝 Babel plugin to add react-docgen info into your code.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Babel Plugin React Docgen

babel-plugin-storybook-csf-title
A Babel plugin to generate titles for Storybook CSF stories at compile time, typically based on the story file's file name.
Stars: ✭ 17 (-89.1%)
Mutual labels:  babel-plugin, storybook
Vue Storybook
Custom <story> blocks for Vue single file components
Stars: ✭ 147 (-5.77%)
Mutual labels:  storybook
Mdx Embed
Embed 3rd party media content in MDX - no import required 🧽
Stars: ✭ 119 (-23.72%)
Mutual labels:  storybook
Storybook Addon Console
storybook-addon. Redirects console output into action logger panel
Stars: ✭ 138 (-11.54%)
Mutual labels:  storybook
Storybook Addon
Develop themable components with Emotion/Styled Components/Material-UI with help of Storybook & React Theming
Stars: ✭ 122 (-21.79%)
Mutual labels:  storybook
Typescript With Electron React Kit
Don't just start your Electron app... TWERKit.
Stars: ✭ 143 (-8.33%)
Mutual labels:  storybook
Antd Data Table
A component that combines antd's Table and Form to do the search, display, and operating jobs for data.
Stars: ✭ 119 (-23.72%)
Mutual labels:  storybook
Workflow Reactjs
My workflow with ReactJS + Webpack 3+
Stars: ✭ 150 (-3.85%)
Mutual labels:  storybook
Babel Plugin Transform Incremental Dom
Turn JSX into IncrementalDOM
Stars: ✭ 146 (-6.41%)
Mutual labels:  babel-plugin
Babel Plugin Polished
Compile polished helper functions at build time
Stars: ✭ 133 (-14.74%)
Mutual labels:  babel-plugin
React Storybook Addon Props Combinations
Given possible values for each prop, renders your component with all combinations of prop values.
Stars: ✭ 130 (-16.67%)
Mutual labels:  storybook
Reactivetradercloud
Real-time FX trading showcase by Adaptive.
Stars: ✭ 1,664 (+966.67%)
Mutual labels:  storybook
Extract React Types
One stop shop to document your react components.
Stars: ✭ 141 (-9.62%)
Mutual labels:  babel-plugin
React95
A React components library with Win95 UI
Stars: ✭ 1,779 (+1040.38%)
Mutual labels:  storybook
Storybook
Storybook integration with Nuxt.js
Stars: ✭ 148 (-5.13%)
Mutual labels:  storybook
Buffer Components
Buffer's shared collection of React UI components 🤜🤛
Stars: ✭ 120 (-23.08%)
Mutual labels:  storybook
React Responsive Carousel
React.js Responsive Carousel (with Swipe)
Stars: ✭ 1,962 (+1157.69%)
Mutual labels:  storybook
Babel Plugin Transform Typescript Metadata
Babel plugin to emit decorator metadata like typescript compiler
Stars: ✭ 142 (-8.97%)
Mutual labels:  babel-plugin
Babel Plugin Object To Json Parse
This plugin converts object literal to JSON.parse
Stars: ✭ 151 (-3.21%)
Mutual labels:  babel-plugin
React Storybook Addon Chapters
📒 Showcase multiple React components within a story
Stars: ✭ 149 (-4.49%)
Mutual labels:  storybook

babel-plugin-react-docgen

react-docgen allows you to write propType descriptions, class descriptions and access propType metadata programatically.

This babel plugin allow you to access those information right inside your React class.

For an example, let's say you've a React class like this:

/**
  This is an awesome looking button for React.
*/
import React from 'react';

export default class Button extends React.Component {
  render() {
    const { label, onClick } = this.props;
    return (
      <button onClick={onClick}>{ label }</button>
    );
  }
}

Button.propTypes = {
  /**
    Label for the button.
  */
  label: React.PropTypes.string,

  /**
    Triggered when clicked on the button.
  */
  onClick: React.PropTypes.func,
};

With this babel plugin, you can access all these information right inside your app with:

console.log(Button.__docgenInfo);
Click to see the output
{
  description: 'This is an awesome looking button for React.',
  props: {
    label: {
      type: {
        name: 'string'
      },
      required: false,
      description: 'Label for the button.'
    },
    onClick: {
      type: {
        name: 'func'
      },
      required: false,
      description: 'Triggered when clicked on the button.'
    }
  }
}

This will be pretty useful for documentations and some other React devtools like Storybook.

Usage

Install the plugin:

npm install -D babel-plugin-react-docgen

Use it inside your .babelrc

{
  "plugins": ["react-docgen"]
}

.babelrc Options

option description default
resolver You may use the 3 built-in react-docgen resolvers by specifying its name as a string, or you may specify a custom resolver by specifying the function explicitly. "findAllExportedComponentDefinition"
handlers All react-docgen handlers are automatically applied. However, custom handlers can be added by specifying them here. Any string value will be loaded by require, and a function will be used directly.
removeMethods Used to remove docgen information about methods. false
DOC_GEN_COLLECTION_NAME The name of a global variable where all docgen information can be stored. See below for more information.
...options Remaining options will be passed directly as react-docgen options. Any options they allowed will be passed through, but the filename will be overwritten by the filename provided by babel.

Collect All Docgen Info

Sometimes, it's a pretty good idea to collect all of the docgen info into a collection. Then you could use that to render style guide or similar.

So, we allow you to collect all the docgen info into a global collection. To do that, add following config to when loading this babel plugin:

{
  "plugins":[
    [
      "babel-plugin-react-docgen",
      {
        "DOC_GEN_COLLECTION_NAME": "MY_REACT_DOCS",
        "resolver": "findAllComponentDefinitions", // optional (default: findAllExportedComponentDefinitions)
        "removeMethods": true, // optional (default: false)
        "handlers": ["react-docgen-deprecation-handler"] // optional array of custom handlers
      }
    ]
  ]
}

Then you need to create a global variable(an object) in your app called MY_REACT_DOCS before any code get's executed. Then we'll save them into that object. We do it by adding a code block like this to the transpiled file:

if (typeof MY_REACT_DOCS !== 'undefined') {
  MY_REACT_DOCS['test/fixtures/case4/actual.js'] = {
    name: 'Button',
    docgenInfo: Button.__docgenInfo,
    path: 'path/to/my/button.js'
  };
}

Compile Performance

We parse your code with react-docgen to get this info, but we only do it for files which contain a React component.

There will be some overhead to your project, but you can leverage babel's cache directory to avoid this a huge performance hit.

Output Size

Yes this increase the output size of your transpiled files. The size increase varies depending on various factors like:

  • How many react classes you've
  • Amount of docs you've written
  • Amount of propTypes you've

Most of the time, you need this plugin when you are developing your app or with another tool like Storybook. So, you may not need to use this on the production version of your app.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].