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:
2026-10-25 23:22:43 +01:00
co-authored by Claude Opus 5.5
parent e013f1436b
commit 18bf0311ef
38 changed files with 2392 additions and 43 deletions
+61
View File
@@ -1,8 +1,11 @@
import fc from 'fast-check';
import type { ContactField, ContactValues } from '../contact/types';
import type { ContactFormEvent } from '../lib/contactFormReducer';
import type { LightboxEvent } from '../lib/lightboxReducer';
import type { Point } from '../lib/swipeDirection';
import type {
EmailAddress,
GalleryItem,
FrameColor,
PricingPackage,
ShootType,
@@ -317,3 +320,61 @@ export const contactEvent: fc.Arbitrary<ContactFormEvent> = fc.oneof(
fc.constant({ type: 'resolved' as const }),
fc.constant({ type: 'rejected' as const }),
);
// --- Gallery (portfolio) ---
// A touch position on a screen, in CSS pixels
export const point: fc.Arbitrary<Point> = fc.record({
x: fc.integer({ min: 0, max: 2000 }),
y: fc.integer({ min: 0, max: 3000 }),
});
// The intrinsic size of a photo: realistic pixel sizes, from very wide
// panoramas to tall portraits
export const imageSize = fc.record({
width: fc.integer({ min: 200, max: 4000 }),
height: fc.integer({ min: 200, max: 4000 }),
});
export const galleryItem: fc.Arbitrary<GalleryItem> = fc
.tuple(
fc.stringMatching(/^[a-z0-9-]{1,12}$/),
imageSize,
fc.integer({ min: 2, max: 3 }),
nonBlank,
fc.option(nonBlank, { nil: undefined }),
)
.map(([id, size, factor, alt, caption]) => ({
id,
thumb: { src: `/${id}-thumb.jpg`, alt, ...size },
full: {
src: `/${id}.jpg`,
width: size.width * factor,
height: size.height * factor,
},
caption,
}));
export const galleryItems = fc.uniqueArray(galleryItem, {
selector: (item) => item.id,
minLength: 1,
maxLength: 12,
});
// Anything that can happen to the lightbox, for the state machine test
export const lightboxEvent: fc.Arbitrary<LightboxEvent> = fc.oneof(
fc.record({
type: fc.constant('open' as const),
index: fc.integer({ min: -3, max: 15 }),
count: fc.integer({ min: 0, max: 12 }),
}),
fc.constant({ type: 'next' as const }),
fc.constant({ type: 'prev' as const }),
fc.constant({ type: 'first' as const }),
fc.constant({ type: 'last' as const }),
fc.constant({ type: 'close' as const }),
fc.record({
type: fc.constant('listChanged' as const),
count: fc.integer({ min: 0, max: 12 }),
}),
);