import * as React from "react"; import { Slot } from "@radix-ui/react-slot"; import { cva, type VariantProps } from "class-variance-authority"; import { Loader2 } from "lucide-react"; import { cn } from "@/lib/utils"; const buttonVariants = cva( "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-[background-color,border-color,color,box-shadow,transform] duration-150 select-none disabled:pointer-events-none disabled:opacity-50 active:translate-y-px [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", { variants: { variant: { default: "bg-fg text-bg hover:bg-fg/90 shadow-xs", primary: "bg-accent text-accent-fg hover:brightness-110 shadow-xs", secondary: "bg-bg-muted text-fg hover:bg-border", outline: "border border-border bg-bg hover:bg-bg-subtle text-fg shadow-xs", ghost: "hover:bg-bg-muted text-fg-muted hover:text-fg", danger: "bg-danger text-white hover:brightness-110 shadow-xs", link: "text-accent underline-offset-4 hover:underline h-auto p-0", }, size: { default: "h-9 px-3.5", sm: "h-8 px-3 text-[13px] rounded-md", xs: "h-7 px-2.5 text-xs rounded-sm", lg: "h-10 px-5 text-[15px] rounded-lg", icon: "size-9", "icon-sm": "size-8", }, }, defaultVariants: { variant: "default", size: "default" }, }, ); export interface ButtonProps extends React.ButtonHTMLAttributes, VariantProps { asChild?: boolean; loading?: boolean; } export const Button = React.forwardRef(({ className, variant, size, asChild = false, loading, children, disabled, ...props }, ref) => { if (asChild) { // Slot requires exactly one child element; the loader is not rendered in asChild mode. return ( {children} ); } return ( ); }); Button.displayName = "Button"; export { buttonVariants };