import React from 'react'; import classNames from 'classnames'; import { Spinner } from '../basic/Spinner'; import { AttachmentTypeWithPath } from '../../types/Attachment'; import { useEncryptedFileFetch } from '../../hooks/useEncryptedFileFetch'; type Props = { alt: string; attachment: AttachmentTypeWithPath; url: string; height?: number; width?: number; overlayText?: string; bottomOverlay?: boolean; closeButton?: boolean; curveBottomLeft?: boolean; curveBottomRight?: boolean; curveTopLeft?: boolean; curveTopRight?: boolean; smallCurveTopLeft?: boolean; darkOverlay?: boolean; playIconOverlay?: boolean; softCorners?: boolean; onClick?: (attachment: AttachmentTypeWithPath) => void; onClickClose?: (attachment: AttachmentTypeWithPath) => void; onError?: () => void; }; export const Image = (props: Props) => { // tslint:disable-next-line max-func-body-length cyclomatic-complexity const { alt, attachment, bottomOverlay, closeButton, curveBottomLeft, curveBottomRight, curveTopLeft, curveTopRight, darkOverlay, height, onClick, onClickClose, onError, overlayText, playIconOverlay, smallCurveTopLeft, softCorners, url, width, } = props; const { caption, pending } = attachment || { caption: null, pending: true }; const canClick = onClick && !pending; const role = canClick ? 'button' : undefined; const { loading, urlToLoad } = useEncryptedFileFetch(url, attachment.contentType); // data will be url if loading is finished and '' if not const srcData = !loading ? urlToLoad : ''; return (