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>
23 lines
905 B
TypeScript
23 lines
905 B
TypeScript
// The masonry grid is a CSS grid with very small implicit rows: one row is
|
|
// 1/ROWS_PER_COLUMN_WIDTH of the column width, so a photo's height in rows
|
|
// follows from its aspect ratio alone, at any screen width. No measuring in
|
|
// the browser, so nothing shifts while photos load.
|
|
export const ROWS_PER_COLUMN_WIDTH = 40;
|
|
|
|
// Vertical space between two photos, in rows (about 5% of the column width)
|
|
export const GAP_ROWS = 2;
|
|
|
|
// How many implicit rows a photo spans: its height at the column width, in
|
|
// rows, plus the gap below it. Rounding crops at most half a row.
|
|
export function masonryRowSpan(
|
|
image: { width: number; height: number },
|
|
rowsPerColumnWidth: number = ROWS_PER_COLUMN_WIDTH,
|
|
gapRows: number = GAP_ROWS,
|
|
): number {
|
|
const photoRows = Math.max(
|
|
1,
|
|
Math.round((rowsPerColumnWidth * image.height) / image.width),
|
|
);
|
|
return photoRows + gapRows;
|
|
}
|