Skip to content

Commit 5f64cf8

Browse files
authored
feat: support react-docgen-typescript (#223)
1 parent 19cfbd6 commit 5f64cf8

33 files changed

+2358
-375
lines changed

.github/workflows/ci.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ jobs:
3232
fetch-depth: 10
3333

3434
- name: Install Pnpm
35-
run: corepack enable
35+
run: |
36+
npm install -g corepack@latest --force
37+
corepack enable
3638
3739
- name: Setup Node.js ${{ matrix.node-version }}
3840
uses: actions/setup-node@v4

packages/builder-rsbuild/src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ export const build: ({ options }: BuilderStartOptions) => Promise<Stats> =
226226
stats = params.stats as Stats
227227
})
228228

229-
await Promise.all([rsbuildBuild.build(), previewFiles])
229+
const [{ close }] = await Promise.all([rsbuildBuild.build(), previewFiles])
230+
231+
await close()
230232
return stats!
231233
}
232234

packages/framework-react/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@
5252
"find-up": "^5.0.0",
5353
"magic-string": "^0.30.17",
5454
"react-docgen": "^7.1.0",
55+
"react-docgen-typescript": "^2.2.2",
5556
"resolve": "^1.22.10",
5657
"storybook-builder-rsbuild": "workspace:*",
5758
"tsconfig-paths": "^4.2.0"
5859
},
5960
"devDependencies": {
6061
"@rsbuild/core": "^1.1.13",
6162
"@storybook/types": "8.5.0-beta.8",
63+
"@types/react": "^18.3.18",
6264
"@types/resolve": "^1.20.6",
6365
"react": "18.3.1",
6466
"react-dom": "18.3.1",

packages/framework-react/src/plugins/docgen-handlers/actualNameHandler.ts

-67
This file was deleted.

packages/framework-react/src/plugins/docgen-resolver.ts

-78
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The code in this directory is copied and modified from [@joshwooding/vite-plugin-react-docgen-typescript](https://github.com/joshwooding/vite-plugin-react-docgen-typescript/tree/bf0ea3a603fb388bc28104c65aea49beb236aa6c) under MIT license.
2+
3+
# @joshwooding/vite-plugin-react-docgen-typescript
4+
5+
[![npm](https://img.shields.io/npm/v/@joshwooding/vite-plugin-react-docgen-typescript.svg)](https://www.npmjs.com/package/@joshwooding/vite-plugin-react-docgen-typescript)
6+
[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
7+
8+
> A vite plugin to inject react typescript docgen information
9+
10+
&nbsp;
11+
12+
### Usage
13+
14+
```ts
15+
import reactDocgenTypescript from '@joshwooding/vite-plugin-react-docgen-typescript'
16+
17+
export default {
18+
plugins: [reactDocgenTypescript()],
19+
}
20+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react'
2+
3+
interface DefaultExportComponentProps {
4+
/** Button color. */
5+
color: 'blue' | 'green'
6+
}
7+
8+
/**
9+
* A simple component.
10+
*/
11+
const DefaultExportComponent: React.FC<DefaultExportComponentProps> = (
12+
props,
13+
) => <button style={{ backgroundColor: props.color }}>{props.children}</button>
14+
15+
export default DefaultExportComponent
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react'
2+
3+
interface DefaultExportComponentProps {
4+
/** Button color. */
5+
color: 'blue' | 'green'
6+
}
7+
8+
/**
9+
* A simple component.
10+
*/
11+
const DefaultExportComponent: React.FC<DefaultExportComponentProps> = (
12+
props,
13+
) => <button style={{ backgroundColor: props.color }}>{props.children}</button>
14+
15+
DefaultExportComponent.displayName = 'DefaultExportComponentWithDisplayName'
16+
17+
export default DefaultExportComponent
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as React from 'react'
2+
3+
interface DefaultPropValueComponentProps {
4+
/**
5+
* Button color.
6+
*
7+
* @default blue
8+
**/
9+
color: 'blue' | 'green'
10+
11+
/**
12+
* Button counter.
13+
*/
14+
counter: number
15+
16+
/**
17+
* Button disabled.
18+
*/
19+
disabled: boolean
20+
}
21+
22+
/**
23+
* Component with a prop with a default value.
24+
*/
25+
export const DefaultPropValueComponent: React.FC<
26+
DefaultPropValueComponentProps
27+
> = (props) => (
28+
<button disabled={props.disabled} style={{ backgroundColor: props.color }}>
29+
{props.counter}
30+
{props.children}
31+
</button>
32+
)
33+
34+
DefaultPropValueComponent.defaultProps = {
35+
counter: 123,
36+
disabled: false,
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react'
2+
3+
interface HyphenatedPropNameProps {
4+
/** Button color. */
5+
'button-color': 'blue' | 'green'
6+
}
7+
8+
/**
9+
* A component with a hyphenated prop name.
10+
*/
11+
export const HyphenatedPropNameComponent: React.FC<HyphenatedPropNameProps> = (
12+
props,
13+
) => (
14+
<button style={{ backgroundColor: props['button-color'] }}>
15+
{props.children}
16+
</button>
17+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react'
2+
3+
interface MultiPropsComponentProps {
4+
/** Button color. */
5+
color: 'blue' | 'green'
6+
7+
/** Button size. */
8+
size: 'small' | 'large'
9+
}
10+
11+
/**
12+
* This is a component with multiple props.
13+
*/
14+
export const MultiPropsComponent: React.FC<MultiPropsComponentProps> = (
15+
props,
16+
) => <button style={{ backgroundColor: props.color }}>{props.children}</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react'
2+
3+
interface MultilineDescriptionProps {
4+
/** Button color. */
5+
color: 'blue' | 'green'
6+
}
7+
8+
/**
9+
* A component with a multiline description.
10+
*
11+
* Second line.
12+
*/
13+
export const MultilineDescriptionComponent: React.FC<
14+
MultilineDescriptionProps
15+
> = (props) => (
16+
<button style={{ backgroundColor: props.color }}>{props.children}</button>
17+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react'
2+
3+
interface MultilinePropDescriptionComponentProps {
4+
/**
5+
* This is a multiline prop description.
6+
*
7+
* Second line.
8+
*/
9+
color: 'blue' | 'green'
10+
}
11+
12+
/**
13+
* A component with multiline prop description.
14+
*/
15+
export const MultilinePropDescriptionComponent: React.FC<
16+
MultilinePropDescriptionComponentProps
17+
> = (props) => (
18+
<button style={{ backgroundColor: props.color }}>{props.children}</button>
19+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
3+
interface SimpleComponentProps {
4+
/** Button color. */
5+
color: 'blue' | 'green'
6+
}
7+
8+
/**
9+
* A simple component.
10+
*/
11+
export const SimpleComponent: React.FC<SimpleComponentProps> = (props) => (
12+
<button style={{ backgroundColor: props.color }}>{props.children}</button>
13+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react'
2+
3+
interface SimpleComponentProps {
4+
/** Button color. */
5+
color: 'blue' | 'green'
6+
}
7+
8+
/**
9+
* A simple component.
10+
*/
11+
export const SimpleComponent: React.FC<SimpleComponentProps> = (props) => (
12+
<button style={{ backgroundColor: props.color }}>{props.children}</button>
13+
)
14+
15+
SimpleComponent.displayName = 'SimpleComponentWithDisplayName'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react'
2+
3+
/**
4+
* A component with only text content wrapped in a div.
5+
*
6+
* Ref: https://github.com/strothj/react-docgen-typescript-loader/issues/7
7+
*/
8+
export const SimpleComponent: React.FC<Record<string, never>> = () => (
9+
<div>Test only component</div>
10+
)

0 commit comments

Comments
 (0)