Socket
Socket
Sign inDemoInstall

@storybook/react-docgen-typescript-plugin

Package Overview
Dependencies
119
Maintainers
27
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @storybook/react-docgen-typescript-plugin

A webpack plugin to inject react typescript docgen information.


Version published
Weekly downloads
3.1M
increased by4.34%
Maintainers
27
Install size
1.05 MB
Created
Weekly downloads
 

Package description

What is @storybook/react-docgen-typescript-plugin?

The @storybook/react-docgen-typescript-plugin is a plugin for Storybook, designed to enhance the documentation of React components written in TypeScript. It automatically generates prop tables and documentation for your components based on the TypeScript definitions. This helps in creating more informative and readable Storybook stories, making it easier for developers to understand the props and functionalities of the components.

What are @storybook/react-docgen-typescript-plugin's main functionalities?

Automatic Prop Documentation

This feature automatically generates documentation for the props of React components based on their TypeScript definitions. The configuration snippet above shows how to set up the plugin in the `.storybook/main.js` file, enabling automatic prop documentation in Storybook.

module.exports = {
  stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    {
      name: '@storybook/preset-typescript',
      options: {
        reactDocgen: 'react-docgen-typescript',
        reactDocgenTypescriptOptions: {
          shouldExtractLiteralValuesFromEnum: true,
          propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
        },
      },
    },
  ],
};

Other packages similar to @storybook/react-docgen-typescript-plugin

Changelog

Source

v1.0.1 (Mon Mar 21 2022)

🐛 Bug Fix
  • fix: respect falsy custom options #49 (@zhzz)
Authors: 1

Readme

Source

react-docgen-typescript-plugin

A webpack plugin to inject react typescript docgen information

Install

npm install --save-dev react-docgen-typescript-plugin
# or
yarn add -D react-docgen-typescript-plugin

Usage

NOTE: The TypeScript compiler options allowSyntheticDefaultImports and esModuleInterop will make react-docgen-typescript-plugin a lot harder! Turn them off for faster build times.

const ts = require('typescript');
const ReactDocgenTypescriptPlugin = require("react-docgen-typescript-plugin").default;

module.exports = {
  plugins: [
    // Will default to loading your root tsconfig.json
    new ReactDocgenTypescriptPlugin(),
    // or with a specific tsconfig
    new ReactDocgenTypescriptPlugin({ tsconfigPath: "./tsconfig.dev.json" }),
    // or with compiler options
    new ReactDocgenTypescriptPlugin({ compilerOptions: { jsx: ts.JsxEmit.Preserve } }),
  ],
};

Options

This plugins support all parser options from react-docgen-typescript and all of the following options

OptionTypeDescriptionDefault
tsconfigPathstringSpecify the location of the tsconfig.json to use.null
compilerOptionsobjectSpecify compiler options. Cannot be used with tsconfigPathnull
docgenCollectionNamestring or nullSpecify the docgen collection name to use. All docgen information will be collected into this global object. Set to null to disable.STORYBOOK_REACT_CLASSES
setDisplayNamebooleanSet the components' display name. If you want to set display names yourself or are using another plugin to do this, you should disable this option.true
typePropNamestringSpecify the name of the property for docgen info prop type.type
excludeglob[]Glob patterns to ignore and not generate docgen information for. (Great for ignoring large icon libraries)[]
includeglob[]Glob patterns to generate docgen information for['**/**.tsx']

Debugging

If you want to see how this plugins is including and excluding modules set the DEBUG environment variable.

  • DEBUG=docgen:* - All logs
  • DEBUG=docgen:include - Included modules
  • DEBUG=docgen:exclude - Excluded modules
  • DEBUG=docgen:docs - Generated docs
DEBUG=docgen:* npm run storybook

Another great way of debugging your generated docs is to use a debugger statement in your component source file. If you turn off source maps you will be able to see the code that this package generates.

Prior Art

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Andrew Lisowski

💻 🎨 📖 🤔 🚧 🚇 ⚠️

Michael Shilman

💻

Kyle Herock

💻

Juho Vepsäläinen

🚇 ⚠️ 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords

FAQs

Last updated on 30 Jul 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc