A year's leaf eases from green to gold to autumn between this year and 2000 (leafColor in color.ts); every year before 2000 is fully turned. Empty-section and form notes use one notice style, a flat tinted panel with a solid left bar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
3.2 KiB
TypeScript
98 lines
3.2 KiB
TypeScript
import { Leaf } from '@phosphor-icons/react'
|
|
import type { CSSProperties } from 'react'
|
|
import type { GroupedYear } from '../../../lib/timeline.ts'
|
|
import { leafColor } from '../../../lib/color.ts'
|
|
import TimelineEntry from './TimelineEntry.tsx'
|
|
|
|
/** Each year is a leaf on the rail, its color turning from green to
|
|
* autumn as the years go back (leafColor), its size growing with
|
|
* the year's entries so the rail still reads as a density chart.
|
|
* Filled, not the icon set's usual bold outline, so the color
|
|
* carries. */
|
|
function leafSize(count: number): string {
|
|
return `${(14 + Math.min(count, 14) * 0.9).toFixed(2)}px`
|
|
}
|
|
|
|
type Props = {
|
|
year: GroupedYear
|
|
open: boolean
|
|
onToggle: (year: number) => void
|
|
}
|
|
|
|
export default function TimelineYear({ year, open, onToggle }: Props) {
|
|
const empty = year.count === 0
|
|
const panelId = `site-tl-year-${year.year}`
|
|
|
|
const className = [
|
|
'site-tl__year',
|
|
year.featured ? 'site-tl__year--featured' : '',
|
|
open ? 'site-tl__year--open' : '',
|
|
empty ? 'site-tl__year--empty' : '',
|
|
]
|
|
.filter(Boolean)
|
|
.join(' ')
|
|
|
|
return (
|
|
<div className={className}>
|
|
<button
|
|
type="button"
|
|
className="site-tl__yearBtn"
|
|
aria-expanded={open}
|
|
aria-controls={panelId}
|
|
onClick={() => onToggle(year.year)}
|
|
>
|
|
<span
|
|
className="site-tl__leaf"
|
|
style={{ '--tl-leaf': leafSize(year.count), color: leafColor(year.year) } as CSSProperties}
|
|
aria-hidden="true"
|
|
>
|
|
<Leaf weight="fill" />
|
|
</span>
|
|
<span className="site-tl__yearLabel">{year.year}</span>
|
|
<span className="site-tl__yearCount">
|
|
{empty ? '-' : `${year.count} ${year.count === 1 ? 'entry' : 'entries'}`}
|
|
</span>
|
|
</button>
|
|
|
|
{open ? (
|
|
empty ? (
|
|
<div className="site-tl__empty" id={panelId}>
|
|
Nothing recorded for {year.year} yet.
|
|
</div>
|
|
) : (
|
|
<div className="site-tl__panel" id={panelId}>
|
|
{year.featuredItems.length > 0 ? (
|
|
<ul className="site-tl__featured site-tl__list">
|
|
{year.featuredItems.map((item) => (
|
|
<TimelineEntry key={item.id} item={item} variant="featured" />
|
|
))}
|
|
</ul>
|
|
) : null}
|
|
|
|
{year.months.map((month) => (
|
|
<section className="site-tl__month" key={month.month}>
|
|
<h4 className="site-tl__monthLabel">{month.label}</h4>
|
|
<ul className="site-tl__list">
|
|
{month.items.map((item) => (
|
|
<TimelineEntry key={item.id} item={item} />
|
|
))}
|
|
</ul>
|
|
</section>
|
|
))}
|
|
|
|
{year.undated.length > 0 ? (
|
|
<section className="site-tl__month site-tl__undated">
|
|
<h4 className="site-tl__monthLabel">Elsewhere in {year.year}</h4>
|
|
<ul className="site-tl__list">
|
|
{year.undated.map((item) => (
|
|
<TimelineEntry key={item.id} item={item} />
|
|
))}
|
|
</ul>
|
|
</section>
|
|
) : null}
|
|
</div>
|
|
)
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|