Switch Component

A toggle switch component that allows users to turn an option on or off.

  • Accessible toggle switch implementation
  • Support for labels and descriptions
  • Customizable styling
  • Disabled state support

Installation

The Switch component is part of our UI library. You can import it directly from the components directory.


Usage

Here is how to use the switch in your project.

React TSX
1import { Switch } from "@/components/modern-ui/switch"

React TSX
1<Switch />

Examples

Basic Switch

Labeled Switch

Disabled Switch

API Reference

Switch

PropTypeDefaultDescription
checkedboolean-The checked state of the switch
defaultCheckedboolean-The default checked state
onCheckedChange(checked: boolean) => void-Event handler called when the checked state changes
disabledbooleanfalseWhether the switch is disabled
requiredbooleanfalseWhether the switch is required
namestring-The name of the switch
valuestring-The value of the switch
classNamestring-Additional CSS classes