mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
5bc2e7e62e
* 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
39 lines
958 B
TypeScript
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 };
|
|
}
|