2023-12-13 14:32:57 +03:00
|
|
|
'use client';
|
|
|
|
|
2025-02-21 21:15:05 +03:00
|
|
|
import { type ReactNode } from 'react';
|
2023-12-07 01:33:34 +03:00
|
|
|
import { createPortal } from 'react-dom';
|
2025-02-21 21:15:05 +03:00
|
|
|
import { type ITooltip, Tooltip as TooltipImpl } from 'react-tooltip';
|
2025-02-12 21:36:25 +03:00
|
|
|
import clsx from 'clsx';
|
2023-07-30 16:48:25 +03:00
|
|
|
|
2025-01-15 16:06:42 +03:00
|
|
|
import { usePreferencesStore } from '@/stores/preferences';
|
2023-07-30 16:48:25 +03:00
|
|
|
|
2024-01-06 03:15:02 +03:00
|
|
|
export type { PlacesType } from 'react-tooltip';
|
|
|
|
|
2024-01-04 19:30:10 +03:00
|
|
|
interface TooltipProps extends Omit<ITooltip, 'variant'> {
|
2024-11-21 15:09:51 +03:00
|
|
|
/** Text to display in the tooltip. */
|
2023-12-28 14:04:44 +03:00
|
|
|
text?: string;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
/** Classname for z-index */
|
|
|
|
layer?: string;
|
2023-07-30 16:48:25 +03:00
|
|
|
}
|
|
|
|
|
2024-11-21 15:09:51 +03:00
|
|
|
/**
|
|
|
|
* Displays content in a tooltip container.
|
|
|
|
*/
|
2025-02-07 10:54:47 +03:00
|
|
|
export function Tooltip({
|
2023-12-28 14:04:44 +03:00
|
|
|
text,
|
|
|
|
children,
|
|
|
|
layer = 'z-tooltip',
|
|
|
|
place = 'bottom',
|
2023-12-18 19:42:27 +03:00
|
|
|
className,
|
2023-11-24 18:03:10 +03:00
|
|
|
style,
|
2023-11-27 13:50:56 +03:00
|
|
|
...restProps
|
2024-01-04 19:30:10 +03:00
|
|
|
}: TooltipProps) {
|
2025-01-15 16:06:42 +03:00
|
|
|
const darkMode = usePreferencesStore(state => state.darkMode);
|
2023-12-13 14:32:57 +03:00
|
|
|
if (typeof window === 'undefined') {
|
|
|
|
return null;
|
|
|
|
}
|
2023-12-07 01:33:34 +03:00
|
|
|
return createPortal(
|
2024-01-04 19:30:10 +03:00
|
|
|
<TooltipImpl
|
2024-08-25 13:49:28 +03:00
|
|
|
delayShow={750}
|
2023-12-28 14:04:44 +03:00
|
|
|
delayHide={100}
|
2024-08-19 22:03:39 +03:00
|
|
|
opacity={1}
|
2024-05-20 17:45:37 +03:00
|
|
|
className={clsx(
|
2025-03-07 20:38:40 +03:00
|
|
|
'relative',
|
2024-06-09 20:41:33 +03:00
|
|
|
'max-h-[calc(100svh-6rem)]',
|
|
|
|
'overflow-y-auto overflow-x-hidden sm:overflow-hidden overscroll-contain',
|
2024-05-20 17:45:37 +03:00
|
|
|
'border shadow-md',
|
2024-09-12 11:17:01 +03:00
|
|
|
'text-pretty',
|
2024-05-20 17:45:37 +03:00
|
|
|
layer,
|
|
|
|
className
|
|
|
|
)}
|
2023-12-28 14:04:44 +03:00
|
|
|
classNameArrow={layer}
|
2024-09-12 11:17:01 +03:00
|
|
|
style={{ ...{ paddingTop: '2px', paddingBottom: '2px', paddingLeft: '8px', paddingRight: '8px' }, ...style }}
|
2023-12-28 14:04:44 +03:00
|
|
|
variant={darkMode ? 'dark' : 'light'}
|
|
|
|
place={place}
|
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{text ? text : null}
|
|
|
|
{children as ReactNode}
|
2024-01-04 19:30:10 +03:00
|
|
|
</TooltipImpl>,
|
2023-12-28 14:04:44 +03:00
|
|
|
document.body
|
|
|
|
);
|
2023-07-30 16:48:25 +03:00
|
|
|
}
|