@@ -4,7 +4,11 @@ import Image from "next/image";
44import Indicator from "@/app/components/pagination/Indicator" ;
55import { isValidS3Url } from "@/utils/checkS3Url" ;
66import { useState } from "react" ;
7- import ImageViewerModal from "./ImageViewerModal" ;
7+ import Lightbox from "yet-another-react-lightbox" ;
8+ import "yet-another-react-lightbox/styles.css" ;
9+ import Zoom from "yet-another-react-lightbox/plugins/zoom" ;
10+ import Counter from "yet-another-react-lightbox/plugins/counter" ;
11+ import "yet-another-react-lightbox/plugins/counter.css" ;
812
913interface FormImageProps {
1014 imageUrls : string [ ] ;
@@ -13,15 +17,15 @@ interface FormImageProps {
1317}
1418
1519export default function FormImage ( { imageUrls, currentPage, onPageChange } : FormImageProps ) {
16- const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
20+ const [ isOpen , setIsOpen ] = useState ( false ) ;
1721
1822 const handleImageClick = ( ) => {
19- setIsModalOpen ( true ) ;
23+ setIsOpen ( true ) ;
2024 } ;
2125
22- const handleCloseModal = ( ) => {
23- setIsModalOpen ( false ) ;
24- } ;
26+ const slides = imageUrls . map ( ( url ) => ( {
27+ src : url ,
28+ } ) ) ;
2529
2630 return (
2731 < >
@@ -34,6 +38,13 @@ export default function FormImage({ imageUrls, currentPage, onPageChange }: Form
3438 index === currentPage ? "opacity-100" : "opacity-0"
3539 } `}
3640 onClick = { handleImageClick }
41+ role = "button"
42+ tabIndex = { 0 }
43+ onKeyDown = { ( e ) => {
44+ if ( e . key === "Enter" || e . key === " " ) {
45+ handleImageClick ( ) ;
46+ }
47+ } }
3748 >
3849 < Image
3950 src = { imageUrl }
@@ -53,15 +64,18 @@ export default function FormImage({ imageUrls, currentPage, onPageChange }: Form
5364 ) }
5465 </ div >
5566
56- { /* 이미지 뷰어 모달 */ }
57- { isModalOpen && (
58- < ImageViewerModal
59- imageUrls = { imageUrls }
60- currentPage = { currentPage }
61- onPageChange = { onPageChange }
62- onClose = { handleCloseModal }
63- />
64- ) }
67+ { /* Lightbox */ }
68+ < Lightbox
69+ open = { isOpen }
70+ close = { ( ) => setIsOpen ( false ) }
71+ slides = { slides }
72+ index = { currentPage }
73+ plugins = { [ Zoom , Counter ] }
74+ counter = { { container : { style : { top : "unset" , bottom : 0 } } } }
75+ on = { {
76+ view : ( { index } ) => onPageChange ( index ) ,
77+ } }
78+ />
6579 </ >
6680 ) ;
6781}
0 commit comments