Skip to content

Commit 89f133f

Browse files
committed
Refactor Youtube Overlay
1 parent 17508a1 commit 89f133f

File tree

10 files changed

+234
-290
lines changed

10 files changed

+234
-290
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,9 @@ export const Card = ({
914914
containerType ===
915915
'fixed/video'
916916
}
917-
imagePositionOnMobile={
918-
imagePositionOnMobile
919-
}
920917
//** TODO: IMPROVE THIS MAPPING */
921918
// image size defaults to small if not provided. However, if the headline size is large or greater, we want to assume the image is also large so that the play icon is correctly sized.
922-
imageSize={
919+
iconSizeOnDesktop={
923920
[
924921
'small',
925922
'medium',
@@ -929,9 +926,23 @@ export const Card = ({
929926
].includes(
930927
headlineSizes?.desktop ??
931928
'',
932-
)
929+
) || imageSize !== 'small'
933930
? 'large'
934-
: imageSize
931+
: 'small'
932+
}
933+
iconSizeOnMobile={
934+
imagePositionOnMobile ===
935+
'left' ||
936+
imagePositionOnMobile ===
937+
'right'
938+
? 'small'
939+
: 'large'
940+
}
941+
hidePillOnMobile={
942+
imagePositionOnMobile ===
943+
'left' ||
944+
imagePositionOnMobile ===
945+
'right'
935946
}
936947
enableAds={false}
937948
aspectRatio={aspectRatio}

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

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { css } from '@emotion/react';
22
import { from, palette } from '@guardian/source/foundations';
33
import type { ThemeIcon } from '@guardian/source/react-components';
44
import { SvgMediaControlsPlay } from '@guardian/source/react-components';
5-
import type { ImagePositionType, ImageSizeType } from './ImageWrapper';
65

7-
type PlayButtonSize = keyof typeof sizes;
6+
export type PlayButtonSize = keyof typeof sizes;
87

98
const sizes = {
109
small: { button: 40, icon: 32 },
@@ -46,42 +45,16 @@ const theme = {
4645
fill: palette.neutral[100],
4746
} satisfies Partial<ThemeIcon>;
4847

49-
const getIconSizeOnDesktop = (imageSize: ImageSizeType) => {
50-
switch (imageSize) {
51-
case 'jumbo':
52-
case 'large':
53-
case 'podcast':
54-
case 'carousel':
55-
case 'medium':
56-
case 'feature':
57-
case 'feature-large':
58-
return 'large';
59-
case 'small':
60-
return 'small';
61-
}
48+
type Props = {
49+
iconSizeOnDesktop: PlayButtonSize;
50+
iconSizeOnMobile: PlayButtonSize;
6251
};
6352

64-
const getIconSizeOnMobile = (imagePositionOnMobile: ImagePositionType) =>
65-
imagePositionOnMobile === 'left' || imagePositionOnMobile === 'right'
66-
? 'small'
67-
: 'large';
68-
69-
export const PlayIcon = ({
70-
imageSize,
71-
imagePositionOnMobile,
72-
}: {
73-
imageSize: ImageSizeType;
74-
imagePositionOnMobile: ImagePositionType;
75-
}) => {
53+
export const PlayIcon = ({ iconSizeOnDesktop, iconSizeOnMobile }: Props) => {
7654
return (
7755
<div
7856
className="play-icon"
79-
css={[
80-
iconStyles(
81-
getIconSizeOnDesktop(imageSize),
82-
getIconSizeOnMobile(imagePositionOnMobile),
83-
),
84-
]}
57+
css={[iconStyles(iconSizeOnDesktop, iconSizeOnMobile)]}
8558
>
8659
<SvgMediaControlsPlay theme={theme} />
8760
</div>

dotcom-rendering/src/components/YoutubeAtom/YoutubeAtom.stories.tsx

Lines changed: 14 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import type { Decorator, Meta, StoryObj } from '@storybook/react';
44
import { useState } from 'react';
55
import { ArticleDesign, ArticleDisplay, Pillar } from '../../lib/articleFormat';
66
import type { AdTargeting } from '../../types/commercial';
7-
import type {
8-
ImagePositionType,
9-
ImageSizeType,
10-
} from '../Card/components/ImageWrapper';
117
import type { Props } from './YoutubeAtom';
128
import { YoutubeAtom } from './YoutubeAtom';
139

@@ -129,9 +125,6 @@ const adTargetingAndConsentGiven = {
129125
...consentGiven,
130126
} satisfies AdTargeting & ConsentState;
131127

132-
const imagePositionOnMobile: ImagePositionType = 'none';
133-
const imageSize: ImageSizeType = 'large';
134-
135128
const baseConfiguration = {
136129
atomId: 'a2502abd-1373-45a2-b508-3e5a2ec050be',
137130
videoId: '-ZCvZmYlQD8',
@@ -153,8 +146,10 @@ const baseConfiguration = {
153146
isMainMedia: false,
154147
abTestParticipations: {},
155148
adTargeting: disableAds,
156-
imagePositionOnMobile,
157-
imageSize,
149+
iconSizeOnDesktop: 'large',
150+
iconSizeOnMobile: 'large',
151+
hidePillOnMobile: false,
152+
showTextOverlay: false,
158153
consentState: consentGiven,
159154
renderingTarget: 'Web',
160155
} satisfies Partial<Props>;
@@ -178,26 +173,7 @@ export const NoOverlay = {
178173
},
179174
} satisfies Story;
180175

181-
export const WithOverrideImage = {
182-
args: {
183-
...baseConfiguration,
184-
videoId: '3jpXAMwRSu4',
185-
alt: 'Microscopic image of COVID',
186-
format: {
187-
theme: Pillar.News,
188-
design: ArticleDesign.Standard,
189-
display: ArticleDisplay.Standard,
190-
},
191-
overrideImage:
192-
'https://i.guim.co.uk/img/media/4b3808707ec341629932a9d443ff5a812cf4df14/0_309_1800_1081/master/1800.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc&enable=upscale&s=aff4b8255693eb449f13070df88e9cac',
193-
height: undefined,
194-
width: undefined,
195-
title: 'How to stop the spread of coronavirus',
196-
},
197-
decorators: [OverlayAutoplayExplainer, Container],
198-
} satisfies Story;
199-
200-
export const WithPosterImage = {
176+
export const WithImage = {
201177
args: {
202178
...baseConfiguration,
203179
videoId: 'N9Cgy-ke5-s',
@@ -206,41 +182,21 @@ export const WithPosterImage = {
206182
design: ArticleDesign.Standard,
207183
display: ArticleDisplay.Standard,
208184
},
209-
posterImage:
210-
'https://media.guim.co.uk/757dd4db5818984fd600b41cdaf687668497051d/0_0_1920_1080/1920.jpg',
185+
image: 'https://media.guim.co.uk/757dd4db5818984fd600b41cdaf687668497051d/0_0_1920_1080/1920.jpg',
211186
title: 'How Donald Trump’s broken promises failed Ohio | Anywhere but Washington',
212187
},
213188
decorators: [OverlayAutoplayExplainer, Container],
214189
} satisfies Story;
215190

216-
export const WithOverlayAndPosterImage = {
217-
args: {
218-
...baseConfiguration,
219-
videoId: WithPosterImage.args.videoId,
220-
format: {
221-
theme: Pillar.Opinion,
222-
design: ArticleDesign.Standard,
223-
display: ArticleDisplay.Standard,
224-
},
225-
posterImage: WithPosterImage.args.posterImage,
226-
overrideImage:
227-
'https://i.guim.co.uk/img/media/4b3808707ec341629932a9d443ff5a812cf4df14/0_309_1800_1081/master/1800.jpg',
228-
title: 'How Donald Trump’s broken promises failed Ohio',
229-
kicker: 'Breaking News',
230-
showTextOverlay: true,
231-
},
232-
decorators: [OverlayAutoplayExplainer, Container],
233-
} satisfies Story;
234-
235191
export const GiveConsent = {
236192
args: {
237193
...baseConfiguration,
238194
...consentNotGiven,
239-
videoId: WithOverrideImage.args.videoId,
240-
alt: WithOverrideImage.args.alt,
241-
format: WithOverrideImage.args.format,
242-
title: WithOverrideImage.args.title,
243-
overrideImage: WithOverlayAndPosterImage.args.overrideImage,
195+
videoId: WithImage.args.videoId,
196+
alt: WithImage.args.alt,
197+
format: WithImage.args.format,
198+
title: WithImage.args.title,
199+
image: WithImage.args.image,
244200
},
245201
render: function Render(args) {
246202
const [consented, setConsented] = useState(false);
@@ -385,7 +341,6 @@ export const PausesOffscreen = {
385341
* The ad enabled tests are a convenience for manual testing.
386342
*
387343
*/
388-
389344
export const NoConsentWithAds = {
390345
args: {
391346
...NoConsent.args,
@@ -407,35 +362,10 @@ export const NoOverlayWithAds = {
407362
},
408363
} satisfies Story;
409364

410-
export const WithOverrideImageWithAds = {
411-
args: {
412-
...WithOverrideImage.args,
413-
...adTargetingAndConsentGiven,
414-
overrideImage: WithOverlayAndPosterImage.args.overrideImage,
415-
},
416-
decorators: [Container],
417-
parameters: {
418-
chromatic: { disableSnapshot: true },
419-
},
420-
} satisfies Story;
421-
422-
export const WithPosterImageWithAds = {
423-
args: {
424-
...WithPosterImage.args,
425-
...adTargetingAndConsentGiven,
426-
},
427-
decorators: [Container],
428-
parameters: {
429-
chromatic: { disableSnapshot: true },
430-
},
431-
} satisfies Story;
432-
433-
export const WithOverlayAndPosterImageWithAds = {
365+
export const WithimageWithAds = {
434366
args: {
435-
...WithOverlayAndPosterImage.args,
367+
...WithImage.args,
436368
...adTargetingAndConsentGiven,
437-
kicker: undefined,
438-
showTextOverlay: undefined,
439369
},
440370
decorators: [Container],
441371
parameters: {
@@ -510,8 +440,7 @@ export const LiveStream = {
510440
design: ArticleDesign.Standard,
511441
display: ArticleDisplay.Standard,
512442
},
513-
overrideImage:
514-
'https://i.guim.co.uk/img/media/4b3808707ec341629932a9d443ff5a812cf4df14/0_309_1800_1081/master/1800.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc&enable=upscale&s=aff4b8255693eb449f13070df88e9cac',
443+
image: 'https://i.guim.co.uk/img/media/4b3808707ec341629932a9d443ff5a812cf4df14/0_309_1800_1081/master/1800.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc&enable=upscale&s=aff4b8255693eb449f13070df88e9cac',
515444
height: undefined,
516445
width: undefined,
517446
title: 'How to stop the spread of coronavirus',

0 commit comments

Comments
 (0)