Skip to content

Commit 7b919b2

Browse files
authored
re-working api to not use global data by default (#2)
* re-working api to not use global data by default * drop node 12 * refactor(:recycle:): :wave: pika, moving to esbuild * feat: add util hook + more docs
1 parent e2fe9f8 commit 7b919b2

File tree

10 files changed

+6817
-4077
lines changed

10 files changed

+6817
-4077
lines changed

.github/workflows/on_push.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ name: Build PR & Push
33
jobs:
44
build:
55
runs-on: ubuntu-latest
6+
env:
7+
HUSKY: 0
68
strategy:
79
matrix:
8-
node-version: [12.x, 14.x]
10+
node-version: [14.x]
911
steps:
10-
- uses: actions/checkout@v1
12+
- uses: actions/checkout@v2
1113
- name: Use Node.js ${{ matrix.node-version }}
12-
uses: actions/setup-node@v1
14+
uses: actions/setup-node@v2
1315
with:
1416
node-version: ${{ matrix.node-version }}
1517
- name: npm install, lint, and build
1618
run: |
17-
npm i
19+
npm ci
1820
npm run lint
1921
npm run build

.github/workflows/on_release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ jobs:
66
publish:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v1
10-
- uses: actions/setup-node@v1
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-node@v2
1111
with:
12-
node-version: 12
12+
node-version: 14
1313
registry-url: https://registry.npmjs.org/
1414
- name: npm install
1515
run: |
16-
npm i
17-
npm run build
16+
npm ci
17+
npm run build
1818
- name: publish
19-
run: npm publish pkg/
19+
run: npm publish
2020
env:
2121
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install lint-staged
5+
npm run lint

README.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
1921
module.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

Comments
 (0)