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

USWDS - Web components: Improve component docs with custom elements manifest #67

Merged
merged 4 commits into from
Sep 6, 2024

Conversation

mejiaj
Copy link
Collaborator

@mejiaj mejiaj commented Sep 5, 2024

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.

"customElements": "custom-elements.json",

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

"manifest:build": "npx cem analyze --litelement",
"manifest:watch": "npx cem analyze --litelement --watch --dev",

You can manually build or automatically create a new manifest while developing via npm start.

Testing and review

  1. Run npm install
  2. Run npm start
  3. View component docs and confirm CSS custom properties are now listed.
  4. Run new tasks [npm run manifest:build and npm run manifest:watch] without errors.

Dependency updates

Dependency name Previous version New version
@chromatic-com/storybook 1.6.1 1.8.0
@custom-elements-manifest/analyzer - 0.10.3
@storybook/addon-a11y 8.2.7 8.2.9
@storybook/addon-docs 8.2.7 8.2.9
@storybook/addon-essentials 8.2.7 8.2.9
@storybook/addon-links 8.2.7 8.2.9
@storybook/blocks 8.2.7 8.2.9
@storybook/manager-api 8.2.7 8.2.9
@storybook/test 8.2.7 8.2.9
custom-elements-manifest - 2.1.0
eslint 9.8.0 9.9.1
wait-on 7.1.0 7.2.0

Comment on lines +1 to +7
/**
* Custom elements for component docs generation.
*/
import { setCustomElementsManifest } from "@storybook/web-components";
import customElements from "../custom-elements.json";

setCustomElementsManifest(customElements);
Copy link
Collaborator Author

@mejiaj mejiaj Sep 5, 2024

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",
Copy link
Collaborator Author

@mejiaj mejiaj Sep 5, 2024

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.

@mejiaj mejiaj marked this pull request as ready for review September 5, 2024 20:46
Copy link
Collaborator

@heymatthenry heymatthenry left a 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!

@heymatthenry heymatthenry merged commit ea6e25d into develop Sep 6, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USWDS - Web components: Improve API docs with custom elements manifest
2 participants