-
Notifications
You must be signed in to change notification settings - Fork 64
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
Docgen info not generated for typescript components #721
Comments
Made a simple component in import * as React from 'react'
import { FunctionComponent } from 'react'
type Props = {
color?: string
} & React.HTMLAttributes<HTMLDivElement>
export const Component: FunctionComponent = ({
children,
color = 'orange', this results in the following docgen info: Component.__docgenInfo = {
description: '',
methods: [],
displayName: 'Component',
props: {
color: {
defaultValue: {
value: "'orange'",
computed: false,
},
required: false,
},
},
} |
Suggest testing with a component using |
The description field is |
I get a description if I place the comment right before the function. If it’s at the top or above the type definition it’s not added. import * as React from 'react'
import { FunctionComponent } from 'react'
type Props = {
color?: string
} & React.HTMLAttributes<HTMLDivElement>
/**
* This is the Component description
*/
export const Component: FunctionComponent = ({
children,
color = 'orange',
}: Props) => <div style={{ color: color }}>{children}</div> results in Component.__docgenInfo = {
"description": "This is the Component description",
"methods": [],
"displayName": "Component",
"props": {
"color": {
"defaultValue": {
"value": "'orange'",
"computed": false
},
"required": false
}
}
}; |
forwardRef works… export const Component = forwardRef<HTMLDivElement, Props>(
function EdsComponent({ children, color = 'orange' }, ref) {
return (
<div style={{ color: color }} ref={ref}>
{children}
</div>
)
},
) |
Compound components work… import { OtherComponent } from './OtherComponent'
import { Component as BaseComponent } from './Component'
type ComponentTypes = typeof BaseComponent & {
OtherComponent: typeof OtherComponent
}
const Component = BaseComponent as ComponentTypes
Component.OtherComponent = OtherComponent
export { Component } |
The Snackbar component works, but SnackbarAction does not. But Snackbar only has one prop, and that’s children. If I add another prop, such as |
Took a look at |
There are two processors that can be used to extract types from components, react-docgen-typescript and react-docgen. The first one is made by Styleguidist, who interestingly enough use react-docgen. Storybook uses react-docgen-typescript in the version we have, because typescript: {
reactDocgen: 'react-docgen',
}, …which causes the Accordion component to only show internal types in the Storybook – and also removes the description from the types for some reason. |
What I’ve done now, in #723, is to disable all the stories for components that have |
So does that mean the function name must match |
That’s correct. In some components we can just leave out |
Describe the bug
A clear and concise description of what the bug is.
Steps to reproduce the bug
Expected behavior
The bundle should have a docgen object for each component
The text was updated successfully, but these errors were encountered: