45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import type { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
|
|
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
|
|
size?: 'sm' | 'md' | 'icon';
|
|
icon?: ReactNode;
|
|
}
|
|
|
|
export function Button({
|
|
variant = 'secondary',
|
|
size = 'sm',
|
|
icon,
|
|
className = '',
|
|
children,
|
|
type = 'button',
|
|
...props
|
|
}: ButtonProps) {
|
|
const variants = {
|
|
primary: 'border-transparent bg-accent text-white hover:bg-accent-hover',
|
|
secondary: 'border-border bg-surface text-text-primary hover:bg-element-hover',
|
|
ghost:
|
|
'border-transparent bg-transparent text-text-secondary hover:bg-element-hover hover:text-text-primary',
|
|
danger: 'border-danger-border bg-danger-soft text-danger hover:bg-danger hover:text-white',
|
|
};
|
|
const sizes = {
|
|
sm: 'h-7 gap-1.5 rounded-md px-2 text-xs',
|
|
md: 'h-8 gap-2 rounded-md px-3 text-sm',
|
|
icon: 'h-7 w-7 rounded-md p-0',
|
|
};
|
|
return (
|
|
<button
|
|
type={type}
|
|
className={`inline-flex shrink-0 select-none items-center justify-center border font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/30 disabled:cursor-not-allowed disabled:opacity-40 ${variants[variant]} ${sizes[size]} ${className}`.trim()}
|
|
{...props}
|
|
>
|
|
{icon && (
|
|
<span aria-hidden="true" className="flex items-center">
|
|
{icon}
|
|
</span>
|
|
)}
|
|
{children}
|
|
</button>
|
|
);
|
|
}
|