Switch
On and off toggle.
npx shadcn@latest add https://ui.thjsecurity.tech/r/switch.jsonPulls the component into components/ui/switch.tsx and its token dependencies. The app owns the copy from then on.
@radix-ui/react-switch
"use client"
import * as React from "react"
import * as SwitchPrimitives from "@radix-ui/react-switch"
import { cn } from "@/lib/utils"
/* The console toggle. Off is a quiet glass track; on is crimson with a faint
glow and a crisp white knob. A drop-in reusable switch: anything that was a
Radix Switch gets this look, in both themes. */
const Switch = React.forwardRef<
React.ElementRef<typeof SwitchPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
>(({ className, ...props }, ref) => (
<SwitchPrimitives.Root
className={cn(
"peer inline-flex h-[24px] w-[42px] shrink-0 cursor-pointer items-center rounded-full border border-transparent p-[2px] transition-colors",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-signal focus-visible:ring-offset-2 focus-visible:ring-offset-ink",
"disabled:cursor-not-allowed disabled:opacity-50",
"data-[state=unchecked]:border-glass-border data-[state=unchecked]:bg-glass-strong",
"data-[state=checked]:bg-signal data-[state=checked]:shadow-[0_0_0_1px_var(--signal),0_2px_10px_-2px_var(--signal-line)]",
className,
)}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb className="pointer-events-none block h-[18px] w-[18px] rounded-full bg-white shadow-[0_1px_2px_rgba(0,0,0,0.35)] ring-0 transition-transform data-[state=checked]:translate-x-[18px] data-[state=unchecked]:translate-x-0" />
</SwitchPrimitives.Root>
))
Switch.displayName = SwitchPrimitives.Root.displayName
export { Switch }