NGU-Web/src/pages/sections/home/Pathfinder.tsx
Zaldimmar 5dbb203519 Featured cards and the connect section as one ruled block; Give beside the footer logo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 14:48:48 -05:00

200 lines
8 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.
Drawn like the featured cards (FeaturedCards.tsx): one continuous
block, no gaps and no frame, a colored rule between cells. The
paths are a strip of cells along the top, the chosen one filled
flat in its accent; under it, the path's blurb and its actions
are cells of the same block.
═══════════════════════════════════════════════════════════════ */
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 CSSProperties, type KeyboardEvent } from 'react'
import HomeLink, { isExternal } from './HomeLink.tsx'
import type { FrontPagePath } from '../../../lib/useFrontPage.ts'
import { ACCENTS, 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])
}
// A cell's rules: right and bottom, the outer ones clipped off
// by the wrapper (the grid runs 2px past it).
const cell = 'border-r-2 border-b-2 border-brand'
const panelFill = `color-mix(in srgb, ${accent} 12%, var(--color-surface))`
return (
<section id={id} className="py-24">
<div className="mx-auto max-w-6xl px-6">
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl">{title}</h2>
{blurb && <p className="mt-4 max-w-2xl text-lg text-muted">{blurb}</p>}
<div className="mt-12 overflow-hidden">
<div className="-mr-[2px] -mb-[2px]">
<div
role="tablist"
aria-label={title}
aria-orientation="horizontal"
className="grid sm:grid-cols-2 lg:grid-cols-[repeat(var(--paths),minmax(0,1fr))]"
style={{ '--paths': Math.min(paths.length, 5) } as CSSProperties}
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={`${cell} flex items-center gap-4 px-6 py-6 text-left transition-colors duration-300 ${
on ? '' : 'bg-surface hover:bg-tint-soft'
}`}
style={on ? { background: color, color: readableOn(color) } : undefined}
>
<span
className="text-2xl"
style={{ color: on ? readableOn(color) : accentText(color) }}
aria-hidden="true"
>
<PathIcon value={option.icon} />
</span>
<span className="font-display text-xl font-bold" style={on ? undefined : { color: 'var(--color-ink)' }}>
{option.label}
</span>
</button>
)
})}
</div>
<div
key={selected}
id={`${base}-panel`}
role="tabpanel"
aria-labelledby={`${base}-tab-${selected}`}
className="grid sm:grid-cols-2 lg:grid-cols-3"
>
{path.blurb && (
<p
className={`${cell} hp-pop p-8 font-display text-2xl leading-snug text-ink md:p-10`}
style={{ background: panelFill }}
>
{path.blurb}
</p>
)}
{path.actions.map((action, index) => (
<HomeLink
key={`${action.url}-${index}`}
url={action.url}
className={`${cell} hp-pop group flex flex-col bg-surface p-8 transition-colors duration-200 hover:bg-tint-soft`}
style={{ animationDelay: `${120 + index * 90}ms` }}
>
<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>
))}
</div>
</div>
</div>
</div>
</section>
)
}