Skip to content

Commit 180a3bf

Browse files
ThomasThomas
authored andcommitted
Merge branch 'main' of github.com:NHSDigital/nhsuk-react-components into feature/storybook-6-upgrade
2 parents 984e4c3 + 3345d95 commit 180a3bf

File tree

21 files changed

+272
-63
lines changed

21 files changed

+272
-63
lines changed

.github/workflows/storybook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build & Deploy Storybook
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77

88
jobs:
99
build-and-deploy:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
NHS.UK Frontend ported to React
44

5-
[![GitHub Actions CI Status](https://github.com/NHSDigital/nhsuk-react-components/workflows/CI/badge.svg)](https://github.com/NHSDigital/nhsuk-react-components/actions?query=workflow%3A%22CI+Build%22+branch%3Amaster) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-airbnb-brightgreen.svg)](https://github.com/airbnb/javascript) [![Bundle Size](https://img.shields.io/bundlephobia/minzip/nhsuk-react-components.svg)](https://bundlephobia.com/result?p=nhsuk-react-components@1.0.0-rc.1)
5+
[![GitHub Actions CI Status](https://github.com/NHSDigital/nhsuk-react-components/workflows/CI/badge.svg)](https://github.com/NHSDigital/nhsuk-react-components/actions?query=workflow%3A%22CI+Build%22+branch%3Amain) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-airbnb-brightgreen.svg)](https://github.com/airbnb/javascript) [![Bundle Size](https://img.shields.io/bundlephobia/minzip/nhsuk-react-components.svg)](https://bundlephobia.com/result?p=nhsuk-react-components)
66

77
## Coming from 0.x?
88

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nhsuk-react-components",
3-
"version": "1.2.6",
3+
"version": "1.2.8",
44
"author": {
55
"email": "[email protected]",
66
"name": "Thomas Judd-Cooper",
@@ -84,7 +84,8 @@
8484
"test:watch": "jest --watch",
8585
"lint": "eslint --fix -c .eslintrc.js --ext .ts --ext .tsx src/*.ts src/components/**/*.ts src/util/*.ts",
8686
"prebuild": "yarn lint && yarn test --coverage",
87-
"build-storybook": "build-storybook --no-dll"
87+
"build-storybook": "build-storybook --no-dll",
88+
"prepare": "yarn build"
8889
},
8990
"files": [
9091
"dist",

src/components/action-link/ActionLink.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import React, { HTMLProps } from 'react';
1+
import React from 'react';
22
import classNames from 'classnames';
33
import { ArrowRightCircle } from '../icons';
4+
import type { AsElementLink } from 'util/types/LinkTypes';
45

5-
const ActionLink: React.FC<HTMLProps<HTMLAnchorElement>> = ({ children, className, ...rest }) => (
6+
const ActionLink: React.FC<AsElementLink<HTMLAnchorElement>> = ({
7+
children,
8+
asElement: Component = 'a',
9+
className,
10+
...rest
11+
}) => (
612
<div className="nhsuk-action-link">
7-
<a className={classNames('nhsuk-action-link__link', className)} {...rest}>
13+
<Component className={classNames('nhsuk-action-link__link', className)} {...rest}>
814
<ArrowRightCircle />
915
<span className="nhsuk-action-link__text">{children}</span>
10-
</a>
16+
</Component>
1117
</div>
1218
);
1319

src/components/back-link/BackLink.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import React, { HTMLProps } from 'react';
1+
import React from 'react';
22
import classNames from 'classnames';
33
import { ChevronLeft } from '../icons';
4+
import type { AsElementLink } from '../../util/types/LinkTypes';
45

5-
const BackLink: React.FC<HTMLProps<HTMLAnchorElement>> = ({ children, className, ...rest }) => (
6+
const BackLink: React.FC<AsElementLink<HTMLAnchorElement>> = ({
7+
children,
8+
className,
9+
asElement: Component = 'a',
10+
...rest }) => (
611
<div className="nhsuk-back-link">
7-
<a className={classNames('nhsuk-back-link__link', className)} {...rest}>
12+
<Component className={classNames('nhsuk-back-link__link', className)} {...rest}>
813
<ChevronLeft />
914
{children}
10-
</a>
15+
</Component>
1116
</div>
1217
);
1318

src/components/breadcrumb/Breadcrumb.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
import React, { HTMLProps, ReactNode } from 'react';
33
import classNames from 'classnames';
44
import { Container } from '../layout';
5+
import type { AsElementLink } from '../../util/types/LinkTypes';
56

6-
type Item = React.FC<HTMLProps<HTMLAnchorElement>>;
7+
type Item = React.FC<AsElementLink<HTMLAnchorElement>>;
78

8-
const Item: Item = ({ className, children, ...rest }) => (
9+
const Item: Item = ({ className, children, asElement: Component = 'a', ...rest }) => (
910
<li className="nhsuk-breadcrumb__item">
10-
<a className={classNames('nhsuk-breadcrumb__link', className)} {...rest}>
11+
<Component className={classNames('nhsuk-breadcrumb__link', className)} {...rest}>
1112
{children}
12-
</a>
13+
</Component>
1314
</li>
1415
);
1516

16-
const Back: Item = ({ className, ...rest }) => (
17+
const Back: Item = ({ className, asElement: Component = 'a', ...rest }) => (
1718
<p className={classNames('nhsuk-breadcrumb__back', className)}>
18-
<a className="nhsuk-breadcrumb__backlink" {...rest} />
19+
<Component className="nhsuk-breadcrumb__backlink" {...rest} />
1920
</p>
2021
);
2122

src/components/header/Header.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import React, { PureComponent, HTMLProps, useContext } from 'react';
22
import classNames from 'classnames';
3-
import NHSLogo from './components/NHSLogo';
3+
import NHSLogo, { NHSLogoNavProps } from './components/NHSLogo';
44
import OrganisationalLogo, { OrganisationalLogoProps } from './components/OrganisationalLogo';
55
import HeaderContext, { IHeaderContext } from './HeaderContext';
66
import Search from './components/Search';
77
import Nav from './components/Nav';
88
import NavItem from './components/NavItem';
9+
import NavItemList from './components/NavItemList';
10+
import NavMenuClose from './components/NavMenuClose';
911
import { Container } from '../layout';
1012
import Content from './components/Content';
1113
import MenuToggle from './components/MenuToggle';
1214
import TransactionalServiceName from './components/TransactionalServiceName';
15+
import NavTitle from './components/NavTitle';
16+
import NavContainer from './components/NavContainer';
1317

14-
const BaseHeaderLogo: React.FC<OrganisationalLogoProps> = props => {
18+
const BaseHeaderLogo: React.FC<OrganisationalLogoProps & NHSLogoNavProps> = props => {
1519
const { orgName } = useContext<IHeaderContext>(HeaderContext);
1620
if (orgName) {
1721
return <OrganisationalLogo {...props} />;
@@ -46,8 +50,16 @@ class Header extends PureComponent<HeaderProps, HeaderState> {
4650

4751
static Nav = Nav;
4852

53+
static NavTitle = NavTitle;
54+
55+
static NavContainer = NavContainer;
56+
57+
static NavItemList = NavItemList;
58+
4959
static NavItem = NavItem;
5060

61+
static NavMenuClose = NavMenuClose;
62+
5163
static Container = HeaderContainer;
5264

5365
static Content = Content;

src/components/header/components/MenuToggle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { HTMLProps, useContext, useEffect, MouseEvent } from 'react';
2-
import HeaderContext, { IHeaderContext } from '../HeaderContext';
32
import classNames from 'classnames';
3+
import HeaderContext, { IHeaderContext } from '../HeaderContext';
44

55
export interface MenuToggleProps extends HTMLProps<HTMLButtonElement> {
66
type?: 'button' | 'submit' | 'reset';

src/components/header/components/NHSLogo.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
import React, { useContext, HTMLProps, SVGProps } from 'react';
1+
import React, { useContext, SVGProps } from 'react';
22
import classNames from 'classnames';
33
import HeaderContext, { IHeaderContext } from '../HeaderContext';
4+
import type { AsElementLink } from '../../../util/types/LinkTypes';
45

56
interface SVGImageWithSrc extends SVGProps<SVGImageElement> {
67
src: string;
78
}
89

10+
export interface NHSLogoNavProps extends AsElementLink<HTMLAnchorElement> {}
11+
912
const SVGImageWithSrc: React.FC<SVGImageWithSrc> = props => <image {...props} />;
1013

11-
const NHSLogo: React.FC<HTMLProps<HTMLAnchorElement>> = ({ className, alt, ...rest }) => {
14+
const NHSLogo: React.FC<NHSLogoNavProps> = ({ className, alt, asElement: Component = 'a', ...rest }) => {
1215
const { serviceName, hasMenuToggle, hasSearch } = useContext<IHeaderContext>(HeaderContext);
1316
return (
1417
<div
1518
className={classNames('nhsuk-header__logo', {
1619
'nhsuk-header__logo--only': !hasMenuToggle && !hasSearch,
1720
})}
1821
>
19-
<a
22+
<Component
2023
className={classNames(
2124
'nhsuk-header__link',
2225
{ 'nhsuk-header__link--service': serviceName },
@@ -41,7 +44,7 @@ const NHSLogo: React.FC<HTMLProps<HTMLAnchorElement>> = ({ className, alt, ...re
4144
<SVGImageWithSrc src="https://assets.nhs.uk/images/nhs-logo.png" xlinkHref="" />
4245
</svg>
4346
{serviceName ? <span className="nhsuk-header__service-name">{serviceName}</span> : null}
44-
</a>
47+
</Component>
4548
</div>
4649
);
4750
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { HTMLProps, useContext } from 'react';
2+
import classNames from 'classnames';
3+
import { Container } from '../../layout';
4+
import HeaderContext, { IHeaderContext } from '../HeaderContext';
5+
6+
const NavContainer: React.FC<HTMLProps<HTMLDivElement>> = ({
7+
className,
8+
children,
9+
open,
10+
...rest
11+
}) => {
12+
const { menuOpen } = useContext<IHeaderContext>(HeaderContext);
13+
14+
return (
15+
<nav
16+
className={classNames(
17+
'nhsuk-header__navigation',
18+
{ 'js-show': open !== undefined ? open : menuOpen },
19+
className,
20+
)}
21+
{...rest}
22+
>
23+
<Container>
24+
{children}
25+
</Container>
26+
</nav>
27+
);
28+
};
29+
30+
export default NavContainer;

0 commit comments

Comments
 (0)