import React from "react"; import { Button, Anchor } from "@mantine/core"; import { Tooltip } from "../../shared/Tooltip"; import { ToolRegistryEntry } from "../../../data/toolsTaxonomy"; import { useToolNavigation } from "../../../hooks/useToolNavigation"; import FitText from "../../shared/FitText"; interface ToolButtonProps { id: string; tool: ToolRegistryEntry; isSelected: boolean; onSelect: (id: string) => void; rounded?: boolean; } const ToolButton: React.FC = ({ id, tool, isSelected, onSelect }) => { const isUnavailable = !tool.component && !tool.link; const { getToolNavigation } = useToolNavigation(); const handleClick = (id: string) => { if (isUnavailable) return; if (tool.link) { // Open external link in new tab window.open(tool.link, '_blank', 'noopener,noreferrer'); return; } // Normal tool selection onSelect(id); }; // Get navigation props for URL support const navProps = !isUnavailable && !tool.link ? getToolNavigation(id, tool) : null; const tooltipContent = isUnavailable ? (Coming soon: {tool.description}) : tool.description; const buttonContent = ( <>
{tool.icon}
); const handleExternalClick = (e: React.MouseEvent) => { // Check if it's a special click (ctrl+click, etc.) if (e.metaKey || e.ctrlKey || e.shiftKey) { return; // Let browser handle it via href } // For regular clicks, prevent default and use window.open e.preventDefault(); handleClick(id); }; const buttonElement = navProps ? ( // For internal tools with URLs, render Button as an anchor for proper link behavior ) : tool.link && !isUnavailable ? ( // For external links, render Button as an anchor with proper href ) : ( // For unavailable tools, use regular button ); return ( {buttonElement} ); }; export default ToolButton;