mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* add animation for grot not found * extract default interval out into constant * improve relative path * extract magic numbers out into constants + throttle properly * better width/height definitions * use consistent background + apply to PageNotFound as well * increase gap in command palette empty state
30 lines
853 B
TypeScript
30 lines
853 B
TypeScript
import { throttle } from 'lodash';
|
|
import { useState, useEffect } from 'react';
|
|
|
|
interface MousePosition {
|
|
x: number | null;
|
|
y: number | null;
|
|
}
|
|
|
|
// For performance reasons, we throttle the mouse position updates
|
|
const DEFAULT_THROTTLE_INTERVAL_MS = 50;
|
|
|
|
const useMousePosition = (throttleInterval = DEFAULT_THROTTLE_INTERVAL_MS) => {
|
|
const [mousePosition, setMousePosition] = useState<MousePosition>({ x: null, y: null });
|
|
|
|
useEffect(() => {
|
|
const updateMousePosition = throttle((event: MouseEvent) => {
|
|
setMousePosition({ x: event.clientX, y: event.clientY });
|
|
}, throttleInterval);
|
|
window.addEventListener('mousemove', updateMousePosition);
|
|
|
|
return () => {
|
|
window.removeEventListener('mousemove', updateMousePosition);
|
|
};
|
|
}, [throttleInterval]);
|
|
|
|
return mousePosition;
|
|
};
|
|
|
|
export default useMousePosition;
|