@hoag/ui — UI components built with shadcn, Radix UI & Tailwind CSS
Components
Switch

Switch

A two-state toggle used to turn an option on or off. Supports multiple visual variants and sizes.

Installation

npx shadcn@latest add switch

Usage

import { Switch } from "@hoag/ui/components/switch";
 
export default function Demo() {
  return <Switch />;
}

Default

<Switch id="default-switch" defaultChecked />
<Label htmlFor="default-switch">Enable notifications</Label>

Variants

Base variants

<Switch defaultChecked variant="default" />
<Switch defaultChecked variant="destructive" />

Heavy status

<Switch defaultChecked variant="heavy-success" />
<Switch defaultChecked variant="heavy-warning" />
<Switch defaultChecked variant="heavy-info" />
<Switch defaultChecked variant="heavy-error" />

Light status

<Switch defaultChecked variant="light-success" />
<Switch defaultChecked variant="light-warning" />
<Switch defaultChecked variant="light-info" />
<Switch defaultChecked variant="light-error" />

Outline status

<Switch defaultChecked variant="outline-success" />
<Switch defaultChecked variant="outline-warning" />
<Switch defaultChecked variant="outline-info" />
<Switch defaultChecked variant="outline-error" />

Sizes

<Switch defaultChecked size="sm" />
<Switch defaultChecked size="default" />
<Switch defaultChecked size="lg" />

With Label

<div className="flex items-center justify-between">
  <Label htmlFor="switch-notifications">Enable notifications</Label>
  <Switch id="switch-notifications" defaultChecked />
</div>
<div className="flex items-center justify-between">
  <Label htmlFor="switch-marketing">Marketing emails</Label>
  <Switch id="switch-marketing" />
</div>
<div className="flex items-center justify-between">
  <Label htmlFor="switch-dark">Dark mode</Label>
  <Switch id="switch-dark" defaultChecked variant="heavy-info" />
</div>

Disabled

<Switch disabled />
<Switch disabled defaultChecked />

API Reference

Props

PropTypeDefaultDescription
variantstring"default"Visual style of the switch
size"sm" | "default" | "lg""default"Size of the switch
defaultCheckedbooleanfalseInitial state (uncontrolled)
checkedbooleanControlled state
onCheckedChange(checked: boolean) => voidCallback on toggle
disabledbooleanfalseDisable the switch

Variants

VariantDescription
defaultPrimary color when on
destructiveDestructive/danger color when on
heavy-success/warning/info/errorSolid status color fill when on
light-success/warning/info/errorLight tinted background, both on and off states
outline-success/warning/info/errorOutlined ring with status color fill when on