Skip to content
NewService Map: 30 components for hosts, ports and routes
<UiToggle />ReactControlsFree

Toggle

Switch with a label and hint whose thumb stretches as it travels and pops a few pixel sparks when it turns on.

View as Markdown
<UiToggle />

Playground

Change a prop and the component re-renders. Props marked remounts set an initial value, so the component starts over.

Loading <UiToggle />
Props
defaultCheckedremounts
childrenlive
hintlive
React
<UiToggle hint="Think longer before answering">Extended thinking</UiToggle>

Installation

pnpm dlx shadcn@latest add @lumesec/ui-toggle
First 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}.json

Or skip the setup and install by URL:

npx shadcn@latest add https://elements.lumesec.ai/r/ui-toggle.json

Usage

ui-toggle-example.tsx
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.

checkedTypeboolean

Controlled state. Use with onCheckedChange.

defaultCheckedTypebooleanDefaultfalse

Initial state when uncontrolled.

childrenTypeReact.ReactNodeDefault"Extended thinking"

Label text. It is also the switch's accessible name.

hintTypeReact.ReactNode

Secondary text under the label, linked to the switch with aria-describedby.

onCheckedChangeType(checked: boolean) => void

Called when the user toggles the switch. Changing checked from outside does not call it.

Ref

ref points at the root HTMLDivElement.

Keyboard

KeysAction
Space / EnterToggle the focused switch.

Accessibility

  • The switch is a native <button> with role="switch" and aria-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 name and is not submitted with a form.
  • The root, the switch and its parts carry data-state="checked" or data-state="unchecked" for styling.
  • Changing checked from outside moves the thumb without the stretch and sparks; they play only for user toggles.

Was this page helpful?