Skip to content

Commit

Permalink
New: [AEA-4513] - Header component (#151)
Browse files Browse the repository at this point in the history
## Summary

- Routine Change

### Details

Introduces functional header to app. Responsive behaviour should kick in
whenever space become insufficient for a menu item. Placeholder# links
are used purely to demonstrate / test this functionality

---------

Co-authored-by: anthony-nhs <[email protected]>
  • Loading branch information
tobytobytoby74 and anthony-nhs authored Nov 27, 2024
1 parent 8b9079d commit ae73a17
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 74 deletions.
56 changes: 56 additions & 0 deletions packages/cpt-ui/__tests__/EpsHeader.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";
import EpsHeader from "../components/EpsHeader";
import {
HEADER_SERVICE,
HEADER_CONFIRM_ROLE_BUTTON,
HEADER_CHANGE_ROLE_BUTTON,
} from "../constants/ui-strings/HeaderStrings";

// Mock useRouter:
jest.mock("next/navigation", () => ({
useRouter() {
return {
prefetch: () => null
};
},
usePathname: () => "/",
}));
describe("EpsHeader", () => {
beforeEach(() => {
render(<EpsHeader />);
})
it("Successfully renders a header component, evidenced by role of 'banner", () => {
const header = screen.getByRole("banner");
expect(header).toBeInTheDocument();
});
it("Extracts HEADER_SERVICE value", () => {
const serviceName = HEADER_SERVICE;
expect(serviceName).toBeTruthy();
});
it("Displays service name in header matching that from HEADER_SERVICE data", () => {
expect(screen.getByTestId("eps_header_serviceName")).toHaveTextContent(
HEADER_SERVICE
);
});
// check behavior of links in header
// confirm role link
it("Extracts HEADER_CONFIRM_ROLE_BUTTON value", () => {
const confirmRoleLink = HEADER_CONFIRM_ROLE_BUTTON;
expect(confirmRoleLink).toBeTruthy();
});
it("Displays correct label for confirm role link from HEADER_CONFIRM_ROLE_BUTTON data", () => {
expect(screen.getByTestId("eps_header_confirmRoleLink")).toHaveTextContent(
HEADER_CONFIRM_ROLE_BUTTON
);
});
// change role link -- test will be more specific as routes are added
it("Extracts HEADER_CHANGE_ROLE_BUTTON value", () => {
const changeRoleLink = HEADER_CHANGE_ROLE_BUTTON;
expect(changeRoleLink).toBeTruthy();
});
it("Check that change role link is not displayed ", () => {
expect(screen.queryByTestId("eps_header_changeRoleLink")).toBeNull();
});
});
36 changes: 3 additions & 33 deletions packages/cpt-ui/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from "react";

import 'nhsuk-frontend/dist/nhsuk.css';
import { Header } from 'nhsuk-react-components';
import EpsHeader from '../components/EpsHeader'
import EpsFooter from '../components/EpsFooter'

export default function RootLayout({
Expand All @@ -12,42 +12,12 @@ export default function RootLayout({
}) {
return (
<html lang="en">

<body>
<Header transactional >
<Header.Container>
<Header.Logo href="/" />
<Header.ServiceName href="/">
Clinical prescription tracking service
</Header.ServiceName>


{/* <Header.Nav>
<Header.NavItem href="/social-care-and-support">
Care and support
</Header.NavItem>
<Header.NavItem href="/news">
Health news
</Header.NavItem>
<Header.NavItem href="/service-search">
Services near you
</Header.NavItem>
<Header.NavItem
home
href="/"
>
Home
</Header.NavItem>
<Header.NavDropdownMenu />
</Header.Nav> */}

</Header.Container>
</Header>

<EpsHeader />
{children}
<EpsFooter />
</body>

</html>
)
}
40 changes: 0 additions & 40 deletions packages/cpt-ui/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,6 @@ export default function Page() {
<p>Etiam lobortis! dolor ac facilisis efficitur, metus leo posuere est, non pharetra orci velit non velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Ut finibus sagittis diam ac feugiat. Curabitur eget venenatis arcu. Ut commodo tempor sollicitudin. Nulla nec congue mauris. Sed cursus interdum arcu. Morbi lacinia lorem ut ante feugiat, eu cursus nisi ultricies.</p>
</Col>
</Row>
{/* <Row>
<Container role="contentinfo">
<Row>
<Col width="full">
<h1 className='nhsuk-heading-xl '>
<span role="text">Select your role
<span className="nhsuk-caption-l nhsuk-caption--bottom">
<span className="nhsuk-u-visually-hidden"> - </span>
Select the role you wish to use to access the service.
</span></span></h1>
</Col>
</Row>
<Row>
<Col width='two-thirds'>
<InsetText className="nhsuk-u-margin-top-0">
<p>
You are currently logged in at <span className='nhsuk-u-font-weight-bold tl-nhsuk-u-text-uppercase'>Greenes Pharmacy (ods:4ft)</span> with <strong>Health Professional Access Role</strong>.
</p>
</InsetText>
<Button>
Confirm and continue to find a prescription
</Button>
<p>Alternatively, you can choose a new role below.</p>
<Card clickable className='tl-nhsuk-newComponent'>
<Card.Content>
<Card.Heading className="nhsuk-heading-m">
<Card.Link href="#">
Introduction to care and support
</Card.Link>
</Card.Heading>
<Card.Description>
A quick guide for people who have care and support needs and their carers
</Card.Description>
</Card.Content>
</Card>
</Col>
</Row>
</Container>
</Row> */}
</Container>
</main>
)
Expand Down
113 changes: 113 additions & 0 deletions packages/cpt-ui/assets/styles/header.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

.nhsuk-header.masthead {
.nhsuk-width-container.nhsuk-header__container.masthead-container {
min-width:100%;
padding-left:24px;
}
.nhsuk-navigation-container{

.nhsuk-header__navigation-list {
display:flex;
right: -353px;
position: absolute;
left: unset;
justify-content:flex-end;
margin:0 16px 0 16px;
gap:unset;
.nhsuk-header__navigation-link {
padding:12px 16px;
}
button.nhsuk-header__menu-toggle.nhsuk-header__navigation-link {
padding-right:30px;
}
.nhsuk-header__drop-down {
color:#005eb8;
}
}
.nhsuk-header__drop-down {
top:65px;
background-color: #ffffff;
border-bottom: 4px solid #f0f4f5;
overflow: hidden;
position: absolute;
right: 0;
left: auto;
width: 100vw;
.nhsuk-header__navigation-link {
padding-left:0;
}
}
}

@media (min-width: 48.0625em) {
.nhsuk-header__container {
margin: 0;
}
}

@media (min-width: 40.0625em) {
.nhsuk-header__navigation-list {
border-top-width:0;
}
.nhsuk-header__navigation-link {
padding:12px 16px;
}
}

@media (max-width: 990px) {
.nhsuk-header__container {
margin: 0;
}
}

.nhsuk-width-container.nhsuk-header__container.masthead-container {
width:460px;
padding-left:24px;
max-width:100%;
}
.nhsuk-navigation-container{
position: relative;
top: -63px;
width: calc(100% - 440px);
right: -102px;
}

@media (max-width: 640px) {

padding-bottom:68px;
.nhsuk-width-container.nhsuk-header__container.masthead-container {
padding-left:10px;
}
.nhsuk-navigation {
min-width:100%;
max-width:100%;
width:100vw;
}
.nhsuk-header {
padding-bottom:68px;
}
// .nhsuk-navigation-container .nhsuk-header__navigation-list {
// right: unset;
// width: 100vw;
// justify-content: flex-start;
// left: -118px;
// top: 64px;
// padding-left: 16px;
// }
.nhsuk-navigation-container .nhsuk-header__navigation-list {
right: unset;
width: 100%;
justify-content: flex-start;
left: 0;
top: 64px;
padding-left: 0;
min-width:100vw;
margin-left:0;
}

.nhsuk-width-container.nhsuk-header__container.masthead-container, .nhsuk-navigation-container {
min-width:100vw;
right:unset;
}
}
}
55 changes: 55 additions & 0 deletions packages/cpt-ui/components/EpsHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use client'
import React from 'react'
import Link from 'next/link';
import "../assets/styles/header.scss"
import { useRouter, usePathname } from 'next/navigation';
import { Header } from "nhsuk-react-components";
import {
HEADER_SERVICE,
HEADER_CONFIRM_ROLE_BUTTON,
HEADER_CONFIRM_ROLE_TARGET,
HEADER_CHANGE_ROLE_BUTTON,
HEADER_CHANGE_ROLE_TARGET
} from "../constants/ui-strings/HeaderStrings"

export default function EpsHeader() {
const router = useRouter()
const pathname = usePathname();
console.log(router); // Query parameters
return (
<Header transactional className="masthead" id="eps-header" >
<Header.Container className="masthead-container">
<Header.Logo href="/" data-testid="eps_header_logoLink" />

<Header.ServiceName href="/" data-testid="eps_header_serviceName">
{HEADER_SERVICE}
</Header.ServiceName>
<Header.Content />
</Header.Container>
<Header.Nav className="masthead-nav">
<li className="nhsuk-header__navigation-item">
<Link className="nhsuk-header__navigation-link" href='/' data-testid="eps_header_placeholder1">Placeholder 1</Link>
</li>
<li className="nhsuk-header__navigation-item">
<Link className="nhsuk-header__navigation-link" href='/' data-testid="eps_header_placeholder2">Placeholder 2</Link>
</li>
{pathname != '/' ? (
<li className="nhsuk-header__navigation-item">
<Link className="nhsuk-header__navigation-link" href={HEADER_CHANGE_ROLE_TARGET} data-testid="eps_header_changeRoleLink">{HEADER_CHANGE_ROLE_BUTTON}</Link>
</li>
) :
(
<li className="nhsuk-header__navigation-item">
<Link className="nhsuk-header__navigation-link" href={HEADER_CONFIRM_ROLE_TARGET} data-testid="eps_header_confirmRoleLink">{HEADER_CONFIRM_ROLE_BUTTON}</Link>
</li>
)
}
<li className="nhsuk-header__navigation-item">
<Link className="nhsuk-header__navigation-link" href='/' data-testid="eps_header_placeholder3">Placeholder 3</Link>
</li>
{/* <Header.NavItem>Placeholder 3</Header.NavItem> */}
<Header.NavDropdownMenu dropdownText="Menu" />
</Header.Nav>
</Header>
)
}
2 changes: 1 addition & 1 deletion packages/cpt-ui/constants/ui-strings/FooterStrings.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const FOOTER_COPYRIGHT = "© NHS England 2024"
export const FOOTER_COPYRIGHT = "© NHS England"
6 changes: 6 additions & 0 deletions packages/cpt-ui/constants/ui-strings/HeaderStrings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// HEADER strings
export const HEADER_SERVICE = "Clinical prescription tracking service"
export const HEADER_CONFIRM_ROLE_BUTTON = "Confirm Role"
export const HEADER_CONFIRM_ROLE_TARGET = "confirmrole"
export const HEADER_CHANGE_ROLE_BUTTON = "Change Role"
export const HEADER_CHANGE_ROLE_TARGET = "changerole"

0 comments on commit ae73a17

Please sign in to comment.