Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support react-docgen-typescript #223

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/framework-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@
"find-up": "^5.0.0",
"magic-string": "^0.30.17",
"react-docgen": "^7.1.0",
"react-docgen-typescript": "^2.2.2",
"resolve": "^1.22.10",
"storybook-builder-rsbuild": "workspace:*",
"tsconfig-paths": "^4.2.0"
},
"devDependencies": {
"@rsbuild/core": "^1.1.13",
"@storybook/types": "8.5.0-beta.8",
"@types/react": "^18.3.18",
"@types/resolve": "^1.20.6",
"react": "18.3.1",
"react-dom": "18.3.1",
Expand Down

This file was deleted.

78 changes: 0 additions & 78 deletions packages/framework-react/src/plugins/docgen-resolver.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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.

# @joshwooding/vite-plugin-react-docgen-typescript

[![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)
[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

> A vite plugin to inject react typescript docgen information

 

### Usage

```ts
import reactDocgenTypescript from '@joshwooding/vite-plugin-react-docgen-typescript'

export default {
plugins: [reactDocgenTypescript()],
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react'

interface DefaultExportComponentProps {
/** Button color. */
color: 'blue' | 'green'
}

/**
* A simple component.
*/
const DefaultExportComponent: React.FC<DefaultExportComponentProps> = (
props,
) => <button style={{ backgroundColor: props.color }}>{props.children}</button>

export default DefaultExportComponent
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react'

interface DefaultExportComponentProps {
/** Button color. */
color: 'blue' | 'green'
}

/**
* A simple component.
*/
const DefaultExportComponent: React.FC<DefaultExportComponentProps> = (
props,
) => <button style={{ backgroundColor: props.color }}>{props.children}</button>

DefaultExportComponent.displayName = 'DefaultExportComponentWithDisplayName'

export default DefaultExportComponent
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from 'react'

interface DefaultPropValueComponentProps {
/**
* Button color.
*
* @default blue
**/
color: 'blue' | 'green'

/**
* Button counter.
*/
counter: number

/**
* Button disabled.
*/
disabled: boolean
}

/**
* Component with a prop with a default value.
*/
export const DefaultPropValueComponent: React.FC<
DefaultPropValueComponentProps
> = (props) => (
<button disabled={props.disabled} style={{ backgroundColor: props.color }}>
{props.counter}
{props.children}
</button>
)

DefaultPropValueComponent.defaultProps = {
counter: 123,
disabled: false,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react'

interface HyphenatedPropNameProps {
/** Button color. */
'button-color': 'blue' | 'green'
}

/**
* A component with a hyphenated prop name.
*/
export const HyphenatedPropNameComponent: React.FC<HyphenatedPropNameProps> = (
props,
) => (
<button style={{ backgroundColor: props['button-color'] }}>
{props.children}
</button>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react'

interface MultiPropsComponentProps {
/** Button color. */
color: 'blue' | 'green'

/** Button size. */
size: 'small' | 'large'
}

/**
* This is a component with multiple props.
*/
export const MultiPropsComponent: React.FC<MultiPropsComponentProps> = (
props,
) => <button style={{ backgroundColor: props.color }}>{props.children}</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react'

interface MultilineDescriptionProps {
/** Button color. */
color: 'blue' | 'green'
}

/**
* A component with a multiline description.
*
* Second line.
*/
export const MultilineDescriptionComponent: React.FC<
MultilineDescriptionProps
> = (props) => (
<button style={{ backgroundColor: props.color }}>{props.children}</button>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react'

interface MultilinePropDescriptionComponentProps {
/**
* This is a multiline prop description.
*
* Second line.
*/
color: 'blue' | 'green'
}

/**
* A component with multiline prop description.
*/
export const MultilinePropDescriptionComponent: React.FC<
MultilinePropDescriptionComponentProps
> = (props) => (
<button style={{ backgroundColor: props.color }}>{props.children}</button>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react'

interface SimpleComponentProps {
/** Button color. */
color: 'blue' | 'green'
}

/**
* A simple component.
*/
export const SimpleComponent: React.FC<SimpleComponentProps> = (props) => (
<button style={{ backgroundColor: props.color }}>{props.children}</button>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react'

interface SimpleComponentProps {
/** Button color. */
color: 'blue' | 'green'
}

/**
* A simple component.
*/
export const SimpleComponent: React.FC<SimpleComponentProps> = (props) => (
<button style={{ backgroundColor: props.color }}>{props.children}</button>
)

SimpleComponent.displayName = 'SimpleComponentWithDisplayName'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react'

/**
* A component with only text content wrapped in a div.
*
* Ref: https://github.com/strothj/react-docgen-typescript-loader/issues/7
*/
export const SimpleComponent: React.FC<Record<string, never>> = () => (
<div>Test only component</div>
)
Loading
Loading