// Copyright 2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import { Manager, Reference, Popper } from 'react-popper'; import { Theme, themeClassName } from '../util/theme'; export enum TooltipPlacement { Top = 'top', Right = 'right', Bottom = 'bottom', Left = 'left', } export type PropsType = { content: string | JSX.Element; direction?: TooltipPlacement; sticky?: boolean; theme?: Theme; }; export const Tooltip: React.FC = ({ children, content, direction, sticky, theme, }) => { const isSticky = Boolean(sticky); const [showTooltip, setShowTooltip] = React.useState(isSticky); const tooltipTheme = theme ? themeClassName(theme) : undefined; return ( {({ ref }) => ( { if (!isSticky) { setShowTooltip(false); } }} onFocus={() => { if (!isSticky) { setShowTooltip(true); } }} onMouseEnter={() => { if (!isSticky) { setShowTooltip(true); } }} onMouseLeave={() => { if (!isSticky) { setShowTooltip(false); } }} ref={ref} > {children} )} {({ arrowProps, placement, ref, style }) => showTooltip && (
{content}
) } ); };