Skip to content

Commit c65cdac

Browse files
committed
feat: Make thumbnails optional
1 parent 2f0cbca commit c65cdac

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/ImageGallery.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function ImageGallery({
1515
const [imageSrc, setImageSrc] = useState<string | undefined>(undefined);
1616
const [slideNumber, setSlideNumber] = useState(1);
1717
const [showModalControls, setShowModalControls] = useState(false);
18+
const [showThumbnails, setShowThumbnails] = useState(false);
1819
const [fullscreen, setFullscreen] = useState(false);
1920
const dialogRef = useRef<HTMLDialogElement | null>(null);
2021
const lightboxRef = useRef<HTMLElement | null>(null);
@@ -201,6 +202,17 @@ export function ImageGallery({
201202
...modalToolbarStyle,
202203
}}
203204
>
205+
<button
206+
type="button"
207+
aria-label="Show thumbnails"
208+
style={modalToolbarBtnStyle}
209+
title="Show thumbnails"
210+
onClick={() => setShowThumbnails(!showThumbnails)}
211+
>
212+
{SvgElement(
213+
<path d="M1 2a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1zM1 7a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1zM1 12a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1z" />
214+
)}
215+
</button>
204216
<button
205217
type="button"
206218
aria-label="Go full screen (Keyboard shortcut f)"
@@ -241,7 +253,12 @@ export function ImageGallery({
241253
)}
242254
</button>
243255
</span>
244-
<section style={modalSlideShowSectionStyle}>
256+
<section
257+
style={{
258+
height: showThumbnails ? "80vh" : "100vh",
259+
...modalSlideShowSectionStyle,
260+
}}
261+
>
245262
<button
246263
type="button"
247264
aria-label="Previous image"
@@ -263,7 +280,10 @@ export function ImageGallery({
263280
<img
264281
src={imageSrc}
265282
alt={imagesInfoArray[slideNumber - 1].alt}
266-
style={modalImageStyle}
283+
style={{
284+
height: showThumbnails ? "80vh" : "100vh",
285+
...modalImageStyle,
286+
}}
267287
/>
268288
<button
269289
type="button"
@@ -284,7 +304,12 @@ export function ImageGallery({
284304
)}
285305
</button>
286306
</section>
287-
<section style={modalThumbnailSectionStyle}>
307+
<section
308+
style={{
309+
opacity: showThumbnails ? 1 : 0,
310+
...modalThumbnailSectionStyle,
311+
}}
312+
>
288313
{imagesInfoArray.map((imageInfo, index) => (
289314
<img
290315
ref={slideNumber - 1 === index ? activeThumbImgRef : null}

src/ImageGalleryStyles.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export function imageGalleryStyles(
66
gapSize?: number,
77
fixedCaption?: boolean
88
): ImageGalleryStylesType {
9-
const modalSlideShowSectionHeight = "80vh";
109
const modalThumbnailSectionHeight = "20vh";
1110
const galleryContainerStyle: React.CSSProperties = {
1211
columnCount,
@@ -91,12 +90,12 @@ export function imageGalleryStyles(
9190
display: "flex",
9291
alignItems: "center",
9392
width: "inherit",
94-
height: `${modalSlideShowSectionHeight}`,
93+
transition: "height .7s linear",
9594
};
9695
const modalImageStyle: React.CSSProperties = {
9796
margin: "auto",
9897
maxWidth: "100vw",
99-
maxHeight: `${modalSlideShowSectionHeight}`,
98+
transition: "height .7s linear",
10099
};
101100
const modalSlideBtnStyle: React.CSSProperties = {
102101
position: "absolute",

0 commit comments

Comments
 (0)