Giter Club home page Giter Club logo

react-uswds's Introduction

@trussworks/react-uswds

All Contributors

npm version uswds version

npm downloads

ReactUSWDS Component Library

This is a frontend component library, built in React with Typescript, based on design patterns defined by the United States Web Design System (USWDS) 3.0. Our primary goal is to document and provide common UI components following the USWDS specification. This library removes a significant amount of overhead UI development for projects based on this standard.

A deployed instance of the ReactUSWDS Storybook is located at: https://trussworks.github.io/react-uswds/

Table of Contents

Install

Install this package with npm or yarn:

yarn add @trussworks/react-uswds

or

npm i @trussworks/react-uswds

Peer Dependencies

This library relies on some peer dependencies. Please verify these peer dependencies were added to your project (if they did not already exist) after adding this library.

Usage

USWDS

It is strongly suggested applications use the same version of USWDS that was used to build the version of ReactUSWDS they're using (see this repo's uswds devDependency in package.json). A version mismatch may result in unexpected markup & CSS combinations. For flexibility, ReactUSWDS will not trigger warnings if consumers choose to use a higher minor version of uswds (hence the careted uswds peerDependency in package.json). If encountering unexpected markup issues when choosing not to use the matching devDependency version of uswds, consumers should check whether aligning the versions resolves their issue(s).

You can import ReactUSWDS components using ES6 syntax:

import { Alert } from '@trussworks/react-uswds'

Warning: Do not include USWDS JS in your project alongside this library (i.e., using import 'uswds'), as that will result in some components that use JS (such as the ComboBox) to initialize twice.

Also make sure to include the following in order to import the compiled CSS from this project:

@import '~@trussworks/react-uswds/lib/index.css';

If you aren't already using USWDS as a dependency, you also need to import USWDS styles. Read more info about using USWDS styles and assets here

Having issues? See FAQs.

NodeJS

We develop on this library with the version of node defined in .node-version. We run the test suite against the major released versions of node that are still in active LTS and not development releases. Specific versions are defined in the workflow: .github/workflows/build-and-test.yml. Those are the versions we exxpect to support, if you are using a pre-release or development version of node you may run into unexpected issues.

Having issues? See FAQs.

Pre-Release

See prelease.md

Implementation examples

We decided to focus on our storybook over hosting an example/boilerplate implementation, but you can find a few such things from our friends:

You can also check out some open source projects using React-USWDS across federal and state governments:

Background

The primary deliverable is a published npm package that can be included as a dependency in other projects that use USWDS with React. In order for these components to be useful, they should follow best practices for accessible, semantic, markup; be well-tested across browsers and devices; and allow for an appropriate level of customization. We adhere to a set of development guidelines as much as possible and use automation to enforce tests, linting, and other standards.

Non-Goals

This is not meant to be a one-size-fits-all front end solution, We are starting off with the opinionated decision to cater towards projects that use the U.S. Design System 2.0, and encapsulate these specific styles and markup in React components.

In the process, we expect to gain learnings around how to best abstract out UI code from implementation; how to better standardize and document front end code practices; and how to develop, maintain, and distribute a shared JS library in alignment with our company values at Truss.

Active Maintainers

We are starting to rotate Trussel maintainer responsibilities. Check out the maintainers README.

Contributing

Interested in contributing? See our guidelines and dev setup here.

Are you a Trussel and new to this project? Check out our on & offboarding guide made just for you!

This repository is governed by the Contributor Covenant

Quick links:

License

Copyright 2021, TrussWorks, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Suzanne Rozier
Suzanne Rozier

💻 📖
haworku
haworku

💻 📖
Andrew Hobson
Andrew Hobson

💻
John Gedeon
John Gedeon

💻 🚧
Emily Mahanna
Emily Mahanna

💻
Brandon Lenz
Brandon Lenz

💻 📖 🚧 🐛
Jeri Sommers
Jeri Sommers

💻
Erin Stanfill
Erin Stanfill

💻
Barry Morrison
Barry Morrison

💻
Duncan
Duncan

💻
Arianna Kellogg
Arianna Kellogg

💻
Christopher Hui
Christopher Hui

💻
Jim Benton
Jim Benton

💻
Jen Duong
Jen Duong

💻
Kim Allen
Kim Allen

💻 ️️️️♿️
Kyle Hill
Kyle Hill

💻
Mazdak Atighi
Mazdak Atighi

💻
Isaac Garfinkle
Isaac Garfinkle

💻
Roger Steve Ruiz
Roger Steve Ruiz

💻 📖
Leo Singer
Leo Singer

🐛 💻
Shauna Keating
Shauna Keating

️️️️♿️ 💻
Jacob Capps
Jacob Capps

💻
pearl-truss
pearl-truss

💻
Andrew Nelson
Andrew Nelson

💻 📖 🚧 🐛 ️️️️♿️
Sawyer Hollenshead
Sawyer Hollenshead

💻 🐛
Ryan Delaney
Ryan Delaney

🚧 🚇
Anna Gingle
Anna Gingle

🎨 💻
Abdullah Umer
Abdullah Umer

💻
Muhammad Adeel
Muhammad Adeel

🐛 💻
Vinod Krishna Vellampalli
Vinod Krishna Vellampalli

💻
Joe Kleinschmidt
Joe Kleinschmidt

💻
James Hancock
James Hancock

🐛 💻
Joseph Andersen
Joseph Andersen

💻 🚧 🚇
Courtney Eimerman-Wallace
Courtney Eimerman-Wallace

🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

react-uswds's People

Contributors

ahobson avatar allcontributors[bot] avatar aybeedee avatar brandonlenz avatar christopherhuii avatar dependabot-preview[bot] avatar dependabot[bot] avatar duncan-truss avatar eamahanna avatar esacteksab avatar gidjin avatar github-actions[bot] avatar haworku avatar jcbcapps avatar jim avatar jpandersen87 avatar kimallen avatar kleinschmidtj avatar m7adeel avatar mlm55 avatar rogeruiz avatar rswerve avatar sawyerh avatar shkeating avatar sirenaborracha avatar sojeri avatar suzubara avatar tinyels avatar vinodkv2511 avatar werdnanoslen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-uswds's Issues

Decide how we want to handle lang strings in components

There are some new components that could include lang strings- see "Return to top" in Footer #78 and SearchInput #104 . Since sites using the library can be in another language, we are creating components that won't be flexible to internationalization.

One solution could be that we don't include any hardcode any strings in our components (or only as a default value that can be overridden by a prop). Other thoughts or ideas?

feat: Add `nav` variant to Link

We have an existing Link component that should be adjusted to handle a new variant prop called nav.

Requirements:

  • Add nav as another possible value to the StyledLinkProps variant type definition
  • Adjust the logic in the linkClasses function so that it includes the usa-nav__link class when the variant prop is nav
  • Add a storybook example to Link.stories.tsx for <Link variant="nav">

Proposal: start using enums instead of booleans for prop variants

We have several components such as Header, Footer, Button, and maybe even aspects of Grid, with boolean props that can conflict.

For example, you should not have the big and medium prop applied to the same footer. Some of this should be on the developer to use our props ... properly 😝... AND we also could starting using variants as well when helpful.

Instead of booleans we could move towards a single prop named something like size or type that accepts one of these types. The types would be enums. How do folks feel about this? Is this something we could start code reviewing for and document as practice?

Proposed requirements to close this issue:

  • Add a type variant to the Button component (keep the old way of doing these props too but add a deprecation warning - it can be removed fully in next major release ).
  • Write out additional issues for other components with this problem.
  • Add description of best practices with props to #73

Add more documentation around how to contribute and write new components

Write some more documentation specifically around how to write new components. Include guidance around:

  • How to decide whether to add a new component
  • Once decided, make sure it is abstract enough for general usage but also fits in the USWDS
  • Make sure props type inherits the HTML element attributes
  • Make sure to add corresponding stories and tests
  • Make sure to export the new component from the package entrypoint (index.ts)

Add a PR template.

New component: Forms / Character count

Character Count

Character count helps users know how much text they can enter when there is a limit on the number of characters.

Proposed Requirements

Props = {
  id: string,
  name: string
  maxLength: number
  defaultValue?: string
  isTextArea?: boolean
  getCharacterCount?: (text: string) => number
  getCharacterCountMessage? : (remainingCount: number) => string
  inputRef: InputRef
} 
  • Supports both <input type="text" /> and <textarea>
  • Character limit is determined by the maxLength. It does not limit the actual input field length, allowing the user to exceed the soft cap.
  • Input is invalid when maxLength is exceeded
  • getCharacterCount prop allows custom logic for character count (that accounts for emojis, ligatures, etc). It defaults to a function that uses .length
  • getMessage returns custom hint messages to display. It defaults to a function that returns English messages.
  • Component state tracks the input text length and validity. The consumer can pass in props that calculate the character count and determine which messages to display.

Other Considerations

  • Account for no-JavaScript environments. Add a default message in the message element that refers to the character limit. This will appear in instances when JavaScript does not load.
  • Instead of using <Label /> inside this component use render props as per #217 (review)

Update USWDS version to 2.7.0

Update the version of USWDS we're using to the latest (2.7.0 as of this writing). I don't believe there are any breaking changes relevant to our code but it's worth double checking.

Search component renders the `usa-search` class twice

Both the Search component and the Form component add the usa-search CSS class to the search form, resulting in the class being output twice in the rendered markup. This isn't causing any issues but there's no reason to include it twice. I'd recommend deleting it from the Form component.

Your .dependabot/config.yml contained invalid details

Dependabot encountered the following error when parsing your .dependabot/config.yml:

Automerging is not enabled for this account. You can enable it from the [account settings](https://app.dependabot.com/accounts/trussworks/settings) screen in your Dependabot dashboard.

Please update the config file to conform with Dependabot's specification using our docs and online validator.

USWDS Component: Footer

Add Footer component: https://designsystem.digital.gov/components/footer/

Should support all options: Big, Medium, Slim
Should support mobile view (seen particularly in Big Footer)

Render content:

  • Return to top link
  • Navigation tree (might be sub components, and/or children)
  • Sign up form or similar form
  • Address, logo, and social media links(sub components rendered as children)

Menu component should take id prop

Right now, the NavDropDownButton component implements a prop called menuId which is meant to be the id attribute of the corresponding Menu. However the Menu component doesn't accept an id prop. It should be modified to accept all ul props (ie., using React.HTMLAttributes<HTMLUListElement>) and pass them into the rendered NavList.

The same change should also be made to the MegaMenu component.

Security PR rotation logistics

Start a conversation and determine logistics for how we want to handle a security rotation. This function should support:

  • Team members from Truss can opt-in to be part of the "on call" rotation
  • On-call shifts should have a pre-determined length of time
  • Add description of responsibilities while on-call -- primarily paying attention to any security alerts that come in from Github, making sure urgent PRs are being attended to, etc. The on-call person may not be required to resolve issues themselves, but instead make sure they are not being dropped or ignored.

Use @storybook/addon-docs instead of deprecated @storybook/addon-info

Deprecated @storybook/addon-info is pulling in a bad marked dependency via marsky. Although this is already fixed in marked, it is unlikely to be fixed any time soon for marksy: storybookjs/marksy#78. (There were breaking changes which marksy maintainers have yet to resolve; it is a non-trivial fix.)

Since @storybook/addon-info is deprecated, even without the security vulnerability we should be switching to @storybook/addon-docs.

yarn audit output

>> yarn audit
yarn audit v1.22.4
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate      │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ marked                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.2                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @storybook/addon-info                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @storybook/addon-info > marksy > marked                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/812                         │
└───────────────┴──────────────────────────────────────────────────────────────┘
1 vulnerabilities found - Packages audited: 328229
Severity: 1 Moderate
✨  Done in 1.60s.

references

[feat] Link Component

Make a basic Link component that wraps a link in the classes we need for an internal link usa-link versus and external link usa-link usa-link--external.

This is another way to encapsulate styles. See Typography > Links.

By default renders an anchor tag, but has an optional prop to accept a different component.

[feat] Investigate `pkg.module` and bundler tools for better module support & tree shaking

Does your feature request relate to a specific USWDS feature?
No

Is your feature request related to a problem? Please describe.
This is an optimization of the lib bundle size which can improve performance

Describe the solution you'd like
Investigate generating pkg.module with a bundler tool (e.g. rollup, esbuild, or adapt existing webpack). Create a PR implementing the suggested approach with a brief rationale.

Describe alternatives you've considered
We can choose to do nothing.

Additional context
Port from initial roadmap -- motivation behind this is to optimize the library exports for better performance & modern JS applications.

Add form template examples

In the interest of minimum coverage of USWDS, it would be good to include implementations of all examples documented on the USWDS site, if only as proof of concepts that our library can do everything it can do. This is achieved by creating Storybook stories for different use cases. We have form templates for Name and Address, but should add Sign-in form and Password reset form: https://designsystem.digital.gov/components/form-templates

New component: Combo box

Combo Box

A combo box helps users select an item from a large list of options.

Proposed Requirements

Props = {
  id: string,
  name: string
  children: React.ReactNode
  options: [],
  onSelect: (option) => void,
  defaultValue? : string
  required?: boolean
} & JSX.IntrinsicElements['select']
  • base element is <select>
  • ability clear selections or already typed text
  • See uswds combo box js

Other Considerations

Generated files changing even if underlying code was not touched

Running a yarn storybook or yarn build or yarn install on any of the branches of this project seems to modify some generated files even if nothing was changed. Not sure what is causing this to be different than before.

❯ git status
On branch release-1.1.0
Your branch is up to date with 'origin/release-1.1.0'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   src/components/Alert/Alert.module.css.d.ts
        modified:   src/components/Modal/Modal.module.scss.d.ts
        modified:   src/components/Table/Table.module.css.d.ts

Search component should accept id, name props

Right now the Search component renders a label & input with hardcoded id and name attributes (search-field and search). It should be modified to accept props to define these instead, since the user will likely need full control over id and name attributes.

Add documentation for Trussel on/off-boarding

Since most of the time, Trussels who are working on this library actively will probably be on Reserve, they may need to be onboarded/offboarded relatively quickly and frequently. We may also often run into the situation where a Trussel is not able to complete work in progress if they end up joining a new client project on short notice. We should add some documentation that outlines what to do when you are onboarding & offboarding as an "active" contributor to this project.

Add Attributes to Set Slim Version of Alert

We currently have Alert included in our system, but the usa-alert--slim class has no means of being applied. We could go about this in a couple of ways:

  • we could add support for custom classes
  • we could add an additional attribute that would apply the class, similarly to how we currently set an Alert to be warning, success, etc.
  • we could do both, just to cover all our bases

Slim Alert sample: https://components.designsystem.digital.gov/components/detail/alerts--slim.html

**Needed for MilMove

Button should take a Component prop

Right now, the Button component will only render a button. However it's very common for a user to want to implement button styles on an <a> element or even a custom link component (such as if they are using client-side routing). So the Button component should be modified to accept an optional Component prop (probably of type ReactNode) to support that use case. It should still default to button if no Component prop is defined.

Grid components should take Component prop

Right now, the Grid components (Grid, GridContainer) render a div. They should be modified to accept an optional Component prop (probably of type ReactNode) in case the user wants to render some other element (such as a ul). They should still default to div if no Component props is defined.

New component: Button group

Button Group

A button group collects similar or related actions

Proposed requirements

Props<T> =  
  type: "default" | "segmented"  
  children: React.ReactNode 
}
  • ButtonGroup wraps Button children in a list. Children are required.
  • Base element by default is <ul> and the button children are rendered as list items

Other Considerations

Convey relationship. If not using a list element, give the parent element role="group" in order to convey to screen readers that actions are part of a group. If using as part of a toolbar, use role="toolbar".

  • add a usage of button group to example app

Only lint merge commits / squash & merge PRs

Right now, commitlint is set up to make sure every commit message follows the conventional commits format. That way, certain types of commits will automatically be included in the changelog. However, we'd like to support a workflow where only merge commits, and/or squash and merge PR titles have to match the format. Ideally a developer can check out a branch, write whatever commits they want, and then when they merge a PR the commit message will match the conventional commits format (probably based off the PR title).

https://github.com/conventional-changelog/standard-version
https://commitlint.js.org/#/

Add example application

Add a basic example application that uses this library and demonstrates how to use it. This can also be used in addition to Storybook for developing/testing new components. It can also be used if we want to set up end-to-end integration & a11y testing.

Acceptance criteria:

  • boilerplate create-react-app is set up in a subdirectory of this project (/example)
  • local react-uswds is a dependency of the example app

Customize Storybook template

Now that we have a public Storybook page, we should add some custom theming, additional info and better organization for our components.

Things we might want to add include:

  • Display ReactUSWDS version and USWDS version somewhere
  • Truss-specific branding/logo
  • Links back to Github repo, Truss site?
  • Custom theme fonts/colors?
  • Some static pages to display documentation, introduction, other info

Please add your own ideas/thoughts!

References:

Add component scaffolding shortcut

Add a yarn shortcut script to use when adding a new component. This will be used by developers adding new components to the project.

Acceptance criteria:

  • yarn create-component <componentName> creates a new directory insrc/component named after the component.
  • The following files are also created:
src/components/ComponentName/ComponentName.tsx
src/components/ComponentName/ComponentName.stories.tsx
src/components/ComponentName/ComponentName.tests.tsx

Optional extensions to this work could be:

  • The command also exports the component from index.js
  • The command also adds boilerplate code with the component Name to the different files.

Upgrade to Node v12

As of 2019-10-21, Node 12 is in active LTS, which means it should be safe for us to update this library to use Node 12 for development.

First, ensure that all dependencies support and function in v12 without issues. You can do this by checking the releases for all dependencies, updating to the latest stable versions, and making sure all tests and builds pass in this project.

Once verified everything looks good, the new Node version should be specified in:

  • package.json
  • docs/contributing.md
  • .circleci/config.yml

[bug] uswds typography mixin not being applied in storybook

Describe the bug
The :hover styles on primary links in Footer(#78) do not match styles applied in the USWDS design system docs. Specifically the blue color that comes from the typeset-link mixin is not being applied in our code.

Expected behavior
We want our storybook examples to look like the examples on uswds design system docs. In this case, all links should be blue when hovered.

Additional context

  • Look more into how $theme-global-link-styles is used we probably need to turn this on in our repo.
  • Also, revisit how we bring in uswds styles our storybook config. We should probably be importing .scss instead of instead of as compiled .css.
  • @suzubara knows more about all of this

[feat] Bootstrap example application UI

Does your feature request relate to a specific USWDS feature?
No

Is your feature request related to a problem? Please describe.
This feature will demonstrate real-life usage of ReactUSWDS components and provide another avenue for testing.

Describe the solution you'd like
Add the following to the /example application:

  • router
  • basic navigation & page UI

Additional context
Initial discussion: #77

Determine standards & conventions for streamlining release process

Right now changelog updates and releases are very manual. If we can decide on some ways to standardize our workflow, hopefully we can streamline this process in the interest of releasing frequently without friction. Ideas may include using https://www.conventionalcommits.org/en/v1.0.0/ and auto-generating changelog items from commit messages. This is a new area for me so I am actively seeking input and ideas. Also if anyone is interested in taking this on, playing around with some ideas and figuring out what might be a good workflow, please feel free!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.