This package is no longer maintained and will not receive updates bringing it beyond govuk-frontend 4.0.1. If you are using this in your project the simplest way forward is to copy and paste the components from here into your project allowing you to keep them up to date with govuk-frontend yourselves.
View the readme
[![govuk-frontend 4.0.1](https://img.shields.io/badge/govuk--frontend%20version-4.0.1-005EA5?logo=gov.uk&style=flat-square)](https://github.com/alphagov/govuk-frontend/releases/tag/v4.0.1)
[![version](https://img.shields.io/npm/v/govuk-react-jsx.svg?style=flat-square)](https://www.npmjs.com/package/govuk-react-jsx)
![(Pipeline)](https://github.com/surevine/govuk-react-jsx/workflows/Pipeline/badge.svg)
[![MIT License](https://img.shields.io/npm/l/govuk-react-jsx.svg?style=flat-square)](https://github.com/surevine/govuk-react-jsx/blob/main/LICENSE)
_Please note - the version number of govuk-react-jsx is independent of the govuk-frontend version number._
View demo at https://govuk-react-jsx.netlify.app/
View example app at https://surevine.github.io/govuk-react-jsx-examples/ (for which the source code is at https://github.com/surevine/govuk-react-jsx-examples)
## WARNING
> **If you do not need the characteristics of a Single Page App framework like React, please consider using something else**. [Government services should be progressively enhanced](https://www.gov.uk/service-manual/technology/using-progressive-enhancement), and [should function without JavaScript enabled](https://kryogenix.org/code/browser/everyonehasjs.html).
>
> If you have an explicit requirement that cannot be delivered effectively in a progressively enhanced manner then you might have a case for using React. If you have plans to build your React app in a progressively enhanced way, you might be fine. Whatever you do, be prepared to defend it at a service assessment.
## Quick install
```
$ npm install govuk-react-jsx
```
(See [installation and usage](#installation--usage) for more details)
## Motivation
This repository contains govuk-frontend compatible React components. The aim of this package is to steer closely to govuk-frontend by consuming the CSS directly from the govuk-frontend npm package. And to strike a balance between mirroring the GOV.UK Nunjucks params vs ideomatic React props.
This has the following benefits
- Generated markup is identical to the output from the govuk-frontend macros. This allows us to benefit from the hard work that GDS has put into forming good markup patterns, including use of aria attributes.
- Keeping up to date with upstream changes in govuk-frontend is as simple as updating the package.json version and mirroring any markup changes made. The test suite helps with this by comparing our output against the reference Nunjucks output - any differences constitute a test failure.
- Anyone that knows the GOV.UK Nunjucks macros will quickly feel familiar with the structure of these components
## Comparison with govuk-react
[govuk-react](https://github.com/govuk-react/govuk-react) is the other main option in this space. Naturally the first thing people ask is why one might use this repository instead of govuk-react. Here's my take on the matter:
| govuk-react | govuk-react-jsx (This repository) |
| ----------- | --------------------------------- |
| An _implementation of_ the govuk design system. CSS, JS and Markup patterns have all been rewritten from scratch. Aria attributes missing. | Directly consumes the govuk-frontend CSS/JS and accurately mirrors their markup patterns, including Aria attributes |
| Upstream CSS/JS changes in govuk-frontend need to be manually transferred across and/or rebuilt | Upstream CSS/JS changes are pulled in automatically. Only markup changes need to manually transferred (But are validated as correct by the test suite) |
| Relatively complex code | Simpler code - just plain JSX ports of the Nunjucks |
| Uses StyledComponents Great if you like them and use them. But if you prefer a different library then you would end up needing both in your toolchain. Increased maintenance burden on govuk-react team | Uses plain Sass compilation of the govuk-frontend code. You are free to use a CSSinJS library of your choice for your own styles if you wish |
| Cleaner component props since it has been designed from the ground up for React | Props mostly mirror the govuk-frontend Nunjucks params with some exceptions as below. This has been done in order to steer as closely to govuk-frontend as possible, and to facilitate the test suite checking the output against the original.