-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
docs: generate documentation for UI components #5849
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
One question: If I update the inline documentation will it then get reflected in the docs as soon as the PR hits develop?
packages/design-system/ui/src/components/currency-input/currency-input.tsx
Outdated
Show resolved
Hide resolved
packages/design-system/ui/src/components/date-picker/date-picker.tsx
Outdated
Show resolved
Hide resolved
No it'll only be reflected if the command is ran to generate the spec files. I've added a GitHub action that runs it either when a new release is out or if we manually trigger the action |
…cy-input.tsx Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
What
This PR introduces the necessary tooling to generate JSON spec files for React components with props and component details. Its created to be used with the Medusa UI package.
react-docs-generator
A new custom tool that combines react-docgen and typedoc to generate spec JSON files for React components.
Although
react-docgen
provides the type of specs we need, it presents complications and caveats, where some props aren't documented or their types aren't inferred properly (more on that in the next section). So, where necessary, Typedoc fills in the gaps of missing props, descriptions, or types. As React Docgen is updated to resolve some of these issues, we can maybe in the future rely on it only.Usage
After installing and building dependencies in the
docs-util
package, run the following command in thedocs-util/packages/react-docs-generator
directory:Pointers on Writing and Inferring UI doc blocks
This section covers some things to keep in mind both when reviewing this PR and performing changes on the UI package moving forward (also open to suggestions for alternative ways of handling certain points if they don't make sense from a development standpoint):
forwardRef
. The props type has to be specified again for the destructured props.For example, we previously wrote the
Avatar
component like this:Now, we change it to clearly specify
AvatarProps
as the type of the destructured props:@prop
tag as we do with TSDoc) like so:They can also be added to the props within the interface definition, however, unless necessary we should keep them at the component's level.
@prop
is only used in cases where it's not possible to directly add a comment for a prop. In that case, it's picked up by Typedoc.interface
rather than atype
. So, where possible, I've changed types into interfaces in the UI package. In scenarios where the change isn't possible, Typedoc fills in the gap. In those cases, we should add the@interface
tag to the type's comments like so:react-docgen
only generates documentation for props either directly defined in the interface or destructured in the component's definition function. Inreact-docs-generator
we create the necessary customization to only output documentation for props having a docblock. This ensures that no unnecessary props that are either defined in the underlying third-party components or HTML attributes are outputted in the documentation.@excludeExternal
tag to the docblock of the component. This ensures that no props defined in any underlying component are part of the generated documentation. For example:@keep
tag. For example:@ignore
tag. For example:Changes in the UI docs
www/apps/ui/src/specs
directory.ComponentProps
component and replaced it withComponentReference
which renders components' descriptions and props based on the generated specs.ComponentReference
Other
docs-util
workspace based on necessary changes for the newreact-docs-generator
tool.