Switch
Form-associated switch whose track fills with a dithered energy field when on; the thumb springs across with a few sparks.
Playground
Change a prop and the component updates. Props marked live animate to the new value; the others rebuild the element.
<HfSwitch checked value="on" name="ultra" />
Installation
pnpm dlx shadcn@latest add @lumesec/hf-switchFirst 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/hf-switch.jsonUsage
import { HfSwitch } from "@/components/lumesec/hf-switch";
export function Example() {
return (
<>
<HfSwitch name="ultra" checked>
Ultracode
<span slot="hint">Plan multi-agent workflows</span>
</HfSwitch>
<HfSwitch name="search" style={{ marginTop: 16 }}>
Web search
<span slot="hint">Look things up while answering</span>
</HfSwitch>
</>
);
}Behaviour
The track charges up with a dithered energy field when it turns on and the thumb springs across with a few sparks. Form-associated, like every control here.
API reference
Attributes
checkedReact propcheckedTypebooleanDefaultfalsePresence attribute. Observed: adding or removing it updates the switch, aria-checked and the form value.
valueReact propvalueTypestringDefaultonValue submitted with the form while checked.
nameReact propnameTypestringForm field name.
Events
Events bubble and cross the shadow boundary unless the description says otherwise.
changeReact proponChangeDetail{ checked: boolean }Fires when the user toggles the switch. Not fired when checked is set from code.
Properties
checkedTypebooleanReflects the checked attribute.
Slots
(default)Label text. Falls back to Ultracode.
hintSecondary text under the label.
Accessibility
- The control is a native
<button>withrole="switch"andaria-checked, so Enter and Space toggle it. aria-labelis the text in the default slot (Ultracodewhen the slot is empty) and follows changes to that content. Thehintslot is linked witharia-describedby.- Clicking anywhere on the row, including the label text, toggles the switch.
- Submits
name=value(defaulton) while checked and nothing while unchecked. No validation; form reset does not change the state. - Reduced motion: the thumb moves without the spring, the fill appears without its sweep or flowing pattern, and no sparks are drawn.
Theming
The element reads your shadcn theme tokens through its shadow root, so light and dark follow your theme. The accent comes from --lumesec. See Theming.
This component reads --foreground, --lumesec, --muted and --muted-foreground.
To restyle only LumeSec elements, set the matching --ui-* overrides: --ui-accent, --ui-fg, --ui-muted and --ui-track.
Related
Was this page helpful?