Skip to content

Commit 0c7d621

Browse files
committed
Refactor Podcast image styling
1 parent 909df92 commit 0c7d621

File tree

3 files changed

+64
-96
lines changed

3 files changed

+64
-96
lines changed

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

Lines changed: 19 additions & 50 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 */
@@ -228,10 +226,10 @@ const HorizontalDivider = () => (
228226
);
229227

230228
const podcastImageStyles = (
231-
fixImageWidth: boolean,
229+
isSmallCard: boolean,
232230
imagePositionOnDesktop: MediaPositionType,
233231
) => {
234-
if (fixImageWidth) {
232+
if (isSmallCard) {
235233
return css`
236234
width: 69px;
237235
height: 69px;
@@ -242,22 +240,17 @@ const podcastImageStyles = (
242240
`;
243241
}
244242

245-
if (
246-
imagePositionOnDesktop === 'top' ||
247-
imagePositionOnDesktop === 'bottom'
248-
) {
249-
return css`
250-
width: 98px;
251-
height: 98px;
252-
${from.tablet} {
253-
width: 120px;
254-
height: 120px;
255-
}
256-
`;
257-
}
243+
const isHorizontalOnDesktop =
244+
imagePositionOnDesktop === 'left' || imagePositionOnDesktop === 'right';
258245

259-
// Don't fix the image width if the image is horizontal on desktop
260-
return undefined;
246+
return css`
247+
width: 98px;
248+
height: 98px;
249+
${from.tablet} {
250+
width: ${isHorizontalOnDesktop ? 'unset' : '120px'};
251+
height: ${isHorizontalOnDesktop ? 'unset' : '120px'};
252+
}
253+
`;
261254
};
262255

263256
const getMedia = ({
@@ -403,7 +396,6 @@ export const Card = ({
403396
showTopBarMobile = true,
404397
trailTextSize,
405398
showKickerImage = false,
406-
fixImageWidth,
407399
headlinePosition = 'inner',
408400
showLabsRedesign = false,
409401
}: Props) => {
@@ -590,27 +582,7 @@ export const Card = ({
590582
containerType === 'flexible/special' ||
591583
containerType === 'flexible/general';
592584

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

615587
const hideTrailTextUntil = () => {
616588
if (isFlexibleContainer) {
@@ -664,7 +636,10 @@ export const Card = ({
664636
return { row: 'small', column: 'small' };
665637
}
666638

667-
if (isSmallCard) {
639+
if (
640+
containerType === 'scrollable/small' ||
641+
containerType === 'scrollable/medium'
642+
) {
668643
return {
669644
row: 'medium',
670645
column: 'medium',
@@ -906,19 +881,13 @@ export const Card = ({
906881
{media && (
907882
<MediaWrapper
908883
mediaSize={mediaSize}
909-
mediaFixedSizes={mediaFixedSizeOptions()}
910884
mediaType={media.type}
911885
mediaPositionOnDesktop={mediaPositionOnDesktop}
912886
mediaPositionOnMobile={mediaPositionOnMobile}
913-
fixImageWidth={
914-
fixImageWidth ??
915-
(!isBetaContainer &&
916-
(mediaPositionOnMobile === 'left' ||
917-
mediaPositionOnMobile === 'right'))
918-
}
919887
hideImageOverlay={media.type === 'slideshow'}
920888
padMedia={isMediaCardOrNewsletter && isBetaContainer}
921889
isBetaContainer={isBetaContainer}
890+
isSmallCard={isSmallCard}
922891
>
923892
{media.type === 'slideshow' && (
924893
<div
@@ -1126,7 +1095,7 @@ export const Card = ({
11261095
{media.podcastImage?.src && !showKickerImage ? (
11271096
<div
11281097
css={podcastImageStyles(
1129-
!!fixImageWidth,
1098+
isSmallCard,
11301099
mediaPositionOnDesktop,
11311100
)}
11321101
>

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

Lines changed: 45 additions & 45 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

@@ -150,6 +141,7 @@ const flexBasisStyles = ({
150141
`;
151142
}
152143
};
144+
153145
/**
154146
* Below tablet, we fix the size of the media and add a margin around it.
155147
* The corresponding content flex grows to fill the space.
@@ -163,43 +155,48 @@ const fixMediaWidthStyles = (width: number) => css`
163155
align-self: flex-start;
164156
`;
165157

166-
const fixMediaWidth = ({
167-
mobile,
168-
tablet,
169-
desktop,
170-
}: MediaFixedSizeOptions) => css`
171-
${mobile &&
172-
css`
158+
const fixMobileMediaWidth = (
159+
isBetaContainer: boolean,
160+
isSmallCard: boolean,
161+
) => {
162+
if (!isBetaContainer) {
163+
return css`
164+
${until.tablet} {
165+
${fixMediaWidthStyles(mediaFixedSize.medium)}
166+
}
167+
`;
168+
}
169+
170+
const size = isSmallCard ? mediaFixedSize.tiny : mediaFixedSize.small;
171+
172+
return css`
173173
${until.tablet} {
174-
${fixMediaWidthStyles(mediaFixedSize[mobile])}
175-
}
176-
`}
177-
${tablet &&
178-
css`
179-
${between.tablet.and.desktop} {
180-
${fixMediaWidthStyles(mediaFixedSize[tablet])}
174+
${fixMediaWidthStyles(size)}
181175
}
182-
`}
183-
${desktop &&
184-
css`
185-
${from.desktop} {
186-
${fixMediaWidthStyles(mediaFixedSize[desktop])}
176+
`;
177+
};
178+
179+
const fixDesktopMediaWidth = () => {
180+
return css`
181+
${from.tablet} {
182+
${fixMediaWidthStyles(mediaFixedSize.small)}
187183
}
188-
`}
189-
`;
184+
`;
185+
};
190186

191187
export const MediaWrapper = ({
192188
children,
193189
mediaSize,
194-
mediaFixedSizes = { mobile: 'medium' },
195190
mediaType,
196191
mediaPositionOnDesktop,
197192
mediaPositionOnMobile,
198-
fixImageWidth,
199193
hideImageOverlay,
200-
isBetaContainer = false,
194+
isBetaContainer,
195+
isSmallCard,
201196
padMedia,
202197
}: Props) => {
198+
const isHorizontalOnMobile =
199+
mediaPositionOnMobile === 'left' || mediaPositionOnMobile === 'right';
203200
const isHorizontalOnDesktop =
204201
mediaPositionOnDesktop === 'left' || mediaPositionOnDesktop === 'right';
205202

@@ -215,15 +212,6 @@ export const MediaWrapper = ({
215212
mediaSize,
216213
isBetaContainer,
217214
}),
218-
mediaType === 'podcast' &&
219-
isHorizontalOnDesktop &&
220-
!fixImageWidth &&
221-
css`
222-
flex-basis: 120px;
223-
${from.desktop} {
224-
flex-basis: 168px;
225-
}
226-
`,
227215
mediaType === 'avatar' &&
228216
css`
229217
display: flex;
@@ -236,7 +224,19 @@ export const MediaWrapper = ({
236224
display: none;
237225
}
238226
`,
239-
fixImageWidth && fixMediaWidth(mediaFixedSizes),
227+
isHorizontalOnMobile &&
228+
mediaType !== 'podcast' &&
229+
fixMobileMediaWidth(isBetaContainer, isSmallCard),
230+
isSmallCard && fixDesktopMediaWidth(),
231+
mediaType === 'podcast' &&
232+
isHorizontalOnDesktop &&
233+
!isSmallCard &&
234+
css`
235+
flex-basis: 120px;
236+
${from.desktop} {
237+
flex-basis: 168px;
238+
}
239+
`,
240240
isHorizontalOnDesktop &&
241241
css`
242242
${from.tablet} {

dotcom-rendering/src/components/ScrollableSmall.importable.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export const ScrollableSmall = ({
104104
showTopBarMobile={mobileBottomCards.includes(index)}
105105
canPlayInline={false}
106106
showLabsRedesign={showLabsRedesign}
107-
fixImageWidth={true}
108107
/>
109108
</ScrollableCarousel.Item>
110109
);

0 commit comments

Comments
 (0)