Switch

A toggle switch component with convenience and compound APIs

A toggle switch component built with Ark UI that supports both a convenience API and a full compound API.

import { Switch } from "@/components/ui/switch";

export default function Example() {
  return <Switch label="Enable notifications" />;
}

Installation

bash
liminal add switch

Usage

import { Switch } from "@/components/ui/switch";

export default function Example() {
  return <Switch label="Enable notifications" />;
}

Examples

Compound API

import {
  SwitchRoot,
  SwitchControl,
  SwitchThumb,
  SwitchLabel,
  SwitchHiddenInput,
} from "@/components/ui/switch";

export default function Example() {
  return (
    <SwitchRoot className="inline-flex items-center gap-2">
      <SwitchHiddenInput />
      <SwitchControl>
        <SwitchThumb />
      </SwitchControl>
      <SwitchLabel>Dark mode</SwitchLabel>
    </SwitchRoot>
  );
}

API

PropTypeDefaultDescription
labelReact.ReactNode-Label text shown next to the switch.
checkedboolean-Controlled checked state.
defaultCheckedboolean-Initial checked state when uncontrolled.
onCheckedChange(details: { checked: boolean }) => void-Callback when checked state changes.