diff --git a/package-lock.json b/package-lock.json index faf9933..afd22db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,8 @@ "sharp": "^0.33.3", "tailwind-scrollbar": "^3.1.0", "tailwindcss": "^3.4.3", - "typescript": "^5.4.5" + "typescript": "^5.4.5", + "yet-another-react-lightbox": "^3.17.4" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -6397,6 +6398,18 @@ "node": ">= 14" } }, + "node_modules/yet-another-react-lightbox": { + "version": "3.17.4", + "resolved": "https://registry.npmjs.org/yet-another-react-lightbox/-/yet-another-react-lightbox-3.17.4.tgz", + "integrity": "sha512-XDCZoEXsjkbRy7Pxk+nsQthbYqW7V2INHv9Qn9GmdILP4GH7wANsRF31TCXIKMU4etr3UHmPzClLXf7KpIwDYQ==", + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 9591611..3b53652 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "sharp": "^0.33.3", "tailwind-scrollbar": "^3.1.0", "tailwindcss": "^3.4.3", - "typescript": "^5.4.5" + "typescript": "^5.4.5", + "yet-another-react-lightbox": "^3.17.4" } } diff --git a/src/components/lightbox.tsx b/src/components/lightbox.tsx index b276ff8..35bee58 100644 --- a/src/components/lightbox.tsx +++ b/src/components/lightbox.tsx @@ -1,7 +1,20 @@ "use client"; -import { useState } from "react"; +import React, { useState } from "react"; import Image from "next/image"; -import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch"; + +import YARL, { + isImageFitCover, + isImageSlide, + useLightboxProps, + useLightboxState, +} from "yet-another-react-lightbox"; +import Thumbnails from "yet-another-react-lightbox/plugins/thumbnails"; +import Zoom from "yet-another-react-lightbox/plugins/zoom"; +import Captions from "yet-another-react-lightbox/plugins/captions"; +import "yet-another-react-lightbox/styles.css"; +import "yet-another-react-lightbox/plugins/thumbnails.css"; +import "yet-another-react-lightbox/plugins/captions.css"; + type ImageData = { width: number, @@ -24,53 +37,77 @@ type LightboxProps = { imageData: ImageData[] } -export default function Lightbox(props: LightboxProps): React.JSX.Element { - const [active, setActive] = useState(null); + +function NextJsImage({ slide, offset, rect, unoptimized = false }: {slide: ImageData, offset: number, rect: {width: number, height: number}, unoptimized: boolean}): React.JSX.Element { + const { + on: { click }, + carousel: { imageFit }, + } = useLightboxProps(); + + const { currentIndex } = useLightboxState(); + + const cover = isImageSlide(slide) && isImageFitCover(slide, imageFit); + + const width = !cover + ? Math.round( + Math.min(rect.width, (rect.height / slide.height) * slide.width), + ) + : rect.width; + + const height = !cover + ? Math.round( + Math.min(rect.height, (rect.width / slide.width) * slide.height), + ) + : rect.height; + + console.log(slide); + + return ( +
+ click?.({ index: currentIndex }) : undefined + } + /> +
+ ); +} + +export default function MyLightbox(props: LightboxProps): React.JSX.Element { + const [active, setActive] = useState(null); return ( <>
{props.children.map((image, index) => ( ))}
- { active ? ( -
-
-
-
- {active.exif.DateTimeOriginal?.toLocaleDateString()} - -
-
- {active.src} -
-
- {active.camera} - {active.exif.LensModel} - {active.exif.FocalLength}mm - f/{active.exif.FNumber} - ISO {active.exif.ISOSpeedRatings} - {active.exif.ExposureBiasValue}EV -
-
-
-
- ) : null} + setActive(null)} + index={active ?? undefined} + slides={props.imageData} + // @ts-expect-error - Todo - This just passes the slide through, but it doesn't know the type + render={{ slide: (args) => NextJsImage({...args, unoptimized: true }), thumbnail: NextJsImage }} + plugins={[Thumbnails, Zoom, Captions]} + /> ); } \ No newline at end of file