| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 1 | import * as React from "react"; |
| 2 | import { Slot } from "@radix-ui/react-slot"; |
| 3 | import { cva, type VariantProps } from "class-variance-authority"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 4 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 5 | import { cn } from "@/lib/utils"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 6 | |
| 7 | const buttonVariants = cva( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 8 | "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", |
| 9 | { |
| 10 | variants: { |
| 11 | variant: { |
| 12 | default: "bg-primary text-primary-foreground shadow hover:bg-primary/90", |
| 13 | destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90", |
| 14 | outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground", |
| 15 | secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80", |
| 16 | ghost: "hover:bg-accent hover:text-accent-foreground", |
| 17 | link: "text-primary underline-offset-4 hover:underline", |
| 18 | }, |
| 19 | size: { |
| 20 | default: "h-9 px-4 py-2", |
| 21 | sm: "h-8 rounded-md px-3 text-xs", |
| 22 | lg: "h-10 rounded-md px-8", |
| 23 | icon: "h-9 w-9", |
| 24 | }, |
| 25 | }, |
| 26 | defaultVariants: { |
| 27 | variant: "default", |
| 28 | size: "default", |
| 29 | }, |
| 30 | }, |
| 31 | ); |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 32 | |
| 33 | export interface ButtonProps |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 34 | extends React.ButtonHTMLAttributes<HTMLButtonElement>, |
| 35 | VariantProps<typeof buttonVariants> { |
| 36 | asChild?: boolean; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 40 | ({ className, variant, size, asChild = false, ...props }, ref) => { |
| 41 | const Comp = asChild ? Slot : "button"; |
| 42 | return <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />; |
| 43 | }, |
| 44 | ); |
| 45 | Button.displayName = "Button"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 46 | |
| gio | d002661 | 2025-05-08 13:00:36 +0000 | [diff] [blame] | 47 | export { Button, buttonVariants }; |