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