switch.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. "use client";
  2. import * as React from "react";
  3. import * as SwitchPrimitive from "@radix-ui/react-switch@1.1.3";
  4. import { cn } from "./utils";
  5. function Switch({
  6. className,
  7. ...props
  8. }: React.ComponentProps<typeof SwitchPrimitive.Root>) {
  9. return (
  10. <SwitchPrimitive.Root
  11. data-slot="switch"
  12. className={cn(
  13. "peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-switch-background focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
  14. className,
  15. )}
  16. {...props}
  17. >
  18. <SwitchPrimitive.Thumb
  19. data-slot="switch-thumb"
  20. className={cn(
  21. "bg-card dark:data-[state=unchecked]:bg-card-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0",
  22. )}
  23. />
  24. </SwitchPrimitive.Root>
  25. );
  26. }
  27. export { Switch };