Create switch.tsx
Browse files- src/components/ui/switch.tsx +27 -0
src/components/ui/switch.tsx
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { forwardRef } from "react";
|
| 2 |
+
import * as SwitchPrimitives from "@radix-ui/react-switch";
|
| 3 |
+
|
| 4 |
+
import { cn } from "@/lib/utils";
|
| 5 |
+
|
| 6 |
+
const Switch = forwardRef<
|
| 7 |
+
React.ElementRef<typeof SwitchPrimitives.Root>,
|
| 8 |
+
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
|
| 9 |
+
>(({ className, ...props }, ref) => (
|
| 10 |
+
<SwitchPrimitives.Root
|
| 11 |
+
className={cn(
|
| 12 |
+
"peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
|
| 13 |
+
className
|
| 14 |
+
)}
|
| 15 |
+
{...props}
|
| 16 |
+
ref={ref}
|
| 17 |
+
>
|
| 18 |
+
<SwitchPrimitives.Thumb
|
| 19 |
+
className={cn(
|
| 20 |
+
"pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"
|
| 21 |
+
)}
|
| 22 |
+
/>
|
| 23 |
+
</SwitchPrimitives.Root>
|
| 24 |
+
));
|
| 25 |
+
Switch.displayName = SwitchPrimitives.Root.displayName;
|
| 26 |
+
|
| 27 |
+
export { Switch };
|