Adds the shared gallery building blocks
A masonry photo grid that keeps the reading order (pure CSS, no measuring in the browser), an accessible lightbox on Chakra's Dialog with wrap-around browsing, keys, swipe and preloading, and a filter bar of toggle buttons. They work on generic gallery items, so other pages can use them. The swipe logic moves out of the hero into a shared hook; the hero behaves as before. The rules behind them live in pure helpers with property-based tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useMediaQuery } from '@chakra-ui/react';
|
||||
|
||||
// Minimale horizontale afstand in px voordat een veeg als swipe telt
|
||||
const SWIPE_THRESHOLD = 50;
|
||||
import useSwipe from '@/hooks/useSwipe';
|
||||
import { wrapIndex } from '@/lib/wrapIndex';
|
||||
|
||||
// Houdt de actieve slide bij en of autoplay mag lopen. Het doorschuiven zelf
|
||||
// gebeurt via de animatie van de voortgangsbalk (zie Hero.tsx), zodat pauzeren
|
||||
@@ -27,7 +26,6 @@ export default function useHeroSlider(count: number) {
|
||||
ssr: false,
|
||||
},
|
||||
);
|
||||
const touchStart = useRef<{ x: number; y: number } | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const onVisibilityChange = () => setHidden(document.hidden);
|
||||
@@ -43,11 +41,13 @@ export default function useHeroSlider(count: number) {
|
||||
const active = index < count ? index : 0;
|
||||
|
||||
const go = (to: number, visitor: boolean) => {
|
||||
setIndex((to + count) % count);
|
||||
setIndex(wrapIndex(to, count));
|
||||
setAnnouncement(visitor ? 'slide' : null);
|
||||
};
|
||||
const next = () => go(active + 1, true);
|
||||
const prev = () => go(active - 1, true);
|
||||
// Swiping only makes sense with something to swipe to
|
||||
const swipe = useSwipe({ onPrev: prev, onNext: next, enabled: count > 1 });
|
||||
|
||||
return {
|
||||
active,
|
||||
@@ -85,28 +85,7 @@ export default function useHeroSlider(count: number) {
|
||||
setFocused(false);
|
||||
}
|
||||
},
|
||||
onTouchStart: (event: React.TouchEvent<HTMLElement>) => {
|
||||
const touch = event.touches[0];
|
||||
touchStart.current = { x: touch.clientX, y: touch.clientY };
|
||||
},
|
||||
onTouchEnd: (event: React.TouchEvent<HTMLElement>) => {
|
||||
const start = touchStart.current;
|
||||
touchStart.current = null;
|
||||
if (!start || count < 2) return;
|
||||
|
||||
const touch = event.changedTouches[0];
|
||||
const dx = touch.clientX - start.x;
|
||||
const dy = touch.clientY - start.y;
|
||||
|
||||
// Horizontaal genoeg, en niet bedoeld als verticaal scrollen
|
||||
if (
|
||||
Math.abs(dx) < SWIPE_THRESHOLD ||
|
||||
Math.abs(dx) < Math.abs(dy)
|
||||
)
|
||||
return;
|
||||
if (dx < 0) next();
|
||||
else prev();
|
||||
},
|
||||
...swipe,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user