Skip to content

Commit f569ff9

Browse files
committed
feat: Support providing different image sizes for the grid, modal, and thumbnail
1 parent d419e10 commit f569ff9

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/ImageGallery.test.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ const imagesArray = [
1414
id: crypto.randomUUID(),
1515
alt: "Image2's alt text",
1616
caption: "Image2's description",
17-
src: "https://cdn.pixabay.com/photo/2023/05/21/11/45/flowers-8008392_1280.jpg",
17+
src: "https://images.unsplash.com/photo-1526047932273-341f2a7631f9?q=80&w=2400",
18+
gridSrc:
19+
"https://images.unsplash.com/photo-1526047932273-341f2a7631f9?q=80&w=1920",
20+
thumbSrc:
21+
"https://images.unsplash.com/photo-1526047932273-341f2a7631f9?q=80&w=640",
1822
},
1923
{
2024
id: crypto.randomUUID(),
@@ -32,7 +36,11 @@ const imagesArray = [
3236
id: crypto.randomUUID(),
3337
alt: "Image5's alt text",
3438
caption: "Image5's description",
35-
src: "https://cdn.pixabay.com/photo/2023/05/09/17/20/flowers-7982037_1280.jpg",
39+
src: "https://images.unsplash.com/photo-1519016871193-d90e3a64d0f5?q=80&w=1974",
40+
gridSrc:
41+
"https://images.unsplash.com/photo-1519016871193-d90e3a64d0f5?q=80&w=1494",
42+
thumbSrc:
43+
"https://images.unsplash.com/photo-1519016871193-d90e3a64d0f5?q=80&w=214",
3644
},
3745
{
3846
id: crypto.randomUUID(),
@@ -44,48 +52,56 @@ const imagesArray = [
4452
id: crypto.randomUUID(),
4553
alt: "Image7's alt text",
4654
src: "https://cdn.pixabay.com/photo/2023/05/25/22/07/river-8018379_1280.jpg",
47-
smallSrc:
55+
thumbSrc:
4856
"https://cdn.pixabay.com/photo/2023/05/25/22/07/river-8018379_640.jpg",
4957
},
5058
{
5159
id: crypto.randomUUID(),
5260
alt: "Image8's alt text",
5361
src: "https://cdn.pixabay.com/photo/2023/05/21/11/45/flowers-8008392_1280.jpg",
54-
smallSrc:
62+
thumbSrc:
5563
"https://cdn.pixabay.com/photo/2023/05/21/11/45/flowers-8008392_640.jpg",
5664
},
5765
{
5866
id: crypto.randomUUID(),
5967
alt: "Image9's alt text",
6068
caption: "Image9's description",
6169
src: "https://cdn.pixabay.com/photo/2020/09/14/15/10/birch-tree-5571242_1280.png",
62-
smallSrc:
70+
thumbSrc:
6371
"https://cdn.pixabay.com/photo/2020/09/14/15/10/birch-tree-5571242_640.png",
6472
},
6573
{
6674
id: crypto.randomUUID(),
6775
alt: "Image10's alt text",
6876
caption: "Image10's description",
69-
src: "https://cdn.pixabay.com/photo/2021/05/06/16/13/children-6233868_1280.png",
70-
smallSrc:
71-
"https://cdn.pixabay.com/photo/2021/05/06/16/13/children-6233868_640.png",
77+
src: "https://images.unsplash.com/photo-1549490349-8643362247b5?q=80&w=1974",
78+
gridSrc:
79+
"https://images.unsplash.com/photo-1549490349-8643362247b5?q=80&w=1494",
80+
thumbSrc:
81+
"https://images.unsplash.com/photo-1549490349-8643362247b5?q=80&w=214",
7282
},
7383
{
7484
id: crypto.randomUUID(),
7585
alt: "Image11's alt text",
7686
caption: "Image11's description",
7787
src: "https://cdn.pixabay.com/photo/2023/05/09/17/20/flowers-7982037_1280.jpg",
78-
smallSrc:
88+
thumbSrc:
7989
"https://cdn.pixabay.com/photo/2023/05/09/17/20/flowers-7982037_640.jpg",
8090
},
8191
{
8292
id: crypto.randomUUID(),
8393
alt: "Image12's alt text",
8494
caption: "Image12's description",
8595
src: "https://cdn.pixabay.com/photo/2023/04/17/00/06/vietnam-7931381_1280.jpg",
86-
smallSrc:
96+
thumbSrc:
8797
"https://cdn.pixabay.com/photo/2023/04/17/00/06/vietnam-7931381_640.jpg",
8898
},
99+
{
100+
id: crypto.randomUUID(),
101+
alt: "13's alt text",
102+
caption: "Image13's description",
103+
src: "https://cdn.pixabay.com/photo/2023/09/29/12/38/winter-8283735_640.jpg",
104+
},
89105
];
90106

91107
test("image gallery renders correctly", () => {

src/ImageGallery.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export function ImageGallery({
151151
>
152152
<img
153153
alt={imageInfo.alt}
154-
src={imageInfo.smallSrc || imageInfo.src}
154+
src={imageInfo.gridSrc || imageInfo.src}
155155
onClick={() => openLightboxOnSlide(imageInfo.src, index + 1)}
156156
style={imageStyle}
157157
/>
@@ -336,7 +336,7 @@ export function ImageGallery({
336336
cursor: "pointer",
337337
}}
338338
key={imageInfo.id}
339-
src={imageInfo.smallSrc || imageInfo.src}
339+
src={imageInfo.thumbSrc || imageInfo.src}
340340
alt={imageInfo.alt}
341341
onClick={() => scrollImage(true, 0, index)}
342342
/>

src/ImageGallery.types.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export interface ImageGalleryPropsType {
2121
alt: string;
2222
caption?: string;
2323
src: string;
24-
smallSrc?: string;
24+
gridSrc?: string;
25+
thumbSrc?: string;
2526
}>;
2627
columnCount?: string | number;
2728
columnWidth?: string | number;

0 commit comments

Comments
 (0)