Skip to content
المشاريع

حول

An implementation of the GOV.UK Design System in React

تطوير الويب والتطبيقات

كيف تُقاس هذه الأرقام

النمو المقاس للنجوم

خلال 24 ساعة
٠
خلال 7 أيام
٠
خلال 15 يومًا
٠
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

govuk-react

An implementation of the GOV.UK Design System in React, built on govuk-frontend-react and styled by govuk-frontend's CSS.

govuk-react is a community project, actively maintained by volunteers. It isn't an official port of GOV.UK Frontend and isn't supported by the GOV.UK Design System team, who maintain GOV.UK Frontend.

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.

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.

Do you need React?

Point 5 of the Service Standard is to make sure everyone can use the service. Alex Russell argues that React is too heavy for users on the margins, and that it has repeatedly led to bloated services that keep people out, in both the public and private sector. His Reckoning series sets out the evidence.

For most public-facing services, plain HTML with govuk-frontend is enough. govuk-react is for teams that have already chosen React. It renders the same markup as govuk-frontend, and every component works before and without JavaScript, so pages can be rendered on the server. The Service Manual's guidance on building a robust frontend using progressive enhancement describes how government services are expected to work without JavaScript. See Server rendering.

If you use React, keep an eye on bundle size and on performance on low-end devices and slow connections, and check that your service still works before JavaScript loads.

Usage

npm install govuk-react govuk-frontend

Load govuk-frontend's CSS once in your app, then govuk-react's, which styles what govuk-frontend has no classes for:

import 'govuk-frontend/dist/govuk/govuk-frontend.min.css';
import 'govuk-react/styles.css';
import { Button } from 'govuk-react';

const MyComponent = ({ title }) => (
  <div>
    <h1>{title}</h1>
    <Button>Save and continue</Button>
  </div>
);

See the Storybook for examples of all available components.

Also see the Example Application for basic usage, and the Astro example for forms that submit and show their errors without JavaScript, and for islands and inline scripts.

Fonts and images

govuk-frontend's CSS loads its fonts and images from /assets. Serve node_modules/govuk-frontend/dist/govuk/assets at /assets, or copy its fonts and images folders and manifest.json into your app's assets folder. See govuk-frontend's guide to importing font and images assets.

"If your service is on the service.gov.uk subdomain you must use the GDS Transport font."

"If your service is publicly available on a subdomain other than service.gov.uk, use an alternative typeface." See the Design System's typeface guidance and using GOV.UK Frontend without GOV.UK branding, which sets $govuk-font-family with govuk-frontend's Sass API.

Using Link with a Router Link

Link, BackLink and the navigation link parts take asChild, which applies their classes to your router link instead of rendering an a:

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

const MyComponent = () => (
  <Link asChild>
    <RouterLink to="/page">Page</RouterLink>
  </Link>
);

Assumptions

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

  • govuk-frontend is installed and its CSS (govuk-frontend/dist/govuk/govuk-frontend.min.css) is loaded, followed by govuk-react/styles.css.
  • govuk-frontend's font and image assets are served at /assets (see Fonts and images).
  • No other styles affecting generic elements (without classes, IDs etc) are present in the CSS.

Imports

Import from the package root, or from a component's own subpath:

import { Body, Heading } from 'govuk-react';
import * as DateInput from 'govuk-react/date-input';

Migrating to 1.0

See MIGRATION.md.

Related sites and projects

GOV.UK

Acknowledgements

We use Chromatic for visual regression testing.

Deploys by Netlify

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…