| 1 | import { ReactNode, useMemo } from "react"; |
| 2 | import { Tooltip } from "react-tooltip"; |
| 3 | import { getFontSize } from "../../../util"; |
| 4 | |
| 5 | interface ToolbarButtonWithTooltipProps { |
| 6 | onClick: () => void; |
| 7 | children: ReactNode; |
| 8 | tooltipContent: string; |
| 9 | "data-testid"?: string; |
| 10 | } |
| 11 | |
| 12 | export function ToolbarButtonWithTooltip({ |
| 13 | onClick, |
| 14 | children, |
| 15 | tooltipContent, |
| 16 | "data-testid": testId, |
| 17 | }: ToolbarButtonWithTooltipProps) { |
| 18 | const tooltipId = useMemo( |
| 19 | () => `tooltip-${Math.random().toString(36).slice(2, 11)}`, |
| 20 | [], |
| 21 | ); |
| 22 | |
| 23 | return ( |
| 24 | <> |
| 25 | <button |
| 26 | onClick={onClick} |
| 27 | style={{ |
| 28 | fontSize: `${getFontSize() - 2}px`, |
| 29 | }} |
| 30 | data-tooltip-id={tooltipId} |
| 31 | data-testid={testId} |
| 32 | className="text-foreground flex items-center border-none bg-transparent px-0.5 outline-none hover:cursor-pointer hover:brightness-125" |
| 33 | > |
| 34 | {children} |
| 35 | </button> |
| 36 | <Tooltip id={tooltipId} place="top"> |
| 37 | {tooltipContent} |
| 38 | </Tooltip> |
| 39 | </> |
| 40 | ); |
| 41 | } |