// The photo mosaic of a shoot page: a 4 x 2 grid from `md`, two columns on // phones (FR-ST-05). Each tile says where it sits; the component only // draws them. // The most photos the mosaic shows; more stay in the content export const MOSAIC_MAX_PHOTOS = 4; export interface MosaicTile { // CSS grid-column from `md`, e.g. '1 / 3' column: string; // CSS grid-row from `md` row: string; // Spans both columns below `md` wide: boolean; // Aspect ratio of the tile below `md` phoneRatio: '4 / 3' | '3 / 2' | '1 / 1'; } const large: MosaicTile = { column: '1 / 3', row: '1 / 3', wide: true, phoneRatio: '4 / 3', }; const layouts: Record<1 | 2 | 3 | 4, readonly MosaicTile[]> = { // Never shown (the view needs at least two photos), kept so that the // function is total 1: [{ column: '1 / 5', row: '1 / 3', wide: true, phoneRatio: '4 / 3' }], 2: [large, { ...large, column: '3 / 5' }], 3: [ large, { column: '3 / 5', row: '1 / 2', wide: true, phoneRatio: '3 / 2' }, { column: '3 / 5', row: '2 / 3', wide: true, phoneRatio: '3 / 2' }, ], 4: [ large, { column: '3 / 5', row: '1 / 2', wide: true, phoneRatio: '3 / 2' }, { column: '3 / 4', row: '2 / 3', wide: false, phoneRatio: '1 / 1' }, { column: '4 / 5', row: '2 / 3', wide: false, phoneRatio: '1 / 1' }, ], }; // The tiles for `count` photos. Nothing for a count below 1 or one that is // not a whole number (fail safe); five or more get the layout for four. export function mosaicLayout(count: number): MosaicTile[] { if (!Number.isInteger(count) || count < 1) return []; const key = Math.min(count, MOSAIC_MAX_PHOTOS) as 1 | 2 | 3 | 4; return layouts[key].map((tile) => ({ ...tile })); }