Add colour tokens, dark mode and drop gradients

- Colour tokens in index.css named by role (ink, body, muted, link,
  brand, action, surface, tint, danger), used everywhere instead of hex
- Dark mode: follows the system, a header toggle (site and admin)
  overrides it and is remembered; set before first paint in index.html
- Data colours go through src/lib/color.ts: withAlpha for tints,
  accentText (lighter on dark) for text in an accent, readableOn for
  text on one, so an admin's pale colour still reads
- Migration 040 drops events.gradient: a card is its photo or plain,
  with its colour as the border; other decorative gradients are solid
- The countdown and a hero event without a photo mix their colour
  toward ink behind white text

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-28 22:42:59 -05:00
parent ee61568911
commit c74ad746f5
70 changed files with 829 additions and 596 deletions

View file

@ -722,7 +722,6 @@ const events = {
{ path: "event_logo", label: "Event logo", widget: "image", resolve: eventLogo, full: true },
{ path: "org_logo", label: "Org logo override", widget: "image", resolve: orgLogo, full: true },
{ path: "color", label: "Colour", widget: "color" },
{ path: "gradient", label: "Gradient", full: true },
{
path: "card_image",
label: "Card background",

View file

@ -83,7 +83,7 @@ export function RequireAuth() {
if (loading) {
return (
<div className="flex min-h-screen items-center justify-center text-[#4a6b72]">
<div className="flex min-h-screen items-center justify-center text-muted">
Checking your session…
</div>
);

39
src/lib/color.ts Normal file
View file

@ -0,0 +1,39 @@
/* ═══════════════════════════════════════════════════════════════
COLOR
Two helpers for colours that arrive as data (a page's accent, an
event's or region's colour), so they work with the theme tokens
in index.css as well as with hex.
withAlpha(color, 20) is that colour at 20% opacity, for tints and
borders. It replaces `${color}33`, which only works on hex.
accentText(color) is that colour as text: itself in light mode,
mixed halfway to white in dark mode (--accent-text-mix), so an
accent picked for a white page still reads on a dark one.
═══════════════════════════════════════════════════════════════ */
export const withAlpha = (color: string, percent: number): string =>
`color-mix(in srgb, ${color} ${percent}%, transparent)`
export const accentText = (color: string): string =>
`color-mix(in srgb, ${color} var(--accent-text-mix), #ffffff)`
/* Text for on top of a colour that arrives as data: white or deep
ink, whichever has more contrast (WCAG), so a pale colour an admin
picks still gets readable text. Anything that isn't #rrggbb (a
CSS variable, say) gets white, which suits the site's own dark
accents. */
export function readableOn(color: string): string {
const hex = /^#([0-9a-f]{6})$/i.exec(color ?? '')?.[1]
if (!hex) return '#ffffff'
const channel = (i: number) => {
const c = parseInt(hex.slice(i, i + 2), 16) / 255
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4
}
const lum = 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4)
const INK_LUM = 0.0161 // #04262e
const onWhite = 1.05 / (lum + 0.05)
const onInk = (lum + 0.05) / (INK_LUM + 0.05)
return onWhite >= onInk ? '#ffffff' : '#04262e'
}

View file

@ -125,7 +125,6 @@ export type EventRecord = {
org_logo?: string | null
event_logo?: string | null
color?: string | null
gradient?: string | null
/** Behind the card. See 029_event_card_image.sql. */
card_image?: string | null
/* In billing order. The first is the one `color` and `org_logo`