import { useEffect, useRef, useState } from "react"; import * as utils from "../helpers/utils"; import { showDialog } from "./Dialog"; import "../less/preview-image-dialog.less"; interface Props extends DialogProps { imgUrl: string; } const PreviewImageDialog: React.FC = ({ destroy, imgUrl }: Props) => { const imgRef = useRef(null); const [imgWidth, setImgWidth] = useState(-1); useEffect(() => { utils.getImageSize(imgUrl).then(({ width }) => { if (width !== 0) { setImgWidth(80); } else { setImgWidth(0); } }); }, []); const handleCloseBtnClick = () => { destroy(); }; const handleDecreaseImageSize = () => { if (imgWidth > 30) { setImgWidth(imgWidth - 10); } }; const handleIncreaseImageSize = () => { setImgWidth(imgWidth + 10); }; return ( <>
Loading image... 😟 Failed to load image
); }; export default function showPreviewImageDialog(imgUrl: string): void { showDialog( { className: "preview-image-dialog", }, PreviewImageDialog, { imgUrl } ); }