52 行
1.7 KiB
TypeScript
52 行
1.7 KiB
TypeScript
import * as React from "react";
|
|
import { Slot } from "@radix-ui/react-slot";
|
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
import { cn } from "../../lib/utils";
|
|
|
|
const buttonVariants = cva(
|
|
"inline-flex items-center justify-center whitespace-nowrap rounded-lg text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-300 disabled:pointer-events-none disabled:opacity-50",
|
|
{
|
|
variants: {
|
|
variant: {
|
|
default: "bg-primary text-white hover:bg-primary-light",
|
|
secondary: "border border-zinc-200 bg-white text-zinc-700 hover:bg-zinc-50",
|
|
outline: "border border-zinc-200 bg-transparent text-zinc-900 hover:bg-zinc-50",
|
|
destructive: "bg-red-600 text-white hover:bg-red-700",
|
|
ghost: "bg-transparent text-zinc-700 hover:bg-zinc-100",
|
|
link: "bg-transparent text-primary underline-offset-4 hover:underline",
|
|
},
|
|
size: {
|
|
default: "h-11 px-4",
|
|
sm: "h-10 rounded-md px-3 text-xs",
|
|
lg: "h-12 rounded-xl px-6 text-base",
|
|
icon: "h-11 w-11 p-0",
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
variant: "default",
|
|
size: "default",
|
|
},
|
|
},
|
|
);
|
|
|
|
export type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> &
|
|
VariantProps<typeof buttonVariants> & {
|
|
asChild?: boolean;
|
|
};
|
|
|
|
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
const Comp = asChild ? Slot : "button";
|
|
return (
|
|
<Comp
|
|
className={cn(buttonVariants({ variant, size, className }))}
|
|
ref={ref}
|
|
{...props}
|
|
/>
|
|
);
|
|
},
|
|
);
|
|
|
|
Button.displayName = "Button";
|
|
|