Continuous Integration / config (pull_request) Successful in 9s
Continuous Integration / prepare (pull_request) Successful in 28s
Continuous Integration / build-production (pull_request) Skipped
Continuous Integration / test (pull_request) Successful in 40s
Continuous Integration / build (pull_request) Successful in 47s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / lighthouse (pull_request) Successful in 1m37s
Continuous Integration / deploy-production (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
147 lines
5.8 KiB
TypeScript
147 lines
5.8 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { navLinks } from '../../features/landing/data/content';
|
|
import { ModeToggle } from '../ui/ModeToggle';
|
|
import { VariantToggle } from '../ui/VariantToggle';
|
|
import { handleAnchorClick } from '../../utils/scrollToHash';
|
|
import { t } from '../../i18n';
|
|
|
|
/**
|
|
* Navigation of design B: part of the brand-red header, white text, the CTA as a white block
|
|
* (desktop only). Below the `md` breakpoint a hamburger opens an animated overlay menu with the
|
|
* section links; the "Start project" CTA is not repeated there (the hero has its own buttons).
|
|
*/
|
|
export function Nav() {
|
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
const sectionLinks = navLinks.filter((link) => !link.isCta);
|
|
const menuLabel = isMenuOpen ? t('site.nav.menuClose') : t('site.nav.menuOpen');
|
|
|
|
// Escape closes the mobile menu (keyboard users).
|
|
useEffect(() => {
|
|
if (!isMenuOpen) return;
|
|
const onKey = (event: KeyboardEvent) => {
|
|
if (event.key === 'Escape') setIsMenuOpen(false);
|
|
};
|
|
document.addEventListener('keydown', onKey);
|
|
return () => document.removeEventListener('keydown', onKey);
|
|
}, [isMenuOpen]);
|
|
|
|
function handleMobileLinkClick(event: React.MouseEvent<HTMLAnchorElement>, href: string) {
|
|
handleAnchorClick(event, href);
|
|
setIsMenuOpen(false);
|
|
}
|
|
|
|
return (
|
|
<nav
|
|
aria-label={t('site.nav.label')}
|
|
className="sticky top-0 z-40 bg-brand text-on-brand md:static"
|
|
>
|
|
<div className="mx-auto flex min-h-[84px] max-w-[1280px] items-center justify-between gap-4 px-6 sm:px-8">
|
|
<a
|
|
href="#top"
|
|
onClick={(event) => handleAnchorClick(event, '#top')}
|
|
className="flex shrink-0 items-baseline gap-2 py-2.5 no-underline"
|
|
>
|
|
<span
|
|
className="text-2xl font-black tracking-tight [font-stretch:125%]"
|
|
data-testid="nav-logo"
|
|
>
|
|
<span aria-hidden="true" className="font-black [font-stretch:100%]">
|
|
{'<'}
|
|
</span>
|
|
SLP
|
|
<span aria-hidden="true" className="font-black [font-stretch:100%]">
|
|
{'/>'}
|
|
</span>
|
|
</span>
|
|
<span className="text-base font-normal">Software</span>
|
|
</a>
|
|
<ul className="flex items-center gap-3 md:gap-5 lg:gap-8">
|
|
{navLinks.map((link) =>
|
|
link.isCta ? (
|
|
<li key={link.href} className="hidden md:block">
|
|
<a
|
|
href={link.href}
|
|
onClick={(event) => handleAnchorClick(event, link.href)}
|
|
className="inline-block whitespace-nowrap bg-white px-[18px] py-[11px] text-[15px] font-bold text-brand no-underline transition-colors hover:bg-inv hover:text-white"
|
|
data-testid="nav-cta-link"
|
|
>
|
|
{link.label}
|
|
</a>
|
|
</li>
|
|
) : (
|
|
<li key={link.href} className="hidden md:block">
|
|
<a
|
|
href={link.href}
|
|
onClick={(event) => handleAnchorClick(event, link.href)}
|
|
className="inline-block whitespace-nowrap py-3 text-[15px] font-medium no-underline decoration-2 underline-offset-[10px] transition-colors hover:underline"
|
|
>
|
|
{link.label}
|
|
</a>
|
|
</li>
|
|
),
|
|
)}
|
|
<li>
|
|
<ModeToggle tone="onBrand" />
|
|
</li>
|
|
<li>
|
|
<VariantToggle tone="onBrand" />
|
|
</li>
|
|
<li className="md:hidden">
|
|
<button
|
|
type="button"
|
|
onClick={() => setIsMenuOpen((open) => !open)}
|
|
aria-label={menuLabel}
|
|
aria-expanded={isMenuOpen}
|
|
aria-controls="mobile-nav-menu"
|
|
data-testid="nav-mobile-toggle"
|
|
className="flex h-11 w-11 items-center justify-center rounded-full border border-white/70 text-on-brand transition-colors hover:border-white hover:bg-white/15 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
|
|
>
|
|
<span className="sr-only">{menuLabel}</span>
|
|
<svg
|
|
aria-hidden="true"
|
|
viewBox="0 0 24 24"
|
|
width="18"
|
|
height="18"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
strokeWidth="2"
|
|
strokeLinecap="round"
|
|
>
|
|
{isMenuOpen ? (
|
|
<path d="M6 6l12 12M18 6L6 18" />
|
|
) : (
|
|
<path d="M4 7h16M4 12h16M4 17h16" />
|
|
)}
|
|
</svg>
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
{/* Always mounted so it can animate; `invisible` removes it from the tab order and the
|
|
accessibility tree while closed. */}
|
|
<ul
|
|
id="mobile-nav-menu"
|
|
data-testid="nav-mobile-menu"
|
|
data-state={isMenuOpen ? 'open' : 'closed'}
|
|
className={`absolute inset-x-0 top-full z-40 flex flex-col gap-1 border-t border-white/30 bg-inv px-6 py-3 text-white shadow-[0_12px_24px_rgba(0,0,0,0.35)] transition-[opacity,transform,visibility] duration-200 ease-out motion-reduce:transition-none md:hidden ${
|
|
isMenuOpen
|
|
? 'visible translate-y-0 opacity-100'
|
|
: 'pointer-events-none invisible -translate-y-2 opacity-0'
|
|
}`}
|
|
>
|
|
{sectionLinks.map((link) => (
|
|
<li key={link.href}>
|
|
<a
|
|
href={link.href}
|
|
onClick={(event) => handleMobileLinkClick(event, link.href)}
|
|
className="block px-1 py-3 text-[15px] font-medium no-underline transition-colors hover:bg-white/10"
|
|
>
|
|
{link.label}
|
|
</a>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</nav>
|
|
);
|
|
}
|