Skip to content

Switch

On and off toggle with immediate effect.

Installation

bun add @xerobi/ui
import { Switch } from "@xerobi/ui/switch"

This component is client-side. In Astro, hydrate it with a client directive.

Examples

Default

import { Switch } from "@xerobi/ui/switch"

export function SwitchDefault() {
  return (
    <div className="flex items-center gap-2">
      <Switch id="notifications" defaultChecked />
      <label htmlFor="notifications" className="text-body2">Notifications</label>
    </div>
  )
}

Sizes and colors

import { Switch } from "@xerobi/ui/switch"

export function SwitchSizes() {
  return (
    <div className="flex items-center gap-4">
      <Switch size="sm" defaultChecked aria-label="Small" />
      <Switch defaultChecked aria-label="Default" />
      <Switch color="success" defaultChecked aria-label="Success" />
    </div>
  )
}

API reference

Switch

Also accepts every prop of Base UI Switch.

PropTypeDescription
size"default" | "sm"
color"info" | "success" | "warning" | "secondary" | "inherit" | "primary" | "error"

Styling hooks: [data-slot="switch"], [data-slot="switch-thumb"].

Search documentation

Search pages, components and blocks.