Browse Source
* fix: changed position of theme button, hiding tooltip after set time. * feat: added usevisibility hook * updating pathspull/745/head
committed by
GitHub
3 changed files with 53 additions and 11 deletions
@ -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; |
|||
} |
|||
Loading…
Reference in new issue