Switch

A toggle switch for boolean values, rendered as an accessible button with role="switch".

Installation

npx @obi/ui add switch

Preview

Receive updates about your account.

Usage

'use client';

import { useState } from 'react';
import Switch from '@/src/components/Switch/Switch';

export default function Example() {
  const [enabled, setEnabled] = useState(false);

  return (
    <div className="flex flex-col gap-4">
      <Switch
        checked={enabled}
        onCheckedChange={setEnabled}
        label="Email notifications"
        hint="Receive updates about your account activity."
      />
      <Switch checked={true} onCheckedChange={() => {}} label="Always on" />
      <Switch checked={false} onCheckedChange={() => {}} label="Disabled" disabled />
    </div>
  );
}

Props

NameTypeDefaultDescription
checkedbooleanControlled checked state.
onCheckedChange(checked: boolean) => voidCallback fired when the switch is toggled.
labelstringVisible label rendered beside the switch.
hintstringHelper text rendered below the label.
disabledbooleanfalseDisables the switch.
idstringautoHTML id for the switch button; auto-derived from label if omitted.