22import React from 'react'
33import $ from 'jquery'
44import { BsChevronLeft , BsChevronRight , BsDashLg } from 'react-icons/bs'
5+ import { v4 as uuid } from 'uuid'
56
67// Custom styles
78import Styles , { PhotoGalleryProps , GallerySlideProps } from './PhotoGalleryStyles'
89
910// General tools
1011import { ANIMATION_TIME , COLORS } from '../../../tools/Constants'
1112
12- export default class PhotoGallery extends React . Component < PhotoGalleryProps , { currentSlide : number } > {
13+ export default class PhotoGallery extends React . Component < PhotoGalleryProps , { currentSlide : number , galleryId : string } > {
1314 constructor ( props : PhotoGalleryProps ) {
1415 super ( props )
1516 this . state = {
16- currentSlide : 0
17+ currentSlide : 0 ,
18+ galleryId : this . props . id ?? uuid ( )
1719 }
1820 }
1921
@@ -48,14 +50,14 @@ export default class PhotoGallery extends React.Component<PhotoGalleryProps, {cu
4850 const slidesLength = Math . ceil ( this . props . galleryInfo . length / 3 )
4951 nextSlide = ( ( nextSlide % slidesLength ) + slidesLength ) % slidesLength
5052
51- $ ( `#slide${ this . state . currentSlide } ` )
53+ $ ( `#${ this . state . galleryId } # slide${ this . state . currentSlide } ` )
5254 . fadeOut ( animationSpeed ) . end ( )
53- $ ( `#slide${ nextSlide } ` )
55+ $ ( `#${ this . state . galleryId } # slide${ nextSlide } ` )
5456 . fadeIn ( animationSpeed ) . end ( )
5557
56- $ ( `#counter${ this . state . currentSlide } ` )
58+ $ ( `#${ this . state . galleryId } # counter${ this . state . currentSlide } ` )
5759 . css ( 'color' , COLORS . TEXT )
58- $ ( `#counter${ nextSlide } ` )
60+ $ ( `#${ this . state . galleryId } # counter${ nextSlide } ` )
5961 . css ( 'color' , COLORS . PRIMARY )
6062
6163 this . setState ( { currentSlide : nextSlide } )
@@ -64,17 +66,17 @@ export default class PhotoGallery extends React.Component<PhotoGalleryProps, {cu
6466 componentDidMount ( ) : void {
6567 // Hide slides after they render
6668 for ( let i = 1 ; i < this . props . galleryInfo . length % 3 ; i ++ ) {
67- $ ( `#slide${ i } ` ) . hide ( )
69+ $ ( `#${ this . state . galleryId } # slide${ i } ` ) . hide ( )
6870 }
69- $ ( '# counter0' ) . css ( 'color' , COLORS . PRIMARY )
71+ $ ( `# ${ this . state . galleryId } # counter0` ) . css ( 'color' , COLORS . PRIMARY )
7072 }
7173
7274 render ( ) : React . ReactElement {
7375 const gridColumns = '100% ' . repeat ( Math . ceil ( this . props . galleryInfo . length / 3 ) )
7476 const width = document . documentElement . style . getPropertyValue ( '--vh' )
7577
7678 return (
77- < Styles . GalleryContainer className = { this . props . className } id = { this . props . id } >
79+ < Styles . GalleryContainer className = { this . props . className } id = { this . state . galleryId } >
7880 < Styles . Title > { this . props . title ?? 'Photo Gallery' } </ Styles . Title >
7981 < Styles . Chevron as = { BsChevronLeft } size = { parseFloat ( width ) * 0.05 } onClick = { this . slideLeft } />
8082 < Styles . SlideContainer gridColumns = { gridColumns } >
0 commit comments