Skip to content

Commit e26099b

Browse files
committed
Pass in fallback image. Remove poster image.
1 parent 4a836f0 commit e26099b

File tree

2 files changed

+13
-39
lines changed

2 files changed

+13
-39
lines changed

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

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ import { log } from '@guardian/libs';
33
import { space } from '@guardian/source/foundations';
44
import { SvgAudio, SvgAudioMute } from '@guardian/source/react-components';
55
import { useEffect, useRef, useState } from 'react';
6-
import type { FEAspectRatio } from '../frontend/feFront';
76
import { getZIndex } from '../lib/getZIndex';
87
import { useIsInView } from '../lib/useIsInView';
98
import { useShouldAdapt } from '../lib/useShouldAdapt';
109
import { palette } from '../palette';
11-
import type { ImageSizeType } from './Card/components/ImageWrapper';
1210
import { narrowPlayIconWidth, PlayIcon } from './Card/components/PlayIcon';
13-
import type { Loading } from './CardPicture';
14-
import { CardPicture } from './CardPicture';
1511
import { useConfig } from './ConfigContext';
1612
import { LoopVideoProgressBar } from './LoopVideoProgressBar';
1713

@@ -49,33 +45,22 @@ const audioButtonStyles = css`
4945
cursor: pointer;
5046
`;
5147

52-
type ImageProps = {
53-
posterImage: string;
54-
imageSize: ImageSizeType;
55-
imageLoading: Loading;
56-
altText?: string;
57-
aspectRatio?: FEAspectRatio;
58-
};
59-
60-
type Props = ImageProps & {
48+
type Props = {
6149
src: string;
6250
videoId?: string;
6351
width?: number;
6452
height?: number;
6553
hasAudio?: boolean;
54+
fallbackImage: JSX.Element;
6655
};
6756

6857
export const LoopVideo = ({
6958
src,
7059
videoId,
71-
posterImage,
72-
imageSize,
73-
imageLoading,
74-
altText,
75-
aspectRatio,
7660
width = 600,
7761
height = 360,
7862
hasAudio = true,
63+
fallbackImage,
7964
}: Props) => {
8065
const adapted = useShouldAdapt();
8166
const { renderingTarget } = useConfig();
@@ -132,15 +117,7 @@ export const LoopVideo = ({
132117
if (renderingTarget !== 'Web') return null;
133118

134119
if (adapted) {
135-
return (
136-
<CardPicture
137-
mainImage={posterImage}
138-
imageSize={imageSize}
139-
alt={altText}
140-
loading={imageLoading}
141-
aspectRatio={aspectRatio}
142-
/>
143-
);
120+
return fallbackImage;
144121
}
145122

146123
const handleClick = (event: React.SyntheticEvent) => {
@@ -226,7 +203,6 @@ export const LoopVideo = ({
226203
loop={true}
227204
muted={isMuted}
228205
playsInline={true}
229-
poster={posterImage}
230206
height={height}
231207
width={width}
232208
onPlaying={() => {
@@ -241,13 +217,7 @@ export const LoopVideo = ({
241217
{/* Ensure webm source is provided */}
242218
{/* <source src={webmSrc} type="video/webm"> */}
243219
<source src={src} type="video/mp4" />
244-
<CardPicture
245-
mainImage={posterImage}
246-
imageSize={imageSize}
247-
alt={altText}
248-
loading={imageLoading}
249-
aspectRatio={aspectRatio}
250-
/>
220+
{fallbackImage}
251221
</video>
252222
{vidRef.current && (
253223
<>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22
import { centreColumnDecorator } from '../../.storybook/decorators/gridDecorators';
3+
import { CardPicture } from './CardPicture';
34
import { LoopVideo } from './LoopVideo.importable';
45

56
export default {
@@ -13,10 +14,13 @@ export const Default = {
1314
name: 'Default',
1415
args: {
1516
src: 'https://uploads.guim.co.uk/2024/10/01/241001HeleneLoop_2.mp4',
16-
posterImage:
17-
'https://i.guim.co.uk/img/media/13dd7e5c4ca32a53cd22dfd90ac1845ef5e5d643/91_0_1800_1080/master/1800.jpg?width=465&dpr=1&s=none&crop=5%3A4',
18-
imageSize: 'large',
19-
imageLoading: 'eager',
17+
fallbackImage: (
18+
<CardPicture
19+
mainImage="https://i.guim.co.uk/img/media/13dd7e5c4ca32a53cd22dfd90ac1845ef5e5d643/91_0_1800_1080/master/1800.jpg?width=465&dpr=1&s=none&crop=5%3A4"
20+
imageSize="large"
21+
loading="eager"
22+
/>
23+
),
2024
},
2125
} satisfies StoryObj<typeof LoopVideo>;
2226

0 commit comments

Comments
 (0)