|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import type { ButtonHTMLAttributes, ComponentType } from "react"; |
| 4 | + |
| 5 | +import { cn } from "@/lib/utils"; |
| 6 | + |
| 7 | +type ButtonVariant = "primary" | "secondary" | "ghost" | "destructive"; |
| 8 | +type ButtonSize = "sm" | "md" | "lg"; |
| 9 | + |
| 10 | +interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { |
| 11 | + /** Visual style; defaults to `"primary"`. */ |
| 12 | + variant?: ButtonVariant; |
| 13 | + /** Button dimensions; defaults to `"md"`. */ |
| 14 | + size?: ButtonSize; |
| 15 | + /** Leading icon component from `@heroicons/react/24/outline`. */ |
| 16 | + icon?: ComponentType<{ className?: string }>; |
| 17 | + /** Trailing icon component from `@heroicons/react/24/outline`. */ |
| 18 | + iconRight?: ComponentType<{ className?: string }>; |
| 19 | +} |
| 20 | + |
| 21 | +const variantClasses: Record<ButtonVariant, string> = { |
| 22 | + primary: |
| 23 | + "bg-nottingham-blue text-paper border border-nottingham-blue hover:bg-[var(--color-primary-deep)]", |
| 24 | + secondary: |
| 25 | + "bg-paper text-ink border border-[var(--border-strong)] hover:bg-portland-stone", |
| 26 | + ghost: |
| 27 | + "bg-transparent text-ink border border-transparent hover:bg-[rgba(16,38,59,0.06)]", |
| 28 | + destructive: |
| 29 | + "bg-paper text-jubilee-red border border-[rgba(185,28,46,0.4)] hover:bg-jubilee-red-20", |
| 30 | +}; |
| 31 | + |
| 32 | +const sizeClasses: Record<ButtonSize, string> = { |
| 33 | + sm: "px-[10px] py-[5px] text-[12px] [&_svg]:w-[14px] [&_svg]:h-[14px]", |
| 34 | + md: "px-[16px] py-[9px] text-[14px] [&_svg]:w-[16px] [&_svg]:h-[16px]", |
| 35 | + lg: "px-[20px] py-[12px] text-[15px] [&_svg]:w-[16px] [&_svg]:h-[16px]", |
| 36 | +}; |
| 37 | + |
| 38 | +/** |
| 39 | + * Primary interaction button with four visual variants and three sizes. |
| 40 | + * Icon-only buttons must provide an `aria-label`. |
| 41 | + * @param variant - Visual style; defaults to `"primary"` |
| 42 | + * @param size - Button dimensions; defaults to `"md"` |
| 43 | + * @param icon - Optional leading icon component |
| 44 | + * @param iconRight - Optional trailing icon component |
| 45 | + */ |
| 46 | +export function Button({ |
| 47 | + variant = "primary", |
| 48 | + size = "md", |
| 49 | + icon: Icon, |
| 50 | + iconRight: IconRight, |
| 51 | + children, |
| 52 | + className, |
| 53 | + disabled, |
| 54 | + type = "button", |
| 55 | + ...props |
| 56 | +}: ButtonProps) { |
| 57 | + return ( |
| 58 | + <button |
| 59 | + type={type} |
| 60 | + disabled={disabled} |
| 61 | + className={cn( |
| 62 | + "inline-flex items-center gap-2 font-sans font-medium tracking-[-0.005em] rounded-sm cursor-pointer", |
| 63 | + "transition-[background-color,transform,border-color] duration-[120ms] ease-[cubic-bezier(0.2,0,0,1)]", |
| 64 | + "active:scale-[0.98] active:transition-[transform] active:duration-[80ms]", |
| 65 | + "disabled:opacity-50 disabled:cursor-not-allowed", |
| 66 | + variantClasses[variant], |
| 67 | + sizeClasses[size], |
| 68 | + className, |
| 69 | + )} |
| 70 | + {...props} |
| 71 | + > |
| 72 | + {Icon && <Icon className="shrink-0" />} |
| 73 | + {children} |
| 74 | + {IconRight && <IconRight className="shrink-0" />} |
| 75 | + </button> |
| 76 | + ); |
| 77 | +} |
0 commit comments