npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

govuk-react

v0.10.7

Published

govuk-react: A port of the govuk-frontend components for React using styled-components.

Downloads

30,191

Readme

govuk-react

An implementation of the GOV.UK Design System in React using CSSinJS using Object notation (with styled-components).

codecov Join the community on Spectrum

We aim to track the following projects (in priority order) as to which components to implement and how they should look/behave. Where possible we are using the existing CSS as a guide. When we need to modify to suit custom markup, we aim to provide a comment in our code as to why this was done.

This project is being or has been used by:

The project is currently maintained for free by a small number of volunteers. If you would like to contribute, help maintain or sponsor this project, please get in touch via Discussions or Twitter.

Usage

npm install govuk-react styled-components @types/styled-components --save
import { Button } from 'govuk-react'

const MyComponent = ({title}) => (<div>
  <h1>{title}</h1>
  <Button />
</div>)

See the Storybook for examples of all available components.

Also see the Example Application for basic usage.

Using Link with a Router Link

We provide a Link component which creates an element styled as a GDS link. As we are using styled-components it is possible to apply that style to an existing component using the as prop. Other props will be passed through.

For example;

import { BrowserRouter, Link as RouterLink } from 'react-router';
import { Link } from '@govuk-react/link';

const MyComponent = () => (
  <nav>
    <BrowserRouter>
      <Link as={RouterLink} to="https://example.com">example</Link>
    </BrowserRouter>
  </nav>
);

Assumptions

Use of these components assumes the following from the peer project:

  • The govuk-react GlobalStyle component is included on all pages.
  • The GDS Transport font face is included (for gov.uk domains only)
  • Optionally, either normalize.css or sanitize.css is used as a CSS reset. We don't test for this, so please raise an issue if you find any problems with compatibility.
  • Other than the reset, no other styles affecting generic elements (without classes, IDs etc) are present in the CSS.

Why CSS-in-JS?

See A Unified Styling Language.

This project is part of a larger initiative to componetise large scale React applications. Using CSSinJS allows us to include styles inside a module bundle that can be published (using npm publish) and consumed by a peer application, without putting dependencies on the peer application to implement a specific CSS build system.

Why not use GDS styles/classes directly

  1. We want to be free to write different DOM structure and/or CSS that is more in keeping with a React and bem-ish architecture. (e.g. in React you often don't need to specify IDs for field inputs, and can wrap inputs with labels so that they are automatically associated. We want to leave the decision of whether to use input IDs to the parent project. GDS styles don't wrap inputs with labels and require IDs and for attributes).
  2. We want a parent project to not have to worry about a specific build system (e.g. for handling import styles.css, particularly if you want universal support) or including certain CSS files. We want a simple npm install govuk-react to be enough to get govuk styled components on to your page, irrespective of your build system.
  3. We want to distribute React applications as modules that have self contained styles. CSS in JS allows all styles to be contained in distributable JS modules that can be ported across projects.

Why is this a monorepo?

Components are published to npm independently. This means users have the ability to upgrade govuk-react and still use older components.

This is particularly relevant in a large application where:

  • some code is reliant on a component that has either been deprecated or had breaking changes
  • you aren't able to refactor the existing code, e.g. it is a large job or managed by another team
  • you don't want to hold back from upgrading to the newest version of govuk-react

e.g. for DateField, you import it separately as follows:

import { H1, Paragraph } from 'govuk-react';
import DateField from '@govuk-react/date-field';

Then in your package.json, you can update govuk-react, but specify the older version of '@govuk-react/date-field'.

About the GDS font

Unfortunately the GDS transport font has a relatively restrictive license described on the gov.uk blog. We are investigating rendering an elegant alternative before falling back to Arial on issue 272.

Related sites and projects

GOV.UK

Other React component libraries

Acknowledgements

We use Chromaticqa for visual regression testing and it is awesome, you should too!

Contributors

Want to contribute? Checkout our Contributing page.