main
tsx 58 lines 1.94 KB
Raw
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:
13 "bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm hover:shadow-md",
14 destructive:
15 "bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm",
16 outline:
17 "border-2 border-primary bg-background text-foreground hover:bg-primary hover:text-primary-foreground",
18 secondary:
19 "bg-secondary text-secondary-foreground hover:bg-secondary/80",
20 ghost: "hover:bg-muted hover:text-foreground",
21 link: "text-primary underline-offset-4 hover:underline",
22 },
23 size: {
24 default: "h-12 px-6 py-3",
25 sm: "h-10 rounded-lg px-4",
26 lg: "h-14 rounded-lg px-8 text-base",
27 icon: "h-12 w-12",
28 },
29 },
30 defaultVariants: {
31 variant: "default",
32 size: "default",
33 },
34 },
35 );
36
37 export interface ButtonProps
38 extends
39 React.ButtonHTMLAttributes<HTMLButtonElement>,
40 VariantProps<typeof buttonVariants> {
41 asChild?: boolean;
42 }
43
44 const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
45 ({ className, variant, size, asChild = false, ...props }, ref) => {
46 const Comp = asChild ? Slot : "button";
47 return (
48 <Comp
49 className={cn(buttonVariants({ variant, size, className }))}
50 ref={ref}
51 {...props}
52 />
53 );
54 },
55 );
56 Button.displayName = "Button";
57
58 export { Button, buttonVariants };