Venues, map blocks and event blocks; schedule entries link to them
Data → Venues: a map picture with its locations marked as pins or boxes (088). A Map block draws a venue with its locations listed; a schedule names a venue and its entries pick a location, linking to the map on the page with it lit up. Entries and sub-items can name an event (a workshop) and take what they leave blank from it, and an Events block shows event cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3d087da005
commit
818d648e91
18 changed files with 964 additions and 35 deletions
155
src/components/MapBlock.tsx
Normal file
155
src/components/MapBlock.tsx
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
MAP BLOCK
|
||||
|
||||
The 'map' content block (088): a venue's map picture with its
|
||||
locations marked on it, each a numbered pin or a box, and the
|
||||
locations listed beside it (under it on a phone).
|
||||
|
||||
One picture, the marks drawn over it in percent of its size, so
|
||||
they stay on their places at any width. A location is lit up
|
||||
(in the accent, the rest dimmed) while its row or mark is hovered
|
||||
or focused, and when the address points at it: #map-<venue>-<key>,
|
||||
the link a schedule entry's place makes (mapAnchor). That id is
|
||||
the mark's own, so Layout's jump to the anchor scrolls it into
|
||||
view and focuses it.
|
||||
|
||||
Reading mode (readingMode.ts) gets the list alone, no picture.
|
||||
|
||||
PageMaps holds the venues that have a map block among the blocks
|
||||
drawn together (ContentBlocks), so a schedule's places link only
|
||||
when there's a map on the page to go to.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { createContext, useState } from 'react'
|
||||
import { Link, useLocation } from 'react-router-dom'
|
||||
|
||||
import { mediaUrl } from '../lib/media.ts'
|
||||
import type { Venue, VenueLocation } from '../lib/useContent.ts'
|
||||
import { accentText, readableOn, withAlpha } from '../lib/color.ts'
|
||||
import { useReadingMode } from '../lib/readingMode.ts'
|
||||
|
||||
export const PageMaps = createContext<Set<string>>(new Set())
|
||||
|
||||
export const mapAnchor = (venueId: string, key: string) => `map-${venueId}-${key}`
|
||||
|
||||
const isBox = (location: VenueLocation) => location.w != null && location.h != null
|
||||
|
||||
export default function MapBlock({ venue, accent }: { venue: Venue; accent: string }) {
|
||||
const { hash, search } = useLocation()
|
||||
const [hovered, setHovered] = useState<string | null>(null)
|
||||
const marked = venue.locations.filter((location) => location.x != null && location.y != null)
|
||||
const fromHash = venue.locations.find((location) => hash === `#${mapAnchor(venue.id, location.key)}`)?.key ?? null
|
||||
const active = hovered ?? fromHash
|
||||
const image = useReadingMode() ? null : mediaUrl(venue.map_image)
|
||||
const fill = accent.startsWith('#') ? accent : '#000000'
|
||||
|
||||
const to = (key: string) => ({ search, hash: mapAnchor(venue.id, key) })
|
||||
const light = (key: string) => ({
|
||||
onMouseEnter: () => setHovered(key),
|
||||
onMouseLeave: () => setHovered(null),
|
||||
onFocus: () => setHovered(key),
|
||||
onBlur: () => setHovered(null),
|
||||
})
|
||||
const number = (location: VenueLocation) => venue.locations.indexOf(location) + 1
|
||||
|
||||
return (
|
||||
<figure className="grid gap-6 md:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]">
|
||||
{image && (
|
||||
<div className="relative self-start">
|
||||
<img src={image} alt={venue.map_alt || `Map of ${venue.name}`} className="block w-full" />
|
||||
{marked.map((location) => {
|
||||
const on = active === location.key
|
||||
const dim = active != null && !on
|
||||
return (
|
||||
<Link
|
||||
key={location.key}
|
||||
id={mapAnchor(venue.id, location.key)}
|
||||
to={to(location.key)}
|
||||
aria-label={location.name}
|
||||
{...light(location.key)}
|
||||
className="absolute transition-opacity"
|
||||
style={
|
||||
isBox(location)
|
||||
? {
|
||||
left: `${location.x}%`,
|
||||
top: `${location.y}%`,
|
||||
width: `${location.w}%`,
|
||||
height: `${location.h}%`,
|
||||
border: `2px solid ${accent}`,
|
||||
background: withAlpha(accent, on ? 35 : 12),
|
||||
opacity: dim ? 0.35 : 1,
|
||||
}
|
||||
: {
|
||||
left: `${location.x}%`,
|
||||
top: `${location.y}%`,
|
||||
transform: 'translate(-50%, -50%)',
|
||||
opacity: dim ? 0.35 : 1,
|
||||
zIndex: on ? 1 : undefined,
|
||||
}
|
||||
}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`flex items-center justify-center rounded-full text-xs font-bold shadow ${
|
||||
isBox(location) ? 'absolute top-1 left-1 h-6 w-6' : on ? 'h-9 w-9' : 'h-7 w-7'
|
||||
}`}
|
||||
style={{ background: accent, color: readableOn(fill), outline: on ? '3px solid white' : undefined }}
|
||||
>
|
||||
{number(location)}
|
||||
</span>
|
||||
{on && (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="absolute top-full left-1/2 mt-1 -translate-x-1/2 whitespace-nowrap bg-raised px-2 py-0.5 text-xs font-semibold text-ink shadow"
|
||||
>
|
||||
{location.name}
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<figcaption className={image ? '' : 'md:col-span-2'}>
|
||||
<p className="font-display font-bold text-ink">{venue.name}</p>
|
||||
{venue.address && <p className="text-sm text-muted">{venue.address}</p>}
|
||||
<ol className="mt-3 space-y-1">
|
||||
{venue.locations.map((location) => {
|
||||
const on = active === location.key
|
||||
const row = (
|
||||
<>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-xs font-bold"
|
||||
style={{ background: accent, color: readableOn(fill) }}
|
||||
>
|
||||
{number(location)}
|
||||
</span>
|
||||
<span className="min-w-0">
|
||||
<span className="block font-semibold" style={on ? { color: accentText(accent) } : undefined}>
|
||||
{location.name}
|
||||
</span>
|
||||
{location.detail && <span className="block text-sm text-muted">{location.detail}</span>}
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
const rowClass = 'flex items-start gap-3 px-2 py-1.5 text-body'
|
||||
const rowStyle = on ? { background: withAlpha(accent, 12) } : undefined
|
||||
return (
|
||||
<li key={location.key}>
|
||||
{location.x != null && location.y != null ? (
|
||||
<Link to={to(location.key)} {...light(location.key)} className={rowClass} style={rowStyle}>
|
||||
{row}
|
||||
</Link>
|
||||
) : (
|
||||
<div className={rowClass}>{row}</div>
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ol>
|
||||
</figcaption>
|
||||
</figure>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue