| 1 | import * as React from "react"; |
| 2 | import * as TogglePrimitive from "@radix-ui/react-toggle"; |
| 3 | import { cva, type VariantProps } from "class-variance-authority"; |
| 4 | |
| 5 | import { cn } from "@/lib/utils"; |
| 6 | |
| 7 | const toggleVariants = cva( |
| 8 | "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground", |
| 9 | { |
| 10 | variants: { |
| 11 | variant: { |
| 12 | default: "bg-transparent", |
| 13 | outline: "border border-input bg-transparent hover:bg-accent hover:text-accent-foreground", |
| 14 | }, |
| 15 | size: { |
| 16 | default: "h-10 px-3", |
| 17 | sm: "h-9 px-2.5", |
| 18 | lg: "h-11 px-5", |
| 19 | }, |
| 20 | }, |
| 21 | defaultVariants: { |
| 22 | variant: "default", |
| 23 | size: "default", |
| 24 | }, |
| 25 | }, |
| 26 | ); |
| 27 | |
| 28 | const Toggle = React.forwardRef< |
| 29 | React.ElementRef<typeof TogglePrimitive.Root>, |
| 30 | React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> & VariantProps<typeof toggleVariants> |
| 31 | >(({ className, variant, size, ...props }, ref) => ( |
| 32 | <TogglePrimitive.Root ref={ref} className={cn(toggleVariants({ variant, size, className }))} {...props} /> |
| 33 | )); |
| 34 | |
| 35 | Toggle.displayName = TogglePrimitive.Root.displayName; |
| 36 | |
| 37 | export { Toggle, toggleVariants }; |