Skip to content

Switch ​

On or off, for a setting that applies at once. For a change that waits for Save, use a Checkbox.

tsx
import { Switch } from '@adecore/ui';
tsx
import { Switch } from '@adecore/ui';
import { useState } from 'react';

export default function SwitchDemo() {
    const [sounds, setSounds] = useState(true);

    return (
        <div className="flex w-72 flex-col gap-3">
            <label className="flex items-center justify-between gap-4 text-sm text-text">
                Play sounds
                <Switch label="Play sounds" checked={sounds} onCheckedChange={setSounds} />
            </label>
            <label className="flex items-center justify-between gap-4 text-sm text-text-muted">
                Sync over cellular
                <Switch label="Sync over cellular" checked={false} onCheckedChange={() => {}} disabled />
            </label>
        </div>
    );
}

label is the accessible name; the visible one usually comes from the row, such as a SettingsRow. Space toggles it.

Props ​

PropTypeDefault
checkedbooleanRequired.
onCheckedChange(checked: boolean) => voidRequired.
labelstringRequired.
disabledboolean
classNamestring
refRef<HTMLButtonElement>

SwitchProps is an exported type.

Licenses and third-party notices are listed in each package.