-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6390bae
commit da3da6d
Showing
5 changed files
with
83 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'react-photoswipe/lib/photoswipe.css' | ||
|
||
import React, { useEffect, useState } from 'react' | ||
import { PhotoSwipe } from 'react-photoswipe' | ||
|
||
import { Portal } from '../webchat/components/portal-modal' | ||
|
||
export const ImageZoomable = props => { | ||
const [imageDimensions, setImageDimensions] = useState({}) | ||
useEffect(() => { | ||
// Remove fullscreen and share buttons | ||
if (props.isImageClicked) { | ||
const fullScreenButton = document.getElementsByClassName( | ||
'pswp__button pswp__button--fs' | ||
)[0] | ||
fullScreenButton.remove() | ||
const shareButton = document.getElementsByClassName( | ||
'pswp__button pswp__button--share' | ||
)[0] | ||
shareButton.remove() | ||
} | ||
}, [props.isImageClicked]) | ||
|
||
useEffect(() => { | ||
if (props.src !== undefined) { | ||
;(async () => { | ||
const dimensions = await getMeta(props.src) | ||
if (dimensions.width <= 1200 || dimensions.height <= 1200) { | ||
dimensions.width = 2 * dimensions.width | ||
dimensions.height = 2 * dimensions.height | ||
} | ||
setImageDimensions(dimensions) | ||
})() | ||
} | ||
}, [props.src]) | ||
|
||
if (!props.isImageClicked) return null | ||
return ( | ||
<Portal> | ||
<PhotoSwipe | ||
isOpen={true} | ||
items={[ | ||
{ | ||
src: props.src, | ||
w: imageDimensions.width, | ||
h: imageDimensions.height, | ||
}, | ||
]} | ||
options={{ bgOpacity: 0.7 }} | ||
onClose={props.onClose} | ||
/> | ||
</Portal> | ||
) | ||
} | ||
|
||
function getMeta(url) { | ||
try { | ||
return new Promise((resolve, reject) => { | ||
const img = new Image() | ||
img.onload = () => resolve({ height: img.height, width: img.width }) | ||
img.onerror = reject | ||
img.src = url | ||
}) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.