- Dark mode: the countdown card, timeline section, Giving text, error text, the Leadership button, skeletons and the admin's dark text all follow the tokens; logos get a light plate in dark mode - One BRAND accent (the button token, so the admin palette reaches every page) and one ACCENTS family in color.ts, replacing 20 local teal constants and the purple, ochre and rust section colours; neon green and gold become mint and brand green - Shadows are tinted with the site's ink; glow shadows are gone - One giving label, Give, in the nav, footer and Giving page - Phosphor icons replace the hand-drawn SVGs and the glyph icons; Pathfinder paths pick a named icon (emoji still shown) and lose the watermark - Home keeps two eyebrows; StatsBand's title is a real heading; section headings step down under the page title - Nav links switch to the menu below lg, so they never wrap; jump links land clear of the header; press feedback on buttons - Empty sections say what's coming and who to ask; loading is a skeleton; form placeholders and borders are readable; one corner-radius rule; theme-color for both modes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
252 lines
9.4 KiB
TypeScript
252 lines
9.4 KiB
TypeScript
/* ═══════════════════════════════════════════════════════════════
|
||
FEATURED TIMELINE RAIL
|
||
|
||
The history page's featured entries, sideways: oldest on the
|
||
left, so scrolling right moves forward through time. A line runs
|
||
under the cards with a dot per entry, and a year label wherever
|
||
the year changes. The last card goes to the full history.
|
||
|
||
Featured is the admin's call, timeline_entries.is_featured,
|
||
"shown large" on the history page. Nothing else is filtered
|
||
here; /history has already decided what's public.
|
||
|
||
Scrolling is native, touch, trackpad, shift-wheel, with
|
||
scroll-snap so it settles on a card. A mouse can also drag it, and
|
||
the arrow buttons step one card. A drag that moved more than a few
|
||
pixels swallows the click it ends in, so letting go over a card
|
||
doesn't open it.
|
||
|
||
Nothing featured, and the section doesn't render at all.
|
||
═══════════════════════════════════════════════════════════════ */
|
||
|
||
import { ArrowRight, CaretRight, CaretLeft } from '@phosphor-icons/react';
|
||
import { useRef, useState, type PointerEvent as ReactPointerEvent } from 'react'
|
||
import { Link } from 'react-router-dom'
|
||
|
||
import HomeLink from './HomeLink.tsx'
|
||
import { useHistory } from '../../../lib/useHistory.ts'
|
||
import { hrefFor, logoSrc } from '../../../lib/timelineRefs.ts'
|
||
import { MONTH_LABELS, type TimelineItem } from '../../../lib/timeline.ts'
|
||
import { accentText, BRAND } from '../../../lib/color.ts'
|
||
import { scrollBehavior } from '../../../lib/motion.ts';
|
||
|
||
const DRAG_SLOP = 6
|
||
|
||
type RailProps = { id: string; title: string; blurb?: string | null }
|
||
|
||
export default function FeaturedTimelineRail({ id, title, blurb }: RailProps) {
|
||
const { items, loading, error, reload } = useHistory()
|
||
const featured = items
|
||
.filter((item) => item.featured)
|
||
.sort((a, b) => a.date.localeCompare(b.date))
|
||
|
||
const railRef = useRef<HTMLOListElement>(null)
|
||
const drag = useRef({ x: 0, left: 0, moved: false, active: false })
|
||
const [dragging, setDragging] = useState(false)
|
||
|
||
if (!loading && !error && featured.length === 0) return null
|
||
|
||
const step = (direction: number) => {
|
||
const rail = railRef.current
|
||
const card = rail?.querySelector('li')
|
||
if (!rail || !card) return
|
||
rail.scrollBy({ left: direction * (card.clientWidth + 24), behavior: scrollBehavior() })
|
||
}
|
||
|
||
const onPointerDown = (e: ReactPointerEvent<HTMLOListElement>) => {
|
||
if (e.pointerType !== 'mouse' || !railRef.current) return
|
||
drag.current = { x: e.clientX, left: railRef.current.scrollLeft, moved: false, active: true }
|
||
}
|
||
|
||
const onPointerMove = (e: ReactPointerEvent<HTMLOListElement>) => {
|
||
const d = drag.current
|
||
if (!d.active || !railRef.current) return
|
||
const dx = e.clientX - d.x
|
||
if (!d.moved && Math.abs(dx) > DRAG_SLOP) {
|
||
d.moved = true
|
||
setDragging(true)
|
||
railRef.current.setPointerCapture(e.pointerId)
|
||
}
|
||
if (d.moved) railRef.current.scrollLeft = d.left - dx
|
||
}
|
||
|
||
const endDrag = () => {
|
||
drag.current.active = false
|
||
setDragging(false)
|
||
}
|
||
|
||
return (
|
||
<section id={id} className="overflow-hidden py-24" style={{ background: 'var(--color-tint-soft)' }}>
|
||
<div className="mx-auto flex max-w-6xl flex-wrap items-end gap-6 px-6">
|
||
<div>
|
||
<h2 className="font-display text-4xl font-extrabold text-ink md:text-5xl">
|
||
{title}
|
||
</h2>
|
||
{blurb && <p className="mt-3 max-w-xl text-lg text-muted">{blurb}</p>}
|
||
</div>
|
||
|
||
{featured.length > 1 && (
|
||
<div className="ml-auto flex gap-2">
|
||
{[
|
||
[-1, <CaretLeft size={22} weight="bold" aria-hidden="true" />, 'Earlier'],
|
||
[1, <CaretRight size={22} weight="bold" aria-hidden="true" />, 'Later'],
|
||
].map(([direction, glyph, label]) => (
|
||
<button
|
||
key={label as string}
|
||
type="button"
|
||
onClick={() => step(direction as number)}
|
||
aria-label={label as string}
|
||
className="flex h-12 w-12 items-center justify-center rounded-full border text-2xl transition-colors hover:bg-surface"
|
||
style={{ borderColor: BRAND, color: accentText(BRAND) }}
|
||
>
|
||
{glyph}
|
||
</button>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{error ? (
|
||
<p className="mx-auto mt-10 max-w-6xl px-6 text-danger">
|
||
Couldn’t load the timeline. {error}{' '}
|
||
<button type="button" onClick={reload} className="underline">
|
||
Try again
|
||
</button>
|
||
</p>
|
||
) : loading ? (
|
||
<div className="mx-auto mt-12 flex max-w-6xl gap-6 px-6" aria-hidden="true">
|
||
{[0, 1, 2].map((i) => (
|
||
<div key={i} className="h-72 w-80 shrink-0 animate-pulse rounded-3xl bg-tint" />
|
||
))}
|
||
</div>
|
||
) : (
|
||
<ol
|
||
ref={railRef}
|
||
className={`hp-rail mt-12 flex gap-6 overflow-x-auto px-6 pb-4 md:px-[max(1.5rem,calc((100vw-72rem)/2+1.5rem))] ${
|
||
dragging ? 'hp-rail--dragging' : ''
|
||
}`}
|
||
onPointerDown={onPointerDown}
|
||
onPointerMove={onPointerMove}
|
||
onPointerUp={endDrag}
|
||
onPointerCancel={endDrag}
|
||
// Links and images are natively draggable, and a native
|
||
// drag cancels the pointer stream this relies on.
|
||
onDragStart={(e) => e.preventDefault()}
|
||
onClickCapture={(e) => {
|
||
if (drag.current.moved) {
|
||
e.preventDefault()
|
||
e.stopPropagation()
|
||
drag.current.moved = false
|
||
}
|
||
}}
|
||
>
|
||
{featured.map((item, index) => (
|
||
<li key={item.id} className="w-[19rem] shrink-0 md:w-[22rem]">
|
||
<RailCard
|
||
item={item}
|
||
showYear={index === 0 || year(item) !== year(featured[index - 1])}
|
||
/>
|
||
</li>
|
||
))}
|
||
|
||
<li className="w-[19rem] shrink-0 md:w-[22rem]">
|
||
<div className="flex h-full flex-col">
|
||
<div className="h-12" />
|
||
<Link
|
||
to="/history"
|
||
draggable={false}
|
||
className="flex flex-1 flex-col justify-center rounded-3xl p-8 text-white transition-transform duration-300 hover:-translate-y-1"
|
||
style={{ background: BRAND }}
|
||
>
|
||
<span className="font-display text-2xl font-extrabold">The whole story</span>
|
||
<span className="mt-2 text-white/75">Every year, every milestone.</span>
|
||
<span className="mt-6 font-semibold">See the full history <ArrowRight size="1em" weight="bold" className="inline align-[-0.125em]" aria-hidden="true" /></span>
|
||
</Link>
|
||
</div>
|
||
</li>
|
||
</ol>
|
||
)}
|
||
</section>
|
||
)
|
||
}
|
||
|
||
const year = (item: TimelineItem) => item.date.slice(0, 4)
|
||
|
||
/* "June 2014", "2014", "12 June 2014", only as much as precision
|
||
says is true. */
|
||
function dateLabel(item: TimelineItem): string {
|
||
const [y, m, d] = item.date.split('-')
|
||
const month = m ? MONTH_LABELS[Number(m) - 1] : null
|
||
if (item.precision === 'day' && d && month) return `${Number(d)} ${month} ${y}`
|
||
if (item.precision !== 'year' && month) return `${month} ${y}`
|
||
return y
|
||
}
|
||
|
||
function RailCard({ item, showYear }: { item: TimelineItem; showYear: boolean }) {
|
||
const href = hrefFor(item)
|
||
const logo = logoSrc(item)
|
||
|
||
const body = (
|
||
<>
|
||
{logo && (
|
||
<img
|
||
src={logo}
|
||
alt=""
|
||
loading="lazy"
|
||
draggable={false}
|
||
className="logo-plate mb-5 h-14 w-14 object-contain"
|
||
/>
|
||
)}
|
||
<p className="text-sm font-semibold" style={{ color: accentText(BRAND) }}>
|
||
{dateLabel(item)}
|
||
</p>
|
||
<p className="mt-2 font-display text-xl font-bold leading-snug text-ink">
|
||
{item.title}
|
||
</p>
|
||
{item.meta && <p className="mt-1 text-sm text-muted">{item.meta}</p>}
|
||
{item.blurb && (
|
||
<p className="mt-3 line-clamp-4 text-sm leading-relaxed text-muted">{item.blurb}</p>
|
||
)}
|
||
{href && (
|
||
<span className="mt-auto pt-5 text-sm font-semibold" style={{ color: accentText(BRAND) }}>
|
||
Read more <ArrowRight size="1em" weight="bold" className="inline align-[-0.125em]" aria-hidden="true" />
|
||
</span>
|
||
)}
|
||
</>
|
||
)
|
||
|
||
const card =
|
||
'flex flex-1 flex-col rounded-3xl border border-brand/15 bg-surface p-7 shadow-sm'
|
||
|
||
return (
|
||
<div className="flex h-full flex-col">
|
||
{/* The line, its dot, and the year where it changes. */}
|
||
<div className="relative mb-4 h-8">
|
||
<div className="absolute inset-x-[-1.5rem] top-1/2 h-px bg-brand/30" />
|
||
<span
|
||
className="absolute left-0 top-1/2 h-3 w-3 -translate-y-1/2 rounded-full border-2 bg-surface"
|
||
style={{ borderColor: BRAND }}
|
||
/>
|
||
{showYear && (
|
||
<span
|
||
className="absolute left-5 top-1/2 -translate-y-1/2 rounded-full px-3 py-0.5 font-display text-sm font-bold text-white"
|
||
style={{ background: BRAND }}
|
||
>
|
||
{year(item)}
|
||
</span>
|
||
)}
|
||
</div>
|
||
|
||
{href ? (
|
||
<HomeLink
|
||
url={href}
|
||
className={`${card} transition-all duration-300 hover:-translate-y-1 hover:shadow-xl`}
|
||
>
|
||
{body}
|
||
</HomeLink>
|
||
) : (
|
||
<div className={card}>{body}</div>
|
||
)}
|
||
</div>
|
||
)
|
||
}
|