|
1
|
"use client" |
|
2
|
|
|
3
|
import React, { forwardRef, useId } from "react" |
|
4
|
import { Tooltip as ReactTooltip } from "react-tooltip" |
|
5
|
import type { ITooltip } from "react-tooltip" |
|
6
|
import clsx from "clsx" |
|
7
|
import "react-tooltip/dist/react-tooltip.css" |
|
8
|
|
|
9
|
export type TooltipProps = { |
|
10
|
text?: string |
|
11
|
tooltipClassName?: string |
|
12
|
html?: string |
|
13
|
tooltipChildren?: React.ReactNode |
|
14
|
innerClassName?: string |
|
15
|
} & React.HTMLAttributes<HTMLSpanElement> & |
|
16
|
ITooltip |
|
17
|
|
|
18
|
export const Tooltip = forwardRef<HTMLSpanElement, TooltipProps>( |
|
19
|
function Tooltip( |
|
20
|
{ |
|
21
|
text = "", |
|
22
|
tooltipClassName = "", |
|
23
|
children, |
|
24
|
html = "", |
|
25
|
tooltipChildren, |
|
26
|
className, |
|
27
|
innerClassName, |
|
28
|
...tooltipProps |
|
29
|
}, |
|
30
|
ref |
|
31
|
) { |
|
32
|
const elementId = useId() |
|
33
|
|
|
34
|
return ( |
|
35
|
<span className={clsx(className, "notranslate")} translate="no" ref={ref}> |
|
36
|
<span |
|
37
|
id={elementId} |
|
38
|
data-tooltip-content={text} |
|
39
|
data-tooltip-html={html} |
|
40
|
data-tooltip-id={elementId} |
|
41
|
className={innerClassName} |
|
42
|
> |
|
43
|
{children} |
|
44
|
</span> |
|
45
|
<ReactTooltip |
|
46
|
anchorId={elementId} |
|
47
|
// anchorSelect={elementId ? `#${elementId}` : undefined} |
|
48
|
className={clsx( |
|
49
|
"!text-compact-x-small !shadow-elevation-tooltip dark:!shadow-elevation-tooltip-dark !rounded-docs_DEFAULT", |
|
50
|
"!py-docs_0.25 !z-[399] hidden !px-docs_0.5 lg:block", |
|
51
|
"!bg-medusa-bg-component", |
|
52
|
"!text-medusa-fg-base text-center", |
|
53
|
tooltipClassName |
|
54
|
)} |
|
55
|
wrapper="span" |
|
56
|
noArrow={true} |
|
57
|
positionStrategy={"fixed"} |
|
58
|
opacity={1} |
|
59
|
{...tooltipProps} |
|
60
|
> |
|
61
|
{tooltipChildren} |
|
62
|
</ReactTooltip> |
|
63
|
</span> |
|
64
|
) |
|
65
|
} |
|
66
|
) |