85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import React from "react";
|
|
|
|
type ButtonVariant =
|
|
| "primary"
|
|
| "secondary"
|
|
| "success"
|
|
| "danger"
|
|
| "warning"
|
|
| "info"
|
|
| "outline"
|
|
| "link";
|
|
|
|
interface ButtonProps {
|
|
children: React.ReactNode;
|
|
type?: "button" | "submit" | "reset";
|
|
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
variant?: ButtonVariant;
|
|
size?: "sm" | "md" | "lg";
|
|
disabled?: boolean;
|
|
className?: string;
|
|
icon?: React.ReactNode;
|
|
}
|
|
|
|
export function Button({
|
|
children,
|
|
type = "button",
|
|
onClick,
|
|
variant = "primary",
|
|
size = "md",
|
|
disabled = false,
|
|
className = "",
|
|
icon,
|
|
}: ButtonProps) {
|
|
const baseClasses =
|
|
"inline-flex items-center justify-center font-medium rounded-md focus:outline-none transition-colors";
|
|
|
|
// Definir classes de variante
|
|
const variantClasses = {
|
|
primary:
|
|
"bg-blue-600 text-white hover:bg-blue-700 focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",
|
|
secondary:
|
|
"bg-gray-600 text-white hover:bg-gray-700 focus:ring-2 focus:ring-offset-2 focus:ring-gray-500",
|
|
success:
|
|
"bg-green-600 text-white hover:bg-green-700 focus:ring-2 focus:ring-offset-2 focus:ring-green-500",
|
|
danger:
|
|
"bg-red-600 text-white hover:bg-red-700 focus:ring-2 focus:ring-offset-2 focus:ring-red-500",
|
|
warning:
|
|
"bg-yellow-500 text-white hover:bg-yellow-600 focus:ring-2 focus:ring-offset-2 focus:ring-yellow-400",
|
|
info: "bg-blue-400 text-white hover:bg-blue-500 focus:ring-2 focus:ring-offset-2 focus:ring-blue-300",
|
|
outline:
|
|
"bg-white text-gray-700 border border-gray-300 hover:bg-gray-50 focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",
|
|
link: "bg-transparent text-blue-600 hover:text-blue-800 hover:underline focus:ring-0",
|
|
};
|
|
|
|
// Definir classes de tamanho
|
|
const sizeClasses = {
|
|
sm: "px-2.5 py-1.5 text-xs",
|
|
md: "px-4 py-2 text-sm",
|
|
lg: "px-6 py-3 text-base",
|
|
};
|
|
|
|
// Definir classes de estado desabilitado
|
|
const disabledClasses = "opacity-50 cursor-not-allowed";
|
|
|
|
const buttonClasses = [
|
|
baseClasses,
|
|
variantClasses[variant],
|
|
sizeClasses[size],
|
|
disabled ? disabledClasses : "",
|
|
className,
|
|
].join(" ");
|
|
|
|
return (
|
|
<button
|
|
type={type}
|
|
onClick={onClick}
|
|
disabled={disabled}
|
|
className={buttonClasses}
|
|
>
|
|
{icon && <span className="mr-2">{icon}</span>}
|
|
{children}
|
|
</button>
|
|
);
|
|
}
|