Spaces:
Running

Bot / frontend /src /shared /components /Button.tsx
ddosvn's picture
Initial deploy of Panel ThTuanIT full stack and Lighthouse-optimized frontend
7e79d39 verified
Raw History Blame Contribute Delete
1.83 kB
import React from 'react';
import { cn } from '@/shared/lib/cn';
type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger' | 'outline';
type ButtonSize = 'sm' | 'md' | 'lg';
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: ButtonVariant;
size?: ButtonSize;
loading?: boolean;
}
const VARIANT_CLASSES: Record<ButtonVariant, string> = {
primary:
'bg-accent hover:bg-accent-hover text-on-accent border border-transparent shadow-sm active:opacity-90',
secondary:
'bg-surface-2 hover:bg-surface-3 text-ink-1 border border-line hover:border-line-strong',
outline:
'bg-transparent hover:bg-surface-2 text-ink-1 border border-line-strong',
ghost:
'bg-transparent hover:bg-surface-2 text-ink-2 hover:text-ink-1 border border-transparent',
danger:
'bg-rose-600/15 hover:bg-rose-600/25 text-rose-500 border border-rose-500/30',
};
const SIZE_CLASSES: Record<ButtonSize, string> = {
sm: 'min-h-[36px] px-3 py-1.5 text-xs rounded-lg gap-1.5',
md: 'min-h-[42px] px-4 py-2 text-xs sm:text-sm rounded-xl gap-2',
lg: 'min-h-[46px] px-6 py-2.5 text-sm rounded-xl gap-2',
};
export function Button({
variant = 'primary',
size = 'md',
loading = false,
disabled,
className,
type = 'button',
children,
...rest
}: ButtonProps) {
return (
<button
type={type}
disabled={disabled || loading}
className={cn(
'inline-flex items-center justify-center font-semibold cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-canvas',
VARIANT_CLASSES[variant],
SIZE_CLASSES[size],
className,
)}
{...rest}
>
{children}
</button>
);
}