Skip to content
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

chore: migrate to HDS v3 #3466

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion frontend/benefit/applicant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"finnish-ssn": "^2.1.2",
"formik": "^2.2.9",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"lodash": "^4.17.21",
"next": "14.2.12",
"next-router-mock": "0.9.12",
Expand Down
2 changes: 2 additions & 0 deletions frontend/benefit/applicant/src/components/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const FooterSection: React.FC = () => {
const { t } = useTranslation();
const locale = useLocale();

return null;

return (
<$FooterWrapper>
<Footer title={t('common:appName')} theme="dark">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Button, IconLock, IconSpeechbubbleText } from 'hds-react';
import noop from 'lodash/noop';
import { useRouter } from 'next/router';
import * as React from 'react';
import BaseHeader from 'shared/components/header/Header';
import BaseHeader from 'shared/components/header/HeaderV3';
import { getFullName } from 'shared/utils/application.utils';

import Messenger from '../messenger/Messenger';
Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"formik": "^2.2.9",
"fuse.js": "^6.6.2",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"ibantools": "^4.3.4",
"lodash": "^4.17.21",
"next": "14.2.12",
Expand Down
1 change: 1 addition & 0 deletions frontend/benefit/handler/src/components/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const FooterSection: React.FC = () => {
if (!isFooterVisible) {
return null;
}
return null;

return (
<$FooterWrapper layoutBackgroundColor={layoutBackgroundColor}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BaseHeader from 'shared/components/header/Header';
import BaseHeader from 'shared/components/header/HeaderV3';
import { respondAbovePx } from 'shared/styles/mediaQueries';
import styled from 'styled-components';

Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/handler/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const Header: React.FC = () => {
<$BaseHeader
title={t('common:appName')}
customItems={[
<HeaderNotifier />,
process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT !== 'production' ? (
<TemporaryAhjoModeSwitch />
) : null,
<HeaderNotifier />,
]}
titleUrl={ROUTES.HOME}
skipToContentLabel={t('common:header.linkSkipToContent')}
Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"camelcase-keys": "^7.0.1",
"date-fns": "^2.24.0",
"formik": "^2.2.9",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"ibantools": "^4.1.5",
"next": "14.2.12",
"next-i18next": "^13.0.3",
Expand Down
2 changes: 1 addition & 1 deletion frontend/kesaseteli/employer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"axios": "^0.27.2",
"dotenv": "^16.0.0",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"ibantools": "^4.1.5",
"lodash": "^4.17.21",
"next": "14.2.12",
Expand Down
2 changes: 1 addition & 1 deletion frontend/kesaseteli/handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dotenv": "^16.0.0",
"finnish-ssn": "^2.1.2",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"lodash": "^4.17.21",
"next": "14.2.12",
"next-compose-plugins": "^2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion frontend/kesaseteli/youth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dotenv": "^16.0.0",
"finnish-ssn": "^2.1.2",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"lodash": "^4.17.21",
"next": "14.2.12",
"next-compose-plugins": "^2.2.1",
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"eslint-plugin-unicorn": "^40.1.0",
"eslint-plugin-you-dont-need-lodash-underscore": "^6.12.0",
"faker": "^5.5.3",
"http-status-typed": "1.0.1",
"husky": "^8.0.1",
"i18next": "^22.4.13",
"jest": "^27.4.7",
Expand Down
2 changes: 1 addition & 1 deletion frontend/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"express": "^4.17.1",
"fast-deep-equal": "^3.1.3",
"finnish-ssn": "^2.1.2",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"js-file-download": "^0.4.12",
"lodash": "^4.17.21",
"next": "14.2.12",
Expand Down
216 changes: 216 additions & 0 deletions frontend/shared/src/components/header/HeaderV3.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import {
Header,
IconGlobe,
IconSignin,
IconSignout,
IconUser,
Logo,
logoFi,
logoFiDark,
logoSv,
logoSvDark,
} from 'hds-react';
import React from 'react';
import { MAIN_CONTENT_ID } from 'shared/constants';
import useGoToPage from 'shared/hooks/useGoToPage';
import {
NavigationItem,
NavigationVariant,
OptionType,
ThemeOption,
} from 'shared/types/common';
import { isTabActive } from 'shared/utils/menu.utils';

import { useHeader } from './useHeader';
import styled from 'styled-components';

export type HeaderProps = {
title?: string;
titleUrl?: string;
skipToContentLabel?: string;
menuToggleAriaLabel?: string;
languages?: OptionType<string>[];
isNavigationVisible?: boolean;
navigationItems?: NavigationItem[];
customItems?: React.ReactNode[];
onLanguageChange?: (
e: React.SyntheticEvent<unknown>,
language: OptionType<string>
) => void;
login?: {
isAuthenticated: boolean;
loginLabel: string;
logoutLabel: string;
userAriaLabelPrefix: string;
onLogin: () => void;
onLogout: () => void;
userName?: string;
};
theme?: ThemeOption;
hideLogin?: boolean;
onTitleClick?: () => void;
className?: string;
customActiveItemFn?: (url: string) => boolean;
};
const HeaderCustomItems = styled.ul`
display: flex;
align-items: center;
margin-right: var(--spacing-s);
list-style-type: none;
margin: 0;
> li {
margin-right: var(--spacing-xs);
}
`;
const HeaderV3: React.FC<HeaderProps> = ({
skipToContentLabel,
title,
titleUrl,
menuToggleAriaLabel,
languages,
isNavigationVisible = true,
navigationItems,
customItems,
onLanguageChange,
login,
hideLogin,
theme,
onTitleClick,
className,
customActiveItemFn,
}) => {
const {
locale,
logoLang,
toggleMenu,
closeMenu,
handleLogin,
handleLogout,
t,
} = useHeader(login);

const goToPage = useGoToPage();

const logoSrcFromLanguageAndTheme = (): string => {
if (theme === 'dark') {
if (logoLang === 'fi') return logoFiDark;
if (logoLang === 'sv') return logoSvDark;
if (logoLang === 'en') return logoFiDark;
}
if (logoLang === 'fi') return logoFi;
if (logoLang === 'sv') return logoSv;
if (logoLang === 'en') return logoFi;
return logoFi;
};

const handleClickLink = React.useCallback(
(url = '/') =>
(event?: Event | MouseEvent) => {
event?.preventDefault();
closeMenu();
goToPage(url as string);
},
[closeMenu, goToPage]
);

return (
<div data-testid="header" className={className}>
<Header theme={theme} title={title}>
<Header.SkipLink
skipTo={`#${MAIN_CONTENT_ID}`}
label={skipToContentLabel}
/>
<Header.ActionBar
title={title}
titleAriaLabel={title}
onLogoClick={onTitleClick}
onMenuClick={toggleMenu}
menuButtonLabel={menuToggleAriaLabel || ''}
logo={<Logo src={logoSrcFromLanguageAndTheme()} alt="Helsinki" />}
titleHref={titleUrl}
onClick={onTitleClick}
frontPageLabel={title}
>
{customItems && customItems.length > 0 && (
<HeaderCustomItems key="custom-items">
{customItems?.map((item) => (
<li key={item.toString()}>{item}</li>
))}
</HeaderCustomItems>
)}

{login && !login?.isAuthenticated && !hideLogin && (
<Header.ActionBarButton
id="login"
label={login.loginLabel}
onClick={() => handleLogin()}
icon={<IconSignin />}
/>
)}

{login && login?.isAuthenticated && !hideLogin && (
<Header.ActionBarItem
id="logout"
icon={<IconUser />}
aria-label={`${login.userAriaLabelPrefix} ${login.userName}`}
label={login.userName}
// onSignIn={handleLogin}
// authenticated={login.isAuthenticated}
// buttonAriaLabel={
// login.userName
// ? `
// : ''
// }
onClick={() => handleLogout}
>
<Header.ActionBarSubItem
label={login.logoutLabel}
onClick={handleLogout}
iconRight={<IconSignout />}
/>
</Header.ActionBarItem>
)}

{languages && onLanguageChange && (
<Header.LanguageSelector
buttonAriaLabel={t('common:header.languageMenuButtonAriaLabel')}
label={locale?.toUpperCase()}
icon={<IconGlobe />}
closeOnItemClick
>
{languages.map((option) => (
<Header.ActionBarItem
id={option.value}
label={option.label}
lang={option.value}
onClick={(e: React.SyntheticEvent<unknown>) =>
onLanguageChange(e, option)
}
/>
))}
</Header.LanguageSelector>
)}
</Header.ActionBar>
{isNavigationVisible && navigationItems && (
<Header.NavigationMenu>
{navigationItems?.map((item) => (
<Header.Link
key={item.url}
label={item.label as string}
active={
customActiveItemFn
? customActiveItemFn(item.url)
: isTabActive(item.url)
}
href={item.url}
onClick={() => handleClickLink(item.url)}
/>
))}
</Header.NavigationMenu>
)}
</Header>
</div>
);
};

export default HeaderV3;
2 changes: 1 addition & 1 deletion frontend/tet/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"date-fns": "^2.24.0",
"dotenv": "^16.0.0",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"leaflet": "^1.7.1",
"next": "14.2.12",
"next-compose-plugins": "^2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion frontend/tet/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@frontend/shared": "*",
"axios": "^0.27.2",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"next": "14.2.12",
"next-i18next": "^13.0.3",
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/tet/youth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"axios": "^0.27.2",
"dotenv": "^16.0.0",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-react": "^3.10.1",
"leaflet": "^1.7.1",
"leaflet.markercluster": "^1.5.3",
"next": "14.2.12",
Expand Down
Loading
Loading