Toggle.
An immediate change, clearly expressed.
Live preview
import { Toggle } from "luminescent";
import "luminescent/style.css";
export function Example() {
return (
<Toggle label="Enable notifications" defaultChecked name="notifications" />
);
}
Installation
npm install luminescent
Import luminescent/style.css once at your application root. The example above uses the same package implementation as Storybook.
Variants and states
Use the preview controls to explore the supported variants, sizes, disabled/loading states and reduced motion. Controls appear only where the component exposes the corresponding prop. Theme and glow apply to every component.
Controlled and uncontrolled state
State contract: checked / defaultChecked / onChange (boolean). Omit the controlled prop to let the component own its initial state; supply a value and callback when your application owns it. Native uncontrolled fields and state-backed form controls participate in form reset. Controlled state must be reset by the application.
import { useState } from "react";
import { Toggle } from "luminescent";
export function ControlledExample() {
const [value, setValue] = useState(false);
return <Toggle label="Notifications" checked={value} onChange={setValue} />;
}
API reference
Generated from the source TypeScript interfaces. Native attributes, className, style, aria-* and data-* also pass through to the documented element. Import ToggleProps from the package for the full inherited contract.
| Prop | Type | Details |
|---|---|---|
checked | boolean | Optional unless marked required. |
defaultChecked | boolean | Optional unless marked required. |
onChange | (checked: boolean) => void | Optional unless marked required. |
size | 'sm' | 'md' | 'lg' | Optional unless marked required. |
readOnly | boolean | Optional unless marked required. |
required | boolean | Optional unless marked required. |
requiredMessage | string | Optional unless marked required. |
glowColor | GlowColor | Optional unless marked required. |
label | React.ReactNode | Optional unless marked required. |
Accessibility and keyboard
Button with switch semantics; Space/Enter and associated labels activate. Optional native checkbox participates in form submission/reset and required validation. readOnly preserves focus while preventing changes. onClick is composed and can preventDefault.
Keep labels meaningful and test application-level contrast, focus order and screen-reader output. See the accessibility guide for composition requirements.
Theme customization
import { LuminescentProvider, Toggle } from "luminescent";
import "luminescent/style.css";
export function Example() {
return (
<LuminescentProvider theme="light" accent="violet" glow="subtle">
<Toggle
label="Enable notifications"
defaultChecked
name="notifications"
/>
</LuminescentProvider>
);
}
Switch between light and dark in the preview, or open the playground for a larger workspace. Custom CSS variables can override spacing, color, typography and effects.