Skip to content

Commit 32a0b30

Browse files
committed
Move image container to image component
1 parent 106655f commit 32a0b30

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

dotcom-rendering/src/components/Masthead/HighlightsCard.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,6 @@ const content = css`
104104
padding-bottom: 10px;
105105
}
106106
`;
107-
108-
const imageStyles = css`
109-
position: relative;
110-
align-self: flex-end;
111-
flex-shrink: 0;
112-
height: 98px;
113-
width: 98px;
114-
115-
${until.tablet} {
116-
margin-top: ${space[2]}px;
117-
}
118-
`;
119-
120-
/** An avatar should align with the bottom of the card */
121-
const nonAvatarImageStyles = css`
122-
margin-bottom: 10px;
123-
`;
124-
125107
const starWrapper = css`
126108
width: fit-content;
127109
margin-top: ${space[1]}px;
@@ -211,15 +193,15 @@ export const HighlightsCard = ({
211193
)}
212194
</div>
213195

214-
<div css={[imageStyles, !avatarUrl && nonAvatarImageStyles]}>
196+
{(!!avatarUrl || !!image) && (
215197
<HighlightsCardImage
216198
imageLoading={imageLoading}
217199
image={image}
218200
avatarUrl={avatarUrl}
219201
byline={byline}
220202
mainMedia={mainMedia}
221203
/>
222-
</div>
204+
)}
223205
</div>
224206
</FormatBoundary>
225207
);

dotcom-rendering/src/components/Masthead/HighlightsCardImage.tsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
import { css } from '@emotion/react';
2+
import { space, until } from '@guardian/source/foundations';
13
import type { DCRFrontImage } from '../../types/front';
24
import type { MainMedia } from '../../types/mainMedia';
35
import { Avatar } from '../Avatar';
46
import type { Loading } from '../CardPicture';
57
import { CardPicture } from '../CardPicture';
68

9+
const imageStyles = css`
10+
position: relative;
11+
align-self: flex-end;
12+
flex-shrink: 0;
13+
height: 98px;
14+
width: 98px;
15+
16+
${until.tablet} {
17+
margin-top: ${space[2]}px;
18+
}
19+
`;
20+
21+
/** An avatar should align with the bottom of the card */
22+
const nonAvatarImageStyles = css`
23+
margin-bottom: 10px;
24+
`;
25+
726
type Props = {
827
imageLoading: Loading;
928
image?: DCRFrontImage;
@@ -21,19 +40,21 @@ export const HighlightsCardImage = ({
2140
}: Props) => {
2241
if (avatarUrl) {
2342
return (
24-
<Avatar
25-
src={avatarUrl}
26-
alt={byline ?? ''}
27-
shape="cutout"
28-
imageSize="large"
29-
/>
43+
<div css={imageStyles}>
44+
<Avatar
45+
src={avatarUrl}
46+
alt={byline ?? ''}
47+
shape="cutout"
48+
imageSize="large"
49+
/>
50+
</div>
3051
);
3152
}
3253

3354
if (image) {
3455
if (mainMedia?.type === 'Audio' && mainMedia.podcastImage?.src) {
3556
return (
36-
<>
57+
<div css={[imageStyles, nonAvatarImageStyles]}>
3758
<CardPicture
3859
imageSize="medium"
3960
mainImage={mainMedia.podcastImage.src}
@@ -43,12 +64,12 @@ export const HighlightsCardImage = ({
4364
aspectRatio="1:1"
4465
/>
4566
<div className="image-overlay" />
46-
</>
67+
</div>
4768
);
4869
}
4970

5071
return (
51-
<>
72+
<div css={[imageStyles, nonAvatarImageStyles]}>
5273
<CardPicture
5374
imageSize="highlights-card"
5475
mainImage={image.src}
@@ -59,7 +80,7 @@ export const HighlightsCardImage = ({
5980
/>
6081
{/* This image overlay is styled when the CardLink is hovered */}
6182
<div className="image-overlay circular" />
62-
</>
83+
</div>
6384
);
6485
}
6586

0 commit comments

Comments
 (0)