Changed position of theme button, hiding tooltip after set time. (#735)
* fix: changed position of theme button, hiding tooltip after set time. * feat: added usevisibility hook * updating paths
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
export function useToggleVisibility({ timeout }: { timeout?: number } = {}) {
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
const show = useCallback(() => {
|
||||
setIsVisible(true);
|
||||
|
||||
if (timeout) {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
setIsVisible(false);
|
||||
timeoutRef.current = null;
|
||||
}, timeout);
|
||||
}
|
||||
}, [timeout]);
|
||||
|
||||
// Clear timeout on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [isVisible, show] as const;
|
||||
}
|
||||
Reference in New Issue
Block a user