Documenting Components
React Showroom generates documentations for your components based on type definition of your components, the comments on the type definitions, and markdown file.
Documenting Component Props
Declare your component props as usual in TypeScript:
src/components/button.tsx
And the following will be generated:
Button
NAME | TYPE | DESCRIPTION |
---|---|---|
variant | "primary" | "secondary" | |
fullWidth | boolean | |
rounded | "sm" | "lg" |
Comments for Component and Props
To provide more descriptions to the props and the comment itself, you can add JSDoc style comments.
src/components/button.tsx
And the documentations will be reflected.
ButtonWithComments
<Button />
component is a wrapper of <button>
element.Unspecified props will be spreaded.
NAME | TYPE | DESCRIPTION |
---|---|---|
variant | "primary" | "secondary" | variant for the button |
fullWidth | boolean | specify if the button should takes up all the available horizontal space. |
rounded | "sm" | "lg" | controls the border radius. |
JSDoc tags will be parsed and displayed as well.
src/components/button.tsx
will results in
OldButton
deprecated: use `<Button />` instead.
version: 1.0.0
see: http://some-stackoverflow-question-that-i-copy-but-dont-understand.com
NAME | TYPE | DESCRIPTION |
---|---|---|
color | "primary" | "secondary" |
Show Usages with Markdown
To show usage examples for the component, create a .mdx
file next to the component with the same name as the component file.
src/components/button.mdx
will produces the following output.
Button
NAME | TYPE | DESCRIPTION |
---|---|---|
variant | "primary" | "secondary" | |
fullWidth | boolean | |
rounded | "sm" | "lg" |
Using React Hooks
Example with states:
Add frame
to render examples in iframe. This is very handy to see how the component is rendered in different screen size.
Calling console.log
, console.info
, console.warn
, console.error
in the example will log the result in a separate panel.
Open the hamburget menu and choose view as Designer to see the technical details hidden.
Click the toggle Switch on the Sidebar to see the technical details hidden.
This is handy for non-technical audience (designer/business) to view the site.
Few things to take note:
- You must tag the code block with
tsx
orjsx
for it to become live example. - If the last expression in your code block is a JSX, that will be the displayed result of the example.
- The component is automatically injected into the scope, so you doesn't need to import it.
React
is automatically injected into the scope as well, but it's fine if you want to import it.
A few scenarios for code blocks:
src/components/button.mdx
And the result:
Button
NAME | TYPE | DESCRIPTION |
---|---|---|
variant | "primary" | "secondary" | |
fullWidth | boolean | |
rounded | "sm" | "lg" |
Manually call render
if you want to add some operations before rendering the output.
Importing third party libraries work as well as long as they are installed in your project.
If user add additional import statement in live editor, they will be loaded from Skypack on the fly.
Use fileName
modifier to add a file name at the top of the code block.
For code blocks with frame
, by default we will adjust the given height based on the rendered content.
You can overwrite the height (fixed) and initial height (initial iframe height while waiting the content to be rendered) using height
and initialHeight
modifier.
Use noEditor
modifier to show only the output result.
Use static
modifier to show static code.
For static code blocks, you can use highlights
to highlight specific lines.
Show Different Variants
A common use case is to show different variants of the component side-by-side so they can be compared visually.
You can, of course, render the component by passing different props to it in an example to do that.
However, you need to maintain the example so any changes to the props will be reflected in the example.
Another options is to use the useUnionProps
custom hook (available in react-showroom/client
), which provide the variants (parsed from the props type definition) as options to your examples.
src/components/button.mdx
Button
NAME | TYPE | DESCRIPTION |
---|---|---|
variant | "primary" | "secondary" | |
fullWidth | boolean | |
rounded | "sm" | "lg" |
Collaboration Tips
React Showroom is developed with helping collaborations in mind, and the following are some tips to use it effectively.
Use Standalone View to Share Particular Example/Snapshot
All examples will generates a standalone view (which can be opened with the "Standalone" button at bottom right).
- The standalone view has its own URL that you can share with others.
- In the standalone view, you can update the code or update the props (for Component Playground) and those changes will be persisted in the URL.
- You can also add comment on particular point of the example, and those will be persisted in the URL as well. For example, try open this link.
Use the Accessibility Check Result to Discuss Accessibility Issues
The accessibility check result (powered by axe-core) is a good starting point to discuss about accessibility issues of your components/designs.
You can highlight the elements in the example by check the "Highlight" checkbox.