2024-11-22 09:05:18 +00:00
|
|
|
import * as Tooltip from '@radix-ui/react-tooltip';
|
|
|
|
|
2024-11-25 15:16:49 +00:00
|
|
|
interface TooltipProps {
|
|
|
|
tooltip: React.ReactNode;
|
|
|
|
children: React.ReactNode;
|
2024-11-22 22:29:16 +00:00
|
|
|
sideOffset?: number;
|
|
|
|
className?: string;
|
|
|
|
arrowClassName?: string;
|
2024-11-25 15:16:49 +00:00
|
|
|
tooltipStyle?: React.CSSProperties;
|
|
|
|
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
|
|
maxWidth?: number;
|
|
|
|
delay?: number;
|
2024-11-22 09:51:52 +00:00
|
|
|
}
|
|
|
|
|
2024-11-22 22:29:16 +00:00
|
|
|
const WithTooltip = ({
|
|
|
|
tooltip,
|
|
|
|
children,
|
|
|
|
sideOffset = 5,
|
|
|
|
className = '',
|
|
|
|
arrowClassName = '',
|
|
|
|
tooltipStyle = {},
|
2024-11-25 15:16:49 +00:00
|
|
|
position = 'top',
|
|
|
|
maxWidth = 250,
|
|
|
|
delay = 0,
|
|
|
|
}: TooltipProps) => {
|
2024-11-22 09:05:18 +00:00
|
|
|
return (
|
2024-11-25 15:16:49 +00:00
|
|
|
<Tooltip.Root delayDuration={delay}>
|
2024-11-22 22:29:16 +00:00
|
|
|
<Tooltip.Trigger asChild>{children}</Tooltip.Trigger>
|
2024-11-22 09:05:18 +00:00
|
|
|
<Tooltip.Portal>
|
|
|
|
<Tooltip.Content
|
2024-11-25 15:16:49 +00:00
|
|
|
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}
|
|
|
|
`}
|
2024-11-22 09:05:18 +00:00
|
|
|
sideOffset={sideOffset}
|
2024-11-25 15:16:49 +00:00
|
|
|
style={{
|
|
|
|
maxWidth,
|
|
|
|
...tooltipStyle,
|
|
|
|
}}
|
2024-11-22 09:05:18 +00:00
|
|
|
>
|
2024-11-25 15:16:49 +00:00
|
|
|
<div className="break-words">{tooltip}</div>
|
|
|
|
<Tooltip.Arrow
|
|
|
|
className={`
|
|
|
|
fill-bolt-elements-background-depth-3
|
|
|
|
${arrowClassName}
|
|
|
|
`}
|
|
|
|
width={12}
|
|
|
|
height={6}
|
|
|
|
/>
|
2024-11-22 09:05:18 +00:00
|
|
|
</Tooltip.Content>
|
|
|
|
</Tooltip.Portal>
|
|
|
|
</Tooltip.Root>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WithTooltip;
|