Files
SluijsensandClaude Sonnet 5.5 0854e3a096 Thema-fundament: variant (B/E) x modus (licht/donker), tijdreis-knop en overgang
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>
2026-11-09 21:14:11 +01:00

4.4 KiB
Raw Permalink Blame History

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 always b at startup and never stored or in the URL; the mode follows the system preference until the first click, after which it is persisted under slp-software-mode. The legacy key slp-software-theme is removed once (BR-U1-1..4, 10, 11).
  • No theme flash: public/theme-init.js is a blocking same-origin script (no inline script) that sets data-variant and data-mode on <html> before first paint; ThemeProvider keeps them in sync (BR-U1-5).
  • Tokens: src/index.css defines the semantic CSS variables for B light, B dark (accent #7A1414 light / #E5524A dark for text contrast), and base tokens for E light/dark (accent #AC0000 light, a lighter red in dark; refined per era in U5). Tailwind color names are unchanged.
  • Buttons: ModeToggle (aria-pressed, label "Donkere weergave") and icon-only VariantToggle (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.toggleVariant runs the time-travel transition (cover → swap → reveal, 300 ms phases, zero under reduced motion): E is preloaded via loadVariant (lazy chunk LandingE), the page scrolls to the top, focus moves to #main, and a live region announces the result. A load failure keeps B and shows VariantAlert with retry; a crash in E is caught by EBoundary (BR-U1-6..9).
  • Transition effect: TransitionOverlay + .tt-overlay CSS (pixel-dither checker, steps() animation); not rendered under prefers-reduced-motion.
  • Layout: RootLayout renders VariantRenderer (B shell = Nav + <main id="main" tabIndex=-1> + Footer), TransitionOverlay, LiveRegion, VariantAlert.
  • Font: @fontsource-variable/archivo (weight + width axes) added and imported; Tailwind fontFamily.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, tests ThemeProvider.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, tests tokens.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 lint 0 errors (same 2 warnings: react-refresh/only-export-components in SentryTestButton.tsx and ThemeProvider.tsx, the latter existed before as well), pnpm build OK (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.yaml also 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() for variant/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.js must be served same-origin (CSP script-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 global window.scrollTo mock in src/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.