From c2b7d97dddbc4c052af380decb301530a0009dba Mon Sep 17 00:00:00 2001 From: Linus Flood Date: Wed, 19 Feb 2025 06:29:22 +0000 Subject: [PATCH] Merged in fix/card-width-fix (pull request #1369) feat(images): calculate width correct using aspect ratio * feat(images): calculate width correct using aspect ratio Approved-by: Erik Tiekstra --- .../DestinationPage/TopImages/index.tsx | 43 +++++++++++-------- components/TempDesignSystem/Card/index.tsx | 4 +- .../TempDesignSystem/TeaserCard/index.tsx | 10 ++++- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/components/ContentType/DestinationPage/TopImages/index.tsx b/components/ContentType/DestinationPage/TopImages/index.tsx index e17d2c46a..190e28432 100644 --- a/components/ContentType/DestinationPage/TopImages/index.tsx +++ b/components/ContentType/DestinationPage/TopImages/index.tsx @@ -30,25 +30,30 @@ export default function TopImages({ images, destinationName }: TopImageProps) { return (
- {visibleImages.map((image, index) => ( - {image.meta.alt 1 ? styles.clickable : ""}`} - onClick={() => - images.length - ? setLightboxState({ open: true, activeIndex: index }) - : null - } - /> - ))} + {visibleImages.map((image, index) => { + const width = index === 0 ? maxWidth : maxWidth / visibleImages.length + const height = + image.dimensions.aspectRatio >= 1 + ? Math.ceil(width / image.dimensions.aspectRatio) + : Math.ceil(width * image.dimensions.aspectRatio) + + return ( + {image.meta.alt 1 ? styles.clickable : ""}`} + onClick={() => + images.length + ? setLightboxState({ open: true, activeIndex: index }) + : null + } + /> + ) + })}
{images.length > 1 && ( <> diff --git a/components/TempDesignSystem/Card/index.tsx b/components/TempDesignSystem/Card/index.tsx index 03ca70add..779febd6b 100644 --- a/components/TempDesignSystem/Card/index.tsx +++ b/components/TempDesignSystem/Card/index.tsx @@ -44,7 +44,9 @@ export default function Card({ imageWidth = imageWidth || (backgroundImage?.dimensions - ? backgroundImage.dimensions.aspectRatio * imageHeight + ? backgroundImage.dimensions.aspectRatio >= 1 + ? backgroundImage.dimensions.aspectRatio * imageHeight + : imageHeight / backgroundImage.dimensions.aspectRatio : 420) return ( diff --git a/components/TempDesignSystem/TeaserCard/index.tsx b/components/TempDesignSystem/TeaserCard/index.tsx index eee3c3c7f..cce965e89 100644 --- a/components/TempDesignSystem/TeaserCard/index.tsx +++ b/components/TempDesignSystem/TeaserCard/index.tsx @@ -25,6 +25,14 @@ export default function TeaserCard({ }: TeaserCardProps) { const classNames = teaserCardVariants({ intent, alwaysStack, className }) + const imageWidth = + image && + Math.ceil( + image.dimensions.aspectRatio >= 1 + ? image.dimensions.aspectRatio * 200 + : 200 / image.dimensions.aspectRatio + ) + return (
{image && ( @@ -32,7 +40,7 @@ export default function TeaserCard({ src={image.url} alt={image.meta?.alt || ""} className={styles.image} - width={Math.ceil(image.dimensions.aspectRatio * 200)} + width={imageWidth} height={200} focalPoint={image.focalPoint} />