NGU-Web/src/pages/sections/home/Pathfinder.tsx
Zaldimmar d81f7bd856 Adopt the new palette; square corners, superellipse buttons
The theme defaults (light and dark) come from the 16-color grid,
kept as PALETTE in src/lib/color.ts; every text pair passes the
admin's 4.5:1 check. Nothing is rounded any more except buttons,
which share one btn utility (Poppins Bold, a superellipse corner
where the browser has corner-shape) and true dots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 14:40:39 -05:00

209 lines
8.4 KiB
TypeScript

/* ═══════════════════════════════════════════════════════════════
PATHFINDER: "Find your way in"
The connect section as a question rather than a wall of forms:
pick what you're here for, and that path's actions arrive. Paths
and actions are the admin's (Front page → Find your way in);
a path with no actions never reaches this component.
The choices are a real tablist: arrow keys move between them,
Home and End jump to the ends, and only the selected tab is in
the tab order. Selection follows focus, which is right when
showing a panel costs nothing.
Re-keying the panel on the selected index is what replays the
entrance animation for each choice.
═══════════════════════════════════════════════════════════════ */
import { ArrowRight, ArrowUpRight, BookOpen, CalendarBlank, ChatCircle, Compass, GraduationCap, HandHeart, Heart, House, MapPin, MusicNotes, Sparkle, Star, Tent, UsersThree, type Icon } from '@phosphor-icons/react'
import { useId, useRef, useState, type KeyboardEvent } from 'react'
import HomeLink, { isExternal } from './HomeLink.tsx'
import type { FrontPagePath } from '../../../lib/useFrontPage.ts'
import { ACCENTS, withAlpha, accentText, readableOn } from '../../../lib/color.ts'
type PathfinderProps = {
id: string
title: string
blurb?: string | null
paths: FrontPagePath[]
}
/* One accent per position, cycling. Paths are data; color is
presentation, so it's assigned here rather than stored. */
/* A path's icon: a key from src/data/pathIcons.ts, drawn from
Phosphor. A path saved before the list existed may hold an emoji;
that shows as it is. Nothing set is a dot. */
const ICONS: Record<string, Icon> = {
heart: Heart,
hands: HandHeart,
people: UsersThree,
calendar: CalendarBlank,
tent: Tent,
map: MapPin,
home: House,
book: BookOpen,
learn: GraduationCap,
chat: ChatCircle,
music: MusicNotes,
compass: Compass,
sparkle: Sparkle,
star: Star,
}
function PathIcon({ value }: { value?: string | null }) {
const Glyph = value ? ICONS[value] : null
if (Glyph) return <Glyph size={26} weight="bold" />
return <>{value || '•'}</>
}
// The site's accent family, in turn (color.ts).
const PATH_ACCENTS = [ACCENTS.teal, ACCENTS.green, ACCENTS.olive, ACCENTS.deep]
export default function Pathfinder({ id, title, blurb, paths }: PathfinderProps) {
const [selected, setSelected] = useState(0)
const tabs = useRef<Array<HTMLButtonElement | null>>([])
const base = useId().replace(/:/g, '')
if (paths.length === 0) return null
const path = paths[Math.min(selected, paths.length - 1)]
const accent = PATH_ACCENTS[selected % PATH_ACCENTS.length]
const focus = (index: number) => {
const next = (index + paths.length) % paths.length
setSelected(next)
tabs.current[next]?.focus()
}
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
const moves: Record<string, number> = {
ArrowRight: selected + 1,
ArrowDown: selected + 1,
ArrowLeft: selected - 1,
ArrowUp: selected - 1,
Home: 0,
End: paths.length - 1,
}
if (!(e.key in moves)) return
e.preventDefault()
focus(moves[e.key])
}
return (
<section id={id} className="py-24" style={{ background: 'var(--color-surface)' }}>
<div className="mx-auto max-w-6xl px-6">
<div className="grid gap-12 lg:grid-cols-12">
<div className="lg:col-span-5">
<h2 className="font-display text-4xl font-extrabold text-ink md:text-5xl">
{title}
</h2>
{blurb && <p className="mt-4 text-lg text-muted">{blurb}</p>}
<div
role="tablist"
aria-label={title}
aria-orientation="vertical"
className="mt-10 flex flex-col gap-3"
onKeyDown={onKeyDown}
>
{paths.map((option, index) => {
const on = index === selected
const color = PATH_ACCENTS[index % PATH_ACCENTS.length]
return (
<button
key={`${option.label}-${index}`}
ref={(el) => {
tabs.current[index] = el
}}
id={`${base}-tab-${index}`}
role="tab"
type="button"
aria-selected={on}
aria-controls={`${base}-panel`}
tabIndex={on ? 0 : -1}
onClick={() => setSelected(index)}
className="group flex items-center gap-4 border-2 px-5 py-4 text-left transition-all duration-300"
style={{
borderColor: on ? color : 'rgba(19,139,160,0.12)',
background: on ? `${withAlpha(color, 7)}` : 'var(--color-surface)',
transform: on ? 'translateX(8px)' : undefined,
}}
>
<span
className="flex h-12 w-12 shrink-0 items-center justify-center text-2xl transition-transform duration-300 group-hover:scale-110"
style={{
background: on ? color : `${withAlpha(color, 12)}`,
color: on ? readableOn(color) : accentText(color),
}}
aria-hidden="true"
>
<PathIcon value={option.icon} />
</span>
<span className="font-display text-xl font-bold" style={{ color: on ? accentText(color) : 'var(--color-ink)' }}>
{option.label}
</span>
<span
className="ml-auto text-xl transition-opacity"
style={{ color, opacity: on ? 1 : 0 }}
aria-hidden="true"
>
<ArrowRight size="1em" weight="bold" className="inline align-[-0.125em]" aria-hidden="true" />
</span>
</button>
)
})}
</div>
</div>
<div
key={selected}
id={`${base}-panel`}
role="tabpanel"
aria-labelledby={`${base}-tab-${selected}`}
className="relative overflow-hidden p-8 md:p-10 lg:col-span-7"
style={{ background: withAlpha(accent, 5) }}
>
{path.blurb && (
<p className="hp-pop relative max-w-md font-display text-2xl font-semibold leading-snug text-ink">
{path.blurb}
</p>
)}
<ul className="relative mt-8 grid gap-4 sm:grid-cols-2">
{path.actions.map((action, index) => (
<li
key={`${action.url}-${index}`}
className="hp-pop"
style={{ animationDelay: `${120 + index * 90}ms` }}
>
<HomeLink
url={action.url}
className="group flex h-full flex-col bg-surface p-6 shadow-sm ring-1 ring-black/5 transition-all duration-300 hover:-translate-y-1 hover:shadow-xl"
>
<span className="flex items-start gap-2 font-display text-lg font-bold text-ink">
{action.label}
<span
className="ml-auto transition-transform group-hover:translate-x-1"
style={{ color: accentText(accent) }}
aria-hidden="true"
>
{isExternal(action.url) ? <ArrowUpRight size="1em" weight="bold" className="inline align-[-0.125em]" aria-hidden="true" /> : <ArrowRight size="1em" weight="bold" className="inline align-[-0.125em]" aria-hidden="true" />}
</span>
</span>
{action.description && (
<span className="mt-2 text-sm leading-relaxed text-muted">
{action.description}
</span>
)}
</HomeLink>
</li>
))}
</ul>
</div>
</div>
</div>
</section>
)
}