Skip to content

Commit 9987787

Browse files
committed
feat(ui): refine photo lightbox with full-resolution max-w-7xl portal display
1 parent 0618d5d commit 9987787

1 file changed

Lines changed: 125 additions & 102 deletions

File tree

‎src/components/TeamPhotos.tsx‎

Lines changed: 125 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import Image from "next/image";
44
import { useEffect, useRef, useState } from "react";
5+
import { createPortal } from "react-dom";
56
import { TEAM_PHOTOS } from "@/data/teamPhotos";
67

78
// Helper to generate a shuffled array of indices from 1 to N-1
@@ -17,6 +18,7 @@ const generateShuffledPlaylist = (length: number): number[] => {
1718
};
1819

1920
export default function TeamPhotos() {
21+
const [mounted, setMounted] = useState(false);
2022
const [currentIndex, setCurrentIndex] = useState(0);
2123
const [prevIndex, setPrevIndex] = useState<number | null>(null);
2224
const [isModalOpen, setIsModalOpen] = useState(false);
@@ -63,6 +65,7 @@ export default function TeamPhotos() {
6365
// Honor the OS "reduce motion" setting: default autoplay off and gate the
6466
// timer so content never swaps on its own for users who opted out of motion.
6567
useEffect(() => {
68+
setMounted(true);
6669
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
6770
const apply = (matches: boolean) => {
6871
setPrefersReducedMotion(matches);
@@ -194,6 +197,18 @@ export default function TeamPhotos() {
194197
};
195198
}, [isModalOpen]);
196199

200+
// Lock body scroll when modal is open
201+
useEffect(() => {
202+
if (isModalOpen) {
203+
document.body.style.overflow = "hidden";
204+
} else {
205+
document.body.style.overflow = "";
206+
}
207+
return () => {
208+
document.body.style.overflow = "";
209+
};
210+
}, [isModalOpen]);
211+
197212
const currentPhoto = TEAM_PHOTOS[currentIndex];
198213

199214
return (
@@ -374,116 +389,124 @@ export default function TeamPhotos() {
374389
</div>
375390
</div>
376391

377-
{/* Lightbox Modal */}
378-
{isModalOpen && (
379-
<div
380-
ref={modalRef}
381-
role="dialog"
382-
aria-modal="true"
383-
aria-label={`Team photo, full screen: ${currentPhoto.location}, ${currentPhoto.date}`}
384-
className="fixed inset-0 z-50 flex items-center justify-center bg-black/85 backdrop-blur-sm transition-opacity duration-300"
385-
onClick={() => setIsModalOpen(false)}
386-
>
387-
{/* Close Button */}
388-
<button
389-
ref={closeButtonRef}
390-
type="button"
391-
className="absolute top-4 right-4 p-2 rounded-full bg-white/10 hover:bg-white/20 text-white transition-colors cursor-pointer z-50"
392+
{/* Lightbox Modal (portaled directly to document.body to avoid parent stacking context traps) */}
393+
{mounted &&
394+
isModalOpen &&
395+
typeof document !== "undefined" &&
396+
createPortal(
397+
<div
398+
ref={modalRef}
399+
role="dialog"
400+
aria-modal="true"
401+
aria-label={`Team photo, full screen: ${currentPhoto.location}, ${currentPhoto.date}`}
402+
className="fixed inset-0 z-[100] flex items-center justify-center bg-black/85 backdrop-blur-md transition-opacity duration-300 p-4 sm:p-6"
392403
onClick={() => setIsModalOpen(false)}
393-
aria-label="Close modal"
394404
>
395-
<svg
396-
className="h-6 w-6"
397-
fill="none"
398-
viewBox="0 0 24 24"
399-
stroke="currentColor"
400-
strokeWidth={2}
405+
{/* Close Button */}
406+
<button
407+
ref={closeButtonRef}
408+
type="button"
409+
className="absolute top-4 right-4 sm:top-6 sm:right-6 p-2.5 rounded-full bg-white/15 hover:bg-white/25 border border-white/20 text-white transition-all cursor-pointer z-[110] hover:scale-110 active:scale-95 shadow-lg backdrop-blur-md"
410+
onClick={() => setIsModalOpen(false)}
411+
aria-label="Close modal"
401412
>
402-
<path
403-
strokeLinecap="round"
404-
strokeLinejoin="round"
405-
d="M6 18L18 6M6 6l12 12"
406-
/>
407-
</svg>
408-
</button>
409-
410-
{/* Left Arrow Button in Modal */}
411-
<button
412-
type="button"
413-
onClick={(e) => {
414-
e.stopPropagation();
415-
handlePrev(e);
416-
}}
417-
className="absolute left-6 p-3 rounded-full bg-white/10 hover:bg-white/20 text-white transition-colors cursor-pointer z-50 hover:scale-105 flex items-center justify-center"
418-
aria-label="Previous photo"
419-
>
420-
<svg
421-
className="h-6 w-6"
422-
fill="none"
423-
viewBox="0 0 24 24"
424-
stroke="currentColor"
425-
strokeWidth={2}
413+
<svg
414+
className="h-6 w-6"
415+
fill="none"
416+
viewBox="0 0 24 24"
417+
stroke="currentColor"
418+
strokeWidth={2}
419+
>
420+
<path
421+
strokeLinecap="round"
422+
strokeLinejoin="round"
423+
d="M6 18L18 6M6 6l12 12"
424+
/>
425+
</svg>
426+
</button>
427+
428+
{/* Left Arrow Button in Modal */}
429+
<button
430+
type="button"
431+
onClick={(e) => {
432+
e.stopPropagation();
433+
handlePrev(e);
434+
}}
435+
className="absolute left-3 sm:left-6 top-1/2 -translate-y-1/2 p-3 rounded-full bg-white/15 hover:bg-white/25 border border-white/20 text-white transition-all cursor-pointer z-[110] hover:scale-110 active:scale-95 flex items-center justify-center shadow-lg backdrop-blur-md"
436+
aria-label="Previous photo"
426437
>
427-
<path
428-
strokeLinecap="round"
429-
strokeLinejoin="round"
430-
d="M15 19l-7-7 7-7"
431-
/>
432-
</svg>
433-
</button>
434-
435-
{/* Right Arrow Button in Modal */}
436-
<button
437-
type="button"
438-
onClick={(e) => {
439-
e.stopPropagation();
440-
handleNext(e);
441-
}}
442-
className="absolute right-6 p-3 rounded-full bg-white/10 hover:bg-white/20 text-white transition-colors cursor-pointer z-50 hover:scale-105 flex items-center justify-center"
443-
aria-label="Next photo"
444-
>
445-
<svg
446-
className="h-6 w-6"
447-
fill="none"
448-
viewBox="0 0 24 24"
449-
stroke="currentColor"
450-
strokeWidth={2}
438+
<svg
439+
className="h-6 w-6"
440+
fill="none"
441+
viewBox="0 0 24 24"
442+
stroke="currentColor"
443+
strokeWidth={2}
444+
>
445+
<path
446+
strokeLinecap="round"
447+
strokeLinejoin="round"
448+
d="M15 19l-7-7 7-7"
449+
/>
450+
</svg>
451+
</button>
452+
453+
{/* Right Arrow Button in Modal */}
454+
<button
455+
type="button"
456+
onClick={(e) => {
457+
e.stopPropagation();
458+
handleNext(e);
459+
}}
460+
className="absolute right-3 sm:right-6 top-1/2 -translate-y-1/2 p-3 rounded-full bg-white/15 hover:bg-white/25 border border-white/20 text-white transition-all cursor-pointer z-[110] hover:scale-110 active:scale-95 flex items-center justify-center shadow-lg backdrop-blur-md"
461+
aria-label="Next photo"
462+
>
463+
<svg
464+
className="h-6 w-6"
465+
fill="none"
466+
viewBox="0 0 24 24"
467+
stroke="currentColor"
468+
strokeWidth={2}
469+
>
470+
<path
471+
strokeLinecap="round"
472+
strokeLinejoin="round"
473+
d="M9 5l7 7-7 7"
474+
/>
475+
</svg>
476+
</button>
477+
478+
{/* Modal Content container: immersive max-w-7xl (1280px matching native photo resolution) with smooth rounded corners, zero padding, and seamless photo fill */}
479+
<div
480+
className="relative w-[94vw] max-w-7xl aspect-video max-h-[86vh] rounded-2xl overflow-hidden border border-white/15 shadow-2xl shadow-black/80 bg-zinc-950 flex items-center justify-center select-none"
481+
onClick={(e) => e.stopPropagation()}
451482
>
452-
<path
453-
strokeLinecap="round"
454-
strokeLinejoin="round"
455-
d="M9 5l7 7-7 7"
483+
<Image
484+
src={currentPhoto.url}
485+
alt={`${currentPhoto.date} - ${currentPhoto.location}`}
486+
fill
487+
className="object-cover"
488+
unoptimized
489+
sizes="(max-width: 1280px) 94vw, 1280px"
490+
priority
456491
/>
457-
</svg>
458-
</button>
459-
460-
{/* Modal Content container */}
461-
<div
462-
className="relative w-[90vw] max-w-4xl max-h-[85vh] aspect-video rounded-2xl overflow-hidden border border-white/10 shadow-2xl bg-zinc-950 flex items-center justify-center p-1"
463-
onClick={(e) => e.stopPropagation()}
464-
>
465-
<Image
466-
src={currentPhoto.url}
467-
alt={`${currentPhoto.date} - ${currentPhoto.location}`}
468-
fill
469-
className="object-contain"
470-
unoptimized
471-
/>
472-
{/* Modal Caption */}
473-
<div className="absolute bottom-0 inset-x-0 bg-gradient-to-t from-black/90 via-black/50 to-transparent p-4 text-white flex justify-between items-end">
474-
<div>
475-
<p className="text-sm font-bold">{currentPhoto.location}</p>
476-
<p className="text-xs text-gray-300 mt-0.5">
477-
{currentPhoto.date}
478-
</p>
492+
{/* Modal Caption smoothly overlaid at the bottom of the photo */}
493+
<div className="absolute bottom-0 inset-x-0 bg-gradient-to-t from-black/90 via-black/50 to-transparent p-5 sm:p-6 text-white flex justify-between items-end pointer-events-none">
494+
<div className="pr-4">
495+
<p className="text-sm sm:text-base md:text-lg font-bold text-white drop-shadow-sm leading-snug">
496+
{currentPhoto.location}
497+
</p>
498+
<p className="text-xs sm:text-sm text-white/75 font-mono mt-0.5">
499+
{currentPhoto.date}
500+
</p>
501+
</div>
502+
<span className="shrink-0 text-xs sm:text-sm font-mono font-medium text-white/90 bg-white/15 backdrop-blur-xs border border-white/20 px-3 py-1 rounded-full select-none shadow-xs">
503+
{currentIndex + 1} / {TEAM_PHOTOS.length}
504+
</span>
479505
</div>
480-
<span className="text-xs font-bold bg-white/10 border border-white/15 px-2 py-0.5 rounded-full select-none">
481-
{currentIndex + 1} / {TEAM_PHOTOS.length}
482-
</span>
483506
</div>
484-
</div>
485-
</div>
486-
)}
507+
</div>,
508+
document.body,
509+
)}
487510
</div>
488511
);
489512
}

0 commit comments

Comments
 (0)