Hardware Switch
Rocker, safety-cover flip and key switches you can almost feel.
Installation
npx shadcn@latest add https://neonkit.heyaadi.com/r/hardware-switch.jsonUsage
import { HardwareSwitch } from "@/components/ui/hardware-switch"
<HardwareSwitch variant="flip" label="Arm" />Examples
Variants
rocker lights its I. flip lifts a hinged guard, then throws the lever; turning off reverses the order. key turns a quarter turn and lights the ring around the lock.
In a form
With a name, each switch submits value ("on" by default) only while it is on, like a checkbox.
Sizes, colors and disabled
The hardware is drawn in em, so size scales every part together.
API reference
className and style go on the outer element. The ref and every other button attribute go on the button, which has role="switch".
| Prop | Type | Default |
|---|---|---|
variant | "rocker"A lit I/O rocker, a toggle under a safety guard, or a key switch. | "rocker" |
checked | booleanControlled state. | None |
defaultChecked | booleanInitial state when uncontrolled. | false |
onCheckedChange | (checked: boolean) => voidCalled with the new state on every flip. | None |
label | ReactNodeEngraved legend under the switch. Names it, and clicking it flips the switch. | None |
name | stringSubmits value under this name while on, through a hidden checkbox. | None |
value | stringValue submitted while on. | "on" |
color | NeonColorPalette name or hex for the lamp, guard tint and ring. | inherited |
size | "sm"Scales the hardware: 12, 16 or 20px to the em. | "md" |
disabled | booleanLocks the switch and keeps its lamp dark. | false |
Accessibility
- Renders a native button with role="switch" and aria-checked, so Space and Enter flip it.
- A visible label names the switch through aria-labelledby; without one, pass aria-label.
- The guard and lever, the key and the rocker all move with transforms only, and stand still under reduced motion.