feat: sidebar for mobiles
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { useRef } from 'react';
|
||||
|
||||
export function useLongPress(
|
||||
onLong: (e: React.PointerEvent, el: HTMLElement) => void,
|
||||
ms = 500
|
||||
) {
|
||||
const timer = useRef<number>(0);
|
||||
const clear = () => window.clearTimeout(timer.current);
|
||||
|
||||
return {
|
||||
onPointerDown: (e: React.PointerEvent<HTMLElement>) => {
|
||||
if (e.pointerType !== 'touch') return; // mouse keeps double-click
|
||||
const el = e.currentTarget; // currentTarget is null inside a timeout
|
||||
clear();
|
||||
timer.current = window.setTimeout(() => onLong(e, el), ms);
|
||||
},
|
||||
onPointerUp: clear,
|
||||
onPointerLeave: clear,
|
||||
onPointerCancel: clear, // fires when the user scrolls
|
||||
onContextMenu: (e: React.MouseEvent) => e.preventDefault(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user