Vervangt rood/paars door tokens per variant en modus, voegt ModeToggle en icoon-knop VariantToggle toe, VariantRenderer met lazy E-chunk, dither-overgang (uit bij minder beweging), theme-init.js tegen themaflits en tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
4.4 KiB
4.4 KiB
Code Summary — theme-foundation (U1)
What was built
- Theme model: variant (
b|e) × mode (light|dark). The old red/purple themes are gone. The variant is alwaysbat startup and never stored or in the URL; the mode follows the system preference until the first click, after which it is persisted underslp-software-mode. The legacy keyslp-software-themeis removed once (BR-U1-1..4, 10, 11). - No theme flash:
public/theme-init.jsis a blocking same-origin script (no inline script) that setsdata-variantanddata-modeon<html>before first paint;ThemeProviderkeeps them in sync (BR-U1-5). - Tokens:
src/index.cssdefines the semantic CSS variables for B light, B dark (accent#7A1414light /#E5524Adark for text contrast), and base tokens for E light/dark (accent#AC0000light, a lighter red in dark; refined per era in U5). Tailwind color names are unchanged. - Buttons:
ModeToggle(aria-pressed, label "Donkere weergave") and icon-onlyVariantToggle(label changes: "Tijdreis: bekijk de site zoals vroeger" / "Terug naar nu"), both real buttons with 44px touch targets on mobile, in the nav of B and in the E placeholder (BR-U1-12). - Variant switching:
ThemeProvider.toggleVariantruns the time-travel transition (cover → swap → reveal, 300 ms phases, zero under reduced motion): E is preloaded vialoadVariant(lazy chunkLandingE), the page scrolls to the top, focus moves to#main, and a live region announces the result. A load failure keeps B and showsVariantAlertwith retry; a crash in E is caught byEBoundary(BR-U1-6..9). - Transition effect:
TransitionOverlay+.tt-overlayCSS (pixel-dither checker,steps()animation); not rendered underprefers-reduced-motion. - Layout:
RootLayoutrendersVariantRenderer(B shell = Nav +<main id="main" tabIndex=-1>+ Footer),TransitionOverlay,LiveRegion,VariantAlert. - Font:
@fontsource-variable/archivo(weight + width axes) added and imported; TailwindfontFamily.archivo. The old families stay until U2. - E placeholder:
src/variants/e/LandingE.tsx(own nav with the two toggles, "in aanbouw" content). Real content is U5.
Files
- Modified:
index.html,package.json,pnpm-lock.yaml,tailwind.config.ts,src/fonts.ts,src/index.css,src/theme/tokens.ts,src/theme/ThemeProvider.tsx,src/components/layout/Nav.tsx,src/components/layout/RootLayout.tsx,src/routes/__root.tsx,src/test/setup.ts, testsThemeProvider.test.tsx,Nav.test.tsx. - Created:
public/theme-init.js,src/theme/loadVariant.ts,src/shared/hooks/{mediaQuery,usePrefersDark,usePrefersReducedMotion}.ts,src/components/ui/{ModeToggle,VariantToggle}.tsx,src/components/layout/{VariantRenderer,TransitionOverlay,LiveRegion,VariantAlert,EBoundary}.tsx,src/variants/e/LandingE.tsx,src/test/matchMedia.ts, teststokens.test.ts,mediaQueryHooks.test.tsx,Toggles.test.tsx,VariantRenderer.test.tsx. - Deleted:
src/components/ui/ThemeToggle.tsx.
Verification (Step 13.5, real output)
- Baseline before changes: 6 test files / 24 tests passed, lint 0 errors (2 existing warnings), build OK.
- After: 10 test files / 56 tests passed,
pnpm lint0 errors (same 2 warnings:react-refresh/only-export-componentsinSentryTestButton.tsxandThemeProvider.tsx, the latter existed before as well),pnpm buildOK (tsc -b + vite). E is a separate chunk (LandingE-*.js, 0.9 kB); main bundle 444.8 kB (baseline 438.3 kB, +Archivo CSS). pnpm-lock.yamlalso contains peer-suffix (supports-color) churn produced by the local pnpm 12; the only real addition is@fontsource-variable/archivo@5.3.0.
Notes for the next units
- Use
useTheme()forvariant/mode; use semantic Tailwind colors (bg-bg,text-text,border-line,text-accent...) so both modes and variants work. U2 restyles the sections to design B and then removes the old font families. - Interim look: until U2 the existing sections use the new B tokens (light by default for many visitors).
- Operations notes:
/theme-init.jsmust be served same-origin (CSPscript-src 'self') and must not be cached for long; the E chunk file name changes per build. - jsdom helpers:
src/test/matchMedia.ts(mockMatchMedia,clearMatchMedia) and a globalwindow.scrollTomock insrc/test/setup.ts. - Not done on purpose: mobile menu keeps the two toggles in the top bar (they are always visible); icons are inline SVG.