Skip to content

Commit ad24e67

Browse files
authored
Merge pull request #14753 from guardian/doml/podcast-sizing-flexgen
Extend podcast image size in Flexible General half-width slot
2 parents 3e89995 + 0c3dc4f commit ad24e67

File tree

2 files changed

+93
-93
lines changed

2 files changed

+93
-93
lines changed

dotcom-rendering/src/components/Card/Card.tsx

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import { CardWrapper } from './components/CardWrapper';
6666
import { ContentWrapper } from './components/ContentWrapper';
6767
import { HeadlineWrapper } from './components/HeadlineWrapper';
6868
import type {
69-
MediaFixedSizeOptions,
7069
MediaPositionType,
7170
MediaSizeType,
7271
} from './components/MediaWrapper';
@@ -157,7 +156,6 @@ export type Props = {
157156
trailTextSize?: TrailTextSize;
158157
/** A kicker image is seperate to the main media and renders as part of the kicker */
159158
showKickerImage?: boolean;
160-
fixImageWidth?: boolean;
161159
/** Determines if the headline should be positioned within the content or outside the content */
162160
headlinePosition?: 'inner' | 'outer';
163161
/** Feature flag for the labs redesign work */
@@ -227,33 +225,37 @@ const HorizontalDivider = () => (
227225
/>
228226
);
229227

230-
const podcastImageStyles = (imageSize: MediaSizeType) => {
231-
switch (imageSize) {
232-
case 'scrollable-small':
233-
return css`
234-
width: 69px;
235-
height: 69px;
236-
${from.tablet} {
237-
width: 98px;
238-
height: 98px;
239-
}
240-
`;
241-
242-
case 'scrollable-medium':
243-
return css`
228+
const podcastImageStyles = (
229+
isSmallCard: boolean,
230+
imagePositionOnDesktop: MediaPositionType,
231+
) => {
232+
if (isSmallCard) {
233+
return css`
234+
width: 69px;
235+
height: 69px;
236+
${from.tablet} {
244237
width: 98px;
245238
height: 98px;
246-
${from.tablet} {
247-
width: 120px;
248-
height: 120px;
249-
}
250-
`;
251-
default:
252-
return css`
253-
width: 120px;
254-
height: 120px;
255-
`;
239+
}
240+
`;
256241
}
242+
243+
const isHorizontalOnDesktop =
244+
imagePositionOnDesktop === 'left' || imagePositionOnDesktop === 'right';
245+
246+
return css`
247+
width: 98px;
248+
height: 98px;
249+
${from.tablet} {
250+
width: 120px;
251+
height: 120px;
252+
}
253+
/** The image takes the full height on desktop, so that the waveform sticks to the bottom of the card. */
254+
${from.desktop} {
255+
width: ${isHorizontalOnDesktop ? 'unset' : '120px'};
256+
height: ${isHorizontalOnDesktop ? 'unset' : '120px'};
257+
}
258+
`;
257259
};
258260

259261
const getMedia = ({
@@ -399,7 +401,6 @@ export const Card = ({
399401
showTopBarMobile = true,
400402
trailTextSize,
401403
showKickerImage = false,
402-
fixImageWidth,
403404
headlinePosition = 'inner',
404405
showLabsRedesign = false,
405406
}: Props) => {
@@ -586,27 +587,7 @@ export const Card = ({
586587
containerType === 'flexible/special' ||
587588
containerType === 'flexible/general';
588589

589-
const isSmallCard =
590-
containerType === 'scrollable/small' ||
591-
containerType === 'scrollable/medium';
592-
593-
const mediaFixedSizeOptions = (): MediaFixedSizeOptions => {
594-
if (isSmallCard) {
595-
return {
596-
mobile: 'tiny',
597-
tablet: 'small',
598-
desktop: 'small',
599-
};
600-
}
601-
602-
if (isFlexibleContainer) {
603-
return {
604-
mobile: 'small',
605-
};
606-
}
607-
608-
return { mobile: 'medium' };
609-
};
590+
const isSmallCard = containerType === 'scrollable/small';
610591

611592
const hideTrailTextUntil = () => {
612593
if (isFlexibleContainer) {
@@ -660,7 +641,10 @@ export const Card = ({
660641
return { row: 'small', column: 'small' };
661642
}
662643

663-
if (isSmallCard) {
644+
if (
645+
containerType === 'scrollable/small' ||
646+
containerType === 'scrollable/medium'
647+
) {
664648
return {
665649
row: 'medium',
666650
column: 'medium',
@@ -902,18 +886,13 @@ export const Card = ({
902886
{media && (
903887
<MediaWrapper
904888
mediaSize={mediaSize}
905-
mediaFixedSizes={mediaFixedSizeOptions()}
906889
mediaType={media.type}
907890
mediaPositionOnDesktop={mediaPositionOnDesktop}
908891
mediaPositionOnMobile={mediaPositionOnMobile}
909-
fixImageWidth={
910-
fixImageWidth ??
911-
(mediaPositionOnMobile === 'left' ||
912-
mediaPositionOnMobile === 'right')
913-
}
914892
hideImageOverlay={media.type === 'slideshow'}
915893
padMedia={isMediaCardOrNewsletter && isBetaContainer}
916894
isBetaContainer={isBetaContainer}
895+
isSmallCard={isSmallCard}
917896
>
918897
{media.type === 'slideshow' && (
919898
<div
@@ -1119,7 +1098,12 @@ export const Card = ({
11191098
{media.type === 'podcast' && (
11201099
<>
11211100
{media.podcastImage?.src && !showKickerImage ? (
1122-
<div css={podcastImageStyles(mediaSize)}>
1101+
<div
1102+
css={podcastImageStyles(
1103+
isSmallCard,
1104+
mediaPositionOnDesktop,
1105+
)}
1106+
>
11231107
<CardPicture
11241108
mainImage={media.podcastImage.src}
11251109
imageSize="small"

dotcom-rendering/src/components/Card/components/MediaWrapper.tsx

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ const mediaFixedSize = {
99
medium: 125,
1010
};
1111

12-
type MediaFixedSize = keyof typeof mediaFixedSize;
13-
14-
export type MediaFixedSizeOptions = {
15-
mobile?: MediaFixedSize;
16-
tablet?: MediaFixedSize;
17-
desktop?: MediaFixedSize;
18-
};
19-
2012
export type MediaPositionType = 'left' | 'top' | 'right' | 'bottom' | 'none';
2113
export type MediaSizeType =
2214
| 'small'
@@ -36,18 +28,17 @@ export type MediaSizeType =
3628
type Props = {
3729
children: React.ReactNode;
3830
mediaSize: MediaSizeType;
39-
mediaFixedSizes?: MediaFixedSizeOptions;
4031
mediaType?: CardMediaType;
4132
mediaPositionOnDesktop: MediaPositionType;
4233
mediaPositionOnMobile: MediaPositionType;
43-
fixImageWidth: boolean;
4434
/**
4535
* Forces hiding the image overlay added to pictures & slideshows on hover.
4636
* This is to allow hiding the overlay on slideshow carousels where we don't
4737
* want it to be shown whilst retaining it for existing slideshows.
4838
*/
4939
hideImageOverlay?: boolean;
50-
isBetaContainer?: boolean;
40+
isBetaContainer: boolean;
41+
isSmallCard: boolean;
5142
padMedia?: boolean;
5243
};
5344

@@ -86,9 +77,13 @@ const mediaPaddingStyles = (
8677
*/
8778
const flexBasisStyles = ({
8879
mediaSize,
80+
mediaType,
81+
isSmallCard,
8982
isBetaContainer,
9083
}: {
9184
mediaSize: MediaSizeType;
85+
mediaType: CardMediaType;
86+
isSmallCard: boolean;
9287
isBetaContainer: boolean;
9388
}): SerializedStyles => {
9489
if (!isBetaContainer) {
@@ -119,6 +114,15 @@ const flexBasisStyles = ({
119114
}
120115
}
121116

117+
if (mediaType === 'podcast' && !isSmallCard) {
118+
return css`
119+
flex-basis: 120px;
120+
${from.desktop} {
121+
flex-basis: 168px;
122+
}
123+
`;
124+
}
125+
122126
switch (mediaSize) {
123127
default:
124128
case 'small':
@@ -150,6 +154,7 @@ const flexBasisStyles = ({
150154
`;
151155
}
152156
};
157+
153158
/**
154159
* Below tablet, we fix the size of the media and add a margin around it.
155160
* The corresponding content flex grows to fill the space.
@@ -163,43 +168,48 @@ const fixMediaWidthStyles = (width: number) => css`
163168
align-self: flex-start;
164169
`;
165170

166-
const fixMediaWidth = ({
167-
mobile,
168-
tablet,
169-
desktop,
170-
}: MediaFixedSizeOptions) => css`
171-
${mobile &&
172-
css`
171+
const fixMobileMediaWidth = (
172+
isBetaContainer: boolean,
173+
isSmallCard: boolean,
174+
) => {
175+
if (!isBetaContainer) {
176+
return css`
177+
${until.tablet} {
178+
${fixMediaWidthStyles(mediaFixedSize.medium)}
179+
}
180+
`;
181+
}
182+
183+
const size = isSmallCard ? mediaFixedSize.tiny : mediaFixedSize.small;
184+
185+
return css`
173186
${until.tablet} {
174-
${fixMediaWidthStyles(mediaFixedSize[mobile])}
187+
${fixMediaWidthStyles(size)}
175188
}
176-
`}
177-
${tablet &&
178-
css`
179-
${between.tablet.and.desktop} {
180-
${fixMediaWidthStyles(mediaFixedSize[tablet])}
181-
}
182-
`}
183-
${desktop &&
184-
css`
185-
${from.desktop} {
186-
${fixMediaWidthStyles(mediaFixedSize[desktop])}
189+
`;
190+
};
191+
192+
const fixDesktopMediaWidth = () => {
193+
return css`
194+
${from.tablet} {
195+
${fixMediaWidthStyles(mediaFixedSize.small)}
187196
}
188-
`}
189-
`;
197+
`;
198+
};
190199

191200
export const MediaWrapper = ({
192201
children,
193202
mediaSize,
194-
mediaFixedSizes = { mobile: 'medium' },
195203
mediaType,
196204
mediaPositionOnDesktop,
197205
mediaPositionOnMobile,
198-
fixImageWidth,
199206
hideImageOverlay,
200-
isBetaContainer = false,
207+
isBetaContainer,
208+
isSmallCard,
201209
padMedia,
202210
}: Props) => {
211+
const isHorizontalOnMobile =
212+
mediaPositionOnMobile === 'left' || mediaPositionOnMobile === 'right';
203213
const isHorizontalOnDesktop =
204214
mediaPositionOnDesktop === 'left' || mediaPositionOnDesktop === 'right';
205215

@@ -209,10 +219,13 @@ export const MediaWrapper = ({
209219
(mediaType === 'slideshow' ||
210220
mediaType === 'picture' ||
211221
mediaType === 'youtube-video' ||
212-
mediaType === 'loop-video') &&
222+
mediaType === 'loop-video' ||
223+
mediaType === 'podcast') &&
213224
isHorizontalOnDesktop &&
214225
flexBasisStyles({
215226
mediaSize,
227+
mediaType,
228+
isSmallCard,
216229
isBetaContainer,
217230
}),
218231
mediaType === 'avatar' &&
@@ -227,7 +240,10 @@ export const MediaWrapper = ({
227240
display: none;
228241
}
229242
`,
230-
fixImageWidth && fixMediaWidth(mediaFixedSizes),
243+
isHorizontalOnMobile &&
244+
mediaType !== 'podcast' &&
245+
fixMobileMediaWidth(isBetaContainer, isSmallCard),
246+
isSmallCard && fixDesktopMediaWidth(),
231247
isHorizontalOnDesktop &&
232248
css`
233249
${from.tablet} {

0 commit comments

Comments
 (0)