control · Canvas 2D
FlameSwitch
An on/off switch with a pilot flame on its knob that catches when you turn it on.
On/off switch with a live pilot flame on its knob
- Canvas 2D
- Reduced motion: static
- 2.98 KB gzip
- Layout shift 0
Install
pnpm dlx shadcn@4.21.1 add @frictionborn/flame-switch
Playground
import { FlameSwitch } from "@/components/ui/flame-switch";
<FlameSwitch label="Pilot flame" />In a full example
The full example loads as you scroll to it.
Accessibility
- A native <button role="switch"> with aria-checked and the required `label` as its accessible name. The flame canvas is aria-hidden; the visible status text under the switch follows the state.
- Keyboard: A native button with role=switch: Space and Enter toggle, focus ring visible
- Touch: Tap toggles; no hover effect
- WCAG criteria it is built for: 1.4.11, 2.1.1, 2.4.7, 4.1.2
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
label | string | none | Required. The switch's accessible name. |
checked | boolean | none | Controlled state. Leave undefined for an uncontrolled switch. |
defaultChecked | boolean | false | Initial state when uncontrolled. |
onCheckedChange | (checked: boolean) => void | none | Called with the new state on every press. |
statusText | { on: string; off: string } | null | "{ on: \"Pilot on\", off: \"Pilot off\" }" | Visible status under the switch; null hides it. |
disabled | boolean | false | Disables the switch. |
palette | "fire" | "ice" | "neon" | "mono" | "custom" | "fire" | Flame colours (DESIGN.md A8). custom reads --fb-heat-0..4 from the page. |
paused | boolean | false | Universal pause prop: the flame stops drawing; the switch still works. |
maxTier | number | 3 | Hard ceiling on the capability tier (0 = switch only). |
nonce | string | none | CSP nonce for the component's <style> element. |
className | string | "" | Extra classes on the root (fb-flame-switch is kept). |
style | React.CSSProperties | none | Inline styles on the root, merged after the palette variables. |
ref | React.Ref<HTMLDivElement> | none | Receives the root <div>. |
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 | 2.98 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 (static): The switch alone: no canvas, no flame, the knob moves without a transition. The state and the status text work as usual.
| Tier | What it does |
|---|---|
| T3 Full | Flame on a canvas at DPR ≤ 2 with the full particle count |
| T2 Standard | Flame on a canvas at DPR ≤ 1.5 with half the flame particles |
| T1 Lite | Same as tier 2 |
| T0 Static | The switch only (server render, reduced motion, Save-Data, no WebGL2): no canvas |
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'.