File size: 2,116 Bytes
baa4c21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as Tooltip from '@radix-ui/react-tooltip';
import { forwardRef, type ForwardedRef, type ReactElement } from 'react';

interface TooltipProps {
  tooltip: React.ReactNode;
  children: ReactElement;
  sideOffset?: number;
  className?: string;
  arrowClassName?: string;
  tooltipStyle?: React.CSSProperties;
  position?: 'top' | 'bottom' | 'left' | 'right';
  maxWidth?: number;
  delay?: number;
}

const WithTooltip = forwardRef(
  (

    {

      tooltip,

      children,

      sideOffset = 5,

      className = '',

      arrowClassName = '',

      tooltipStyle = {},

      position = 'top',

      maxWidth = 250,

      delay = 0,

    }: TooltipProps,

    _ref: ForwardedRef<HTMLElement>,

  ) => {
    return (
      <Tooltip.Root delayDuration={delay}>

        <Tooltip.Trigger asChild>{children}</Tooltip.Trigger>

        <Tooltip.Portal>

          <Tooltip.Content

            side={position}

            className={`

              z-[2000]

              px-2.5

              py-1.5

              max-h-[300px]

              select-none

              rounded-md

              bg-bolt-elements-background-depth-3

              text-bolt-elements-textPrimary

              text-sm

              leading-tight

              shadow-lg

              animate-in

              fade-in-0

              zoom-in-95

              data-[state=closed]:animate-out

              data-[state=closed]:fade-out-0

              data-[state=closed]:zoom-out-95

              ${className}

            `}

            sideOffset={sideOffset}

            style={{

              maxWidth,

              ...tooltipStyle,

            }}

          >

            <div className="break-words">{tooltip}</div>

            <Tooltip.Arrow

              className={`

                fill-bolt-elements-background-depth-3

                ${arrowClassName}

              `}

              width={12}

              height={6}

            />

          </Tooltip.Content>

        </Tooltip.Portal>

      </Tooltip.Root>
    );
  },
);

export default WithTooltip;