Import
Usage
Props
The Toggle component extends all standard HTML checkbox input attributes (withtype locked to "checkbox") and accepts the following additional props:
Label text or content displayed next to the toggle. The label is automatically linked to the input via the
id prop.When true, displays as a checkbox style with a checkmark that fades in. When false (default), displays as a sliding switch.
When true, uses fully rounded corners (
rounded-full). When false (default), uses the theme’s standard border radius (rounded-lum).Additional CSS classes to apply to the toggle element.
Toggle Modes
Switch Mode (default)
Whencheckbox is not set or is false, the component renders as a sliding switch:
- Width of
3rem(48px) - Sliding indicator that moves from left to right when checked
- The indicator translates 100% of its width when checked
Checkbox Mode
Whencheckbox={true}, the component renders as a checkbox:
- Square/circular shape with fixed width of
1.75rem(28px) - Checkmark indicator that fades in with opacity when checked
- More compact than switch mode
Behavior
- The actual checkbox input is visually hidden but remains accessible to screen readers
- All interactions work with keyboard navigation and assistive technologies
- Smooth transitions with
ease-outtiming and motion-safe preferences - Hover states reduce transition duration for responsive feel
- Labels are selectable with
select-noneand automatically hide when empty
Examples
The Toggle component always renders as
type="checkbox" internally. The visual appearance changes with the checkbox prop, but the underlying input type remains consistent for form compatibility.