From fff6dce8fcdc9355a255ba51e4573a09a5391fb1 Mon Sep 17 00:00:00 2001 From: Brett Jephson Date: Thu, 21 Mar 2024 11:46:46 +0000 Subject: [PATCH] RND-3192: images expanding card content beyond their width (#281) * Fix for RND-3192: images expanding card content beyond their width * Wrap Image in a size-restricting container --------- Co-authored-by: Viktor Renkema --- src/components/DocumentView/InlineImage.tsx | 54 ++++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/components/DocumentView/InlineImage.tsx b/src/components/DocumentView/InlineImage.tsx index 24cafc897..919028da6 100644 --- a/src/components/DocumentView/InlineImage.tsx +++ b/src/components/DocumentView/InlineImage.tsx @@ -3,6 +3,7 @@ import assertNever from 'assert-never'; import { getImageSize } from '@/lib/images'; import { ResolvedContentRef } from '@/lib/references'; +import { tcls } from '@/lib/tailwind'; import { InlineProps } from './Inline'; import { Image } from '../utils'; @@ -21,41 +22,45 @@ export async function InlineImage(props: InlineProps) { } return ( - {inline.data.caption + /* Ensure images dont expand to the size of the container where this Image may be nested in. Now it's always nested in a size-restricted container */ + + {inline.data.caption + ); } async function getImageSizes(size: 'original' | 'line', src: ResolvedContentRef) { switch (size) { case 'line': { - // We estimate that the maximum height of the line will be 40px - // and from the aspect-ratio, we can deduce the width - const lineHeight = 40; const imageSize = src.fileDimensions ?? (await getImageSize(src.href, { dpr: 3, })); + // We estimate that the maximum height of the line will be 40px + // and from the aspect-ratio, we can deduce the width + const lineHeight = 40; + const aspectRatio = imageSize ? imageSize.width / imageSize.height : 1; return [ @@ -68,6 +73,7 @@ async function getImageSizes(size: 'original' | 'line', src: ResolvedContentRef) // The max-width is 300px return [ { + // if we know the image size and it is smaller than 300px use its width width: 300, }, ];