Switch · toggle
A toggle with a springy, stretching thumb — labels and descriptions, three sizes, tones, icons and track text, async saves with rollback, and form support.
Settings · labels, descriptions, tones, async
Alerts for mentions, replies and new followers.
A ✓ / ✕ in the thumb.
Saved to a (simulated) server — a spinner until it answers; every third save fails and the switch goes back.
A danger tone for the switches that deserve a second look.
Disabled — on, and cannot be changed here.
Sizes · text in the track · label after
In a form · name
Usage
import { signal } from "./index.js";import { Switch } from "./components/switch.js"; const notifications = signal(true); // a label (the whole text is clickable) and a description under itSwitch({ value: notifications, label: "Notifications", description: "Alerts for mentions and replies" }) // async: return a promise — a spinner in the thumb until it settles;// a rejection (or resolving false) switches it backSwitch({ value: autoUpdate, label: "Auto-update", onChange: (on) => api.save({ autoUpdate: on }) }) // looks: size "sm" · "md" · "lg", tone "success" · "danger" · "warning",// ✓ / ✕ in the thumb, text in the trackSwitch({ size: "lg", tone: "success", icons: true, defaultValue: true, ariaLabel: "Wi-Fi" })Switch({ onLabel: "On", offLabel: "Off", value: on }) // in a form: name submits onValue / offValue ("on" / "" by default)Switch({ name: "beta", onValue: "yes", offValue: "no", label: "Beta features", labelPosition: "end" })