summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/components/TextPopover.tsx
blob: 3649e0453cae0eb6429d7de3ea44afc5a82d59a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { FunctionComponent, ReactElement } from "react";
import { Tooltip, TooltipProps } from "@mantine/core";
import { isNull, isUndefined } from "lodash";

interface TextPopoverProps {
  children: ReactElement;
  text: string | undefined | null;
  tooltip?: Omit<TooltipProps, "opened" | "label" | "children">;
}

const TextPopover: FunctionComponent<TextPopoverProps> = ({
  children,
  text,
  tooltip,
}) => {
  if (isNull(text) || isUndefined(text)) {
    return children;
  }

  return (
    <Tooltip
      label={text}
      {...tooltip}
      style={{ textWrap: "wrap" }}
      events={{ hover: true, focus: false, touch: true }}
    >
      <div>{children}</div>
    </Tooltip>
  );
};

export default TextPopover;