40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
import { cva, type VariantProps } from "class-variance-authority";
|
|
import { Slot } from "@radix-ui/react-slot";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const buttonVariants = cva(
|
|
"inline-flex items-center justify-center gap-2 rounded-lg text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-60",
|
|
{
|
|
variants: {
|
|
variant: {
|
|
default: "bg-primary-600 text-white hover:bg-primary-700 focus-visible:ring-primary-500",
|
|
secondary: "border border-neutral-300 bg-white text-neutral-700 hover:bg-neutral-50 focus-visible:ring-neutral-400",
|
|
destructive: "bg-danger text-white hover:opacity-90 focus-visible:ring-danger",
|
|
success: "bg-success text-white hover:opacity-90 focus-visible:ring-success",
|
|
warning: "border border-warning bg-warning-50 text-warning-700 hover:bg-warning-100 focus-visible:ring-warning",
|
|
ghost: "text-neutral-700 hover:bg-neutral-100 focus-visible:ring-neutral-400",
|
|
link: "text-primary-600 underline-offset-4 hover:underline focus-visible:ring-primary-500",
|
|
},
|
|
size: {
|
|
sm: "h-8 px-3 py-1.5 text-xs",
|
|
md: "h-10 px-4 py-2.5",
|
|
lg: "h-11 px-5 py-3",
|
|
icon: "h-10 w-10",
|
|
},
|
|
},
|
|
defaultVariants: { variant: "default", size: "md" },
|
|
}
|
|
);
|
|
|
|
export interface ButtonProps
|
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
VariantProps<typeof buttonVariants> {
|
|
asChild?: boolean;
|
|
}
|
|
|
|
export function Button({ className, variant, size, asChild, ...props }: ButtonProps) {
|
|
const Comp = asChild ? Slot : "button";
|
|
return <Comp className={cn(buttonVariants({ variant, size }), className)} {...props} />;
|
|
}
|
|
|
|
export { buttonVariants };
|