Skip to content

NCRS-3933 add header with logo on same row as nav items #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ce439a1
NCRS-3933: transferred files over
alice-bell May 7, 2025
6c273dc
NCRS-3933: added whole folder
alice-bell May 7, 2025
21fa313
NCRS-3933: doing the same thing in a different way
alice-bell May 8, 2025
ef958ff
NCRS-3933: tidy
alice-bell May 8, 2025
5d6a48d
NCRS-3933: re-added arrow
alice-bell May 8, 2025
14ca9e6
NCRS-3933: edited tsconfig.json to get rid of 'property toHaveClass' …
alice-bell May 8, 2025
e42f1cd
NCRS-3933: sorting imports
alice-bell May 8, 2025
0ff3bbb
NCRS-3933: added babel-jest to get rid of 'unexpected token export' e…
alice-bell May 8, 2025
c122227
NCRS-3933: updated tests
alice-bell May 8, 2025
764009a
NCRS-3933: committed install-state.gz after yarn build
alice-bell May 9, 2025
7ee29ee
NCRS-3933: started adding HeaderWithLogo to storybook, more work to f…
alice-bell May 9, 2025
aa35abd
2.1.0-test.1
alice-bell May 9, 2025
09bee69
NCRS-3933: experimenting with another way to do it
alice-bell May 9, 2025
34c773b
NCRS-3933: storybook formatting, still more to do (resize)
alice-bell May 13, 2025
e9bed07
NCRS-3933: more storybook formatting
alice-bell May 13, 2025
750d446
NCRS-3933: more storybook formatting
alice-bell May 13, 2025
a295ee3
NCRS-3933: more storybook formatting
alice-bell May 13, 2025
ecbe329
NCRS-3933: got everything working
alice-bell May 14, 2025
21c9b7c
NCRS-3933: tidy up
alice-bell May 14, 2025
03dda9e
NCRS-3933: added LocalLinkTypes
alice-bell May 14, 2025
9b7b0bf
2.1.0-test-2
alice-bell May 14, 2025
8886724
NCRS-3933: removed 'use client' as it was causing issues with the build
alice-bell May 14, 2025
a9fe548
NCRS-3933: minor changes to MaskedInput to get rid of build errors
alice-bell May 14, 2025
75036a7
2.0.0-test.1
alice-bell May 14, 2025
b1245e9
2.1.0-test.3
alice-bell May 14, 2025
04030c7
NCRS-3933: got it working :)
alice-bell May 19, 2025
e56576d
NCRS-3933: working :)
alice-bell May 19, 2025
790dc06
NCRS-3933: final fix???
alice-bell May 21, 2025
d384748
NCRS-3933: added snap test
alice-bell May 21, 2025
959685f
NCRS-3933: test fix
alice-bell May 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .storybook/_storybook.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@
.ribbonlink-demo {
padding: 20px;
}

.header-with-logo-demo {
ul {
list-style-type: none;
padding-left: 20px;
}
}
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
roots: ['./src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
"^.+\\.(js)$": "babel-jest"
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nhsuk-react-components-extensions",
"version": "2.0.0-beta.1",
"version": "2.1.0-test.3",
"author": {
"email": "thomas.judd-cooper1@nhs.net",
"name": "Thomas Judd-Cooper",
Expand Down Expand Up @@ -31,6 +31,7 @@
"@types/react-input-mask": "^3.0.5",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
"babel-jest": "^29.7.0",
"babel-loader": "^8.0.0",
"css-loader": "^5.0.0",
"eslint": "^9.14.0",
Expand Down Expand Up @@ -82,7 +83,7 @@
"build:lib": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline && tsc --emitDeclarationOnly",
"build:sass": "sass src:css",
"cleanup": "bash scripts/cleanup.sh",
"lint": "stylelint src/**/*.scss && eslint --fix src/*.ts src/components/**/*.ts src/components/**/*.tsx",
"lint": "stylelint --fix src/**/*.scss src/**/**/*.scss && eslint --fix src/*.ts src/components/**/*.ts src/components/**/*.tsx",
"prebuild": "yarn lint && yarn test --coverage && yarn cleanup",
"storybook": "start-storybook",
"test": "jest",
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ describe('Index', () => {
it('contains all expected elements', () => {
expect(Object.keys(index)).toEqual([
'AccordionMenu',
'HeaderWithLogo',
'MaskedInput',
'FormGroup',
'Label',
Expand Down
2 changes: 2 additions & 0 deletions src/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
@use './components/ribbon-link/RibbonLink';
@use './components/timeline/Timeline';

@use './components/header-with-logo/headerWithLogo'

2 changes: 2 additions & 0 deletions src/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
@use './components/tooltip/Tooltip';
@use './components/ribbon-link/RibbonLink';
@use './components/timeline/Timeline';

@use './components/header-with-logo/headerWithLogo';
34 changes: 34 additions & 0 deletions src/components/header-with-logo/HeaderContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createContext } from 'react';

export interface IHeaderContext {
orgName: string | undefined;
serviceName: string | undefined;
orgSplit: string | undefined;
orgDescriptor: string | undefined;
setSearch: (toggle: boolean) => void;
setMenuToggle: (toggle: boolean) => void;
setServiceName: (toggle: boolean) => void;
toggleMenu: () => void;
hasSearch: boolean;
hasMenuToggle: boolean;
hasServiceName: boolean;
menuOpen: boolean;
transactional: boolean;
}

export default createContext<IHeaderContext>({

orgName: undefined,
serviceName: undefined,
orgSplit: undefined,
orgDescriptor: undefined,
setSearch: () => {},
setMenuToggle: () => {},
setServiceName: () => {},
hasSearch: false,
hasMenuToggle: false,
hasServiceName: false,
toggleMenu: () => {},
menuOpen: false,
transactional: false,
});
133 changes: 133 additions & 0 deletions src/components/header-with-logo/HeaderWithLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React, { FC, HTMLProps, useContext, useState, useEffect, useMemo } from 'react';
import classNames from 'classnames';
import NHSLogo, { NHSLogoNavProps } from './components/LocalNHSLogo';
import OrganisationalLogo, { OrganisationalLogoProps } from './components/LocalOrganisationalLogo';
import HeaderContext, { IHeaderContext } from './HeaderContext';
import Search from './components/LocalSearch';
import Nav from './components/LocalNav';
import NavItem from './components/LocalNavItem';
import NavDropdownMenu from './components/LocalNavDropdownMenu';
import { Container } from 'nhsuk-react-components';
import Content from './components/LocalContent';
import TransactionalServiceName from './components/LocalTransactionalServiceName';
import HeaderJs from './header';

const BaseHeaderLogo: FC<OrganisationalLogoProps & NHSLogoNavProps> = (props) => {
const { orgName } = useContext<IHeaderContext>(HeaderContext);
if (orgName) {
return <OrganisationalLogo {...props} />;
}
return <NHSLogo {...props} />;
};

const HeaderContainer: FC<HTMLProps<HTMLDivElement>> = ({ className, ...rest }) => (
<Container className={classNames('nhsuk-header__container', className)} {...rest} />
);

interface HeaderProps extends HTMLProps<HTMLDivElement> {
transactional?: boolean;
orgName?: string;
orgSplit?: string;
orgDescriptor?: string;
serviceName?: string;
white?: boolean;
}

const HeaderWithLogo = ({
className,
children,
transactional,
orgName,
orgSplit,
orgDescriptor,
role = 'banner',
serviceName,
white,
...rest
}: HeaderProps) => {

const [hasMenuToggle, setHasMenuToggle] = useState(false);
const [hasSearch, setHasSearch] = useState(false);
const [hasServiceName, setHasServiceName] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);

useEffect(() => {
HeaderJs();
}, []);

const setMenuToggle = (toggle: boolean): void => {
setHasMenuToggle(toggle);
};

const setSearch = (toggle: boolean): void => {
setHasSearch(toggle);
};

const toggleMenu = (): void => {
setMenuOpen(!menuOpen);
};

const setServiceName = (toggle: boolean): void => {
setHasServiceName(toggle);
};

const contextValue: IHeaderContext = useMemo(() => {
return {
orgName,
orgSplit,
orgDescriptor,
serviceName,
hasSearch,
hasMenuToggle,
hasServiceName,
setMenuToggle,
setSearch,
setServiceName,
toggleMenu,
menuOpen,
transactional: transactional ?? false,
};
}, [
orgName,
orgSplit,
orgDescriptor,
serviceName,
hasSearch,
hasMenuToggle,
hasServiceName,
setMenuToggle,
setSearch,
setServiceName,
toggleMenu,
menuOpen,
transactional,
]);

return (
<header
className={classNames(
'nhsuk-header',
{ 'nhsuk-header__transactional': transactional },
{ 'nhsuk-header--organisation': orgName },
{ 'nhsuk-header--white': white },
className,
)}
role={role}
{...rest}
>
<HeaderContext.Provider value={contextValue}>{children}</HeaderContext.Provider>
</header>
);

};

HeaderWithLogo.Logo = BaseHeaderLogo;
HeaderWithLogo.Search = Search;
HeaderWithLogo.Nav = Nav;
HeaderWithLogo.NavItem = NavItem;
HeaderWithLogo.NavDropdownMenu = NavDropdownMenu;
HeaderWithLogo.Container = HeaderContainer;
HeaderWithLogo.Content = Content;
HeaderWithLogo.ServiceName = TransactionalServiceName;

export default HeaderWithLogo;
Loading