@@ -22,11 +22,7 @@ import { SubtitleOverlay } from './SubtitleOverlay';
2222
2323export type SubtitleSize = 'small' | 'medium' | 'large' ;
2424
25- const videoStyles = (
26- width : number ,
27- height : number ,
28- subtitleSize : SubtitleSize ,
29- ) => css `
25+ const videoStyles = ( width : number , height : number ) => css `
3026 position : relative;
3127 display : block;
3228 height : auto;
@@ -35,7 +31,9 @@ const videoStyles = (
3531 /* Prevents CLS by letting the browser know the space the video will take up. */
3632 aspect-ratio : ${ width } / ${ height } ;
3733 object- fit: cover;
34+ ` ;
3835
36+ const subtitleStyles = ( subtitleSize : SubtitleSize | undefined ) => css `
3937 ::cue {
4038 /* Hide the cue by default as we prefer custom overlay */
4139 visibility : hidden;
@@ -112,19 +110,21 @@ type Props = {
112110 handleLoadedMetadata : ( event : SyntheticEvent ) => void ;
113111 handleLoadedData : ( event : SyntheticEvent ) => void ;
114112 handleCanPlay : ( event : SyntheticEvent ) => void ;
115- handlePlayPauseClick : ( event : SyntheticEvent ) => void ;
116- handleAudioClick : ( event : SyntheticEvent ) => void ;
117- handleKeyDown : ( event : React . KeyboardEvent < HTMLVideoElement > ) => void ;
118- handlePause : ( event : SyntheticEvent ) => void ;
113+ handlePlayPauseClick ? : ( event : SyntheticEvent ) => void ;
114+ handleAudioClick ? : ( event : SyntheticEvent ) => void ;
115+ handleKeyDown ? : ( event : React . KeyboardEvent < HTMLVideoElement > ) => void ;
116+ handlePause ? : ( event : SyntheticEvent ) => void ;
119117 onError : ( event : SyntheticEvent < HTMLVideoElement > ) => void ;
120118 AudioIcon : ( ( iconProps : IconProps ) => JSX . Element ) | null ;
121119 posterImage ?: string ;
122120 preloadPartialData : boolean ;
123121 showPlayIcon : boolean ;
124122 subtitleSource ?: string ;
125- subtitleSize : SubtitleSize ;
123+ subtitleSize ? : SubtitleSize ;
126124 /* used in custom subtitle overlays */
127125 activeCue ?: ActiveCue | null ;
126+ /* Cinemagraphs do not display subtitles or video controls */
127+ isCinemagraph : boolean ;
128128} ;
129129
130130/**
@@ -165,16 +165,26 @@ export const LoopVideoPlayer = forwardRef(
165165 subtitleSource,
166166 subtitleSize,
167167 activeCue,
168+ isCinemagraph,
168169 } : Props ,
169170 ref : React . ForwardedRef < HTMLVideoElement > ,
170171 ) => {
171172 const loopVideoId = `loop-video-${ uniqueId } ` ;
173+ const showSubtitles =
174+ ! ! subtitleSource &&
175+ ! ! subtitleSize &&
176+ ! ! activeCue ?. text &&
177+ ! isCinemagraph ;
178+
172179 return (
173180 < >
174181 { /* eslint-disable-next-line jsx-a11y/media-has-caption -- Captions will be considered later. */ }
175182 < video
176183 id = { loopVideoId }
177- css = { videoStyles ( width , height , subtitleSize ) }
184+ css = { [
185+ videoStyles ( width , height ) ,
186+ showSubtitles && subtitleStyles ( subtitleSize ) ,
187+ ] }
178188 crossOrigin = "anonymous"
179189 ref = { ref }
180190 tabIndex = { 0 }
@@ -228,61 +238,65 @@ export const LoopVideoPlayer = forwardRef(
228238 ) }
229239 { FallbackImageComponent }
230240 </ video >
231- { ! ! activeCue ?. text && (
241+ { showSubtitles && (
232242 < SubtitleOverlay
233243 text = { activeCue . text }
234244 subtitleSize = { subtitleSize }
235245 />
236246 ) }
237- { ref && 'current' in ref && ref . current && isPlayable && (
238- < >
239- { /* Play icon */ }
240- { showPlayIcon && (
241- < button
242- type = "button"
243- onClick = { handlePlayPauseClick }
244- css = { playIconStyles }
245- data-link-name = { `gu-video-loop-play-${ atomId } ` }
246- data-testid = "play-icon"
247- >
248- < PlayIcon iconWidth = "narrow" />
249- </ button >
250- ) }
251- { /* Progress bar */ }
252- < LoopVideoProgressBar
253- videoId = { loopVideoId }
254- currentTime = { currentTime }
255- duration = { ref . current . duration }
256- />
257- { /* Audio icon */ }
258- { AudioIcon && (
259- < button
260- type = "button"
261- onClick = { handleAudioClick }
262- css = { audioButtonStyles }
263- data-link-name = { `gu-video-loop-${
264- isMuted ? 'unmute' : 'mute'
265- } -${ atomId } `}
266- >
267- < div
268- css = { audioIconContainerStyles }
269- data-testid = { `${
247+ { ref &&
248+ 'current' in ref &&
249+ ref . current &&
250+ isPlayable &&
251+ ! isCinemagraph && (
252+ < >
253+ { /* Play icon */ }
254+ { showPlayIcon && (
255+ < button
256+ type = "button"
257+ onClick = { handlePlayPauseClick }
258+ css = { playIconStyles }
259+ data-link-name = { `gu-video-loop-play-${ atomId } ` }
260+ data-testid = "play-icon"
261+ >
262+ < PlayIcon iconWidth = "narrow" />
263+ </ button >
264+ ) }
265+ { /* Progress bar */ }
266+ < LoopVideoProgressBar
267+ videoId = { loopVideoId }
268+ currentTime = { currentTime }
269+ duration = { ref . current . duration }
270+ />
271+ { /* Audio icon */ }
272+ { AudioIcon && (
273+ < button
274+ type = "button"
275+ onClick = { handleAudioClick }
276+ css = { audioButtonStyles }
277+ data-link-name = { `gu-video-loop-${
270278 isMuted ? 'unmute' : 'mute'
271- } -icon `}
279+ } -${ atomId } `}
272280 >
273- < AudioIcon
274- size = "xsmall"
275- theme = { {
276- fill : palette (
277- '--loop-video-audio-icon' ,
278- ) ,
279- } }
280- />
281- </ div >
282- </ button >
283- ) }
284- </ >
285- ) }
281+ < div
282+ css = { audioIconContainerStyles }
283+ data-testid = { `${
284+ isMuted ? 'unmute' : 'mute'
285+ } -icon`}
286+ >
287+ < AudioIcon
288+ size = "xsmall"
289+ theme = { {
290+ fill : palette (
291+ '--loop-video-audio-icon' ,
292+ ) ,
293+ } }
294+ />
295+ </ div >
296+ </ button >
297+ ) }
298+ </ >
299+ ) }
286300 </ >
287301 ) ;
288302 } ,
0 commit comments