81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
/**
|
|
* Button Component
|
|
* Reusable button with multiple variants and sizes
|
|
*/
|
|
|
|
import React, { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
|
|
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
|
|
size?: 'sm' | 'md' | 'lg';
|
|
loading?: boolean;
|
|
icon?: ReactNode;
|
|
children: ReactNode;
|
|
}
|
|
|
|
export const Button: React.FC<ButtonProps> = ({
|
|
variant = 'primary',
|
|
size = 'md',
|
|
loading = false,
|
|
icon,
|
|
children,
|
|
disabled,
|
|
className = '',
|
|
...props
|
|
}) => {
|
|
const baseStyles = 'inline-flex items-center justify-center font-semibold rounded-lg transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2';
|
|
|
|
const variantStyles = {
|
|
primary: 'bg-gradient-to-r from-purple-600 to-pink-600 text-white hover:from-purple-700 hover:to-pink-700 focus:ring-purple-500',
|
|
secondary: 'bg-gray-800 text-gray-100 border border-gray-700 hover:bg-gray-700 focus:ring-gray-600',
|
|
ghost: 'bg-transparent text-gray-300 hover:bg-gray-800 focus:ring-gray-700',
|
|
danger: 'bg-red-600 text-white hover:bg-red-700 focus:ring-red-500',
|
|
};
|
|
|
|
const sizeStyles = {
|
|
sm: 'px-3 py-1.5 text-sm',
|
|
md: 'px-4 py-2 text-base',
|
|
lg: 'px-6 py-3 text-lg',
|
|
};
|
|
|
|
const disabledStyles = 'opacity-50 cursor-not-allowed';
|
|
|
|
return (
|
|
<button
|
|
className={`
|
|
${baseStyles}
|
|
${variantStyles[variant]}
|
|
${sizeStyles[size]}
|
|
${(disabled || loading) ? disabledStyles : ''}
|
|
${className}
|
|
`}
|
|
disabled={disabled || loading}
|
|
{...props}
|
|
>
|
|
{loading && (
|
|
<svg
|
|
className="animate-spin -ml-1 mr-2 h-4 w-4"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
fill="none"
|
|
viewBox="0 0 24 24"
|
|
>
|
|
<circle
|
|
className="opacity-25"
|
|
cx="12"
|
|
cy="12"
|
|
r="10"
|
|
stroke="currentColor"
|
|
strokeWidth="4"
|
|
/>
|
|
<path
|
|
className="opacity-75"
|
|
fill="currentColor"
|
|
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
/>
|
|
</svg>
|
|
)}
|
|
{icon && !loading && <span className="mr-2">{icon}</span>}
|
|
{children}
|
|
</button>
|
|
);
|
|
};
|