Skip to content

Loader to use react-tsdoc blobs in Storybook Docs plugin (ArgsTable, Controls)

License

Notifications You must be signed in to change notification settings

noahbuscher/react-tsdoc-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-tsdoc-loader

react-tsdoc-loader allows for parsing of React components with react-tsdoc and injecting the result for use in Storybook, such as in:

Install

To install, first run the following in your root directory.

npm install -D react-tsdoc-loader

To add to storybook, add the following to your .storybook/main.js file:

module.exports = {
  typescript: {
    reactDocgen: false // Turns off Storybook's built-in docgen tools
  },
  webpackFinal: async (config, { configType }) => {
    // Run the loader on Typescript component files in your project
    config.module.rules.push({
      test: /\.tsx$/,
      use: ['react-tsdoc-loader'],
      include: path.resolve(__dirname, '../'),
      enforce: 'post'
    });
    
    return config;
  },
}

That's it! Now your docs will be visible in Storybook.

Writing Docs

This loader is powered by react-tsdoc and uses the @prop tag to document props. It will also inject if the prop is required, default value(s), and a lot of helpful type information.

An example component with a default value and description for a prop might look like this:

/**
 * Nice button
 *
 * @prop label - Label for the button
 */
const Button = ({
	label = 'Click me!'
}: {
	label: string
}) => (
  <button>{label}</button>
);

To learn more, visit the react-tsdoc.

About

Loader to use react-tsdoc blobs in Storybook Docs plugin (ArgsTable, Controls)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published