darshan-rajadhyaksha

Switch

Component

About

A themeable on/off toggle switch with semantic colors (default, success, warning, info, error), three sizes, controlled/uncontrolled state, and slot customization for the track and handle — ported to React from Darshan Rajadhyaksha's RockSolid SolidJS component library.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Switch to your project and fits it to your theme.

Code

How Switch is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import Switch from "@/components/ui/switch";
import { useState } from "react";

export default function SwitchControlledDemo() {
  const [enabled, setEnabled] = useState(false);

  return (
    <div className="flex items-center gap-2">
      <Switch
        id="dark-mode"
        checked={enabled}
        onChange={(_, checked) => setEnabled(checked)}
      />
      <label htmlFor="dark-mode">Dark mode: {enabled ? "On" : "Off"}</label>
    </div>
  );
}

Dependencies

More by darshan-rajadhyaksha

View all
  • Backdrop

    Backdrop

    1
  • Avatar

    Avatar

  • Chip

    Chip

  • Progress Bar

    Progress Bar

  • Accessible Dialog

    Accessible Dialog

  • Input

    Input

  • Card Content

    Card Content

  • Breadcrumbs

    Breadcrumbs