mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-08 23:21:58 +02:00
- Add hamburger drawer navigation for mobile (< 768px) - Create useIsMobile hook for responsive breakpoint detection - Create useLongPress hook for touch gesture context menus - Update Button component with 44px min-height for WCAG touch compliance - Update Toggle component with larger mobile size (44x28px) - Add responsive padding (p-4 md:p-8) to all pages - Update ArchivesPage with mobile menu button and horizontal scroll filters - Update SettingsPage with stacked column layout on mobile - Increase drag handle sizes for touch-friendly reordering - Add CSS utilities for touch-manipulation and safe-area insets
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { useCallback, useRef } from 'react';
|
|
|
|
interface LongPressOptions {
|
|
onLongPress: (e: React.TouchEvent | React.MouseEvent) => void;
|
|
onClick?: () => void;
|
|
delay?: number;
|
|
}
|
|
|
|
export function useLongPress({ onLongPress, onClick, delay = 500 }: LongPressOptions) {
|
|
const timeoutRef = useRef<number | null>(null);
|
|
const targetRef = useRef<EventTarget | null>(null);
|
|
const longPressTriggered = useRef(false);
|
|
|
|
const start = useCallback(
|
|
(e: React.TouchEvent | React.MouseEvent) => {
|
|
longPressTriggered.current = false;
|
|
targetRef.current = e.target;
|
|
timeoutRef.current = window.setTimeout(() => {
|
|
longPressTriggered.current = true;
|
|
onLongPress(e);
|
|
}, delay);
|
|
},
|
|
[onLongPress, delay]
|
|
);
|
|
|
|
const clear = useCallback(
|
|
(e: React.TouchEvent | React.MouseEvent, shouldTriggerClick = true) => {
|
|
if (timeoutRef.current) {
|
|
clearTimeout(timeoutRef.current);
|
|
timeoutRef.current = null;
|
|
}
|
|
if (shouldTriggerClick && !longPressTriggered.current && onClick && targetRef.current === e.target) {
|
|
onClick();
|
|
}
|
|
},
|
|
[onClick]
|
|
);
|
|
|
|
return {
|
|
onMouseDown: start,
|
|
onMouseUp: (e: React.MouseEvent) => clear(e, true),
|
|
onMouseLeave: (e: React.MouseEvent) => clear(e, false),
|
|
onTouchStart: start,
|
|
onTouchEnd: (e: React.TouchEvent) => clear(e, true),
|
|
};
|
|
}
|