Switch

This is a Switch component.

Notifications

Installation

1. Dependencies

npm install clsx tailwind-merge

2. Paste inside @/lib/utils.ts

import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: Parameters<typeof clsx>) {
  return twMerge(clsx(...inputs));
}

3. Copy Switch Code

Loading...

Copy Switch Code

Switch Props

NameTypeRequiredDefaultDescription
idstringYesundefinedThe unique identifier for the switch.
namestringYesundefinedThe name of the switch.
checkedbooleanYesfalseWhether the switch is checked or not.
onChange(event) => voidYesundefinedCallback function triggered when the switch state changes.
variant"circle" | "square"No"circle"The shape of the switch (circle or square).
activeIconReact.ReactNodeNoundefinedIcon to display when the switch is active.
inactiveIconReact.ReactNodeNoundefinedIcon to display when the switch is inactive.
activeColorstringNo"bg-green-500"Background color when the switch is active.
inactiveColorstringNo"bg-gray-300"Background color when the switch is inactive.
classNamestringNo""Additional class names for custom styling.