Files
AndreaSlopFotografie/aidlc-docs/features/portfolio-page/construction/gallery-blocks/code/code-summary.md
T
SluijsensandClaude Opus 5.5 18bf0311ef 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>
2026-10-25 23:22:43 +01:00

3.7 KiB
Raw Blame History

Code Summary — Unit 2: Gallery building blocks

Plan: gallery-blocks-code-generation-plan.md · Design: functional-design/

Created (web/src/)

File What
lib/wrapIndex.ts (+ test) Position that wraps both ways; PBT: range, periodicity, idempotence, round-trip, oracle (step-by-step)
lib/swipeDirection.ts (+ test) next/prev/null from two touch points, SWIPE_THRESHOLD = 50; PBT: mirror, translation, threshold rule
lib/masonryRowSpan.ts (+ test) Row span from aspect ratio (ROWS_PER_COLUMN_WIDTH = 40, GAP_ROWS = 2); PBT: minimum, monotonic, scale invariance, ≤ ½ row crop
lib/neighbourIndexes.ts (+ test) Large photos to preload around the current one; PBT: unique, excludes current, size, oracle (brute force)
lib/lightboxReducer.ts (+ test) Lightbox state machine; stateful PBT against a model
hooks/useSwipe.ts (+ test) Touch handlers on top of swipeDirection
recipes/filterControl.ts Eyebrow-style toggle button, pressed = accent.deep + 2 px underline
components/FilterBar/ (+ test) Group of toggle buttons with aria-pressed; nothing for < 2 options
components/PortfolioGrid/ (+ test) CSS-only masonry in reading order (--cols, --row in container units), first 3 eager with fetchPriority="high", tile = link to the large photo, modifier clicks left to the browser, onIntent once
components/Lightbox/ (+ test) Chakra Dialog (unstyled), wrap-around browsing with buttons/arrows/Home/End/swipe, counter, caption, announcement, thumb while loading, error note, preload 2 each side, phone bottom bar, crossfade (0.3 s, off under reduced motion); default export for React.lazy
test/galleryFixtures.ts Gallery items from the homepage intro photos

Modified

File Change
content/types.ts ImageSource, GalleryItem, FilterOption
test/arbitraries.ts point, imageSize, galleryItem, galleryItems, lightboxEvent
theme.ts Duration token swap (0.3 s); recipe filterControl registered (typegen run)
components/Hero/useHeroSlider.ts Uses useSwipe (enabled with more than one slide) and wrapIndex; inline touch handlers and local threshold removed. Hero tests unchanged and passing

Docs: own RE lines (code-structure, architecture, api-documentation).

Verification

  • tsc, ESLint, Prettier: clean. ESLint flagged setState inside effects in the first Lightbox version; fixed at the cause (load state lives in the keyed Photo; announcement reset during render when open changes), not by disabling the rule.
  • Tests: ✅ 80 files, 426 tests (coverage thresholds met).
  • Generated masonry CSS checked in jsdom: --cols 1/2/3 per breakpoint, --row uses var(--slp-spacing-grid-gap), tiles span n, photo height 100% - 2 × --row.
  • jsdom limits, handled in the tests with comments: the focus trap needs layout boxes (focus test stubs getClientRects); Chakra unmounts after the fade-out, which needs real animation events, so the close test checks data-state="closed" and onClose.
  • Lighthouse desktop: ✅ all 7 URLs.
  • Lighthouse mobile: ❌ / (0.75, rerun 0.79; budget 0.8) and /contact (0.88; budget 0.9). Pre-existing, not caused by this unit: master measured right before on the same machine gives / 0.78 and /contact 0.88; this unit adds 0.54 kB (0.12 kB gzip) to the main bundle and no route of these pages renders the new components. Known open item (memory note "Open follow-ups", owner chose to handle it separately). Portfolio itself was not measured as a real page yet (still the placeholder until unit 3).
  • Visual check: deferred to unit 3 (the components are on no page yet).