DesignSwitch

A toggle switch component with smooth sliding animation. Perfect for boolean on/off settings.

Sizes

Default
32×20px
size="default"
Small
24×16px
size="small"

States

On
Active state
checked={true}
Off
Inactive state
checked={false}
Disabled (On)
Non-interactive
disabled={true}
Disabled (Off)
Non-interactive
disabled={true}

Interactive Demo

Enable notifications
Receive push notifications
Dark mode
Use dark theme

Settings Toggle

Toggle a boolean setting

Props:
{ checked: "boolean" }
OffOn

Disabled State

Non-interactive switch

Props:
{ disabled: "true" }

Form Integration

Use in forms with labels

Props:
{ id: "string" }

Multiple Toggles

Group of switch controls

Props:
{ checked: "boolean" }
Email
SMS

Usage Example

import { useState } from "react";
import { DesignSwitch } from "@/components/ui/design-switch";

// Basic usage
const [checked, setChecked] = useState(false);

<DesignSwitch
  checked={checked}
  onCheckedChange={setChecked}
/>

// Small size
<DesignSwitch
  checked={checked}
  onCheckedChange={setChecked}
  size="small"
/>

// Disabled state
<DesignSwitch
  checked={true}
  onCheckedChange={() => {}}
  disabled
/>

// With label
<label className="flex items-center gap-3 cursor-pointer">
  <DesignSwitch
    checked={enabled}
    onCheckedChange={setEnabled}
  />
  <span>Enable feature</span>
</label>

Design Specifications

Default Size
  • • Track: 32×20px
  • • Thumb: 16×16px
  • • Padding: 2px
Small Size
  • • Track: 24×16px
  • • Thumb: 12×12px
  • • Padding: 2px
Colors
  • • On: #40bf59 (green)
  • • Off: #d4d1d1 (light) / gray-600 (dark)
  • • Thumb: white (light) / gray-700 (dark)
Animation
  • • Type: spring
  • • Stiffness: 500, Damping: 30
  • • Properties: transform, background-color
Accessibility
  • • Role: switch
  • • aria-checked: boolean
  • • Focus ring on keyboard navigation

API Reference

PropTypeDefaultDescription
checkedbooleanrequiredThe controlled state of the switch
onCheckedChange(checked: boolean) => voidrequiredCallback when the state changes
size"default" | "small""default"Size of the switch (default: 32×20px, small: 24×16px)
disabledbooleanfalseWhether the switch is disabled
classNamestring-Additional CSS classes