russellbloxwich

Switch

Forms

About

A toggle switch control for turning a single setting on or off, built on Radix UI's switch primitive with a compact and small size variant.

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 * as React from "react";
import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";

export default function SwitchDemo() {
  const id = React.useId();
  const [preview, setPreview] = React.useState(false);

  return (
    <div className="flex flex-col gap-4 bg-background p-6 text-foreground">
      <div className="flex items-center gap-2">
        <Switch
          id={`${id}-preview`}
          checked={preview}
          onCheckedChange={setPreview}
        />
        <Label htmlFor={`${id}-preview`}>Enable preview deployments</Label>
      </div>
      <div className="flex items-center gap-2">
        <Switch id={`${id}-disabled-switch`} checked disabled />
        <Label htmlFor={`${id}-disabled-switch`}>Managed by policy</Label>
      </div>
    </div>
  );
}

Dependencies

More by russellbloxwich

View all
  • Chart

    Chart

    2
  • Code Block

    Code Block

    2
  • Sensitive Input

    Sensitive Input

    2
  • Layer Card

    Layer Card

    1
  • Direction Provider

    Direction Provider

    1
  • Bubble

    Bubble

  • Meter

    Meter

  • Field

    Field

More in Forms

View all
  • Premium Auth

    Premium Auth

    524
  • Contact Card

    Contact Card

    1K
  • Book A Demo 1

    Book A Demo 1

    73
  • Form

    Form

    16
  • Login 1

    Login 1

    53
  • Book A Demo 3

    Book A Demo 3

    89
  • Hand-Drawn Checkbox

    Hand-Drawn Checkbox

    48
  • Login Card

    Login Card

    6