47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import React from 'react';
|
|
import { Loader2 } from 'lucide-react';
|
|
|
|
type ButtonVariant = 'primary' | 'secondary' | 'danger';
|
|
|
|
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
variant?: ButtonVariant;
|
|
loading?: boolean;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
const variantClasses: Record<ButtonVariant, string> = {
|
|
primary: 'bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500',
|
|
secondary: 'bg-gray-200 text-gray-800 hover:bg-gray-300 focus:ring-gray-400',
|
|
danger: 'bg-red-600 text-white hover:bg-red-700 focus:ring-red-500',
|
|
};
|
|
|
|
export default function Button({
|
|
variant = 'primary',
|
|
loading = false,
|
|
disabled,
|
|
children,
|
|
className = '',
|
|
...props
|
|
}: ButtonProps) {
|
|
const isDisabled = disabled || loading;
|
|
|
|
return (
|
|
<button
|
|
disabled={isDisabled}
|
|
className={`
|
|
inline-flex items-center justify-center px-4 py-2 rounded-md font-medium transition-colors
|
|
focus:outline-none focus:ring-2 focus:ring-offset-2
|
|
disabled:opacity-50 disabled:cursor-not-allowed
|
|
${variantClasses[variant]}
|
|
${className}
|
|
`}
|
|
{...props}
|
|
>
|
|
{loading ? (
|
|
<Loader2 className="w-4 h-4 animate-spin" />
|
|
) : (
|
|
children
|
|
)}
|
|
</button>
|
|
);
|
|
} |