import { IconType } from '@standardnotes/snjs' import { FunctionComponent } from 'preact' import { useEffect, useRef, useState } from 'preact/hooks' import { IconButton } from '../Button/IconButton' type Props = { objectUrl: string } export const ImagePreview: FunctionComponent = ({ objectUrl }) => { const initialImgHeightRef = useRef() const [imageZoomPercent, setImageZoomPercent] = useState(100) const [imageHeight, setImageHeight] = useState(initialImgHeightRef.current) useEffect(() => { if (initialImgHeightRef.current) { setImageHeight(imageZoomPercent * (initialImgHeightRef.current / 100)) } }, [imageZoomPercent]) return (
{ if (!initialImgHeightRef.current) { initialImgHeightRef.current = imgElement?.height } }} />
Zoom: { setImageZoomPercent((percent) => percent + 10) }} /> {imageZoomPercent}% { setImageZoomPercent((percent) => { const newPercent = percent - 10 if (newPercent >= 10) { return newPercent } else { return percent } }) }} />
) }