Skip to content

Commit 0218f92

Browse files
authored
Web components : Enhance documentation and Storybook features (uswds#203)
* update readme with more details * add extra info to readme
1 parent adf2c05 commit 0218f92

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

.storybook/preview.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const preview = {
2525
docs: {
2626
toc: true, // Autogenerate table of contents.
2727
theme: UswdsTheme,
28+
codePanel: true,
2829
canvas: {
2930
sourceState: "shown",
3031
},

README.md

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,33 @@ Over the course of the next several months and beyond, we will incrementally bui
1515

1616
We are releasing these Web Components (USWDS Elements) incrementally with the intent that they can also be added gradually to existing sites that are currently using USWDS. If you aren't currently using USWDS or you're using a version older than USWDS 3, we recommend adopting version 3 in the near term rather than waiting until all of USWDS Elements is production-ready.
1717

18-
## Installation
18+
## Installation using node and npm
1919

20-
For now, the best way to install USWDS Elements is via npm:
20+
1. Install `node/npm`. Below is a link to find the install method that coincides with your operating system:
21+
- Node (see [.nvmrc](https://github.com/uswds/uswds-elements/blob/develop/.nvmrc) for version number), [Installation guides](https://nodejs.org/en/download)
2122

22-
```bash
23-
npm install -S @uswds/elements
24-
```
23+
**Note for Windows users:** If you are using Windows and are unfamiliar with Node or npm, we recommend following [Team Treehouse's tutorial](http://blog.teamtreehouse.com/install-node-js-npm-windows) for more information or [installing and running your project from Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl#install-nvm-nodejs-and-npm).
24+
25+
2. Make sure you have installed it correctly:
26+
27+
```shell
28+
npm -v
29+
10.9.4 # This line may vary depending on what version of Node you've installed.
30+
```
31+
32+
3. Create a `package.json` file. You can do this manually, but an easier method is to use the `npm init` command. This command will prompt you with a few questions to create your `package.json` file.
33+
34+
4. Add `@uswds/uswds` to your project’s `package.json`:
35+
36+
```shell
37+
npm install -S @uswds/elements
38+
```
39+
40+
The `@uswds/elements` module is now installed as a dependency.
41+
42+
**Note:** We do _not_ recommend directly editing the design system files in `node_modules`. One of the benefits of using a package manager is its ease of upgrade and installation. If you make customizations to the files in the package, any upgrade or re-installation will wipe them out.
43+
44+
## Using USWDS Elements in your project
2545

2646
How you add the component to a page may vary depending on the tools you use in your work. If you use Vite, you can add components by importing them into a script that is imported elsewhere into a page:
2747

@@ -31,19 +51,57 @@ import { UsaBanner } from "@uswds/elements";
3151
```
3252
3353
```html
34-
<!-- importing directy into an HTML page -->
54+
<!-- importing directly into an HTML page -->
3555
<script type="module">
3656
import { UsaBanner } from "@uswds/elements";
3757
</script>
3858
<usa-banner></usa-banner>
3959
```
4060
61+
## Style theming and tokens
62+
63+
Each USWDS Element provides support for theming by exposing CSS custom properties (CSS variables) that can be used to control the appearance of the component.
64+
65+
There are interactive form controls in our Storybook instance that demonstrate how to use the theming variables, provide custom text, and otherwise customize the components.
66+
67+
For example, the `usa-banner` component can be customized by setting the `--usa-banner-background-color` CSS variable to a color of your choosing:
68+
69+
```html
70+
<style>
71+
usa-banner {
72+
--usa-banner-background-color: #d9e8f6; /** equivalent to `primary-lighter` from USWDS - https://designsystem.digital.gov/design-tokens/color/theme-tokens/#theme-color-tokens-table-2 */
73+
--usa-banner-button-close-background-color: #d6f3ff;
74+
}
75+
</style>
76+
<usa-banner></usa-banner>
77+
```
78+
79+
This can be seen in the demo on the [USWDS Elements Storybook](<https://federalist-ab6c0bdb-eccd-4b26-bb5f-b0154661e999.sites.pages.cloud.gov/site/uswds/web-components/?path=/story/components-banner--default&args=--usa-banner-background-color:!hex(e4f7ff)>).
80+
81+
**Note:** Please be mindful of the accessibility implications of customizing component appearance. It is your responsibility to ensure that your customizations meet the [accessibility requirements](https://designsystem.digital.gov/accessibility/) of the design system and pass any [WCAG 2.2](https://www.w3.org/TR/WCAG22/) or [Section 508](https://www.section508.gov/) accessibility tests.
82+
4183
> [!IMPORTANT]
4284
> If you are bundling your application using Vite, you may encounter a JavaScript error when using the `usa-banner` component with Vite's dev server (this also applies to other Vite-based tools such as Astro). To work around this, you may need to run the dev server in production mode by prefixing the command to start the server with `NODE_ENV=production`. For instance, if you run the command `npm run dev` to start your dev server, you should start it with `NODE_ENV=production npm run dev`.
4385
4486
## Documentation
4587
46-
For more detailed documention, refer to the Storybook for USWDS Elements. You can visit the most up-to-date Storybook documentation on [Cloud.gov Pages](https://federalist-ab6c0bdb-eccd-4b26-bb5f-b0154661e999.sites.pages.cloud.gov/site/uswds/web-components/?path=/docs/readme--docs).
88+
For more detailed documentation, refer to the Storybook for USWDS Elements. You can visit the most up-to-date Storybook documentation on [Cloud.gov Pages](https://federalist-ab6c0bdb-eccd-4b26-bb5f-b0154661e999.sites.pages.cloud.gov/site/uswds/web-components/?path=/docs/readme--docs).
89+
90+
## Browser support
91+
92+
We’ve designed the design system to support older and newer browsers through [progressive enhancement](https://en.wikipedia.org/wiki/Progressive_enhancement). The current major version of USWDS Elements (v1) follows the [2% rule](https://gds.blog.gov.uk/2012/01/25/support-for-browsers/): we officially support any browser above 2% usage as observed by [analytics.usa.gov](https://analytics.usa.gov/). Currently, this means support for the newest versions of Chrome, Firefox, and Safari.
93+
94+
## Accessibility
95+
96+
The design system also meets the [WCAG 2.0 AA accessibility guidelines](https://www.w3.org/TR/WCAG20/) and conforms to the standards of [Section 508 of the Rehabilitation Act](http://www.section508.gov/). Additionally, we try to meet the requirements of [WCAG 2.2](https://www.w3.org/TR/WCAG22/).
97+
98+
We use the following tools to ensure USWDS is accessible:
99+
100+
- [ANDI](https://www.ssa.gov/accessibility/andi/help/install.html).
101+
- [Axe core](https://www.deque.com/axe/).
102+
- [Axe dev tools](https://chrome.google.com/webstore/detail/axe-devtools-web-accessib/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US).
103+
104+
If you find any issues with our accessibility conformance, please create an issue in our GitHub repo or send us an email at [uswds@gsa.gov](mailto:uswds@gsa.gov). We prioritize accessibility issues. See [the Accessibility page of our website](https://designsystem.digital.gov/documentation/accessibility/) for more information.
47105
48106
## Component Versions
49107

0 commit comments

Comments
 (0)