2025-08-19 13:31:09 +01:00
|
|
|
import React from "react";
|
|
|
|
import { Button } from "@mantine/core";
|
|
|
|
import { Tooltip } from "../../shared/Tooltip";
|
|
|
|
import { ToolRegistryEntry } from "../../../data/toolsTaxonomy";
|
|
|
|
import FitText from "../../shared/FitText";
|
|
|
|
|
|
|
|
interface ToolButtonProps {
|
|
|
|
id: string;
|
|
|
|
tool: ToolRegistryEntry;
|
|
|
|
isSelected: boolean;
|
|
|
|
onSelect: (id: string) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ToolButton: React.FC<ToolButtonProps> = ({ id, tool, isSelected, onSelect }) => {
|
2025-08-26 11:51:10 +01:00
|
|
|
const isUnavailable = !tool.component && !tool.link;
|
2025-08-19 13:31:09 +01:00
|
|
|
const handleClick = (id: string) => {
|
2025-08-26 11:51:10 +01:00
|
|
|
if (isUnavailable) return;
|
2025-08-19 13:31:09 +01:00
|
|
|
if (tool.link) {
|
2025-08-22 13:53:06 +01:00
|
|
|
// Open external link in new tab
|
2025-08-19 13:31:09 +01:00
|
|
|
window.open(tool.link, '_blank', 'noopener,noreferrer');
|
2025-08-22 13:53:06 +01:00
|
|
|
return;
|
2025-08-19 13:31:09 +01:00
|
|
|
}
|
|
|
|
// Normal tool selection
|
|
|
|
onSelect(id);
|
|
|
|
};
|
|
|
|
|
2025-08-26 11:51:10 +01:00
|
|
|
const tooltipContent = isUnavailable
|
|
|
|
? (<span><strong>Coming soon:</strong> {tool.description}</span>)
|
|
|
|
: tool.description;
|
|
|
|
|
2025-08-19 13:31:09 +01:00
|
|
|
return (
|
2025-08-26 11:51:10 +01:00
|
|
|
<Tooltip content={tooltipContent} position="right" arrow={true} delay={500}>
|
2025-08-19 13:31:09 +01:00
|
|
|
<Button
|
|
|
|
variant={isSelected ? "filled" : "subtle"}
|
|
|
|
onClick={()=> handleClick(id)}
|
2025-08-26 02:54:38 +01:00
|
|
|
size="sm"
|
2025-08-19 13:31:09 +01:00
|
|
|
radius="md"
|
|
|
|
fullWidth
|
|
|
|
justify="flex-start"
|
|
|
|
className="tool-button"
|
2025-08-26 11:51:10 +01:00
|
|
|
aria-disabled={isUnavailable}
|
|
|
|
styles={{ root: { borderRadius: 0, color: "var(--tools-text-and-icon-color)", cursor: isUnavailable ? 'not-allowed' : undefined } }}
|
2025-08-19 13:31:09 +01:00
|
|
|
>
|
2025-08-26 11:51:10 +01:00
|
|
|
<div className="tool-button-icon" style={{ color: "var(--tools-text-and-icon-color)", marginRight: "0.5rem", transform: "scale(0.8)", transformOrigin: "center", opacity: isUnavailable ? 0.25 : 1 }}>{tool.icon}</div>
|
2025-08-19 13:31:09 +01:00
|
|
|
<FitText
|
|
|
|
text={tool.name}
|
|
|
|
lines={1}
|
|
|
|
minimumFontScale={0.8}
|
|
|
|
as="span"
|
2025-08-26 11:51:10 +01:00
|
|
|
style={{ display: 'inline-block', maxWidth: '100%', opacity: isUnavailable ? 0.25 : 1 }}
|
2025-08-19 13:31:09 +01:00
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2025-08-22 13:53:06 +01:00
|
|
|
export default ToolButton;
|