From c0cfe153c6969a70a4a97c6fa9f71204a373e573 Mon Sep 17 00:00:00 2001 From: William Grant Date: Wed, 18 Oct 2023 16:42:22 +1100 Subject: [PATCH] feat: image comp supports string dimensions --- ts/components/conversation/Image.tsx | 51 +++++++++++++++------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/ts/components/conversation/Image.tsx b/ts/components/conversation/Image.tsx index 44ecab416..2fd207747 100644 --- a/ts/components/conversation/Image.tsx +++ b/ts/components/conversation/Image.tsx @@ -1,19 +1,19 @@ -import React, { useCallback } from 'react'; import classNames from 'classnames'; +import React, { useCallback } from 'react'; import styled from 'styled-components'; -import { Spinner } from '../basic/Spinner'; -import { AttachmentType, AttachmentTypeWithPath } from '../../types/Attachment'; -import { useEncryptedFileFetch } from '../../hooks/useEncryptedFileFetch'; import { useDisableDrag } from '../../hooks/useDisableDrag'; +import { useEncryptedFileFetch } from '../../hooks/useEncryptedFileFetch'; +import { AttachmentType, AttachmentTypeWithPath } from '../../types/Attachment'; +import { Spinner } from '../basic/Spinner'; type Props = { alt: string; attachment: AttachmentTypeWithPath | AttachmentType; url: string | undefined; // url is undefined if the message is not visible yet - height?: number; - width?: number; + height?: number | string; + width?: number | string; overlayText?: string; @@ -46,7 +46,7 @@ export const Image = (props: Props) => { attachment, closeButton, darkOverlay, - height, + height: _height, onClick, onClickClose, onError, @@ -56,7 +56,7 @@ export const Image = (props: Props) => { forceSquare, attachmentIndex, url, - width, + width: _width, } = props; const onErrorUrlFilterering = useCallback(() => { @@ -78,6 +78,9 @@ export const Image = (props: Props) => { // data will be url if loading is finished and '' if not const srcData = !loading ? urlToLoad : ''; + const width = typeof _width === 'number' ? `${_width}px` : _width; + const height = typeof _height === 'number' ? `${_height}px` : _height; + return (
{ softCorners ? 'module-image--soft-corners' : null )} style={{ - maxHeight: `${height}px`, - maxWidth: `${width}px`, - minHeight: `${height}px`, - minWidth: `${width}px`, + maxHeight: height, + maxWidth: width, + minHeight: height, + minWidth: width, }} data-attachmentindex={attachmentIndex} > @@ -104,11 +107,11 @@ export const Image = (props: Props) => {
@@ -123,12 +126,12 @@ export const Image = (props: Props) => { )} alt={alt} style={{ - maxHeight: `${height}px`, - maxWidth: `${width}px`, - minHeight: `${height}px`, - minWidth: `${width}px`, - width: forceSquare ? `${width}px` : '', - height: forceSquare ? `${height}px` : '', + maxHeight: height, + maxWidth: width, + minHeight: height, + minWidth: width, + width: forceSquare ? width : '', + height: forceSquare ? height : '', }} src={srcData} onDragStart={disableDrag} @@ -165,7 +168,7 @@ export const Image = (props: Props) => {
) : null} {overlayText ? ( -
+
{overlayText}
) : null}