The reader (ReaderView.tsx) now reads an icon-only link's label, puts a card's link on its first line or picture when it has no heading, gives each item of a row of facts or links its own line, keeps line breaks, skips what CSS hides, turns a form into one line saying it can't be used there, shows empty table cells as "-", keeps section and heading ids so #links land, and opens file links as files. What it can't read draws its own text version (useReadingMode()): the hero, pathfinder, front page history, event lists (every event, past ones too), org lists and groups map (every region and group, linked), history timeline (every year open), schedules (every day, fold-outs included), people tiles (everyone, with details) and videos. Also: org names are linked headings, heading levels fixed where cards repeated their section's, Team pages lose the doubled "Members", Giving links the treasurer's email and names Church Center. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
227 lines
8.8 KiB
TypeScript
227 lines
8.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.
|
|
|
|
Reading mode (readingMode.ts) gets every path at once, no tabs:
|
|
its label as a heading, its blurb and a list of its actions.
|
|
═══════════════════════════════════════════════════════════════ */
|
|
|
|
import { ArrowRight, ArrowUpRight, BookOpen, Dot, 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'
|
|
import { useReadingMode } from '../../../lib/readingMode.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. Nothing set (or a key no longer on the list) 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 <Dot size={26} weight="bold" />
|
|
}
|
|
|
|
// The site's accent family, in turn (color.ts).
|
|
const PATH_ACCENTS = [ACCENTS.teal, ACCENTS.green, ACCENTS.amber, 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, '')
|
|
const reading = useReadingMode()
|
|
|
|
if (paths.length === 0) return null
|
|
|
|
if (reading) {
|
|
return (
|
|
<section id={id}>
|
|
<h2>{title}</h2>
|
|
{blurb && <p>{blurb}</p>}
|
|
{paths.map((option, index) => (
|
|
<div key={`${option.label}-${index}`}>
|
|
<h3>{option.label}</h3>
|
|
{option.blurb && <p>{option.blurb}</p>}
|
|
<ul>
|
|
{option.actions.map((action, i) => (
|
|
<li key={`${action.url}-${i}`}>
|
|
<HomeLink url={action.url}>{action.label}</HomeLink>
|
|
{action.description && `: ${action.description}`}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
))}
|
|
</section>
|
|
)
|
|
}
|
|
|
|
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 4px past it).
|
|
const cell = 'border-r-4 border-b-4 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 shadow-md">
|
|
<div className="-mr-[4px] -mb-[4px]">
|
|
<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-raised 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-raised 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>
|
|
)
|
|
}
|