Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
yyluchkiv committed Nov 3, 2023
2 parents 9fdd86d + 495feb5 commit 8e7af2e
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions src/components/ImageGallery/ImageGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const ImageGallery: React.FC<{
}) => {
const [showPreview, setShowPreview] = useState(false)
const [initialSlide, setInitialSlide] = useState(0)
const [loadedImage, setLoadedImage] = useState(true)
let isHorizontalOrientation: boolean
let isVerticalOrientation: boolean
let galleryHeight: number = height
Expand Down Expand Up @@ -235,13 +234,6 @@ const ImageGallery: React.FC<{
return styles
}

function getImageStyle () {
return {
display: loadedImage ? 'none' : 'block',
borderRadius: `${ imageBorderRadius }%`
}
}

function openPreview (initialSlideNumber: number) {
setShowPreview(true)
setInitialSlide(initialSlideNumber)
Expand All @@ -264,6 +256,34 @@ const ImageGallery: React.FC<{
}
}, [showPreview])

const ImageItem: React.FC<{ image: any }> = ({ image }) => {
const [loadedImage, setLoadedImage] = useState(true)

function getImageStyle () {
return {
display: loadedImage ? 'none' : 'block',
borderRadius: `${ imageBorderRadius }%`
}
}

return (
<div className={ Styles.roundedImage }>
<Loader loading={ loadedImage } />
<Image
onClick={ () => preview && openPreview(image.id - 1) }
className={ Styles.image }
style={ getImageStyle() }
src={ image.source }
alt={ image.alt }
fill={ true }
onLoad={ () => setLoadedImage(false) }
priority={ true }
sizes='(max-width: 768px) 1200w, (max-width: 1200px) 1000w, 33vw'
/>
</div>
)
}

return (
<div className={ getGalleryCssClass() } style={ getGalleryStyles() }>
{
Expand All @@ -273,20 +293,7 @@ const ImageGallery: React.FC<{
{
galleryItem.images.map(image => (
<div className={ Styles.container } style={ getImageContainerStyles(image.ratio) } key={ uuId() }>
<div className={ Styles.roundedImage }>
<Loader loading={ loadedImage } />
<Image
onClick={ () => preview && openPreview(image.id - 1) }
className={ Styles.image }
style={ getImageStyle() }
src={ image.source }
alt={ image.alt }
fill={ true }
onLoad={ () => setLoadedImage(false) }
priority={ true }
sizes='(max-width: 768px) 1200w, (max-width: 1200px) 1000w, 33vw'
/>
</div>
<ImageItem image={ image } />
</div>
))
}
Expand Down

0 comments on commit 8e7af2e

Please sign in to comment.