import { useRef, type MouseEvent } from 'react'; import { Box, chakra, Image, VisuallyHidden } from '@chakra-ui/react'; import DeferredImage from '@/components/DeferredImage/DeferredImage'; import Reveal from '@/components/Reveal/Reveal'; import type { GalleryItem } from '@/content/types'; import { GAP_ROWS, masonryRowSpan, ROWS_PER_COLUMN_WIDTH, } from '@/lib/masonryRowSpan'; type PortfolioGridProps = { items: readonly GalleryItem[]; // How many photos at the start load straight away (the first row on // desktop); the rest wait until the page has loaded and they are near eagerCount?: number; onOpen: (index: number) => void; // First hover or focus on a photo: a good moment to load the lightbox onIntent?: () => void; 'data-testid'?: string; }; // Masonry grid of photos in reading order (design .portfolio-grid): every // photo is shown whole in its own shape, row by row, so keyboard and screen // reader follow the order Andrea chose. Pure CSS: the implicit rows are a // fraction of the column width (container units) and each photo spans as // many as its aspect ratio needs, so nothing shifts while photos load. // Every photo is a link to its large version; a plain click asks the page // to open the lightbox instead. export default function PortfolioGrid({ items, eagerCount = 3, onOpen, onIntent, 'data-testid': testId = 'portfolio-grid', }: PortfolioGridProps) { const intentReported = useRef(false); const reportIntent = () => { if (intentReported.current) return; intentReported.current = true; onIntent?.(); }; const handleClick = ( event: MouseEvent, index: number, ) => { // Ctrl/Cmd/Shift/Alt or middle click: let the browser open the link if ( event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey ) { return; } event.preventDefault(); onOpen(index); }; return ( {items.map((item, index) => { const span = masonryRowSpan(item.thumb); const imageStyle = { display: 'block', w: '100%', h: '100%', objectFit: 'cover', transitionProperty: 'transform', transitionDuration: 'interaction', transitionTimingFunction: 'smooth', _groupHover: { transform: 'scale(1.05)' }, _groupFocusVisible: { transform: 'scale(1.05)' }, _motionReduce: { transform: 'none !important' }, } as const; return ( handleClick(event, index) } onPointerEnter={reportIntent} onFocus={reportIntent} > {index < eagerCount ? ( {item.thumb.alt} ) : ( )} {/* The alt names the photo; this says what the link does */}{' '} (groot bekijken) ); })} ); }