Inputs & Switches
Toggle Latch
Hazard-striped red safety cover lifts, chrome lever throws to armed, commit flash races across the cover as it slams shut. Click to trigger.
canvasmedium complexitymoderate motionclickmobile-ready
Open on the canvas to copy the code → Free account · 3 copies a day · membership goes unlimited
1
When to use it
Dark-themed dashboards, dramatic on/off controls, game UIs needing tactile mechanical weight for a toggle action.
When not to
Light backgrounds (panel hardcoded dark green-black). High-frequency toggling — multi-phase animation takes ~154 frames per cycle.
Working with an AI agent
Every component ships agent-ready metadata. An example instruction for this one:
Change accent color from green to red alert by setting AC='#ff4444', update ARMED/SAFE legend colors to match, and slow the cover lift by changing DUR.lift to 70. Theme: dark tokens live in :root, the light variant in :root[data-theme="light"]; ?theme=light or a {type:'forever:theme'} postMessage switches at runtime.
Safe to edit
- accent color (AC='#9fe870')
- phase durations (DUR object: lift/throw/slam/rest)
- cover swing angle (cover*1.05 rad)
- lever travel arc (ang=(lever-0.5)*1.6)
- hazard stripe color (#f4d03f) and opacity (0.16)
- idle demo cadence (LEAD=24 / GAP=14; ARMED↔SAFE flip every ~2.8 s)
- theme tokens (:root dark defaults + [data-theme=light] overrides)
Keep intact
- phase state machine (phase/pt guards prevent re-triggering mid-animation)
- DPR-aware canvas sizing
- visibilitychange pause/resume
- reduced-motion guard with static draw fallback
- idle demo flip (the same trigger() a click runs; real input takes over)
- theme hook (?theme= bootstrap + forever:theme message listener + theme tokens)
- demo-v1 preview lifecycle: initialize demoEnabled from window.__foreverPreview and stop attract work on the window forever:interactive event; retain manual feedback, settling, cleanup and explicit sessions
Known limitations
- Pointer click and Space/Enter toggle the safety latch; manual phases finish without restarting the demo.
- State remains local to each mounted instance; format/theme remount preserves takeover, not component values.
More Inputs & Switches components
- Liquid ToggleSVG liquid toggle with a goo filter, trailing droplets and a native button. First deliberate input stops the idle demo; the chosen on/off state settles fully.
- Glow SliderSVG range slider with a muted plum-to-teal fill, glow and value bubble, driven by a native range input. First input stops demo oscillation; drag and…
- Spring StepperMint stepper with native minus/plus buttons and a number reel that settles with spring feedback. First deliberate input stops automatic steps; the chosen…
- Segmented ControlSlate-to-sage pill slides between four native segment buttons with elastic spring stretch. First input stops automatic cycling; committed selection remains.
- Checkbox MorphThree native amber checkbox buttons animate their check strokes and expose pressed state. First input stops the demo; checked values remain.
- Star RatingFive gold SVG star radio controls commit ratings on click or keyboard input and settle with a scale bounce. First input stops automatic sweeping.