53129
Pa
PAT / files
PAT / src / components / Button.tsx
1.3 KB
1"use client"; 2 3import type { AnchorHTMLAttributes, ReactNode } from "react"; 4import { Children } from "react"; 5 6type ButtonProps = AnchorHTMLAttributes<HTMLAnchorElement> & { 7 children: ReactNode; 8 isSelected?: boolean; 9 disabled?: boolean; 10 inline?: boolean; 11}; 12 13export default function Button({ 14 children, 15 isSelected = false, 16 disabled = false, 17 inline = false, 18 className = "", 19 onClick, 20 ...props 21}: ButtonProps) { 22 const processedChildren = Children.map(children, (child) => { 23 if (typeof child === "string" || typeof child === "number") { 24 return <span className="min-w-0 truncate">{child}</span>; 25 } 26 return child; 27 }); 28 29 const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => { 30 if (disabled) { 31 e.preventDefault(); 32 return; 33 } 34 onClick?.(e); 35 }; 36 37 const flexClass = inline ? "inline-flex max-w-fit mx-2" : "flex"; 38 39 return ( 40 <a 41 className={`${flexClass} min-w-0 cursor-pointer flex-row items-center gap-2 rounded px-2 py-1 align-middle ${ 42 isSelected 43 ? "bg-neutral-200 dark:bg-neutral-800" 44 : "hover:bg-neutral-300 dark:hover:bg-neutral-700" 45 } ${disabled ? "cursor-not-allowed opacity-50" : ""} ${className}`} 46 onClick={handleClick} 47 {...props} 48 > 49 {processedChildren} 50 </a> 51 ); 52}