feat(ui): Button with variants + sizes + disabled state

This commit is contained in:
Bastien Chanot committed 2026-05-18 21:15:33 +02:00
1 parent 86f65767de
commit fe5adcd249
2 files changed
+63 -2

No files matched your search

+45 -2
View File
@@ -1,3 +1,46 @@
export default function Button() {
return <div>Button placeholder</div>
import type { ButtonHTMLAttributes, ReactNode } from 'react'
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary' | 'ghost' | 'danger'
size?: 'sm' | 'md' | 'lg'
children?: ReactNode
}
const VARIANTS: Record<NonNullable<ButtonProps['variant']>, string> = {
primary:
'bg-[var(--color-accent)] text-white hover:bg-[var(--color-accent-strong)] focus-visible:ring-[var(--color-accent)]',
secondary:
'bg-[var(--color-surface)] text-[var(--color-ink)] border border-[var(--color-border)] hover:bg-[var(--color-surface-strong)]',
ghost:
'bg-transparent text-[var(--color-ink)] hover:bg-[var(--color-surface)]',
danger:
'bg-[var(--color-danger)] text-white hover:bg-[var(--color-danger-strong)]',
}
const SIZES: Record<NonNullable<ButtonProps['size']>, string> = {
sm: 'h-8 px-3 text-sm rounded-md',
md: 'h-10 px-4 text-base rounded-lg',
lg: 'h-12 px-6 text-base rounded-lg',
}
export default function Button({
variant = 'primary',
size = 'md',
className = '',
children,
...rest
}: ButtonProps) {
return (
<button
className={[
'inline-flex items-center justify-center font-medium transition disabled:opacity-50 disabled:cursor-not-allowed focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2',
VARIANTS[variant],
SIZES[size],
className,
].join(' ')}
{...rest}
>
{children}
</button>
)
}