Toggle
Switch with a label and hint whose thumb stretches as it travels and pops a few pixel sparks when it turns on.
Playground
Change a prop and the component re-renders. Props marked remounts set an initial value, so the component starts over.
<UiToggle hint="Think longer before answering">Extended thinking</UiToggle>
Installation
pnpm dlx shadcn@latest add @lumesec/ui-toggleFirst timeRegister the @lumesec registry once, or install by URL+
Adds @lumesec to your components.json:
pnpm dlx shadcn@latest registry add @lumesec=https://elements.lumesec.ai/r/{name}.jsonOr skip the setup and install by URL:
npx shadcn@latest add https://elements.lumesec.ai/r/ui-toggle.jsonUsage
import { UiToggle } from "@/components/lumesec/ui-toggle";
export function Example() {
return (
<UiToggle defaultChecked hint="Think longer before answering">
Extended thinking
</UiToggle>
);
}Behaviour
The thumb stretches like a drop as it travels, the accent floods out from under it, and a few pixel sparks pop when it switches on. Clicking the label works too.
API reference
Props
Also accepts every prop of <div> (React.ComponentProps<"div">), spread onto the root element.
checkedTypebooleanControlled state. Use with onCheckedChange.
defaultCheckedTypebooleanDefaultfalseInitial state when uncontrolled.
childrenTypeReact.ReactNodeDefault"Extended thinking"Label text. It is also the switch's accessible name.
hintTypeReact.ReactNodeSecondary text under the label, linked to the switch with aria-describedby.
onCheckedChangeType(checked: boolean) => voidCalled when the user toggles the switch. Changing checked from outside does not call it.
Ref
ref points at the root HTMLDivElement.
Keyboard
| Keys | Action |
|---|---|
| Space / Enter | Toggle the focused switch. |
Accessibility
- The switch is a native
<button>withrole="switch"andaria-checked. - The label is the switch's accessible name (
aria-labelledby) and the hint its description (aria-describedby). - Clicking anywhere on the row, including the label and hint, toggles the switch.
- Reduced motion: the thumb moves without the stretch animation and no sparks fire; the accent fill still transitions.
Theming
Styled with Tailwind classes on your shadcn theme tokens, so light and dark follow your theme. The accent comes from --lumesec. See Theming.
This component reads --lumesec, --lumesec-glint, --muted, --foreground and --muted-foreground.
Notes
- Not a form control: it has no
nameand is not submitted with a form. - The root, the switch and its parts carry
data-state="checked"ordata-state="unchecked"for styling. - Changing
checkedfrom outside moves the thumb without the stretch and sparks; they play only for user toggles.
Related
Was this page helpful?