1- import React , { useEffect } from "react" ;
1+ import React , { useEffect } from "react" ;
22import "photoswipe/dist/photoswipe.css" ;
33import "./IonPhotoViewer.css" ;
4- import { getImageDimensions , renderIonHeader } from "./utils" ;
4+ import { createElementFromHTML , getImageDimensions } from "./utils" ;
55import { IonPhotoViewerProps } from "./IonPhotoViewer.types" ;
6- import { Gallery , Item } from "react-photoswipe-gallery" ;
6+ import { Gallery , GalleryProps , Item } from "react-photoswipe-gallery" ;
7+ import renderIonHeaderToString from "./renderIonHeaderToString" ;
8+ import { DataSourceArray } from "photoswipe" ;
79
810const IonPhotoViewer : React . FC < IonPhotoViewerProps > = ( {
911 children,
@@ -16,18 +18,101 @@ const IonPhotoViewer: React.FC<IonPhotoViewerProps> = ({
1618 width : 0 ,
1719 } ) ;
1820
21+ const uiElements : GalleryProps [ 'uiElements' ] = [
22+ {
23+ name : 'bulletsIndicator' ,
24+ order : 9 ,
25+ isButton : false ,
26+
27+ appendTo : 'wrapper' ,
28+ onInit : ( el , pswpInstance ) => {
29+
30+
31+ // el.style.position = 'absolute'
32+ el . style . top = '0'
33+ // el.style.left = '50%'
34+ // el.style.right = '50%'
35+ // el.style.display = 'grid'
36+ // el.style.gridGap = '10px'
37+ el . style . gridTemplateColumns = 'repeat(auto-fit, 40px)'
38+ el . style . gridTemplateRows = 'repeat(auto-fit, 40px)'
39+ el . style . justifyContent = 'left'
40+
41+
42+ // const dataSource = pswpInstance.options.dataSource as DataSourceArray
43+ el . append ( createElementFromHTML ( renderIonHeaderToString ( title ) ) ) ;
44+
45+ // renderIonHeaderToString(title, 'ionPhotoViewerClose')
46+
47+ // for (let i = 0; i < dataSource.length; i++) {
48+ // const slideData = dataSource[i]
49+
50+ // const thumbnail = document.createElement('div')
51+ // thumbnail.style.transition = 'transform 0.15s ease-in'
52+ // thumbnail.style.opacity = '0.6'
53+ // thumbnail.style.cursor = 'pointer'
54+ // thumbnail.onclick = (e: MouseEvent) => {
55+ // const target = e.target as HTMLImageElement | HTMLDivElement
56+ // const thumbnailEl =
57+ // target.tagName === 'IMG'
58+ // ? target.parentElement
59+ // : (e.target as HTMLImageElement | HTMLDivElement)
60+ // thumbnailEl && pswpInstance.goTo(thumbnails.indexOf(thumbnailEl))
61+ // }
62+
63+ // const thumbnailImage = document.createElement('img')
64+ // slideData.msrc && thumbnailImage.setAttribute('src', slideData.msrc)
65+ // thumbnailImage.style.width = '100%'
66+ // thumbnailImage.style.height = '100%'
67+ // thumbnailImage.style.objectFit = 'cover'
68+
69+ // thumbnail.appendChild(thumbnailImage)
70+
71+ // el.appendChild(thumbnail)
72+
73+ // thumbnails.push(thumbnail)
74+ // }
75+
76+ // pswpInstance.on('change', () => {
77+ // if (prevIndex >= 0) {
78+ // const prevThumbnail = thumbnails[prevIndex]
79+ // prevThumbnail.style.opacity = '0.6'
80+ // prevThumbnail.style.cursor = 'pointer'
81+ // prevThumbnail.style.transform = 'scale(1)'
82+ // }
83+
84+ // const currentThumbnail = thumbnails[pswpInstance.currIndex]
85+ // currentThumbnail.style.opacity = '1'
86+ // currentThumbnail.style.cursor = 'unset'
87+ // currentThumbnail.style.transform = 'scale(1.2)'
88+
89+ // prevIndex = pswpInstance.currIndex
90+ // })
91+ } ,
92+ onClick : ( e , el , pswpInstance ) => {
93+ const target = e . target as HTMLImageElement | HTMLDivElement
94+ if ( target ?. id === 'ion-header-close-button' ) {
95+ pswpInstance . close ( )
96+ }
97+ }
98+ } ,
99+ ]
100+
19101
20102 useEffect ( ( ) => {
21- getImageDimensions ( src ) . then ( ( dimensions :any ) => setImageDimensions ( dimensions ) ) ;
103+ getImageDimensions ( src ) . then ( ( dimensions : any ) =>
104+ setImageDimensions ( dimensions )
105+ ) ;
22106 } , [ ] ) ;
107+
23108 return (
24109 < div
25110 className = "ion-photo-viewer"
26111 onClick = { ( e ) => e . stopPropagation ( ) }
27112 onKeyDown = { ( e ) => e . stopPropagation ( ) }
28113 role = "presentation"
29114 >
30- < Gallery >
115+ < Gallery uiElements = { uiElements } >
31116 < Item
32117 original = { src }
33118 thumbnail = { src }
0 commit comments