Files
school_compare/nextjs-app/components/Navigation.tsx
TudorandClaude Opus 5 8ab0ac0a04
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m6s
PR Checks / Backend Smoke (pull_request) Successful in 7s
PR Checks / Build Backend (no push) (pull_request) Successful in 12s
PR Checks / Build Frontend (no push) (pull_request) Successful in 49s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 10s
PR Checks / AI Code Review (Claude) (pull_request) Failing after 3m13s
feat(design): adopt the Cohort identity — new palette, type, mark and dark theme
Implements the direction agreed from the identity board: Route C ("Cohort")
with the paper ground from C1, the Schibsted Grotesk / Literata pairing from
C2, and the iris accent from C3. Dark theme is in scope from the start rather
than retrofitted.

The audit found three things wrong beyond taste:

* No brand asset set. og:image was absent entirely, so every link shared into
  a class WhatsApp group rendered as a bare grey card. apple-touch-icon pointed
  at an SVG, which iOS ignores, and the manifest shipped no PNGs, so Android
  installs had no icon. The header mark and the favicon had also drifted into
  two different logos.
* No colour discipline. --primary and --trend-down were the same coral, so the
  main CTA and "below average" shared a hue. 58 distinct hex values were spread
  across component CSS, and the chart palette was still Chart.js's stock demo
  colours.
* A dark theme that was declared but never built — themeColor announced a dark
  variant with no dark styling behind it.

What changed:

Colour now has exactly three jobs that never borrow each other's hues: brand
(iris) for interactive and identity, status (teal/amber) for above/below a
comparison point, and phase for categories. Teal/amber rather than green/red
keeps the above/below signal readable for every form of colour blindness.
Every chromatic literal in component CSS is now a token, and the JS-painted
surfaces (Chart.js, Leaflet) read the tokens through lib/theme so they follow
the theme instead of ignoring it.

The mark is the five-bar cohort spread — the same object as the distribution
strip inside a school row, built from opacity steps so it inverts cleanly.
components/Logo.tsx is the single source; the favicon, apple-icon and share
card all derive from its geometry.

globals.css drops 123 dead global classes left over from the vanilla-JS app
(only the btn family, .skip-link and .main were still referenced), along with
the noise overlay. It also gains prefers-reduced-motion support, which was
missing entirely, and a type scale so the 54 ad-hoc font sizes have somewhere
to converge.

Verified: tsc clean, 159 unit tests pass, production build succeeds and
prerenders /icon.svg, /apple-icon and /opengraph-image. Three e2e journeys
added for the asset set, the themeColor/background match, and the dark theme
actually repainting — all silent failures that nothing on the page reveals.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:13:04 +01:00

153 lines
5.4 KiB
TypeScript

/**
* Navigation Component
* Top header nav for desktop; bottom tab bar for mobile (≤640px).
*/
'use client';
import { useEffect } from 'react';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { useComparison } from '@/hooks/useComparison';
import { LogoMark } from './Logo';
import styles from './Navigation.module.css';
type IconProps = { className?: string };
const SearchIcon = ({ className }: IconProps) => (
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<circle cx="11" cy="11" r="7" />
<path d="m20 20-3.5-3.5" />
</svg>
);
const CompareIcon = ({ className }: IconProps) => (
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M4 7h13l-3-3" />
<path d="M20 17H7l3 3" />
</svg>
);
const RankingsIcon = ({ className }: IconProps) => (
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M7 21V11" />
<path d="M12 21V4" />
<path d="M17 21v-7" />
</svg>
);
const AdmissionsIcon = ({ className }: IconProps) => (
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<rect x="3" y="5" width="18" height="16" rx="2" />
<path d="M3 10h18M8 3v4M16 3v4" />
</svg>
);
export function Navigation() {
const pathname = usePathname();
const { selectedSchools } = useComparison();
const isActive = (path: string) => {
if (path === '/') return pathname === '/';
return pathname.startsWith(path);
};
/**
* iOS Chrome (and some Android browsers) auto-hide their URL bar on scroll,
* which grows the visual viewport without changing the layout viewport.
* `position: fixed; bottom: 0` sticks to the layout viewport, so our tab
* bar appears to float mid-screen with a gap beneath it. Track the delta
* via VisualViewport and apply it as a translate so the bar always sits
* flush against the visible bottom edge.
*/
useEffect(() => {
const vv = window.visualViewport;
if (!vv) return;
const root = document.documentElement;
const update = () => {
const offset = window.innerHeight - (vv.height + vv.offsetTop);
// Only positive offsets are meaningful (bar hidden → push down).
root.style.setProperty('--mobile-bar-offset', `${Math.max(0, offset)}px`);
};
update();
vv.addEventListener('resize', update);
vv.addEventListener('scroll', update);
return () => {
vv.removeEventListener('resize', update);
vv.removeEventListener('scroll', update);
root.style.removeProperty('--mobile-bar-offset');
};
}, []);
const items = [
{ href: '/', label: 'Search', Icon: SearchIcon },
{ href: '/compare', label: 'Compare', Icon: CompareIcon },
{ href: '/rankings', label: 'Rankings', Icon: RankingsIcon },
{ href: '/admissions', label: 'Admissions', Icon: AdmissionsIcon },
] as const;
return (
<>
<header className={styles.header}>
<div className={styles.container}>
<Link href="/" className={styles.logo} aria-label="SchoolCompare home">
<span className={styles.logoIcon}>
<LogoMark />
</span>
<span className={styles.logoText}>
School<span className={styles.logoTextAccent}>Compare</span>
</span>
</Link>
<nav className={styles.nav} aria-label="Main navigation">
{items.map(({ href, label }) => {
const active = isActive(href);
const showBadge = href === '/compare' && selectedSchools.length > 0;
return (
<Link
key={href}
href={href}
className={active ? `${styles.navLink} ${styles.active}` : styles.navLink}
aria-current={active ? 'page' : undefined}
>
{label}
{showBadge && (
<span key={selectedSchools.length} className={styles.badge}>
{selectedSchools.length}
</span>
)}
</Link>
);
})}
</nav>
</div>
</header>
<nav className={styles.bottomBar} aria-label="Main navigation">
{items.map(({ href, label, Icon }) => {
const active = isActive(href);
const showBadge = href === '/compare' && selectedSchools.length > 0;
return (
<Link
key={href}
href={href}
className={active ? `${styles.tab} ${styles.tabActive}` : styles.tab}
aria-current={active ? 'page' : undefined}
>
<span className={styles.tabIconWrap}>
<Icon className={styles.tabIcon} />
{showBadge && (
<span key={selectedSchools.length} className={styles.tabBadge} aria-label={`${selectedSchools.length} selected`}>
{selectedSchools.length}
</span>
)}
</span>
<span className={styles.tabLabel}>{label}</span>
</Link>
);
})}
</nav>
</>
);
}