36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { Slot } from "@radix-ui/react-slot";
|
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
import type { ComponentProps } from "react";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const buttonVariants = cva(
|
|
"inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-semibold transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0",
|
|
{
|
|
variants: {
|
|
variant: {
|
|
default: "bg-primary text-primary-foreground hover:bg-primary/85",
|
|
outline: "border border-border bg-background hover:bg-muted",
|
|
ghost: "hover:bg-muted",
|
|
},
|
|
size: {
|
|
default: "h-10 px-4",
|
|
sm: "h-8 px-3",
|
|
icon: "size-9",
|
|
},
|
|
},
|
|
defaultVariants: { variant: "default", size: "default" },
|
|
},
|
|
);
|
|
|
|
export function Button({
|
|
asChild,
|
|
className,
|
|
variant,
|
|
size,
|
|
type = "button",
|
|
...props
|
|
}: ComponentProps<"button"> & VariantProps<typeof buttonVariants> & { asChild?: boolean }) {
|
|
const Component = asChild ? Slot : "button";
|
|
return <Component data-slot="button" type={asChild ? undefined : type} className={cn(buttonVariants({ variant, size }), className)} {...props} />;
|
|
}
|