mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-27 07:58:31 -06:00
improved tooltips
This commit is contained in:
28
src/components/useTooltip.ts
Normal file
28
src/components/useTooltip.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { useState, useRef, useCallback } from "react";
|
||||
|
||||
export const useTooltip = (delayMs: number = 150) => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const targetRef = useRef<HTMLAnchorElement>(null);
|
||||
|
||||
const showTooltip = useCallback(() => {
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
setVisible(true);
|
||||
}, delayMs);
|
||||
}, [delayMs]);
|
||||
|
||||
const hideTooltip = useCallback(() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = null;
|
||||
}
|
||||
setVisible(false);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
visible,
|
||||
targetRef,
|
||||
showTooltip,
|
||||
hideTooltip,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user