Navigation: section dropdowns, a side nav, Home's sections from the front page
- The header's second strip is gone: each top link drops down its page's sections on hover or keyboard focus. - Retreats, Community, Resources, Organization and History get the admin editors' "On this page" column (SectionNav), sticky at the left from lg up, with the section being read lit. - Home's sections in the dropdown, mobile menu, footer site map, the feedback form and the QR maker are the bands the front page is showing, in its order and under its headings (navSections.ts, frontPageBands.ts, which Home.tsx now draws from too). - Resources comes before Organization in the nav and footer. - The Organization page draws from its own editor's content. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
43797f38bc
commit
ed0f12022f
16 changed files with 283 additions and 237 deletions
|
|
@ -1,7 +1,8 @@
|
|||
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 { PAGE_LINKS, NAV_ACTIONS } from "../navConfig.ts";
|
||||
import { useNavSections } from "../lib/navSections.ts";
|
||||
import Banner from "./Banner.tsx";
|
||||
import siteLogo from "../assets/logos/NGU_Logo.svg";
|
||||
import Footer from "./Footer.tsx";
|
||||
|
|
@ -76,23 +77,18 @@ const navActions = NAV_ACTIONS as NavActionItem[];
|
|||
|
||||
export default function Layout() {
|
||||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
|
||||
const [activeSection, setActiveSection] = useState<string | null>(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),
|
||||
);
|
||||
// Measured below; this first guess keeps the content from jumping
|
||||
// when it lands.
|
||||
const [headerHeight, setHeaderHeight] = useState(72);
|
||||
const headerRef = useRef<HTMLElement>(null);
|
||||
const closeMenuRef = useRef<HTMLButtonElement>(null);
|
||||
const location = useLocation();
|
||||
|
||||
const sections = PAGE_SECTIONS[location.pathname] ?? [];
|
||||
const activePage = PAGE_LINKS.find((p) => p.path === location.pathname);
|
||||
const sectionsOf = useNavSections();
|
||||
|
||||
// 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
|
||||
|
|
@ -105,9 +101,9 @@ export default function Layout() {
|
|||
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.
|
||||
// The header grows and shrinks: the banner can be dismissed, and
|
||||
// wraps on a narrow screen. Measure it instead of guessing, so the
|
||||
// spacer below always matches.
|
||||
useEffect(() => {
|
||||
const el = headerRef.current;
|
||||
if (!el) return;
|
||||
|
|
@ -132,33 +128,6 @@ export default function Layout() {
|
|||
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
|
||||
|
|
@ -195,23 +164,51 @@ export default function Layout() {
|
|||
<img src={siteLogo} alt="Next Generation of Unity" className="h-10 w-auto" />
|
||||
</Link>
|
||||
|
||||
{/* Each page, and under it on hover or keyboard focus its
|
||||
sections (navSections.ts): the sections live in these
|
||||
dropdowns rather than a strip of their own. */}
|
||||
<div className="hidden lg:flex items-center gap-6">
|
||||
{PAGE_LINKS.map((page) => (
|
||||
<NavLink
|
||||
key={page.path}
|
||||
to={page.path}
|
||||
end={page.path === "/"}
|
||||
className={({ isActive }) =>
|
||||
`text-base font-bold pb-1 border-b-2 transition-colors duration-200 ${
|
||||
isActive
|
||||
? "text-white border-[#9cc47c]"
|
||||
: "text-white/75 hover:text-white border-transparent"
|
||||
}`
|
||||
}
|
||||
>
|
||||
{page.label}
|
||||
</NavLink>
|
||||
))}
|
||||
{PAGE_LINKS.map((page) => {
|
||||
const pageSections = sectionsOf(page.path);
|
||||
return (
|
||||
<div key={page.path} className="group relative">
|
||||
<NavLink
|
||||
to={page.path}
|
||||
end={page.path === "/"}
|
||||
className={({ isActive }) =>
|
||||
`block text-base font-bold pb-1 border-b-2 transition-colors duration-200 ${
|
||||
isActive
|
||||
? "text-white border-[#9cc47c]"
|
||||
: "text-white/75 hover:text-white border-transparent"
|
||||
}`
|
||||
}
|
||||
>
|
||||
{page.label}
|
||||
</NavLink>
|
||||
{pageSections.length > 0 && (
|
||||
// pt-3 is the bridge the pointer crosses from the
|
||||
// link into the menu without it closing.
|
||||
<div className="invisible absolute top-full left-0 z-10 pt-3 opacity-0 transition-opacity duration-150 group-hover:visible group-hover:opacity-100 group-focus-within:visible group-focus-within:opacity-100">
|
||||
<ul
|
||||
className="min-w-56 py-2 shadow-xl"
|
||||
style={{ background: "rgba(0, 16, 17, 0.97)", borderTop: "2px solid #9cc47c" }}
|
||||
>
|
||||
{pageSections.map((section) => (
|
||||
<li key={section.hash}>
|
||||
<Link
|
||||
to={`${page.path}${section.hash}`}
|
||||
className="block px-4 py-2 text-sm text-white/80 transition-colors hover:bg-white/10 hover:text-[#f0bd4f] focus-visible:bg-white/10"
|
||||
>
|
||||
{section.label}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -235,43 +232,6 @@ export default function Layout() {
|
|||
</div>
|
||||
</nav>
|
||||
|
||||
{/* Tier 2, sections of the current page */}
|
||||
{sections.length > 0 && (
|
||||
<nav
|
||||
className="hidden md:flex items-center px-6 py-2"
|
||||
aria-label={`On this page: ${activePage?.label}`}
|
||||
style={{
|
||||
background: "rgba(0, 16, 17, 0.92)",
|
||||
borderBottom: "1px solid rgba(92, 231, 255, 0.15)",
|
||||
}}
|
||||
>
|
||||
<span className="text-xs text-white/65">{activePage?.label}</span>
|
||||
|
||||
{/* Separates the page label from its sections */}
|
||||
<span
|
||||
aria-hidden
|
||||
className="mx-5 h-4 w-px"
|
||||
style={{ background: "rgba(92, 231, 255, 0.3)" }}
|
||||
/>
|
||||
|
||||
<div className="flex items-center gap-6">
|
||||
{sections.map((section) => (
|
||||
<a
|
||||
key={section.hash}
|
||||
href={section.hash}
|
||||
aria-current={activeSection === section.hash ? "location" : undefined}
|
||||
className={`text-sm transition-colors duration-200 ${
|
||||
activeSection === section.hash
|
||||
? "text-[#9cc47c]"
|
||||
: "text-white/75 hover:text-[#9cc47c]"
|
||||
}`}
|
||||
>
|
||||
{section.label}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</nav>
|
||||
)}
|
||||
</header>
|
||||
|
||||
<PageBackdrop />
|
||||
|
|
@ -313,7 +273,7 @@ export default function Layout() {
|
|||
|
||||
<div className="w-64">
|
||||
{PAGE_LINKS.map((page) => {
|
||||
const pageSections = PAGE_SECTIONS[page.path] ?? [];
|
||||
const pageSections = sectionsOf(page.path);
|
||||
const isActive = location.pathname === page.path;
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue