| 1 | import { ReactNode, useMemo } from "react"; |
| 2 | import { Tooltip } from "react-tooltip"; |
| 3 | import styled from "styled-components"; |
| 4 | import { lightGray, vscForeground } from "../.."; |
| 5 | import { getFontSize } from "../../../util"; |
| 6 | |
| 7 | export const ToolbarButton = styled.button` |
| 8 | display: flex; |
| 9 | align-items: center; |
| 10 | border: none; |
| 11 | outline: none; |
| 12 | background: transparent; |
| 13 | |
| 14 | color: ${vscForeground}; |
| 15 | font-size: ${getFontSize() - 2}px; |
| 16 | |
| 17 | &:hover { |
| 18 | cursor: pointer; |
| 19 | filter: brightness(1.25); |
| 20 | } |
| 21 | `; |
| 22 | |
| 23 | interface ToolbarButtonWithTooltipProps { |
| 24 | onClick: () => void; |
| 25 | children: ReactNode; |
| 26 | tooltipContent: string; |
| 27 | "data-testid"?: string; |
| 28 | } |
| 29 | |
| 30 | export function ToolbarButtonWithTooltip({ |
| 31 | onClick, |
| 32 | children, |
| 33 | tooltipContent, |
| 34 | "data-testid": testId, |
| 35 | }: ToolbarButtonWithTooltipProps) { |
| 36 | const tooltipId = useMemo( |
| 37 | () => `tooltip-${Math.random().toString(36).slice(2, 11)}`, |
| 38 | [], |
| 39 | ); |
| 40 | |
| 41 | return ( |
| 42 | <> |
| 43 | <ToolbarButton |
| 44 | onClick={onClick} |
| 45 | style={{ color: lightGray }} |
| 46 | data-tooltip-id={tooltipId} |
| 47 | data-testid={testId} |
| 48 | className="px-0.5" |
| 49 | > |
| 50 | {children} |
| 51 | </ToolbarButton> |
| 52 | <Tooltip id={tooltipId} place="top"> |
| 53 | {tooltipContent} |
| 54 | </Tooltip> |
| 55 | </> |
| 56 | ); |
| 57 | } |