eratic / packages / core / src / components / PhotoGrid.astro
234 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
/**
 * A set of photographs laid out together.
 *
 *   <PhotoGrid photos={frontmatter.photos} columns={2} exif />
 *
 * `photos` is the array from a photo-set's frontmatter: { src, alt, caption }.
 * The grid is intrinsically sized — tall and wide frames keep their own
 * proportions instead of being cropped to a common ratio, which is usually
 * what you want for a set shot on one walk.
 */
import Figure from './Figure.astro';
import type { ImageMetadata } from 'astro';

interface Photo {
	src: ImageMetadata;
	alt: string;
	caption?: string;
}

interface Props {
	photos: Photo[];
	/** Target column count on a wide screen. Collapses to 1 on a phone. */
	columns?: 1 | 2 | 3;
	width?: 'content' | 'wide' | 'full';
	exif?: boolean;
}

const { photos, columns = 2, width = 'wide', exif = false } = Astro.props;
---

<div
	class:list={['photo-grid', width === 'wide' && 'u-wide', width === 'full' && 'u-full']}
	style={`--columns: ${columns}`}
>
	{
		photos.map((photo, index) => (
			<Figure
				src={photo.src}
				alt={photo.alt}
				caption={photo.caption}
				exif={exif}
				priority={index === 0}
			/>
		))
	}
</div>

<style>
	.photo-grid {
		display: grid;
		grid-template-columns: repeat(var(--columns, 2), 1fr);
		gap: var(--space-m);
		margin-block: var(--space-l);
	}

	/* One column below the reading measure — two side-by-side photos on a
	   phone are two photos nobody can see. */
	@media (width < 40rem) {
		.photo-grid {
			grid-template-columns: 1fr;
		}
	}

	.photo-grid :global(figure) {
		margin-block: 0;
	}

	.photo-grid :global(figcaption) {
		max-inline-size: none;
	}
</style>

static mirror of HEAD · about · clone: git clone https://git.makefuture.ro/eratic.git