NGU-Web/src/components/FeaturedCards.tsx
Zaldimmar a397f3eac0 Overhaul fixes: raised cards, balanced people rows, solid map, small button radius
- Cards sit on a raised surface (white, or a touch of tint in dark
  mode) with a shadow: featured cards, the connect block, people
  tiles. tint-soft is a faint teal again, not green.
- Buttons: a small plain radius everywhere; no superellipse.
- Video stills use YouTube's 16:9 frame (the 4:3 one cropped as a
  fallback), have small rounded corners, and show a round, centered
  play button on hover or focus (always on touch screens).
- People tiles: rows balanced between 2 and 10 across, never ending
  on a lone tile where it can be helped.
- Map tiles and region tags are solid, dimmed by color, not opacity.
- Admin: white (surface) background, header and footer as wide as
  the content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 16:24:36 -05:00

149 lines
5.2 KiB
TypeScript

/* ═══════════════════════════════════════════════════════════════
FEATURED CARDS
A grid of cards that point somewhere: the front page's featured
band now, the Community blog's posts next. The data comes from
loadFeaturedCards in server/src/shape.js, already resolved, so
this only draws.
Three kinds of card:
record links to the record's own page (hrefs.ts builds it)
link links to its URL, a new tab when it leaves the site
video VideoPlayer: a still with a play button that swaps in
the player when pressed. The still is the card's
image, else YouTube's thumbnail, else a plain panel.
A photo fills the picture area; a logo sits inside it on a soft
panel instead, since cropping a logo to 16:9 cuts it off.
The grid is one continuous block: no gaps and no frame, only a
colored rule between cards (each card's right and bottom border,
with the grid pulled past its clipping wrapper so the outer ones
fall outside), 4px thick. With three or more cards the first is the large
one, two rows tall, and the next two stack beside it, so it no
longer stretches its neighbor.
═══════════════════════════════════════════════════════════════ */
import HomeLink from '../pages/sections/home/HomeLink.tsx'
import VideoPlayer from './VideoPlayer.tsx'
import { refHref } from '../lib/hrefs.ts'
import { mediaUrl } from '../lib/media.ts'
import type { FeaturedCard } from '../lib/useFrontPage.ts'
import { useSmallImage } from '../lib/useSmallImage.ts'
/* Image kinds that are photographs, drawn edge to edge. Anything
else is a logo, drawn whole. */
const PHOTO_KINDS = new Set(['event-background', 'featured', 'person'])
function hrefFor(card: FeaturedCard): string | null {
if (card.kind === 'record' && card.ref) {
return refHref(card.ref.kind, card.ref.id, card.ref.org_kind)
}
return card.kind === 'link' ? card.url : null
}
function Picture({ card }: { card: FeaturedCard }) {
const img = useSmallImage(card.image ? mediaUrl(card.image.file) : null)
const photo = card.image ? PHOTO_KINDS.has(card.image.kind) : false
if (img.failed) {
return <div className="aspect-video w-full bg-tint" />
}
return photo ? (
<img
src={img.src}
alt=""
loading="lazy"
onError={img.onError}
className="aspect-video w-full object-cover"
/>
) : (
<div className="flex aspect-video w-full items-center justify-center bg-tint p-8">
<img
src={img.src}
alt=""
loading="lazy"
onError={img.onError}
className="logo-plate max-h-full max-w-full object-contain"
/>
</div>
)
}
function VideoPicture({ card }: { card: FeaturedCard }) {
const own = card.image ? mediaUrl(card.image.file) : null
return <VideoPlayer url={card.url} still={own} title={card.title} />
}
const RULE = 'border-brand'
function Card({ card, large }: { card: FeaturedCard; large: boolean }) {
const href = hrefFor(card)
const text = (
<div className={`flex flex-1 flex-col ${large ? 'p-8 md:p-10' : 'p-7'}`}>
{card.eyebrow && (
<p className="text-sm font-semibold text-link">{card.eyebrow}</p>
)}
{card.title && (
<h3 className={`mt-2 font-display font-bold leading-snug text-ink ${large ? 'text-2xl md:text-3xl' : 'text-lg'}`}>
{href ? (
// Stretched over the whole card, so the picture and the
// blurb are part of the click without nesting links.
<HomeLink
url={href}
className="after:absolute after:inset-0 after:content-[''] hover:underline"
>
{card.title}
</HomeLink>
) : (
card.title
)}
</h3>
)}
{card.blurb && (
<p className={`mt-2 leading-relaxed text-muted ${large ? '' : 'line-clamp-3 text-sm'}`}>{card.blurb}</p>
)}
</div>
)
return (
<li
className={`relative flex flex-col overflow-hidden border-r-4 border-b-4 ${RULE} bg-raised transition-colors hover:bg-tint-soft ${
large ? 'lg:col-span-2 lg:row-span-2' : ''
}`}
>
{card.kind === 'video' ? (
// Above the stretched link, which a video card doesn't have
// anyway, so the play button always gets the click. Inset
// from the card's edges, so the frame sits inside the cell.
<div className="relative z-10 p-4 pb-0">
<VideoPicture card={card} />
</div>
) : (
<Picture card={card} />
)}
{text}
</li>
)
}
export default function FeaturedCards({ cards }: { cards: FeaturedCard[] }) {
const leadLarge = cards.length >= 3
return (
<div className="overflow-hidden shadow-md">
<ul className="-mr-[4px] -mb-[4px] grid sm:grid-cols-2 lg:grid-cols-3">
{cards.map((card, index) => (
<Card
key={`${card.kind}-${card.ref?.id ?? card.url}-${index}`}
card={card}
large={leadLarge && index === 0}
/>
))}
</ul>
</div>
)
}