# Frontend Components — theme-foundation (U1) ## Component hierarchy ```mermaid graph TD root[__root route] --> eb[ErrorBoundary] eb --> tp[ThemeProvider] tp --> qc[QueryClientProvider] qc --> rl[RootLayout] rl --> ua[UmamiAnalytics] rl --> vr[VariantRenderer] rl --> to[TransitionOverlay] rl --> lr[LiveRegion] vr --> lb[LandingB eager] vr --> ee[EBoundary] ee --> le[LandingE lazy] lb --> mt[ModeToggle] lb --> vt[VariantToggle] le --> mt2[ModeToggle] le --> vt2[VariantToggle] tp -.provides.-> hooks[useTheme] hooks --> mt hooks --> vt classDef layout fill:#4CAF50,stroke:#2e7d32,color:#000; classDef guard fill:#FF9800,stroke:#e65100,color:#000; classDef ui fill:#2196F3,stroke:#0d47a1,color:#000; classDef hook fill:#9C27B0,stroke:#4a148c,color:#000; class root,rl,tp,qc layout; class eb,ee guard; class vr,lb,le,mt,vt,mt2,vt2,to,lr,ua ui; class hooks hook; ``` Text alternative: the root route wraps the app in an error boundary, theme provider and query provider; the layout renders the variant renderer (eager B, lazy E behind its own boundary), the transition overlay and a live region; both landings contain the two toggle buttons that use the theme hook. ## Components | Component | Props | State / behaviour | |---|---|---| | `ThemeProvider` | `children` | holds `ThemeState` and `TransitionState`; exposes `{ variant, mode, toggleMode, toggleVariant, transition, announce }` via `useTheme()`; implements BR-U1-1..11 | | `ModeToggle` | none | button, `aria-pressed = (mode==='dark')`, label "Donkere weergave", icon sun/moon; calls `toggleMode` | | `VariantToggle` | none | icon-only button (clock/rewind), label "Tijdreis: bekijk de site zoals vroeger" in B and "Terug naar nu" in E, tooltip equal to the label; calls `toggleVariant` | | `VariantRenderer` | none | renders `LandingB` or `React.lazy(LandingE)` inside `Suspense`; fallback is the cover overlay | | `EBoundary` | `children` | error boundary for the lazy chunk; on error resets variant to `'b'` and shows the alert with a retry button (BR-U1-8) | | `TransitionOverlay` | none | reads `transition.phase`; renders the dither overlay only for `cover` and `reveal`; `aria-hidden`, blocks pointer events; nothing under reduced motion | | `LiveRegion` | none | polite `aria-live` region for the announcements in BR-U1-7 | | `usePrefersReducedMotion` / `usePrefersDark` | none | subscribe to the media queries (SSR-safe defaults) | ## User interaction flows - Mode button: click → mode flips immediately, persisted, `aria-pressed` updates. - Variant button: click → transition (or immediate under reduced motion) → new variant at top of page, focus on `main`, announcement. - Keyboard: both buttons reachable in the nav in DOM order (mode, variant), Enter/Space activate; Escape does not interfere with the mobile menu. ## Form validation rules None in this unit. ## API integration points None (client-only). The existing Sentry and Umami integration is untouched. ## Acceptance tests (Vitest + Testing Library) 1. `resolveInitialMode`: stored valid wins; invalid/absent falls back to system; table-driven. 2. First render: `data-variant="b"`, `data-mode` from system; legacy key removed. 3. System preference change flips the mode while source is system, not after a user click. 4. Mode click persists to `slp-software-mode`; storage that throws does not break the toggle. 5. Variant is `'b'` after a fresh mount even if E was active before (not persisted). 6. `toggleVariant`: scrolls to top and moves focus; announces; under reduced motion no overlay phases occur. 7. Lazy chunk failure: variant stays `'b'`, alert shown, retry works. 8. Accessibility: accessible names, `aria-pressed`, 44×44 px class, focus-visible styles.