feat: sidebar for mobiles

This commit is contained in:
Lucas
2026-10-26 15:27:04 +01:00
parent cb34e5ef41
commit 845b23cf21
7 changed files with 184 additions and 9 deletions
+22
View File
@@ -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(),
};
}