Files
outline/app/hooks/useClickIntent.ts
T
Tom Moor 5bc2e7e62e Sidebar design tweaks (#10684)
* Single line sidebar items

* fix: Letter icon in breadcrumb missing letter
Alignment of sidebar items

* fix: Editing state

* fix: Shared sidebar

* fix: Drag over unloaded document in sidebar does not allow drop

* perf

* Sidebar hover background

* Allow click toggle closed

* fix: Disclosure toggle

* perf: Avoid rendering collapsed folders
2025-11-23 11:38:40 +01:00

39 lines
958 B
TypeScript

import * as React from "react";
import useUnmount from "./useUnmount";
/**
* Hook to handle click intent logic with mouse enter/leave events.
* Sets a timer on mouse enter to call the intent callback after a delay,
* and clears the timer on mouse leave or component unmount.
*/
export default function useClickIntent(
onClickIntent?: React.MouseEventHandler<HTMLElement>,
delay = 100
) {
const timer = React.useRef<number>();
const handleMouseEnter = React.useCallback(() => {
if (timer.current) {
clearTimeout(timer.current);
}
if (onClickIntent) {
timer.current = window.setTimeout(onClickIntent, delay);
}
}, [onClickIntent, delay]);
const handleMouseLeave = React.useCallback(() => {
if (timer.current) {
clearTimeout(timer.current);
}
}, []);
useUnmount(() => {
if (timer.current) {
clearTimeout(timer.current);
}
});
return { handleMouseEnter, handleMouseLeave };
}