44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { forwardRef, type ButtonHTMLAttributes } from 'react';
|
|||
|
|
import { cn } from '@/lib/cn';
|
||
|
|
|
||
|
|
type Variant = 'primary' | 'secondary' | 'ghost' | 'danger';
|
||
|
|
type Size = 'sm' | 'md' | 'lg';
|
||
|
|
|
||
|
|
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||
|
|
variant?: Variant;
|
||
|
|
size?: Size;
|
||
|
|
}
|
||
|
|
|
||
|
|
const VARIANT: Record<Variant, string> = {
|
||
|
|
primary: 'bg-brand-500 text-white hover:bg-brand-600 shadow-sm shadow-brand-500/25',
|
||
|
|
secondary: 'bg-white text-ink-900 border border-ink-200 hover:border-ink-300',
|
||
|
|
ghost: 'text-ink-700 hover:text-ink-900 hover:bg-ink-100',
|
||
|
|
danger: 'bg-rose-500 text-white hover:bg-rose-600 shadow-sm shadow-rose-500/25',
|
||
|
|
};
|
||
|
|
|
||
|
|
const SIZE: Record<Size, string> = {
|
||
|
|
sm: 'px-3 py-1.5 text-sm rounded-lg gap-1.5',
|
||
|
|
md: 'px-4 py-2 text-sm rounded-xl gap-2',
|
||
|
|
lg: 'px-5 py-2.5 text-sm rounded-xl gap-2',
|
||
|
|
};
|
||
|
|
|
||
|
|
export const Button = forwardRef<HTMLButtonElement, Props>(function Button(
|
||
|
|
{ variant = 'primary', size = 'md', className, ...rest },
|
||
|
|
ref,
|
||
|
|
) {
|
||
|
|
return (
|
||
|
|
<button
|
||
|
|
ref={ref}
|
||
|
|
className={cn(
|
||
|
|
'inline-flex items-center justify-center font-medium transition',
|
||
|
|
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500 focus-visible:ring-offset-2',
|
||
|
|
'disabled:pointer-events-none disabled:opacity-60',
|
||
|
|
VARIANT[variant],
|
||
|
|
SIZE[size],
|
||
|
|
className,
|
||
|
|
)}
|
||
|
|
{...rest}
|
||
|
|
/>
|
||
|
|
);
|
||
|
|
});
|