Events block: a card opens the event in full, its own blocks too
An events block's events bring their own page's blocks (one level deep, so events listing each other stop there), photo and place. A card opens the event under the cards: photo, type and date, title, place, person host, its blocks (else its card text) and a link to its page. Reading mode shows them all in full, and the presentation's event spotlight shows its blocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
df8052c75e
commit
375c364861
4 changed files with 174 additions and 33 deletions
|
|
@ -35,7 +35,9 @@
|
|||
link to it
|
||||
events items as event cards: event (from
|
||||
event_id), text the title shown, detail
|
||||
in place of the event's card text
|
||||
in place of the event's card text; a card
|
||||
opens the event in full under them, its
|
||||
own page's blocks too (EventsBlock)
|
||||
divider nothing
|
||||
|
||||
"Formatted" is InlineText.tsx: **bold**, *italic*, [text](url),
|
||||
|
|
@ -50,14 +52,18 @@
|
|||
visible even if the renderer hasn't caught up with it.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { CaretDown } from '@phosphor-icons/react'
|
||||
import { useEffect, useId, useRef, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
import { mediaUrl } from '../lib/media.ts'
|
||||
import PeopleTiles from './PeopleTiles.tsx'
|
||||
import type { ContentBlock, ContentBlockItem, ItemEvent } from '../lib/useContent.ts'
|
||||
import { Anchor, Inline, Paragraphs, isExternalUrl } from './InlineText.tsx'
|
||||
import VideoPlayer from './VideoPlayer.tsx'
|
||||
import ScheduleBlock from './ScheduleBlock.tsx'
|
||||
import ScheduleBlock, { Avatar } from './ScheduleBlock.tsx'
|
||||
import MapBlock, { PageMaps } from './MapBlock.tsx'
|
||||
import { eventHref } from '../lib/hrefs.ts'
|
||||
import { eventHref, personHref } from '../lib/hrefs.ts'
|
||||
import { occurrenceLabel } from '../lib/eventSeries.ts'
|
||||
import { accentText, BRAND } from '../lib/color.ts'
|
||||
import { headingAnchors } from '../lib/contents.ts'
|
||||
|
|
@ -160,15 +166,34 @@ export function eventLine(event: ItemEvent): string | null {
|
|||
return [kind, when].filter(Boolean).join(' · ') || null
|
||||
}
|
||||
|
||||
function EventCard({ item, accent }: { item: ContentBlockItem; accent: string }) {
|
||||
function EventCard({
|
||||
item,
|
||||
accent,
|
||||
open,
|
||||
panelId,
|
||||
onToggle,
|
||||
}: {
|
||||
item: ContentBlockItem
|
||||
accent: string
|
||||
open: boolean
|
||||
panelId: string
|
||||
onToggle: () => void
|
||||
}) {
|
||||
const event = item.event!
|
||||
const img = useSmallImage(mediaUrl(event.image))
|
||||
const color = event.color || accent
|
||||
const line = eventLine(event)
|
||||
return (
|
||||
<Anchor
|
||||
href={eventHref(event.id)}
|
||||
className="group flex h-full flex-col overflow-hidden border border-brand/15 bg-raised shadow-sm transition-shadow hover:shadow-lg"
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggle}
|
||||
aria-expanded={open}
|
||||
aria-controls={panelId}
|
||||
className="group flex h-full w-full flex-col overflow-hidden border bg-raised text-left shadow-sm transition-shadow hover:shadow-lg"
|
||||
style={{
|
||||
borderColor: open ? accent : 'color-mix(in srgb, var(--color-brand) 15%, transparent)',
|
||||
boxShadow: open ? `inset 0 -4px 0 ${accent}` : undefined,
|
||||
}}
|
||||
>
|
||||
{!img.failed && (
|
||||
<img src={img.src} alt="" loading="lazy" onError={img.onError} className="aspect-video w-full object-cover" />
|
||||
|
|
@ -185,8 +210,101 @@ function EventCard({ item, accent }: { item: ContentBlockItem; accent: string })
|
|||
{(item.detail || event.blurb) && (
|
||||
<span className="line-clamp-3 text-sm leading-snug text-body">{item.detail || event.blurb}</span>
|
||||
)}
|
||||
<span className="mt-auto inline-flex items-center gap-1 pt-2 text-sm font-semibold" style={{ color: accentText(color) }}>
|
||||
{open ? 'Close' : 'More'}
|
||||
<CaretDown aria-hidden="true" weight="bold" className={`h-4 w-4 transition-transform ${open ? 'rotate-180' : ''}`} />
|
||||
</span>
|
||||
</span>
|
||||
</Anchor>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
/* An event in full (088): its photo, type and date, title, place and
|
||||
person host, then its own page's blocks (else its card text), and
|
||||
a link to its page. */
|
||||
function EventInFull({ item, accent, level }: { item: ContentBlockItem; accent: string; level: 3 | 4 | 5 }) {
|
||||
const event = item.event!
|
||||
const color = event.color || accent
|
||||
const photo = mediaUrl(event.photo || event.image)
|
||||
const line = eventLine(event)
|
||||
const Title = `h${level}` as 'h3'
|
||||
const blurb = item.detail || event.blurb
|
||||
return (
|
||||
<section aria-label={item.text || event.title} className="space-y-6 bg-raised p-6 shadow-md">
|
||||
{photo && <img src={photo} alt={event.photo_alt ?? ''} loading="lazy" className="aspect-video w-full object-cover" />}
|
||||
<div>
|
||||
{line && (
|
||||
<p className="text-sm font-semibold capitalize" style={{ color: accentText(color) }}>
|
||||
{line}
|
||||
</p>
|
||||
)}
|
||||
<Title className="text-2xl font-bold text-ink">{item.text || event.title}</Title>
|
||||
{(event.location_label || item.person) && (
|
||||
<p className="mt-2 flex flex-wrap items-center gap-x-4 gap-y-2 text-sm text-muted">
|
||||
{event.location_label && <span>{event.location_label}</span>}
|
||||
{item.person && (
|
||||
<Link to={personHref(item.person.id)} className="inline-flex items-center gap-2 hover:underline">
|
||||
<Avatar person={item.person} size="h-8 w-8" />
|
||||
{item.person.name}
|
||||
</Link>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{event.blocks?.length ? (
|
||||
<ContentBlocks blocks={event.blocks} accent={color} anchorPrefix={`${event.id}-`} />
|
||||
) : blurb ? (
|
||||
<div className="space-y-3 leading-relaxed" style={{ color: BODY }}>
|
||||
<Paragraphs text={blurb} accent={color} />
|
||||
</div>
|
||||
) : null}
|
||||
<Anchor href={eventHref(event.id)} className="inline-block text-sm font-semibold underline" style={{ color: accentText(color) }}>
|
||||
{event.title}: the event's page
|
||||
</Anchor>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/* An events block (088): its events as cards; one opened shows in
|
||||
full under them, scrolled into view. Reading mode has them all in
|
||||
full. */
|
||||
function EventsBlock({ items, accent, level }: { items: ContentBlockItem[]; accent: string; level: 3 | 4 | 5 }) {
|
||||
const [open, setOpen] = useState<number | null>(null)
|
||||
const panelId = useId()
|
||||
const panel = useRef<HTMLDivElement>(null)
|
||||
const reading = useReadingMode()
|
||||
useEffect(() => {
|
||||
if (open != null) panel.current?.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
|
||||
}, [open])
|
||||
|
||||
if (reading) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{items.map((item, i) => (
|
||||
<EventInFull key={i} item={item} accent={accent} level={level} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<ul className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{items.map((item, i) => (
|
||||
<li key={i}>
|
||||
<EventCard
|
||||
item={item}
|
||||
accent={accent}
|
||||
open={open === i}
|
||||
panelId={panelId}
|
||||
onToggle={() => setOpen(open === i ? null : i)}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<div ref={panel} id={panelId}>
|
||||
{open != null && items[open] && <EventInFull item={items[open]} accent={accent} level={level} />}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -445,15 +563,7 @@ function Block({
|
|||
case 'events': {
|
||||
const events = (block.items ?? []).filter((item) => item.event)
|
||||
if (events.length === 0) return null
|
||||
return (
|
||||
<ul className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{events.map((item, i) => (
|
||||
<li key={i}>
|
||||
<EventCard item={item} accent={accent} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
return <EventsBlock items={events} accent={accent} level={level} />
|
||||
}
|
||||
|
||||
case 'people': {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue