YuhuanStudioYunUIDocs
Forms & Inputs

Switch

Controlled on/off toggle with sizes and color variants.

A controlled on/off toggle. It's controlled-only: pass checked and onCheckedChange. Supports two sizes (sm, md) and four color variants for the checked state.

Import

import { Switch } from "@yuhuanowo/yunui";

Usage

Switch is controlled — wire it to state:

const [on, setOn] = useState(false);
<Switch checked={on} onCheckedChange={setOn} />

Sizes & variants

Sizes (sm, md) and variants (default, success, warning, danger)

Props

PropTypeDefaultDescription
checked*booleanWhether the switch is on (controlled).
classNamestring
disabledbooleanfalseDisable interaction and dim the control.
idstringElement id (e.g. to pair with a `<label htmlFor>`).
onCheckedChange*(checked: boolean) => voidCalled with the next checked state when toggled.
size"sm" | "md"smSize: `sm` (default) or `md`.
variant"default" | "success" | "warning" | "danger"defaultChecked-state color: `default`, `success`, `warning`, or `danger`.

On this page