2023-03-14 19:35:24 +01:00
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { Tooltip } from 'react-basics';
|
|
|
|
import styles from './HoverTooltip.module.css';
|
|
|
|
|
2023-05-25 06:40:02 +02:00
|
|
|
export function HoverTooltip({ children }) {
|
2023-03-14 19:35:24 +01:00
|
|
|
const [position, setPosition] = useState({ x: -1000, y: -1000 });
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const handler = e => {
|
|
|
|
setPosition({ x: e.clientX, y: e.clientY });
|
|
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener('mousemove', handler);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
document.removeEventListener('mousemove', handler);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2023-06-16 05:15:31 +02:00
|
|
|
<Tooltip className={styles.tooltip} style={{ left: position.x, top: position.y }}>
|
|
|
|
{children}
|
|
|
|
</Tooltip>
|
2023-03-14 19:35:24 +01:00
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default HoverTooltip;
|