Warren UI

Switch

Two-state toggle with square thumb.

Source
"use client"

import { useState } from "react"
import { Label } from "@/registry/warren/label/label"
import { Switch } from "@/registry/warren/switch/switch"

export default function SwitchDemo() {
  const [autoRoute, setAutoRoute] = useState(true)

  return (
    <div className="flex w-72 flex-col gap-3 border-2 border-border bg-panel p-3">
      <div className="flex items-center justify-between gap-3">
        <Label htmlFor="auto-route">AUTO-ROUTE</Label>
        <Switch id="auto-route" checked={autoRoute} onCheckedChange={setAutoRoute} />
      </div>
      <div className="flex items-center justify-between gap-3">
        <Label htmlFor="log-stream">LOG-STREAM</Label>
        <Switch id="log-stream" checked={false} disabled />
      </div>
    </div>
  )
}

Installation

npx shadcn@latest add https://warren.eduard3v.com/r/switch.json

Usage

import { Switch } from "@/components/ui/switch"
<Switch checked={checked} onCheckedChange={setChecked} aria-label="Auto route" />

Switch is a controlled component: pass the current state in checked and update it in onCheckedChange. Set disabled to block interaction while keeping the state visible.

Accessible name

A bare <Switch /> announces the generic "toggle". Pass aria-label — or aria-labelledby pointing at a nearby label — whenever the toggle's meaning isn't obvious, and it wins over the fallback.

API Reference

Prop

Type

On this page