blob: f44eeb166af779a130d1e19333fc182adeb8d7c0 [file] [log] [blame]
giod0026612025-05-08 13:00:36 +00001import * as React from "react";
2import { Slot } from "@radix-ui/react-slot";
3import { cva, type VariantProps } from "class-variance-authority";
gio5f2f1002025-03-20 18:38:48 +04004
giod0026612025-05-08 13:00:36 +00005import { cn } from "@/lib/utils";
gio5f2f1002025-03-20 18:38:48 +04006
7const buttonVariants = cva(
giod0026612025-05-08 13:00:36 +00008 "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);
gio5f2f1002025-03-20 18:38:48 +040032
33export interface ButtonProps
giod0026612025-05-08 13:00:36 +000034 extends React.ButtonHTMLAttributes<HTMLButtonElement>,
35 VariantProps<typeof buttonVariants> {
36 asChild?: boolean;
gio5f2f1002025-03-20 18:38:48 +040037}
38
39const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
giod0026612025-05-08 13:00:36 +000040 ({ 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);
45Button.displayName = "Button";
gio5f2f1002025-03-20 18:38:48 +040046
giod0026612025-05-08 13:00:36 +000047export { Button, buttonVariants };