-
Notifications
You must be signed in to change notification settings - Fork 4
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
USWDS - Web components: Improve component docs with custom elements manifest #67
Conversation
Improve autogenerated StorybookJS documentation by re-using existing JSDoc comments that follow [custom elements manifest tags](https://custom-elements-manifest.open-wc.org/analyzer/getting-started/#supported-jsdoc)
/** | ||
* Custom elements for component docs generation. | ||
*/ | ||
import { setCustomElementsManifest } from "@storybook/web-components"; | ||
import customElements from "../custom-elements.json"; | ||
|
||
setCustomElementsManifest(customElements); |
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.
Tip
This is how StorybookJS uses the manifest to generate docs.
@@ -3,6 +3,7 @@ | |||
"private": true, | |||
"version": "1.0.0-alpha", | |||
"type": "module", | |||
"customElements": "custom-elements.json", |
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.
Tip
Allows other tools to pickup these hints. Could be useful to developers building with these components.
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.
This is cool as heck. Thanks for wiring it together!
Summary
Improve component API documentation by re-using JSDoc comments.
You can see in the screenshot below attributes and CSS custom properties are now documented automatically. ✨
Related issue
Closes #66.
Preview link
Problem statement
Desired state
Component API is automatically documented based on our code comments. This information should be accessible for reuse by other developers too.
Actual state
We have to manually document component API in code and in StorybookJS.
Consequences of remaining in current state
This is time consuming, tedious, and slows down development efforts.
There's also very little benefit to users of these web components because our documentation is internal.
Solution
Added the
custom-elements-manifest
dependency so that we can autogenerate the JSON for our component API's. StorybookJS looks for this information to create documentation.Adding it to
package.json
also allows other tools to access this information too.web-components/package.json
Line 6 in c13acdc
Source →
Major changes
Followed guidance here to install and setup this tool for StorybookJS.
How to use
Simply add JSDoc comments with this guidance and manifest and docs will automatically be generated.
New NPM scripts
web-components/package.json
Lines 34 to 35 in 2be8e1f
You can manually build or automatically create a new manifest while developing via
npm start
.Testing and review
npm install
npm start
npm run manifest:build
andnpm run manifest:watch
] without errors.Dependency updates