control · Canvas 2D
EclipseSwitch
A light and dark switch where the moon slides across the sun until only the corona is left.
Light/dark theme switch: the moon slides across the sun until only the corona remains
- Canvas 2D
- Reduced motion: still-frame
- 3.18 KB gzip
- Layout shift 0
Install
pnpm dlx shadcn@4.21.1 add @frictionborn/eclipse-switch
Playground
import { EclipseSwitch } from "@/components/ui/eclipse-switch";
<EclipseSwitch />In a full example
The full example loads as you scroll to it.
Accessibility
- A native <button role="switch"> with aria-checked; its visible label is its name. The status (Day / Totality) is aria-live=polite. Before the canvas mounts a CSS sun shows the state. The sky canvas is aria-hidden.
- Keyboard: A native <button role=switch>: Space and Enter toggle
- Touch: Tap the switch
- WCAG criteria it is built for: 1.4.3, 2.1.1, 4.1.2, 4.1.3
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
checked | boolean | none | Controlled state: true is the eclipse (dark). |
defaultChecked | boolean | false | Initial state when uncontrolled. |
onCheckedChange | (checked: boolean) => void | none | Called with the new state. |
label | string | "Eclipse mode" | Visible label and accessible name of the switch. |
statusText | { on: string; off: string } | null | "{ on: \"Totality\", off: \"Day\" }" | Visible, announced status; null hides it. |
palette | "fire" | "ice" | "neon" | "mono" | "custom" | "fire" | Colours of the effect (DESIGN.md A8). custom reads --fb-heat-0..4 from the page. |
paused | boolean | false | Universal pause prop: the effect stops drawing; the control keeps working. |
maxTier | number | 3 | Hard ceiling on the capability tier. |
nonce | string | none | CSP nonce for the component's <style> element. |
className | string | "" | Extra classes on the root. |
style | React.CSSProperties | none | Inline styles on the root, merged after the palette variables. |
ref | React.Ref<HTMLDivElement> | none | Receives the root element. |
Measured on the bench
Measured by the automated bench at commit 801163e on 2026-10-21. These numbers are written by the bench, never by hand.
| Measure | Result |
|---|---|
| Size, gzip | 3.18 KB at load, 0.02 KB loaded later |
| Layout shift | 0 |
| Frames when nothing should move | off screen 0, hidden tab 0, reduced motion 0 |
| axe accessibility scan | 0 serious, 0 critical |
Browsers it ran in
Automated Playwright runs, some with device emulation. Results from physical phones and tablets are still pending, so none are listed.
| Environment | Tier | Result | Date | Notes |
|---|---|---|---|---|
| Chromium Desktop (SwiftShader) | 3 | pass | 2026-10-21 | 16 passed, 0 failed |
| Chromium Mobile (Pixel 7 emulation) | 2 | pass | 2026-10-21 | 15 passed, 0 failed |
| Firefox Desktop | 3 | pass | 2026-10-21 | 14 passed, 0 failed |
| WebKit Desktop | 3 | pass | 2026-10-21 | 15 passed, 0 failed |
| WebKit Mobile (iPhone 14 emulation) | 2 | pass | 2026-10-21 | 15 passed, 0 failed |
On different devices
Reduced motion (still-frame): The sky jumps straight to day or totality: one frame per change, no sliding moon.
| Tier | What it does |
|---|---|
| T3 Full | Animated at DPR <= 2 with the full particle count |
| T2 Standard | Animated at DPR <= 1.5 with half the particles |
| T1 Lite | Same as tier 2 |
| T0 Static | One still frame on the canvas (reduced motion, Save-Data, no WebGL2), redrawn only when the value changes |
Content Security Policy
- Works without
'unsafe-eval'. - Uses the reveal gate (
[data-motion="ok"]): render<MotionReadyScript />in<head>(with yournonce), or callinitMotionReady()in Vite. - Sets inline
styleattributes, so allowstyle-src-attr 'unsafe-inline'.