Skip to content

Commit 149120f

Browse files
committed
use inline display to correctly placing lightbox btn
1 parent 26f4cd2 commit 149120f

File tree

2 files changed

+28
-46
lines changed

2 files changed

+28
-46
lines changed

dotcom-rendering/src/components/GalleryImage.tsx

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const styles = css`
3636
`;
3737

3838
const galleryBodyImageStyles = css`
39-
display: flex;
39+
display: inline;
40+
position: relative;
4041
${grid.column.all}
4142
4243
${from.tablet} {
@@ -74,32 +75,33 @@ export const GalleryImage = ({
7475

7576
return (
7677
<figure css={styles}>
77-
<div css={galleryBodyImageStyles}>
78-
<div
79-
css={css`
80-
position: relative;
81-
`}
82-
>
83-
<Picture
84-
alt={image.data.alt ?? ''}
85-
format={format}
78+
<div
79+
css={galleryBodyImageStyles}
80+
/**
81+
* This ensures that the image height never goes above 96vh.
82+
*/
83+
style={{
84+
maxWidth: `calc(${width / height} * 96vh)`,
85+
}}
86+
>
87+
<Picture
88+
alt={image.data.alt ?? ''}
89+
format={format}
90+
role={image.role}
91+
master={asset.url}
92+
width={width}
93+
height={height}
94+
loading="lazy"
95+
/>
96+
{renderingTarget === 'Web' && !isUndefined(image.position) && (
97+
<LightboxLink
8698
role={image.role}
87-
master={asset.url}
88-
width={width}
89-
height={height}
90-
loading="lazy"
99+
format={format}
100+
elementId={image.elementId}
101+
isMainMedia={false}
102+
position={image.position}
91103
/>
92-
{renderingTarget === 'Web' &&
93-
!isUndefined(image.position) && (
94-
<LightboxLink
95-
role={image.role}
96-
format={format}
97-
elementId={image.elementId}
98-
isMainMedia={false}
99-
position={image.position}
100-
/>
101-
)}
102-
</div>
104+
)}
103105
</div>
104106

105107
<GalleryCaption

dotcom-rendering/src/components/Picture.tsx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { css } from '@emotion/react';
22
import { breakpoints } from '@guardian/source/foundations';
3-
import {
4-
type CSSProperties,
5-
Fragment,
6-
useCallback,
7-
useEffect,
8-
useState,
9-
} from 'react';
3+
import { Fragment, useCallback, useEffect, useState } from 'react';
104
import {
115
ArticleDesign,
126
ArticleDisplay,
@@ -471,19 +465,6 @@ export const Sources = ({ sources }: { sources: ImageSource[] }) => {
471465
);
472466
};
473467

474-
/**
475-
* This ensures that the image height never goes above 96vh.
476-
* The ratio parameter should be width:height.
477-
*/
478-
const imageMaxWidth = (
479-
design: ArticleDesign,
480-
ratio: number,
481-
isMainMedia: boolean,
482-
): CSSProperties | undefined =>
483-
design === ArticleDesign.Gallery && !isMainMedia
484-
? { maxWidth: `calc(${ratio} * 96vh)` }
485-
: undefined;
486-
487468
const styles = ({ design }: ArticleFormat, isLightbox: boolean) => {
488469
if (design === ArticleDesign.Gallery) {
489470
return css(css`
@@ -595,7 +576,6 @@ export const Picture = ({
595576
height={fallbackSource.width * ratio}
596577
loading={Picture.disableLazyLoading ? undefined : loading}
597578
css={isLightbox ? flex : block}
598-
style={imageMaxWidth(format.design, 1 / ratio, isMainMedia)}
599579
/>
600580
</picture>
601581
);

0 commit comments

Comments
 (0)