Switch
A switch whose thumb is a tiny mochi. Flip it and the mochi smears across the track, slams into the far end with a splash and wakes up with a !. Flip it back and it dozes off with a little Zzz. The colour floods out from under it.
Installation
❯ npx shadcn@latest add https://yan.moe/r/switch.jsonUsage
import { Switch } from "@/components/ui/switch"<Switch defaultChecked aria-label="Sparkles" />Accessibility
- Built on Radix Switch: it renders a
<button role="switch">and toggles with Space or Enter. - Wrap it in a
<label>or passaria-label; the mochi face is decorative and hidden from assistive tech. - With
prefers-reduced-motion: reduce, the smear, splash and emote are skipped.
API
| Prop | Type | Default |
|---|---|---|
intensitykawaii: smear, slam, splash and an emote. subtle: a small stretch and sparkles. off: plain. | "kawaii" | "subtle" | "off" | "kawaii" |
fxOverrides for the splash fired when the thumb lands. | BurstOptions | - |
checked / defaultCheckedControlled and uncontrolled state, as in Radix. | boolean | - |
onCheckedChangeCalled when the state changes. | (checked: boolean) => void | - |