mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-12 12:37:33 +01:00
28 lines
670 B
JavaScript
28 lines
670 B
JavaScript
import { useEffect, useState } from 'react';
|
|
import { Tooltip } from 'react-basics';
|
|
import styles from './HoverTooltip.module.css';
|
|
|
|
export function HoverTooltip({ children }) {
|
|
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 (
|
|
<Tooltip className={styles.tooltip} style={{ left: position.x, top: position.y }}>
|
|
{children}
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
export default HoverTooltip;
|