11# Docusaurus Plugin ` react-docgen-typescript `
22
3- A Docusaurus 2.x plugin that help generate and consume auto-generated docs from ` react-docgen-typescript ` .
3+ A Docusaurus 2.x plugin that help generate and consume auto-generated docs from
4+ ` react-docgen-typescript ` .
45
56## Installation
67
@@ -13,7 +14,8 @@ yarn add docusaurus-plugin-react-docgen-typescript react-docgen-typescript
1314
1415## Usage
1516
16- Inside your ` docusaurus.config.js ` add to the ` plugins ` field and configure with the ` src ` option with full glob support :+1 : .
17+ Inside your ` docusaurus.config.js ` add to the ` plugins ` field and configure with the ` src ` option
18+ with full glob support :+1 : .
1719
1820``` js
1921module .exports = {
@@ -26,6 +28,9 @@ module.exports = {
2628 src: [' path/to/**/*.tsx' , ' !path/to/**/*test.*' ],
2729 global: true ,
2830 parserOptions: {
31+ // pass parserOptions to react-docgen-typescript
32+ // here is a good starting point which filters out all
33+ // types from react
2934 propFilter : (prop , component ) => {
3035 if (prop .parent ) {
3136 return ! prop .parent .fileName .includes (' @types/react' );
@@ -40,7 +45,62 @@ module.exports = {
4045};
4146```
4247
43- Any pattern supported by [ ` fast-glob ` ] ( https://github.com/mrmlnc/fast-glob ) is allowed here (including negations).
48+ Any pattern supported by [ ` fast-glob ` ] ( https://github.com/mrmlnc/fast-glob ) is allowed here
49+ (including negations).
50+
51+ ## Reading Annotations
52+
53+ Using the default settings, annotations are stored inside of the ` .docusaurus ` directory. The
54+ ` @docgen ` alias is set to ensure stable access to these files.
55+
56+ ### Build a Prop Table
57+
58+ Most of the time props will want to be shown as API information to a particular component. For
59+ convenience, we can use a simple hook from this package to dynamically import ` .json ` files:
60+
61+ ``` jsx
62+ import * as React from ' react' ;
63+ import { useDynamicImport } from ' docusaurus-plugin-react-docgen-typescript/pkg/dist-src/hooks/useDynamicImport' ;
64+
65+ export const PropTable = ({ name }) => {
66+ const props = useDynamicImport (name);
67+
68+ return (
69+ < table>
70+ < thead>
71+ < tr>
72+ < th> Name< / th>
73+ < th> Type< / th>
74+ < th> Default Value< / th>
75+ < th> Required< / th>
76+ < th> Description< / th>
77+ < / tr>
78+ < / thead>
79+ < tbody>
80+ {Object .keys (props).map (key => {
81+ return (
82+ < tr key= {key}>
83+ < td>
84+ < code> {key}< / code>
85+ < / td>
86+ < td>
87+ < code> {props[key].type ? .name }< / code>
88+ < / td>
89+ < td>
90+ {props[key].defaultValue && (
91+ < code> {props[key].defaultValue .value }< / code>
92+ )}
93+ < / td>
94+ < td> {props[key].required ? ' Yes' : ' No' }< / td>
95+ < td> {props[key].description }< / td>
96+ < / tr>
97+ );
98+ })}
99+ < / tbody>
100+ < / table>
101+ );
102+ };
103+ ` ` `
44104
45105## Options
46106
0 commit comments