Docs
Switch Input
Switch Input

A customizable toggle switch with Zod validation, animations, and extended functionality.

Receive notifications about account activity and updates

Notifications are currently: Enabled

Overview

The Switch Input component provides an elegant toggle interface with smooth animations and extensive customization options, essential for boolean settings and preferences. It features multiple variants, custom colors, extended click areas for mobile usability, and comprehensive validation support. Perfect for feature toggles, notification settings, and any scenario requiring clear on/off state management with excellent user experience.

Installation

pnpm dlx shadcn@latest add https://deltacomponents.dev/r/switch-input.json

Usage

"use client"
 
import { SwitchInput } from "@/registry/inputs/switch-input"
 
export function Component() {
  return (
    <SwitchInput
      label="Enable notifications"
      name="notifications"
      description="Receive email updates about your account"
      onCheckedChange={(checked) => console.log("Toggle:", checked)}
    />
  )
}

API Reference

Props

PropTypeDefaultDescription
labelstring-Label text for the switch (required)
namestring-Form field name for submission (required)
descriptionstringundefinedDescription text below the switch
hintstringundefinedHint text below the switch
errorstringundefinedError message to display
requiredbooleanfalseWhether the field is required
pendingbooleanfalseWhether the field is in a loading state
defaultCheckedbooleanfalseDefault checked state (uncontrolled)
checkedbooleanundefinedControlled checked state
disabledbooleanfalseWhether the switch is disabled
idstringnameID for the switch element
variant"pill" | "rectangular""rectangular"Switch shape variant
size"default" | "large""default"Switch size (24px / 30px height)
activeColorstringundefinedCustom CSS color for active state
extendedClickAreabooleanfalseExtends clickable area for better mobile UX
labelVariant"default" | "muted""default"Label text styling variant
containerClassNamestring""CSS classes for the container
switchClassNamestring""CSS classes for the switch
labelClassNamestring""CSS classes for the label
schemaZodType<boolean>undefinedZod schema for validation
onValidate(isValid: boolean, value: boolean, error?: string) => voidundefinedValidation callback
onCheckedChange(checked: boolean) => voidundefinedCallback when state changes

Examples

Pill Variant

Rounded pill-shaped switch with smooth corner transitions.

Pill variant has fully rounded corners

Standalone Switch

Switch without label for compact layouts and custom implementations.

Toggle to see alert functionality

Custom Colors

Switches with custom active colors for brand consistency.

Using custom red color

Using custom green color

Using custom purple color

Size Variants

Different switch sizes for various interface contexts.

Standard switch size (24px height)

Large switch size (30px height)