| 1 | import * as React from "react"; |
| 2 | import { Slot } from "@radix-ui/react-slot"; |
| 3 | import { cva, type VariantProps } from "class-variance-authority"; |
| 4 | |
| 5 | import { cn } from "@/lib/utils"; |
| 6 | |
| 7 | const buttonVariants = cva( |
| 8 | "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-semibold ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 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 hover:bg-primary/90 shadow-sm hover:shadow-md", |
| 13 | destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm", |
| 14 | outline: "border-2 border-primary bg-background text-foreground hover:bg-primary hover:text-primary-foreground", |
| 15 | secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80", |
| 16 | ghost: "hover:bg-muted hover:text-foreground", |
| 17 | link: "text-primary underline-offset-4 hover:underline", |
| 18 | }, |
| 19 | size: { |
| 20 | default: "h-12 px-6 py-3", |
| 21 | sm: "h-10 rounded-lg px-4", |
| 22 | lg: "h-14 rounded-lg px-8 text-base", |
| 23 | icon: "h-12 w-12", |
| 24 | }, |
| 25 | }, |
| 26 | defaultVariants: { |
| 27 | variant: "default", |
| 28 | size: "default", |
| 29 | }, |
| 30 | }, |
| 31 | ); |
| 32 | |
| 33 | export interface ButtonProps |
| 34 | extends React.ButtonHTMLAttributes<HTMLButtonElement>, |
| 35 | VariantProps<typeof buttonVariants> { |
| 36 | asChild?: boolean; |
| 37 | } |
| 38 | |
| 39 | const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( |
| 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"; |
| 46 | |
| 47 | export { Button, buttonVariants }; |