import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" import React, { useState } from "react" export const TAB_NAVBAR_HEIGHT = 24 const BUTTON_MARGIN_RIGHT = "3px" const LAST_BUTTON_MARGIN_RIGHT = "13px" type TabNavbarProps = { onPlusClick: () => void onHistoryClick: () => void onSettingsClick: () => void } type TooltipProps = { text: string isVisible: boolean position: { x: number; y: number } align?: "left" | "center" | "right" } const Tooltip: React.FC = ({ text, isVisible, position, align = "center" }) => { let leftPosition = position.x let triangleStyle: React.CSSProperties = { left: "50%", marginLeft: "-5px", } if (align === "right") { leftPosition = position.x - 10 // Adjust this value as needed triangleStyle = { right: "10px", // Adjust this value to match the tooltip's right padding marginLeft: "0", } } else if (align === "left") { leftPosition = position.x + 10 // Adjust this value as needed triangleStyle = { left: "10px", // Adjust this value to match the tooltip's left padding marginLeft: "0", } } return (
{text}
) } const TabNavbar = ({ onPlusClick, onHistoryClick, onSettingsClick }: TabNavbarProps) => { const [tooltip, setTooltip] = useState({ text: "", isVisible: false, position: { x: 0, y: 0 }, align: "center", }) const showTooltip = (text: string, event: React.MouseEvent, align: "left" | "center" | "right" = "center") => { const rect = event.currentTarget.getBoundingClientRect() setTooltip({ text, isVisible: true, position: { x: rect.left + rect.width / 2, y: rect.bottom + 7 }, align, }) } const hideTooltip = () => { setTooltip((prev) => ({ ...prev, isVisible: false })) } const buttonStyle = { marginRight: BUTTON_MARGIN_RIGHT, } const lastButtonStyle = { ...buttonStyle, marginRight: LAST_BUTTON_MARGIN_RIGHT, } return ( <>
showTooltip("New Chat", e, "center")} onMouseLeave={hideTooltip} onMouseMove={(e) => showTooltip("New Chat", e, "center")}> showTooltip("History", e, "center")} onMouseLeave={hideTooltip} onMouseMove={(e) => showTooltip("History", e, "center")}> showTooltip("Settings", e, "right")} onMouseLeave={hideTooltip} onMouseMove={(e) => showTooltip("Settings", e, "right")}>
) } export default TabNavbar