d89304845a
- Backend: FastAPI, JWT auth (HS256), bcrypt, RBAC middleware - User CRUD (admin-only), soft-delete, pagination - Pydantic BaseSettings config, async SQLAlchemy 2.0 - 50 backend tests, 88% coverage - Frontend: Next.js 14 App Router, Tailwind, design tokens - Login page, auth context, API client with auto-refresh - i18n: next-intl, DE/EN (31 keys each) - 6 base UI components (Button, Input, Card, Table, Modal, Toast) - 12 frontend tests, npm build success
38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import { ButtonHTMLAttributes, forwardRef } from 'react';
|
|
|
|
type Variant = 'primary' | 'secondary' | 'danger' | 'ghost';
|
|
|
|
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
variant?: Variant;
|
|
loading?: boolean;
|
|
}
|
|
|
|
const variantClasses: Record<Variant, string> = {
|
|
primary: 'bg-primary text-white hover:bg-primary-hover focus:ring-primary',
|
|
secondary: 'bg-secondary text-white hover:bg-secondary/80 focus:ring-secondary',
|
|
danger: 'bg-error text-white hover:bg-error/80 focus:ring-error',
|
|
ghost: 'bg-transparent text-primary hover:bg-primary/10 focus:ring-primary',
|
|
};
|
|
|
|
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
({ variant = 'primary', loading = false, children, className = '', disabled, ...props }, ref) => {
|
|
return (
|
|
<button
|
|
ref={ref}
|
|
className={`inline-flex items-center justify-center px-4 py-2 rounded-lg font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed ${variantClasses[variant]} ${className}`}
|
|
disabled={disabled || loading}
|
|
{...props}
|
|
>
|
|
{loading ? (
|
|
<svg className="animate-spin h-5 w-5 mr-2" 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 12h4z" />
|
|
</svg>
|
|
) : null}
|
|
{children}
|
|
</button>
|
|
);
|
|
}
|
|
);
|
|
Button.displayName = 'Button';
|