46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { forwardRef, type ButtonHTMLAttributes } from 'react'
|
|
import { cn } from '../../lib/utils'
|
|
|
|
export type ButtonVariant = 'primary' | 'ghost' | 'outline'
|
|
export type ButtonSize = 'sm' | 'md' | 'icon'
|
|
|
|
export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
variant?: ButtonVariant
|
|
size?: ButtonSize
|
|
}
|
|
|
|
const variants: Record<ButtonVariant, string> = {
|
|
primary: 'bg-accent text-on-accent hover:bg-accent-strong',
|
|
ghost: 'bg-transparent text-primary hover:bg-primary-soft',
|
|
outline: 'border border-border bg-surface text-primary hover:bg-primary-soft',
|
|
}
|
|
|
|
const sizes: Record<ButtonSize, string> = {
|
|
sm: 'h-8 px-3 text-sm',
|
|
md: 'h-10 px-4 text-sm',
|
|
icon: 'size-9',
|
|
}
|
|
|
|
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
({ className, variant = 'ghost', size = 'md', type = 'button', ...props }, ref) => {
|
|
return (
|
|
<button
|
|
ref={ref}
|
|
type={type}
|
|
className={cn(
|
|
// `transition-*` explícito en vez de `transition-all`: solo se animan
|
|
// color, fondo, borde y transform. El feedback de presión se anula
|
|
// con `motion-reduce` para respetar prefers-reduced-motion.
|
|
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-xl font-medium transition-[color,background-color,border-color,fill,stroke,transform] duration-150 ease-out active:scale-[0.96] motion-reduce:active:scale-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:pointer-events-none disabled:opacity-50',
|
|
variants[variant],
|
|
sizes[size],
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
)
|
|
},
|
|
)
|
|
|
|
Button.displayName = 'Button'
|