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
This commit is contained in:
@@ -30,25 +30,30 @@ export default function TopImages({ images, destinationName }: TopImageProps) {
|
|||||||
return (
|
return (
|
||||||
<div className={styles.topImages}>
|
<div className={styles.topImages}>
|
||||||
<div className={styles.imageWrapper}>
|
<div className={styles.imageWrapper}>
|
||||||
{visibleImages.map((image, index) => (
|
{visibleImages.map((image, index) => {
|
||||||
<Image
|
const width = index === 0 ? maxWidth : maxWidth / visibleImages.length
|
||||||
key={image.url}
|
const height =
|
||||||
src={image.url}
|
image.dimensions.aspectRatio >= 1
|
||||||
alt={image.meta.alt || image.meta.caption || ""}
|
? Math.ceil(width / image.dimensions.aspectRatio)
|
||||||
width={index === 0 ? maxWidth : maxWidth / visibleImages.length}
|
: Math.ceil(width * image.dimensions.aspectRatio)
|
||||||
height={Math.ceil(
|
|
||||||
(index === 0 ? maxWidth : maxWidth / visibleImages.length) /
|
return (
|
||||||
image.dimensions.aspectRatio
|
<Image
|
||||||
)}
|
key={image.url}
|
||||||
focalPoint={image.focalPoint}
|
src={image.url}
|
||||||
className={`${styles.image} ${images.length > 1 ? styles.clickable : ""}`}
|
alt={image.meta.alt || image.meta.caption || ""}
|
||||||
onClick={() =>
|
width={width}
|
||||||
images.length
|
height={height}
|
||||||
? setLightboxState({ open: true, activeIndex: index })
|
focalPoint={image.focalPoint}
|
||||||
: null
|
className={`${styles.image} ${images.length > 1 ? styles.clickable : ""}`}
|
||||||
}
|
onClick={() =>
|
||||||
/>
|
images.length
|
||||||
))}
|
? setLightboxState({ open: true, activeIndex: index })
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
{images.length > 1 && (
|
{images.length > 1 && (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ export default function Card({
|
|||||||
imageWidth =
|
imageWidth =
|
||||||
imageWidth ||
|
imageWidth ||
|
||||||
(backgroundImage?.dimensions
|
(backgroundImage?.dimensions
|
||||||
? backgroundImage.dimensions.aspectRatio * imageHeight
|
? backgroundImage.dimensions.aspectRatio >= 1
|
||||||
|
? backgroundImage.dimensions.aspectRatio * imageHeight
|
||||||
|
: imageHeight / backgroundImage.dimensions.aspectRatio
|
||||||
: 420)
|
: 420)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ export default function TeaserCard({
|
|||||||
}: TeaserCardProps) {
|
}: TeaserCardProps) {
|
||||||
const classNames = teaserCardVariants({ intent, alwaysStack, className })
|
const classNames = teaserCardVariants({ intent, alwaysStack, className })
|
||||||
|
|
||||||
|
const imageWidth =
|
||||||
|
image &&
|
||||||
|
Math.ceil(
|
||||||
|
image.dimensions.aspectRatio >= 1
|
||||||
|
? image.dimensions.aspectRatio * 200
|
||||||
|
: 200 / image.dimensions.aspectRatio
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article className={classNames}>
|
<article className={classNames}>
|
||||||
{image && (
|
{image && (
|
||||||
@@ -32,7 +40,7 @@ export default function TeaserCard({
|
|||||||
src={image.url}
|
src={image.url}
|
||||||
alt={image.meta?.alt || ""}
|
alt={image.meta?.alt || ""}
|
||||||
className={styles.image}
|
className={styles.image}
|
||||||
width={Math.ceil(image.dimensions.aspectRatio * 200)}
|
width={imageWidth}
|
||||||
height={200}
|
height={200}
|
||||||
focalPoint={image.focalPoint}
|
focalPoint={image.focalPoint}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user