Bedform UIControls
Switch
Turn on or off.
Switch
*
*
boolean
*
boolean
*
string
*
Usage
import { Switch } from "@bedform/ui/switch";
import { useState } from "react";
export function AutosaveSwitch() {
const [checked, setChecked] = useState(false);
return (
<Switch
checked={checked}
name="autosave"
value="enabled"
variant="icons"
onChange={(event) => {
setChecked(event.currentTarget.checked);
}}
>
Enable autosave
</Switch>
);
}Switch renders a native checkbox with role="switch" inside a label, and its children become the label text.
Variants
<Switch>Default</Switch>
<Switch variant="icons">Icons</Switch>Colors
Use color to change the checked state color.
<Switch color="primary" defaultChecked aria-label="Primary" />
<Switch color="secondary" defaultChecked aria-label="Secondary" />
<Switch color="destructive" defaultChecked aria-label="Destructive" />
<Switch color="dungeons" defaultChecked aria-label="Dungeons" />
<Switch color="legends" defaultChecked aria-label="Legends" />
<Switch color="realms" defaultChecked aria-label="Realms" />
<Switch color="gold" defaultChecked aria-label="Gold" />Forms
Checked values are included in FormData, and reset restores the initial defaultChecked state.
Events
The native input dispatches input and change events after its checked state changes, so onChange works as it does on any checkbox.
API
Switch accepts every checkbox attribute, such as checked, defaultChecked, disabled, name, required and value. Its ref points to the input.
| Prop | Type | Default |
|---|---|---|
color | "primary" | "secondary" | "destructive" | "dungeons" | "legends" | "realms" | "gold" | "primary" |
labelClassName | string | — |
variant | "default" | "icons" | "default" |
CSS variables
| Variable | Purpose |
|---|---|
--ore-switch-unit | Base size unit |
--ore-switch-track-background | Inactive track background |
--ore-switch-track-highlight | Inactive track highlight |
--ore-switch-track-border | Track border color |
--ore-switch-thumb-background | Thumb background |
--ore-switch-thumb-highlight | Thumb highlight |
--ore-switch-thumb-shadow | Thumb shadow |
--ore-switch-thumb-border | Thumb border color |
--ore-switch-active-track-background | Active track background |
--ore-switch-active-track-highlight | Active track highlight |
--ore-switch-icon | Thumb icon color |
Accessibility
The native checkbox provides form and keyboard behavior, while role="switch" exposes switch semantics. Use a label to describe the control.