8058
Ir
irvc / files
irvc / web / src / ui / Button.tsx
1.2 KB
1import type { ButtonHTMLAttributes, ReactNode } from "react"; 2import { cn } from "cn"; 3 4export type Variant = "primary" | "secondary" | "ghost" | "danger"; 5export type Size = "sm" | "md" | "lg"; 6 7export function Button({ 8 variant = "secondary", 9 size = "md", 10 className, 11 type = "button", 12 ...props 13}: ButtonHTMLAttributes<HTMLButtonElement> & { variant?: Variant; size?: Size }) { 14 return ( 15 <button 16 type={type} 17 className={cn("btn", `btn-${variant}`, `btn-${size}`, className)} 18 {...props} 19 /> 20 ); 21} 22 23// IconButton is a square button. `label` is required: it is the only thing 24// screen readers and tooltips have to go on. 25export function IconButton({ 26 label, 27 variant = "ghost", 28 size = "md", 29 className, 30 children, 31 ...props 32}: ButtonHTMLAttributes<HTMLButtonElement> & { 33 label: string; 34 variant?: Variant; 35 size?: Size; 36 children: ReactNode; 37}) { 38 return ( 39 <button 40 type="button" 41 aria-label={label} 42 title={label} 43 className={cn( 44 "btn", 45 `btn-${variant}`, 46 "icon-btn", 47 `icon-btn-${size}`, 48 className, 49 )} 50 {...props} 51 > 52 {children} 53 </button> 54 ); 55}