1.1.5-rc.19 • Published 8 months ago

@digigov/docusaurus-plugin-docgen v1.1.5-rc.19

Weekly downloads
-
License
BSD-2-Clause
Repository
-
Last release
8 months ago

Docusaurus Plugin react-docgen-typescript

A Docusaurus 2.x plugin that help generate and consume auto-generated docs from react-docgen-typescript.

Installation

Grab from NPM and install along with react-docgen-typescript:

npm i docusaurus-plugin-react-docgen-typescript react-docgen-typescript # or
yarn add docusaurus-plugin-react-docgen-typescript react-docgen-typescript

Usage

Inside your docusaurus.config.js add to the plugins field and configure with the src option with full glob support :+1:.

module.exports = {
    // ...
    plugins: [
        [
            'docusaurus-plugin-react-docgen-typescript',
            {
                // pass in a single string or an array of strings
                src: ['path/to/**/*.tsx', '!path/to/**/*test.*'],
                global: true,
                parserOptions: {
                    // pass parserOptions to react-docgen-typescript
                    // here is a good starting point which filters out all
                    // types from react
                    propFilter: (prop, component) => {
                        if (prop.parent) {
                            return !prop.parent.fileName.includes('@types/react');
                        }

                        return true;
                    },
                },
            },
        ],
    ],
};

Any pattern supported by fast-glob is allowed here (including negations).

Generating Routes

By enabling createRoutes flag in the options, the following routes will be created:

  • {baseRoute}, listing all the components
  • {baseRoute}/{ComponentDisplayName}, rendering the component information (name, description, props)

You may also override the default interface by implementing the following components in your src/components folder:

  • <ReactComponentList />
  • <ReactComponent />
  • <PropTable />

Reading Annotations

Using the default settings, annotations are stored inside of the .docusaurus directory. The @docgen alias is set to ensure stable access to these files.

Build a Prop Table

Most of the time props will want to be shown as API information to a particular component. For convenience, we can use a simple hook from this package to dynamically import .json files:

import * as React from 'react';
import { useDynamicImport } from 'docusaurus-plugin-react-docgen-typescript/pkg/dist-src/hooks/useDynamicImport';

export const PropTable = ({ name }) => {
    const { props } = useDynamicImport(name);

    if (!props) {
        return null;
    }

    return (
        <table>
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Default Value</th>
                    <th>Required</th>
                    <th>Description</th>
                </tr>
            </thead>
            <tbody>
                {Object.keys(props).map(key => {
                    return (
                        <tr key={key}>
                            <td>
                                <code>{key}</code>
                            </td>
                            <td>
                                <code>{props[key].type?.name}</code>
                            </td>
                            <td>
                                {props[key].defaultValue && (
                                    <code>{props[key].defaultValue.value}</code>
                                )}
                            </td>
                            <td>{props[key].required ? 'Yes' : 'No'}</td>
                            <td>{props[key].description}</td>
                        </tr>
                    );
                })}
            </tbody>
        </table>
    );
};

Options

NameTypeRequiredDescription
srcstring | string[]YesTell react-docgen where to look for source files.
globalbooleanNoStore results so they're globally accessible in docusaurus
routeRouteConfigNoMakes docgen results accessible at the specified URL. Note modules cannot be overridden.
tsConfigstringNoSpecify the path to your custom tsconfig file (note that in most cases the default config is sufficient)
compilerOptionsCompilerOptionsNoPass custom ts compiler options in lieu of of a custom tsConfig
parserOptionsParserOptionsNoOptions passed to react-docgen-typescript
createRoutesbooleanNoWhether to create a route for each component
baseRoutestringNoWhen creating routes, defines the base route
1.1.5-60d81ed8

8 months ago

1.1.5-b4cd6916

8 months ago

1.1.5-rc.19

8 months ago

1.1.5-36b707c1

8 months ago

1.1.5-6e3977bc

9 months ago

1.1.5-daaf7bdf

9 months ago

1.1.5-113e6661

9 months ago

1.1.5-6c42d5eb

10 months ago

1.1.5-462194bf

1 year ago

1.1.5-2445d5cb

11 months ago

1.1.5-f0a886ce

11 months ago

1.1.5-rc.15

12 months ago

1.1.5-rc.14

12 months ago

1.1.5-rc.13

12 months ago

1.1.5-rc.12

12 months ago

1.1.5-rc.11

1 year ago

1.1.5-rc.10

1 year ago

1.1.5-rc.18

9 months ago

1.1.5-rc.17

11 months ago

1.1.5-rc.16

12 months ago

1.1.5-rc.8

1 year ago

1.1.5-rc.9

1 year ago

1.1.5-85c27c19

10 months ago

1.1.5-d57821ba

11 months ago

1.1.5-0edebf87

1 year ago

1.1.5-4be8f7cc

1 year ago

1.1.5-rc.7

1 year ago

1.1.5-fec6f1f7

1 year ago

1.1.5-7d9a8d86

1 year ago

1.1.5-rc.6

1 year ago

1.1.5-cbc56209

1 year ago

1.1.5-rc.3

1 year ago

1.1.5-rc.4

1 year ago

1.1.5-rc.5

1 year ago

1.1.5-rc.2

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

2 years ago

1.1.0-2a507fd6

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.0-rc.5

2 years ago

1.0.0-rc.6

2 years ago

1.0.0-51c931ab

2 years ago

1.0.0-23c81d9f

2 years ago

1.0.0-b0737a96

2 years ago

1.0.0-47312a12

2 years ago

1.0.0-rc.4

2 years ago

1.0.0-b4257f67

2 years ago

1.0.0-a131264d

2 years ago

1.0.0-8b33e4c8

2 years ago

1.0.0-8ae63a77

2 years ago

1.0.0-77ee23d9

2 years ago

1.0.0-eb2842b4

2 years ago

1.0.0-266e80f3

2 years ago

1.0.0-7c9716da

2 years ago

1.0.0-c768d137

2 years ago

1.0.0-290a96e2

2 years ago

1.0.0-002c630d

2 years ago

1.0.0-rc.3

2 years ago

1.0.0-rc.1

2 years ago

1.0.0-079f34f3d

2 years ago

1.0.0-rc.2

2 years ago

1.0.0-6c481065

2 years ago

1.0.0-75e5086d

2 years ago

0.7.10

2 years ago

0.7.9

2 years ago

1.0.0-758a1807

2 years ago

1.0.0-rc

2 years ago

1.0.0-60addd4a

2 years ago

1.0.0-05af31dd

2 years ago

1.0.0-8bbf3ef2

2 years ago

1.0.0-ab30975f

2 years ago

1.0.0-88820b1e

2 years ago

1.0.0-480e3d97

2 years ago

1.0.0-3bfc7d37

2 years ago

1.0.0-605437dc

2 years ago

1.0.0-e322b0cc

2 years ago

1.0.0-55e4210c

2 years ago

1.0.0-6b93ebf2

2 years ago

1.0.0-4e7b7994

2 years ago

1.0.0-00643e1d

2 years ago

1.0.0-21c8c3dc

2 years ago

1.0.0-871b6be5

2 years ago

0.7.6

2 years ago

0.7.5

2 years ago

0.7.8

2 years ago

0.7.7

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.7.0

2 years ago

0.6.10

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.6.3

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.2

3 years ago

0.5.0

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.4.1-alpha

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.2

3 years ago

0.4.2-alpha

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago