import { X, List } from "@phosphor-icons/react"; import { Suspense, useState, useEffect, useRef } from "react"; import { NavLink, Link, Outlet, useLocation } from "react-router-dom"; import { PAGE_LINKS, PAGE_SECTIONS, NAV_ACTIONS } from "../navConfig.ts"; import Banner from "./Banner.tsx"; import siteLogo from "../assets/logos/NGU_Logo.svg"; import Footer from "./Footer.tsx"; import PrivacyNotice from "./PrivacyNotice.tsx"; import PageBackdrop from "./PageBackdrop.tsx"; import AccessibilityPanel from "./AccessibilityPanel.tsx"; import ThemeToggle from "./ThemeToggle.tsx"; import { scrollBehavior } from "../lib/motion.ts"; /* ── Right-side nav actions ──────────────────────────────── */ type NavActionItem = { label: string; to: string; variant: string; external?: boolean; }; const ACTION_VARIANTS: Record< string, { className: string; style: React.CSSProperties } > = { ghost: { className: "font-semibold border border-white/30 text-white/85 hover:border-white/60 hover:text-white hover:bg-white/10", style: {}, }, fancy: { className: "font-bold text-white hover:scale-105", style: { background: "var(--color-action)" }, }, }; const ACTION_SIZES = { desktop: "px-5 py-2 text-sm leading-relaxed", mobile: "px-8 py-3 text-lg", }; function NavAction({ item, size = "desktop", onClick, }: { item: NavActionItem; size?: keyof typeof ACTION_SIZES; onClick?: () => void; }) { const v = ACTION_VARIANTS[item.variant] ?? ACTION_VARIANTS.ghost; const className = `inline-block whitespace-nowrap btn transition-all duration-200 active:scale-[0.98] ${ACTION_SIZES[size]} ${v.className}`; return item.external ? ( {item.label} ) : ( {item.label} ); } const navActions = NAV_ACTIONS as NavActionItem[]; /* ── Layout ──────────────────────────────────────────────── */ export default function Layout() { const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [activeSection, setActiveSection] = useState(null); // Measured below; this first guess (nav, plus the section strip on // pages that have one) keeps the content from jumping when it lands. const [headerHeight, setHeaderHeight] = useState(() => 72 + ((PAGE_SECTIONS[window.location.pathname] ?? []).length ? 36 : 0), ); const headerRef = useRef(null); const closeMenuRef = useRef(null); const location = useLocation(); const sections = PAGE_SECTIONS[location.pathname] ?? []; const activePage = PAGE_LINKS.find((p) => p.path === location.pathname); // Close the mobile menu whenever the route changes useEffect(() => { setMobileMenuOpen(false); setActiveSection(null); }, [location.pathname]); // The open menu is modal: focus starts on its close button, Escape // shuts it, and everything behind it is inert (below). useEffect(() => { if (!mobileMenuOpen) return; closeMenuRef.current?.focus(); const onKey = (e: KeyboardEvent) => e.key === "Escape" && setMobileMenuOpen(false); window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [mobileMenuOpen]); // The header grows and shrinks: the banner can be dismissed and the // subnav only exists on some pages. Measure it instead of guessing, // so the spacer below always matches. useEffect(() => { const el = headerRef.current; if (!el) return; const ro = new ResizeObserver(([entry]) => setHeaderHeight(entry.contentRect.height) ); ro.observe(el); return () => ro.disconnect(); }, []); // Router does not scroll on navigation. Go to top on a new page, // or to the anchor if the URL carries one (handles deep links too). useEffect(() => { if (location.hash) { const el = document.querySelector(location.hash); if (el) { el.scrollIntoView({ behavior: scrollBehavior() }); return; } } window.scrollTo({ top: 0 }); }, [location.pathname, location.hash, location.key]); // Highlight whichever section is currently in view useEffect(() => { if (sections.length === 0) return; const targets = sections .map((s) => document.querySelector(s.hash)) .filter(Boolean); if (targets.length === 0) return; const observer = new IntersectionObserver( (entries) => { const visible = entries .filter((e) => e.isIntersecting) .sort( (a, b) => a.boundingClientRect.top - b.boundingClientRect.top )[0]; if (visible) setActiveSection(`#${visible.target.id}`); }, // Top margin tracks the live header height so the highlight stays // accurate whether or not the banner is showing. { rootMargin: `-${headerHeight + 30}px 0px -60% 0px`, threshold: 0 } ); targets.forEach((t) => observer.observe(t)); return () => observer.disconnect(); }, [location.pathname, headerHeight]); return ( // overflow-x-clip, not -hidden: hidden makes this div a scroll // container, and then nothing inside it can be position: sticky // (a blog post's contents column scrolled away with the page).
Skip to content {/* ── NAV ─────────────────────────────────────────────── */}
{/* Tier 0, site-wide announcement */} {/* Tier 1, site navigation */} {/* Tier 2, sections of the current page */} {sections.length > 0 && ( )}
{/* Keeps page content clear of the fixed header */}
{/* Page content */}
{/*Site Footer applied to every page*/}
{/* Mobile menu */} {mobileMenuOpen && (
{PAGE_LINKS.map((page) => { const pageSections = PAGE_SECTIONS[page.path] ?? []; const isActive = location.pathname === page.path; return (
`block text-2xl font-bold py-3 transition-colors ${ isActive ? "text-[#9cc47c]" : "text-white hover:text-[#f0bd4f]" }` } > {page.label} {/* Sections nest under the page they belong to */} {isActive && pageSections.length > 0 && (
{pageSections.map((section) => ( setMobileMenuOpen(false)} > {section.label} ))}
)}
); })}
{navActions.map((item) => ( setMobileMenuOpen(false)} /> ))}
)}
); }