%PDF- %PDF-
| Direktori : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/components/ui/ |
| Current File : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/components/ui/Button.tsx |
import type { ButtonHTMLAttributes, ReactNode } from "react";
type Variant = "primary" | "ghost" | "danger" | "subtle";
type Size = "sm" | "md" | "lg";
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: Variant;
size?: Size;
isLoading?: boolean;
children: ReactNode;
}
const variantClasses: Record<Variant, string> = {
primary:
"bg-gradient-to-r from-blue-500 to-blue-600 text-white hover:from-blue-400 hover:to-blue-500 active:scale-[0.98]",
ghost:
"border border-white/[0.08] bg-white/[0.03] text-slate-200 hover:bg-white/[0.06] hover:border-white/[0.14] active:scale-[0.98]",
danger:
"border border-red-500/25 bg-red-500/10 text-red-300 hover:bg-red-500/15 hover:border-red-400/35 active:scale-[0.98]",
subtle:
"text-slate-400 hover:bg-white/[0.04] hover:text-slate-200 active:scale-[0.98]",
};
const sizeClasses: Record<Size, string> = {
sm: "px-3 py-1.5 text-xs rounded-lg",
md: "px-4 py-2.5 text-sm rounded-xl",
lg: "px-5 py-3 text-sm rounded-xl",
};
export default function Button({
variant = "primary",
size = "md",
isLoading = false,
disabled,
className = "",
children,
type,
...rest
}: ButtonProps) {
return (
<button
type={type ?? "button"}
disabled={disabled || isLoading}
className={`inline-flex items-center justify-center gap-2 font-semibold transition-all duration-150 outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 disabled:cursor-not-allowed disabled:opacity-50 ${variantClasses[variant]} ${sizeClasses[size]} ${className}`}
{...rest}
>
{isLoading && (
<span className="h-4 w-4 animate-spin rounded-full border-2 border-white/25 border-t-white" />
)}
{children}
</button>
);
}