26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
import type { ButtonHTMLAttributes } from 'react'
|
|
import { cx } from './cx'
|
|
|
|
type Variant = 'primary' | 'secondary' | 'ghost' | 'icon'
|
|
|
|
const BASE =
|
|
'inline-flex items-center gap-1.5 text-left font-extrabold text-sm leading-tight ' +
|
|
'border border-transparent cursor-pointer transition-colors ' +
|
|
'disabled:opacity-45 disabled:cursor-not-allowed'
|
|
|
|
const VARIANTS: Record<Variant, string> = {
|
|
primary: 'justify-start bg-accent text-ground px-3.5 py-2 hover:bg-accent-600 active:bg-accent-700',
|
|
secondary: 'justify-start border-divider text-ink px-3.5 py-2 hover:bg-ink/7 active:bg-ink/15',
|
|
ghost: 'justify-start text-accent-700 px-1 py-2 hover:bg-accent/10 active:bg-accent/20',
|
|
icon: 'justify-center w-9 h-9 p-0 text-ink hover:bg-ink/7 active:bg-ink/15',
|
|
}
|
|
|
|
type Props = ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
variant?: Variant
|
|
block?: boolean
|
|
}
|
|
|
|
export function Button({ variant = 'primary', block = false, className, type = 'button', ...rest }: Props) {
|
|
return <button type={type} className={cx(BASE, VARIANTS[variant], block && 'w-full', className)} {...rest} />
|
|
}
|