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

V3-breadcrumb-menu #838

Merged
merged 17 commits into from
Oct 30, 2024
Merged
56 changes: 56 additions & 0 deletions src/components/navigation/breadCrumbMenu/BreadCrumbMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Link from "next/link";

import Text from "src/components/text/Text";

import styles from "./breadCrumbMenu.module.css";

export interface BreadCrumbProps {
currentLanguage: string;
pathname: string;
}

export const BreadCrumbMenu = ({
currentLanguage,
pathname,
}: BreadCrumbProps) => {
return (
<ul className={styles.breadCrumbMenu}>
{/* TODO: "Hjem" should be updated with translation */}
{[
"Hjem",
...(pathname.includes("/" + currentLanguage + "/")
? pathname.split("/").slice(2)
: pathname.split("/").slice(1)),
].map((slug, index, path) => {
const href =
"/" + currentLanguage + "/" + path.slice(1, index + 1).join("/");
const isLast = index === path.length - 1;

return (
<li key={index} className={styles.breadCrumb}>
<Link className={styles.breadCrumb} href={href}>
{index !== 0 && (
<span
className={
isLast ? styles.lastDotSeparator : styles.dotSeparator
}
>
</span>
)}
<Text
className={
isLast ? styles.breadCrumbText : styles.breadCrumbLink
}
type={isLast ? "labelSemibold" : "desktopLink"}
>
{slug.charAt(0).toUpperCase() +
(slug.length > 1 ? slug.slice(1).toLowerCase() : "")}
</Text>
</Link>
</li>
);
})}
</ul>
);
};
38 changes: 38 additions & 0 deletions src/components/navigation/breadCrumbMenu/breadCrumbMenu.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.breadCrumbMenu {
color: var(--primary-black);
background-color: var(--primary-bg);
display: flex;
flex-direction: row;
gap: 0.5rem;
align-items: center;
list-style: none;
text-decoration: none;
}

.breadCrumb {
display: flex;
flex-direction: row;
align-items: center;
gap: 0.5rem;
color: var(--primary-black);
text-decoration: none;
list-style: none;
}

.breadCrumbText {
color: var(--primary-black);
}

.breadCrumbLink {
color: var(--primary-black);
text-decoration: underline;
}

.dotSeparator,
.lastDotSeparator {
font-size: 2.5em;
}

.lastDotSeparator {
color: var(--secondary-red);
}
110 changes: 58 additions & 52 deletions src/components/navigation/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SanityImage } from "src/components/image/SanityImage";
import LanguageSwitcher from "src/components/languageSwitcher/LanguageSwitcher";
import CustomLink from "src/components/link/CustomLink";
import LinkButton from "src/components/linkButton/LinkButton";
import { BreadCrumbMenu } from "src/components/navigation/breadCrumbMenu/BreadCrumbMenu";
import { getHref } from "src/utils/link";
import { BrandAssets } from "studio/lib/interfaces/brandAssets";
import { InternationalizedString } from "studio/lib/interfaces/global";
Expand Down Expand Up @@ -68,60 +69,65 @@ export const Header = ({
}, []);

return (
<FocusOn
enabled={isOpen}
onClickOutside={toggleMenu}
onEscapeKey={toggleMenu}
className={`${styles.focusOn} ${isOpen && styles.isOpen}`}
>
<header>
<nav aria-label="Main menu">
<div className={styles.wrapper}>
{assets?.primaryLogo && (
<div className={styles.logo}>
<Link href="/" aria-label="Home">
<SanityImage image={assets.primaryLogo} />
</Link>
</div>
)}
{renderPageLinks(links, false, pathname)}
{renderPageCTAs(ctas, false)}
<div className={styles.languageSwitcher}>
{defaultLanguage && (
<LanguageSwitcher
currentLanguage={currentLanguage}
pathTranslations={pathTranslations}
/>
)}
</div>
<button
aria-haspopup="true"
aria-controls={sidebarID}
className={isOpen ? styles.open : styles.closed}
aria-expanded={isOpen}
onClick={toggleMenu}
/>
</div>
{isOpen && (
<div
className={styles.mobileMenu}
id={sidebarID}
aria-label="Mobile Menu"
onClick={() => setIsOpen(false)}
>
{renderPageLinks(sidebarLinks, true, pathname)}
{renderPageCTAs(sidebarCtas, true)}
{defaultLanguage && (
<LanguageSwitcher
currentLanguage={currentLanguage}
pathTranslations={pathTranslations}
/>
<>
<FocusOn
enabled={isOpen}
onClickOutside={toggleMenu}
onEscapeKey={toggleMenu}
className={`${styles.focusOn} ${isOpen && styles.isOpen}`}
>
<header>
<nav aria-label="Main menu">
<div className={styles.wrapper}>
{assets?.primaryLogo && (
<div className={styles.logo}>
<Link href="/" aria-label="Home">
<SanityImage image={assets.primaryLogo} />
</Link>
</div>
)}
{renderPageLinks(links, false, pathname)}
{renderPageCTAs(ctas, false)}
<div className={styles.languageSwitcher}>
{defaultLanguage && (
<LanguageSwitcher
currentLanguage={currentLanguage}
pathTranslations={pathTranslations}
/>
)}
</div>
<button
anemne marked this conversation as resolved.
Show resolved Hide resolved
anemne marked this conversation as resolved.
Show resolved Hide resolved
aria-haspopup="true"
aria-controls={sidebarID}
className={isOpen ? styles.open : styles.closed}
aria-expanded={isOpen}
onClick={toggleMenu}
/>
</div>
)}
</nav>
</header>
</FocusOn>
{isOpen && (
<div
className={styles.mobileMenu}
id={sidebarID}
aria-label="Mobile Menu"
onClick={() => setIsOpen(false)}
>
{renderPageLinks(sidebarLinks, true, pathname)}
{renderPageCTAs(sidebarCtas, true)}
{defaultLanguage && (
<LanguageSwitcher
currentLanguage={currentLanguage}
pathTranslations={pathTranslations}
/>
)}
</div>
)}
</nav>
</header>
</FocusOn>
{pathname !== "/" && pathname !== "/" + currentLanguage && (
<BreadCrumbMenu currentLanguage={currentLanguage} pathname={pathname} />
)}
</>
);
};

Expand Down
4 changes: 0 additions & 4 deletions src/components/navigation/header/header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
background-color: var(--primary-black);
}

.scrolled {
background-color: var(--primary-black);
}

.isOpen {
height: 100vh;
display: flex;
Expand Down
17 changes: 13 additions & 4 deletions src/components/text/text.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@
line-height: 120%;
}

/* TODO: add font variables */
/* .labelSemibold, */
/* .labelBold, */
/* .quoteItalic, */
.labelSemibold {
font-size: 1rem;
font-style: normal;
font-weight: 600;
line-height: 120%;
}

.quoteNormal {
font-size: 1.5rem;
Expand All @@ -115,3 +117,10 @@
line-height: 130%;
white-space: pre-line;
}

/* TODO: add font variables */
/* .labelBold */
/* .quoteItalic */
/* .labelSemibold, */
/* .labelBold, */
/* .quoteItalic, */
3 changes: 3 additions & 0 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ html {

--focus-color: #8b0f40;

/* TODO: upgrade color-scheme with correct colors */
--secondary-red: #f0503f;

/* breakpoints */
--breakpoint-mobile: 767px;
--breakpoint-tablet: 640px;
Expand Down