RealisticSwitch

A latching push switch, a raised box that sinks into its socket when pressed, stays down and glows while on, and springs back up on the next press.

Preview

Props

Variants

Colors

Pass any CSS color.

Sizes

Install

npx shadcn@latest add @evilbuttons/realistic-switch

Usage

import { RealisticSwitch } from "@/components/evil-buttons/realistic-switch";

export function PowerSwitch() {
  return (
    <RealisticSwitch
      sound
      aria-label="Main power"
      onCheckedChange={(on) => console.log("power:", on)}
    />
  );
}
<RealisticSwitch checked={isLive} onCheckedChange={setIsLive} color="#1f6feb" />

Props

PropTypeDefaultDescription
checkedboolean-Controlled on state.
defaultCheckedbooleanfalseInitial state when uncontrolled.
onCheckedChange(checked: boolean) => void-Called when the switch latches or releases.
colorstring"#e1261c"Cap color. Any CSS color.
markColorstringwhiteColor of the power mark on the cap.
tone"auto" | "light" | "dark""auto"Socket finish: follow the theme, or force ceramic white or graphite.
illuminatedbooleantrueLight the cap from inside while it is latched on.
soundbooleanfalsePlay a short mechanical click when it latches or releases.
size"sm" | "default" | "lg""default"Scales the whole switch.
disabledbooleanfalseDisables the switch.
aria-labelstring"Power"Accessible name for the switch.
classNamestring-Extra classes on the button.

Good to know

  • The click is synthesized with Web Audio, no audio files.
  • size scales the whole switch.

Search docs

Jump to a button documentation page