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:
parent
ee61568911
commit
c74ad746f5
70 changed files with 829 additions and 596 deletions
79
src/components/ThemeToggle.tsx
Normal file
79
src/components/ThemeToggle.tsx
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
THEME TOGGLE
|
||||
|
||||
Light or dark. The theme lives on <html data-theme>, which
|
||||
index.html sets before the first paint (from this browser's
|
||||
choice, else the system setting) so a dark visitor never sees a
|
||||
white flash. Pressing this makes an explicit choice and remembers
|
||||
it; until then the site follows the system, including a change
|
||||
made while the page is open. Colours come from the tokens in
|
||||
index.css.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
type Theme = 'light' | 'dark'
|
||||
|
||||
export const THEME_STORAGE_KEY = 'ngu-theme'
|
||||
|
||||
const current = (): Theme =>
|
||||
document.documentElement.dataset.theme === 'dark' ? 'dark' : 'light'
|
||||
|
||||
function chosen(): Theme | null {
|
||||
try {
|
||||
const value = localStorage.getItem(THEME_STORAGE_KEY)
|
||||
return value === 'dark' || value === 'light' ? value : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export default function ThemeToggle({ className = '' }: { className?: string }) {
|
||||
const [theme, setTheme] = useState<Theme>(current)
|
||||
|
||||
// No choice made: follow the system as it changes.
|
||||
useEffect(() => {
|
||||
const media = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
const follow = () => {
|
||||
if (chosen()) return
|
||||
const next: Theme = media.matches ? 'dark' : 'light'
|
||||
document.documentElement.dataset.theme = next
|
||||
setTheme(next)
|
||||
}
|
||||
media.addEventListener('change', follow)
|
||||
return () => media.removeEventListener('change', follow)
|
||||
}, [])
|
||||
|
||||
const toggle = () => {
|
||||
const next: Theme = theme === 'dark' ? 'light' : 'dark'
|
||||
document.documentElement.dataset.theme = next
|
||||
setTheme(next)
|
||||
try {
|
||||
localStorage.setItem(THEME_STORAGE_KEY, next)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const dark = theme === 'dark'
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggle}
|
||||
aria-label={dark ? 'Switch to light mode' : 'Switch to dark mode'}
|
||||
title={dark ? 'Light mode' : 'Dark mode'}
|
||||
className={`flex h-9 w-9 items-center justify-center rounded-full transition-colors ${className}`}
|
||||
>
|
||||
{dark ? (
|
||||
// Sun
|
||||
<svg viewBox="0 0 24 24" className="h-5 w-5" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" strokeLinecap="round" />
|
||||
</svg>
|
||||
) : (
|
||||
// Moon
|
||||
<svg viewBox="0 0 24 24" className="h-5 w-5" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
|
||||
<path d="M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z" strokeLinejoin="round" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue