import BackLink from '@govuk-react/back-link';
Simple
<BackLink>Back</BackLink>
With custom click handler
<BackLink onClick={this.myCustomFunction}>Back</BackLink>
With href
attribute
<BackLink href='#'>Back</BackLink>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
'Back' |
string | Text that will appear in the back link | |
onClick |
undefined |
func | Custom function to run when the onClick event is fired |
import Breadcrumb from '@govuk-react/breadcrumb';
Simple
<Breadcrumb>
<a href="/section">Section</a>
<a href="/section/sub-section">Sub-section</a>
Current page
</Breadcrumb>
Using asAnchor
HOC with, or without React Router
import { Link } from 'react-router-dom';
import { asAnchor } from '@govuk-react/hoc';
const AnchorLink = asAnchor(Link);
const AnchorTag = asAnchor('a');
<Breadcrumb>
<AnchorLink to="/section">Section</AnchorLink>
<AnchorTag href="/section">Sub-section</AnchorTag>
</Breadcrumb>
- Consider using the context API https://github.com/reactjs/rfcs/blob/master/text/0002-new-version-of-context.md
- Consider nested anchors, create an Atom for Breadcrumb links?
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | Breadcrumb contents |
import Button from '@govuk-react/button';
Simple
<Button>My button text</Button>
With Icon
import { ButtonArrow } from '@govuk-react/icons';
<Button icon={<ButtonArrow />}>My button text</Button>
- https://govuk-elements.herokuapp.com/buttons/
- https://github.com/alphagov/govuk_frontend_toolkit/blob/master/stylesheets/design-patterns/_buttons.scss
- https://github.com/alphagov/govuk-frontend/blob/master/src/components/button/_button.scss
- https://github.com/alphagov/govuk_elements/blob/master/packages/govuk-elements-sass/public/sass/elements/_buttons.scss
- Use constants for some of the values cssinjs values
- Remove cascade styling for nested elements such as
svg
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
'Button' |
node | Button text | |
disabled |
false |
bool | Renders a disabled button and removes pointer events if set to true | |
icon |
undefined |
node | Button icon | |
start |
false |
bool | Renders a large button if set to true |
import Checkbox from '@govuk-react/checkbox';
Simple
<Checkbox>Text displayed next to checkbox</Checkbox>
With disabled state
<Checkbox disabled="disabled">Disabled checkbox option</Checkbox>
Checkbox preselected
<Checkbox defaultChecked>Farm or agricultural waste</Checkbox>
Checkbox preselected & disabled
<Checkbox disabled="disabled" defaultChecked>Farm or agricultural waste</Checkbox>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | Text content for checkbox |
className |
undefined |
string | CSS Classname for outermost container |
import DateField from '@govuk-react/date-field';
Simple
<DateField>What is your date of birth?</DateField>
Date with hint text
<DateField hintText="For example, 31 03 1980">
What is your date of birth?
</DateField>
Date with hint text & error
<DateField
hintText="For example, 31 03 1980"
errorText="Error message goes here"
>
What is your date of birth?
</DateField>
With custom input name props
<DateInput hintText="For example, 31 03 1980"
inputNames={{
day: 'dayInputName',
month: 'monthInputName',
year: 'yearInputName',
}}
>
What is your date of birth?
</DateField>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | |
defaultValues |
{ day: undefined, month: undefined, year: undefined, } |
custom | ||
errorText |
undefined |
string | Error text | |
hintText |
undefined |
string | Optional hint text | |
input |
undefined |
shape[object Object] | Properties that are sent to the input, matching final form input type | |
inputNames |
{ day: undefined, month: undefined, year: undefined, } |
shape[object Object] | Input name attributes |
import DocumentFooterMetadata from '@govuk-react/document-footer-metadata';
Simple
import { asAnchor } from '@govuk-react/hoc';
const AnchorTag = asAnchor('a');
const fromData = [
<AnchorTag href="/government/organisations/ministry-of-defence">
Ministry of Defence
</AnchorTag>,
];
<DocumentFooterMetadata from={fromData} />
DFM From & part of example
import { asAnchor } from '@govuk-react/hoc';
const AnchorTag = asAnchor('a');
const fromData = [
<AnchorTag href="/government/organisations/ministry-of-defence">
Ministry of Defence
</AnchorTag>,
];
const partOfData = [
<AnchorTag href="/government/topics/energy">Energy</AnchorTag>,
<AnchorTag href="/government/topics/environment">Environment</AnchorTag>,
];
<DocumentFooterMetadata from={fromData} partOf={partOfData} />
DFM From & other data example
import { asAnchor } from '@govuk-react/hoc';
const AnchorTag = asAnchor('a');
const fromData = [
<AnchorTag href="/government/organisations/ministry-of-defence">
Ministry of Defence
</AnchorTag>,
];
const otherData = [
{
id: 0,
title: 'Consultation type',
content: <AnchorTag href="/government/publications">Open</AnchorTag>,
},
{
id: 1,
title: 'Published',
content: '20 January 2012',
},
];
<DocumentFooterMetadata from={fromData} other={otherData} />
Prop | Required | Default | Type | Description |
---|---|---|---|---|
from |
undefined |
arrayOf[object Object] | Array of JSX nodes to render underneath the from: title |
|
other |
undefined |
arrayOf[object Object] | Array of Objects for any additional items, each object should contain an id , title and content property |
|
partOf |
undefined |
arrayOf[object Object] | Array of JSX nodes to render underneath the part of: title |
import ErrorSummary from '@govuk-react/error-summary';
Simple
const heading = 'Message to alert the user to a problem goes here';
const description = 'Optional description of the errors and how to correct them';
const errors = [
{
targetName: 'national-insurance-number',
text: 'National Insurance number error',
},
{
targetName: 'description',
text: 'Description of what you saw error',
},
];
const onHandleErrorClick = (targetName) => {
document.getElementsByName(targetName)[0].scrollIntoView();
};
<div>
<ErrorSummary
heading={heading}
description={description}
onHandleErrorClick={onHandleErrorClick}
errors={errors}
/>
<InputField
name="national-insurance-number"
hint="It’s on your National Insurance card, benefit letter, payslip or P60."
>
National Insurance number
</InputField>
<br />
<TextArea name="description">Description of what you saw</TextArea>
</div>
- https://govuk-elements.herokuapp.com/errors/#summarise-errors
- https://github.com/alphagov/govuk-frontend/tree/master/src/components/error-summary
- Swap out browser dependancy for context API to help with React Native support
Prop | Required | Default | Type | Description |
---|---|---|---|---|
description |
undefined |
string | Optional description of the errors | |
errors |
[] |
arrayOf[object Object] | Array of errors with text and target element name to scroll into view when clicked | |
heading |
true | `````` | string | Heading text |
onHandleErrorClick |
() => {} |
func | onClick function to scroll the target element into view |
import ErrorText from '@govuk-react/error-text';
Simple
<ErrorText errorText="example">Example</ErrorText>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | string | Text to describe the error |
import FileUpload from '@govuk-react/file-upload';
Simple
<FileUpload name="group0">Upload a document</FileUpload>
Input with hint text
<FileUpload
name="group1"
acceptedFormats=".jpg, .png"
hint={['This can be in either JPG or PNG format']}
>
Upload a photo
</FileUpload>
Input with hint text & error
const meta = {
touched: true,
error: 'Example',
};
<FileUpload
name="group1"
acceptedFormats=".jpg, .png"
hint={['This can be in either JPG or PNG format']}
meta={meta}
>
Upload a photo
</FileUpload>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
acceptedFormats |
undefined |
string | ||
children |
true | `````` | node | |
hint |
undefined |
string | Optional hint text | |
meta |
{} |
shape[object Object] | Final form meta object, pending adjustment/removal |
import GridCol from '@govuk-react/grid-col';
Should always be wrapped by GridRow
. Will always render a column at 100% width if
the browser width is below the LARGESCREEN
breakpoint.
Example
Simple
import GridRow from '@govuk-react/grid-row';
import GridCol from '@govuk-react/grid-col';
<Fragment>
<GridRow>
<GridCol>
...
</GridCol>
</GridRow>
<GridRow>
<GridCol columnOneHalf>
...
</GridCol>
<GridCol columnOneQuarter>
...
</GridCol>
<GridCol columnOneQuarter>
...
</GridCol>
<GridRow>
<GridCol columnOneThird>
...
</GridCol>
<GridCol columnTwoThirds>
...
</GridCol>
</GridRow>
</Fragment>
- https://github.com/alphagov/govuk_frontend_toolkit/blob/master/stylesheets/_grid_layout.scss
- https://github.com/alphagov/govuk_elements/blob/master/assets/sass/elements/_layout.scss
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
undefined |
node | GridCol content | |
columnOneHalf |
false |
bool | Dimension setting for the column | |
columnOneQuarter |
false |
bool | Dimension setting for the column | |
columnOneThird |
false |
bool | Dimension setting for the column | |
columnTwoThirds |
false |
bool | Dimension setting for the column |
import GridRow from '@govuk-react/grid-row';
Example
Simple
import GridRow from '@govuk-react/grid-row';
import GridCol from '@govuk-react/grid-col';
<Fragment>
<GridRow>
<GridCol>
...
</GridCol>
</GridRow>
</Fragment>
- https://github.com/alphagov/govuk_frontend_toolkit/blob/master/stylesheets/_grid_layout.scss
- https://github.com/alphagov/govuk_elements/blob/master/assets/sass/elements/_layout.scss
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | One or more GridCol nodes |
import Header from '@govuk-react/header';
Simple
<Header level={1}>Heading text</Header>
Using shortcuts
import { H1, H2, H3, H4, H5, H6 } from "@govuk-react/header";
<H1>h1</H1>
<H2>h2</H2>
<H3>h3</H3>
<H4>h4</H4>
<H5>h5</H5>
<H6>h6</H6>
Differing sizes
<Header level={6} size="XXLARGE">
h6 with XXLARGE style
</Header>
<Header level={2} size="XSMALL">
h2 with XSMALL style
</Header>
<H3 size="LARGE">h3 with LARGE style</H3>
Props pass through
<Header onClick={() => { console.log('clicked'); }}>Click me</Header>
- https://govuk-elements.herokuapp.com/typography/#typography-headings
- https://github.com/alphagov/govuk_frontend_toolkit/blob/master/stylesheets/_typography.scss
- https://github.com/alphagov/govuk-frontend/blob/master/src/globals/scss/core/_typography.scss
- https://github.com/alphagov/govuk_elements/blob/master/packages/govuk-elements-sass/public/sass/elements/_elements-typography.scss
Prop | Required | Default | Type | Description |
---|---|---|---|---|
level |
1 |
number | Semantic heading level value between 1 and 6 | |
size |
undefined |
enumObject.keys(FONT_SIZES) | Visual size level, accepts XLARGE , LARGE , MEDIUM , SMALL , XSMALL |
HiddenText
import HiddenText from '@govuk-react/hidden-text';
Simple
import Paragraph from '@govuk-react/paragraph';
<HiddenText summaryText={'Help with nationality'}>
<Paragraph mb={0}>I am a paragraph. Please read me.</Paragraph>
</HiddenText>
- https://govuk-elements.herokuapp.com/typography/#typography-hidden-text
- https://github.com/alphagov/govuk-frontend/blob/master/src/components/details/_details.scss
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
undefined |
node | The nodes that will be displayed within the InsetText component | |
summaryText |
true | `````` | string | Text for the summary button link e.g. Help with nationality |
import HintText from '@govuk-react/hint-text';
Simple
<HintText>Example</HintText>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | Text for the hint |
import InputField from '@govuk-react/input-field';
Simple
<InputField name="group0">National Insurance number</InputField>
Input with hint text
<InputField
name="group1"
hint={[
'It’s on your National Insurance card, benefit letter, payslip or P60.',
<br />,
'For example, ‘QQ 12 34 56 C’.',
]}
>
National Insurance number
</InputField>
Input with hint text & error
const meta = {
touched: true,
error: 'Example',
};
<InputField
name="group1"
hint={[
'It’s on your National Insurance card, benefit letter, payslip or P60.',
<br />,
'For example, ‘QQ 12 34 56 C’.',
]}
meta={meta}
>
National Insurance number
</InputField>
- https://github.com/alphagov/govuk-frontend/blob/master/src/components/input/_input.scss
- https://github.com/alphagov/govuk_elements/blob/master/assets/sass/elements/_forms.scss
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | |
hint |
undefined |
node | ||
input |
{} |
shape[object Object] | ||
meta |
{} |
shape[object Object] |
import Input from '@govuk-react/input';
Simple
<Input />
- Remove
errorColor
and provide examples on how to extend the component
Prop | Required | Default | Type | Description |
---|---|---|---|---|
type |
'text' |
string | HTML <Input /> type |
import InsetText from '@govuk-react/inset-text';
Simple
import Paragraph from '@govuk-react/paragraph';
<InsetText>
<Paragraph mb={0}>Hello</Paragraph>
</InsetText>
Narrow border
import Paragraph from '@govuk-react/paragraph';
<InsetText isNarrow>
<Paragraph mb={0}>Hello</Paragraph>
</InsetText>
- https://govuk-elements.herokuapp.com/typography/#typography-inset-text
- https://github.com/alphagov/govuk-frontend/blob/master/src/components/inset-text/_inset-text.scss
- https://github.com/alphagov/govuk_elements/blob/master/packages/govuk-elements-sass/public/sass/elements/_panels.scss
Prop | Required | Default | Type | Description |
---|---|---|---|---|
isNarrow |
false |
bool | Renders a narrow border following GDS guides if set to true |
import LabelText from '@govuk-react/label-text';
Simple
<LabelText>Example</LabelText>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | Text for the label |
import Label from '@govuk-react/label';
Simple
<Label>Example</Label>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | Text for the label |
import Layout from '@govuk-react/layout';
THIS COMPONENT IS NO LONGER REQUIRED TO ACHIEVE LAYOUT;
-
GridCol
contains the required gutters, we do not need to provide additional gutter to build an accurate grid layout. -
GridRow
contains the requireddisplay: flex;
and associated properties forGridCol
. -
Main
contains the required properties to center a container that matches up withTopNav
and house the remaining body of content for the page.
If you feel you may still need a Layout
component, please do raise a ticket on Github
This component provides default padding. You can use this component to wrap Grid components however it is not required.
Simple usage
import GridRow from '@govuk-react/grid-row';
import GridCol from '@govuk-react/grid-col';
<Layout>
<GridRow>
<GridCol>
...
</GridCol>
</GridRow>
</Layout>
- https://github.com/alphagov/govuk_frontend_toolkit/blob/master/stylesheets/_grid_layout.scss
- https://github.com/alphagov/govuk_elements/blob/master/assets/sass/elements/_layout.scss
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | GridRow and GridCol children nodes |
import LeadParagraph from '@govuk-react/lead-paragraph';
Simple
<LeadParagraph>LeadParagraph example</LeadParagraph>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | Text in the Lead paragraph |
import ListItem from '@govuk-react/list-item';
Simple
<ListItem>List item example</ListItem>
With anchor
import { asAnchor } from '@govuk-react/hoc';
<ListItem>
<AnchorTag href="https://www.google.com/">{text('Children', 'List item example')}</AnchorTag>
</ListItem>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | List item content |
import ListNavigation from '@govuk-react/list-navigation';
Simple
<ListNavigation>
<a href="/section-a">Section A</a>
<a href="/section-b">Section B</a>
</ListNavigation>
Current recommended approach using the asAnchor
HOC for GDS styled links
import { asAnchor } from '@govuk-react/hoc';
const AnchorTag = asAnchor('a');
<ListNavigation listStyleType="square">
<AnchorTag href="https://example.com/link-a">Link A</AnchorTag>
<AnchorTag href="https://example.com/link-b">Link B</AnchorTag>
</ListNavigation>
Using React Router and asAnchor
HOC for GDS styled links
import { Link } from 'react-router-dom';
import { asAnchor } from '@govuk-react/hoc';
const AnchorLink = asAnchor(Link);
<ListNavigation listStyleType="circle">
<AnchorLink to="/link-a">Link A</AnchorLink>
<AnchorLink to="/link-b">Link B</AnchorLink>
</ListNavigation>
- Consider using the context API https://github.com/reactjs/rfcs/blob/master/text/0002-new-version-of-context.md
- Consider nested anchors, should developers have to use the HOC to preserve link styling?
- Fix active state overlaping siblings
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | List navigation content |
listStyleType |
undefined |
string | CSS value for list-style-type |
import LoadingBox from '@govuk-react/loading-box';
Simple
<LoadingBox loading>
Lorem ipsum dolor sit amet
</LoadingBox>
Loading box complex
<LoadingBox
loading={false}
backgroundColor={'#fff'}
timeIn={800}
timeOut={200}
backgroundColorOpacity={0.85}
spinnerColor={'#000'}
>
Lorem ipsum dolor sit amet
</LoadingBox>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
backgroundColor |
WHITE |
string | Background color (3 or 6 Hex char) of loading spinner overlay when loading is true. | |
backgroundColorOpacity |
0.85 |
number | Opacity of loading spinner backgroud colour when loading is true | |
children |
true | `````` | node | One or more children nodes that loading box will overlay |
loading |
false |
bool | Whether loading is currently set to true or false | |
spinnerColor |
BLACK |
string | Color (3 or 6 Hex char) of loading spinner | |
timeIn |
800 |
number | Length of fade-in animation in milliseconds | |
timeOut |
200 |
number | Length of fade-out animation in milliseconds | |
title |
undefined |
string | Loading spinner title text |
import Main from '@govuk-react/main';
Provides a container which aligns to the topNav component, is centered, and provides top padding.
Example
Simple
import GridRow from '@govuk-react/grid-row';
import GridCol from '@govuk-react/grid-col';
<Main>
<GridRow>
<GridCol>
...
</GridCol>
</GridRow>
</Main>
- Implement the 1020px min-width MQ to constants
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
undefined |
node | Child nodes for the page being built |
import MultiChoice from '@govuk-react/multi-choice';
Simple
import Radio from '@govuk-react/radio';
<MultiChoice label="example">
<Radio name="group1" inline>
Yes
</Radio>
<Radio name="group1" inline>
No
</Radio>
</MultiChoice>
- https://govuk-elements.herokuapp.com/errors/
- https://govuk-elements.herokuapp.com/errors/example-form-validation-single-question-radio
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | |
hint |
undefined |
string | ||
label |
true | `````` | node | |
meta |
{} |
shape[object Object] |
import OrderedList from '@govuk-react/ordered-list';
Simple
import ListItem from '@govuk-react/list-item';
<OrderedList>
<ListItem>Lorem ipsum dolor sit.</ListItem>
<ListItem>Consectetur adipiscing elit.</ListItem>
<ListItem>Curabitur et libero nec.</ListItem>
</OrderedList>
with Roman
import ListItem from '@govuk-react/list-item';
<OrderedList listStyleType="lower-roman">
<ListItem>Lorem ipsum dolor sit.</ListItem>
<ListItem>Consectetur adipiscing elit.</ListItem>
<ListItem>Curabitur et libero nec.</ListItem>
</OrderedList>
- Consider using the context API https://github.com/reactjs/rfcs/blob/master/text/0002-new-version-of-context.md
Prop | Required | Default | Type | Description |
---|---|---|---|---|
listStyleType |
undefined |
string | CSS value for list-style-type |
import Pagination from '@govuk-react/pagination';
Simple usage with asPaginationItem
HOC
import { asPaginationItem } from '@govuk-react/hoc';
const PaginationAnchor = asPaginationItem('a');
<Pagination>
<PaginationAnchor href="#prev" previousPage>
Previous page
</PaginationAnchor>
<PaginationAnchor href="#next" nextPage>
Next page
</PaginationAnchor>
</Pagination>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | asPaginationItem nodes |
import Panel from '@govuk-react/panel';
Simple
<Panel panelTitle="Application complete" />
Panel with header and HTML body
<Panel
panelTitle="Application complete"
panelBody={['Your reference number', <br />, <strong>HDJ2123F</strong>]}
/>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
panelBody |
undefined |
union(string | array) | |
panelTitle |
true | `````` | string | Panel title text |
import Paragraph from '@govuk-react/paragraph';
Supports bold, italic, links, inline code and block code in Markdown ONLY. This is to ensure we follow GDS as closely as possible. It is worth noting that GDS recommends avoiding bold and italics.
Bold should be avoided in general as not only can it dilute the message, it will also cause Screenreaders to increase the volume of any bold text to reflect the increase in font-weight.
Simple
<Paragraph>Lorem `ipsum` **dolor** sit *amet* with [some link](https://google.com)</Paragraph>
As supporting text
<Paragraph supportingText>Lorem `ipsum` **dolor** sit *amet* with [some link](https://google.com)</Paragraph>
With a block of code
<Paragraph>
Some other text...
```
Some Code Block
```
Some more text.
</Paragraph>
With React router
const ReactRouterLinkRenderer = ({ href, children }) => (
href.match(/^\//)
? <Link to={href}>{children}</Link>
: <a href={href}>{children}</a>
);
<Paragraph linkRenderer={ReactRouterLinkRenderer}>
...
</Paragraph>
- Add test for supporting text
- Review code snippet styling
- Remove magic numbers from inline code styling blocks
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
'' |
node | Text content supporting markdown | |
linkRenderer |
props => <Anchor {...props} /> |
func | ||
supportingText |
false |
bool | Is this paragraph supporting text for another element? |
import PhaseBadge from '@govuk-react/phase-badge';
Simple
<PhaseBadge>beta</PhaseBadge>
import PhaseBanner from '@govuk-react/phase-banner';
Alpha
<PhaseBanner level="alpha">
This part of GOV.UK is being rebuilt –{' '}
<AnchorLink href="https://example.com">find out what that means</AnchorLink>
</PhaseBanner>
Beta
<PhaseBanner level="beta">
This part of GOV.UK is being rebuilt –{' '}
<AnchorLink href="https://example.com">find out what that means</AnchorLink>
</PhaseBanner>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | Children text and links |
level |
true | `````` | string | Alpha or beta banner |
import Radio from '@govuk-react/radio';
Simple
<Radio name="group1">Radio button text example</Radio>
Radio stacked
<div>
<Radio name="group1">Waste from animal carcasses</Radio>
<Radio name="group1">Waste from mines or quarries</Radio>
<Radio name="group1">Farm or agricultural waste</Radio>
</div>
Radio inline
<div>
<Radio name="group1" inline>
Yes
</Radio>
<Radio name="group1" inline>
No
</Radio>
</div>
Radio disabled
<div>
<Radio name="group1" disabled="disabled">
Disabled checkbox option
</Radio>
</div>
Radio preselected
<div>
<Radio name="group1" checked>
Farm or agricultural waste
</Radio>
</div>
Radio preselected & disabled
<div>
<Radio name="group1" disabled="disabled" checked>
Farm or agricultural waste
</Radio>
</div>
- https://github.com/alphagov/govuk-frontend/blob/master/src/components/radios/_radios.scss
- https://github.com/alphagov/govuk_elements/blob/master/assets/sass/elements/_forms.scss
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | |
className |
undefined |
string | ||
inline |
false |
bool |
import RelatedItems from '@govuk-react/related-items';
Simple
import Header from '@govuk-react/header';
import UnorderedList from '@govuk-react/unordered-list';
import ListItem from '@govuk-react/list-item';
import { asAnchor } from '@govuk-react/hoc';
const AnchorTag = asAnchor('a');
<RelatedItems>
<Header level={3}>Example header</Header>
<UnorderedList listStyleType="none">
<ListItem>
<AnchorTag href="https://example.com">Link A</AnchorTag>
</ListItem>
</UnorderedList>
</RelatedItems>
- Replace CSS selectors with imported components
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | Related items content |
import SearchBox from '@govuk-react/search-box';
Simple
import Layout from '@govuk-react/layout';
import GridRow from '@govuk-react/grid-row';
import GridCol from '@govuk-react/grid-col';
<Layout>
<GridRow>
<GridCol>
<SearchBox placeholder="Search GOV.UK">SearchBox example</SearchBox>
</GridCol>
</GridRow>
</Layout>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
placeholder |
undefined |
string |
import Select from '@govuk-react/select';
Simple
<Select name="group1" label="This is a label">
<option value="0">GOV.UK elements option 1</option>
<option value="1">GOV.UK elements option 2</option>
<option value="2">GOV.UK elements option 3</option>
</Select>
Select with hint text
<Select
name="group1"
label="This is a label"
hint={[
'This is and example of hintText/description of what we need from you.',
]}
>
<option value="0">GOV.UK elements option 1</option>
<option value="1">GOV.UK elements option 2</option>
<option value="2">GOV.UK elements option 3</option>
</Select>
Select with hint text & error
const meta = {
touched: true,
error: 'Example',
};
<Select
name="group1"
label="This is a label"
hint={[
'This is and example of hintText/description of what we need from you.',
]}
meta={meta}
>
<option value="0">GOV.UK elements option 1</option>
<option value="1">GOV.UK elements option 2</option>
<option value="2">GOV.UK elements option 3</option>
</Select>
Standalone input with inline label
import LabelText from '@govuk-react/label-text';
import { SelectInput } '@govuk-react/select';
<label>
<LabelText>Sort by:
<SelectInput>
<option value="0">People</option>
<option value="1">Animals</option>
<option value="2">Vegetables</option>
</SelectInput>
</LabelText>
</label>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | |
errorText |
undefined |
string | ||
hint |
undefined |
string | ||
input |
{} |
shape[object Object] | ||
label |
true | `````` | string | |
meta |
{} |
shape[object Object] |
import SupportingHeader from '@govuk-react/supporting-header';
Simple
<SupportingHeader>Heading text</SupportingHeader>
With another header
import { H1 } from '@govuk-react/header';
<SupportingHeader>Supporting header text</SupportingHeader>
<H1>Main header text</H1>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | string | Text to be rendered as a supporting header |
import Table from '@govuk-react/table';
Component default
const example1Body = (
<React.Fragment>
<Table.Row>
<Table.CellHeader>First 6 weeks</Table.CellHeader>
<Table.Cell>£109.80 per week</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Next 33 weeks</Table.Cell>
<Table.Cell>£109.80 per week</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Total estimated pay</Table.Cell>
<Table.Cell>£4,282.20</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Tell the mother’s employer</Table.Cell>
<Table.Cell>28 days before they want to start maternity pay</Table.Cell>
</Table.Row>
</React.Fragment>
);
<Table caption="Dates and amounts" body={example1Body} />
Numeric tabular data
const example2Head = (
<Table.Row>
<Table.CellHeader>Month you apply</Table.CellHeader>
<Table.CellHeader alignRight>Rate for vehicles</Table.CellHeader>
<Table.CellHeader alignRight>Rate for bicycles</Table.CellHeader>
</Table.Row>
);
const example2Body = (
<React.Fragment>
<Table.Row>
<Table.CellHeader>January</Table.CellHeader>
<Table.Cell alignRight>£165.00</Table.Cell>
<Table.Cell alignRight>£85.00</Table.Cell>
</Table.Row>
<Table.Row>
<Table.CellHeader>February</Table.CellHeader>
<Table.Cell alignRight>£165.00</Table.Cell>
<Table.Cell alignRight>£85.00</Table.Cell>
</Table.Row>
<Table.Row>
<Table.CellHeader>March</Table.CellHeader>
<Table.Cell alignRight>£151.00</Table.Cell>
<Table.Cell alignRight>£77.00</Table.Cell>
</Table.Row>
<Table.Row>
<Table.CellHeader>April</Table.CellHeader>
<Table.Cell alignRight>£136.00</Table.Cell>
<Table.Cell alignRight>£70.00</Table.Cell>
</Table.Row>
</React.Fragment>
);
<Table
caption="Attention, I am the caption of this ship!"
head={example2Head}
body={example2Body}
/>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
body |
true | `````` | node | Table body rows and cells |
caption |
undefined |
string | Table caption title | |
head |
undefined |
node | Table header rows and cells |
import TextArea from '@govuk-react/text-area';
Simple
<TextArea name="group1">Description of what you saw</TextArea>
TextArea with hint text
<TextArea name="group1" hint={['Enter as many words as you like']}>
Description of what you saw
</TextArea>
TextArea with hint text & error
const meta = {
touched: true,
error: 'Example',
};
<TextArea
name="group1"
hint={['Enter as many words as you like']}
meta={meta}
>
Description of what you saw
</TextArea>
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | |
hint |
undefined |
string | ||
input |
{} |
shape[object Object] | ||
meta |
{} |
shape[object Object] |
import TopNav from '@govuk-react/top-nav';
TopNav with logo, service title and navigation items
import CrownIcon from '@govuk-react/icon-crown';
import SearchBox from '@govuk-react/search-box';
import Header from '@govuk-react/header';
import TopNav, { asNavLinkAnchor, asTopNavAnchor } from '@govuk-react/top-nav';
const LogoAnchor = asTopNavAnchor('a');
const NavAnchor = asNavLinkAnchor('a');
const link = 'https://example.com?=1';
const Company = (
<LogoAnchor href={link} target="new">
<TopNav.IconTitle icon={<CrownIcon width="36" height="32" />}>GOV.UK</TopNav.IconTitle>
</LogoAnchor>
);
const ServiceTitle = (
<NavAnchor href={link} target="new">
<Header mb="0" level={3}>Service Title</Header>
</NavAnchor>
);
const Search = (
<SearchBox placeholder="Search">hi</SearchBox>
);
<TopNav company={Company} serviceTitle={ServiceTitle} search={Search} active={0}>
<NavAnchor href="https://example.com?q=catdog" target="new">Navigation item #1</NavAnchor>
<NavAnchor href="https://example.com?q=dogcat" target="new">Navigation item #2</NavAnchor>
</TopNav>
import { BrowserRouter, Link } from 'react-router-dom';
import CrownIcon from '@govuk-react/icon-crown';
import Header from '@govuk-react/header';
import TopNav, { asLogoAnchor, asNavLinkAnchor } from '@govuk-react/top-nav';
const LogoLink = asTopNavAnchor(Link);
const NavLink= asNavLinkAnchor(Link);
const reactRouterLink = '/section';
const CompanyLink = (
<LogoLink to={reactRouterLink}>
<TopNav.IconTitle icon={<CrownIcon width="36" height="32" />}>GOV.UK</TopNav.IconTitle>
</LogoLink>
);
const ServiceTitleLink = (
<NavLink to={reactRouterLink}>
<Header mb="0" level={3}>Service Title</Header>
</NavLink>
);
<BrowserRouter>
<TopNav company={CompanyLink} serviceTitle={ServiceTitleLink} />
</BrowserRouter>
- http://alphagov.github.io/govuk_template/example-proposition-menu.html
- https://design-system.service.gov.uk/components/header/
- TODO: this component is a work in progress and needs to more closely match existing examples
- TODO: is TopNav the right name? What's it called in other GDS styles/patterns?
- TODO: (The name Header is ambiguous)
- TODO: #205 Use context api and/or render props for
active
navigation items - TODO: Vertical alignment here needs some work, perhaps should be its own component
- TODO: Icon should be lined up with font baseline, e.g. vertical-align: baseline
Prop | Required | Default | Type | Description |
---|---|---|---|---|
bgColor |
BLACK |
string | Top nav background color | |
children |
undefined |
node | List Navigation items with anchor tags e.g. NavAnchor components | |
color |
WHITE |
string | Top nav text color | |
company |
undefined |
node | Company component e.g. GOV UK | |
defaultOpen |
false |
bool | Is the mobile navigation open by default? | |
search |
false |
node | Search component | |
serviceTitle |
undefined |
node | Service title component e.g. Food Standards Authority |
import UnorderedList from '@govuk-react/unordered-list';
Simple
import ListItem from '@govuk-react/list-item';
<UnorderedList>
<ListItem>Lorem ipsum dolor sit.</ListItem>
<ListItem>Consectetur adipiscing elit.</ListItem>
<ListItem>Curabitur et libero nec.</ListItem>
</UnorderedList>
With listStyleType option
import ListItem from '@govuk-react/list-item';
<UnorderedList listStyleType="square">
<ListItem>Lorem ipsum dolor sit.</ListItem>
<ListItem>Consectetur adipiscing elit.</ListItem>
<ListItem>Curabitur et libero nec.</ListItem>
</UnorderedList>
- Consider using the context API https://github.com/reactjs/rfcs/blob/master/text/0002-new-version-of-context.md
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | One or more ListItem components |
listStyleType |
undefined |
string | CSS value for list-style-type |
import WarningText from '@govuk-react/warning-text';
Simple
<WarningText>Example</WarningText>
- https://govuk-elements.herokuapp.com/typography/#typography-warning-text
- https://github.com/alphagov/govuk-frontend/tree/master/src/components/warning-text
Prop | Required | Default | Type | Description |
---|---|---|---|---|
children |
true | `````` | node | Warning text to be displayed |