Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork85
An implementation of the GOV.UK Design System in React using CSSinJS
License
govuk-react/govuk-react
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
An implementation of theGOV.UK Design System inReact usingCSSinJS using Object notation (withstyled-components).
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.
- GOV.UK Frontend
- GOV.UK Design System (source)
- GOV.UK Publishing Components
- GOV.UK Design System Backlog (where there are open tickets in the backlog that reference patterns/components in existing govuk sites)
- GOV.UK/elements
- Any other established govuk pattern
This project is being or has been used by:
- Connected Open Government Statistics2
- Department for Education
- Department for Environment, Food & Rural Affairs2
- Department for International Trade234
- Department of Business, Energy and Industrial Strategy
- Department of Health
- Department for Environment, Food and Rural Affairs
- Department for Transport
- Food Standards Agency2
- HM Courts & Tribunals Service2
- HM Land Registry
- HM Passport Office
- HM Prison and Probation Services2
- Home Office [2]
- Made Tech2
- Ministry of Justice2
- London Borough of Hackney
- Public Health England/UK Health Security Agency
- Skills Funding Agency2
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 viaDiscussions orTwitter.
npm install govuk-react styled-components @types/styled-components --save
import{Button}from'govuk-react'constMyComponent=({title})=>(<div><h1>{title}</h1><Button/></div>)
See theStorybook for examples of all available components.
Also see theExample Application for basic usage.
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 theas prop. Other props will be passed through.
For example;
import{BrowserRouter,LinkasRouterLink}from'react-router';import{Link}from'@govuk-react/link';constMyComponent=()=>(<nav><BrowserRouter><Linkas={RouterLink}to="https://example.com">example</Link></BrowserRouter></nav>);
Use of these components assumes the following from the peer project:
- The govuk-react
GlobalStylecomponent is included on all pages. - The GDS Transport font face is included (for gov.uk domains only)
- Optionally, eithernormalize.css orsanitize.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.
SeeA 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 (usingnpm publish) and consumed by a peer application, without putting dependencies on the peer application to implement a specific CSS build system.
- 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).
- 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 simplenpm install govuk-reactto be enough to get govuk styled components on to your page, irrespective of your build system. - 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.
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';importDateFieldfrom'@govuk-react/date-field';
Then in your package.json, you can update govuk-react, but specify the older version of '@govuk-react/date-field'.
Unfortunately the GDS transport font has a relatively restrictive licensedescribed on the gov.uk blog. We are investigating rendering an elegant alternative before falling back to Arial onissue 272.
- govuk-elements (source)
- govuk_frontend_toolkit
- govuk-frontend
- govuk_template (source)
- GOV.UK Design Patterns
We useChromaticqa for visual regression testing and it is awesome, you should too!
Want to contribute? Checkout ourContributing page.
About
An implementation of the GOV.UK Design System in React using CSSinJS
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.