import { useTranslate } from "ra-core";
import * as React from "react";
import type { MouseEvent } from "react";
import { Button } from "@/components/ui/button";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
/**
* A button with a tooltip that ensures the tooltip is closed on click to avoid ghost tooltips.
*
* Prevents ghost tooltips that can appear when the button position changes after interaction.
* Supports internationalization for the label text.
*
* @example
* // Basic usage with icon and label
*
*
*
*/
export const IconButtonWithTooltip = ({
label,
onClick,
children,
disabled,
...props
}: IconButtonWithTooltipProps) => {
const translate = useTranslate();
const [open, setOpen] = React.useState(false);
const handleClose = () => {
setOpen(false);
};
const handleOpen = () => {
setOpen(true);
};
let translatedLabel = label;
if (typeof label === "string") {
translatedLabel = translate(label, { _: label });
}
const handleClick = (event: MouseEvent) => {
handleClose();
onClick?.(event);
};
return (
{translatedLabel}
);
};
export interface IconButtonWithTooltipProps
extends React.ComponentProps<"button"> {
label: React.ReactNode;
children: React.ReactNode;
}