11import { css } from '@emotion/react' ;
22import { log , storage } from '@guardian/libs' ;
3- import { space } from '@guardian/source/foundations' ;
3+ import { from , space } from '@guardian/source/foundations' ;
44import { SvgAudio , SvgAudioMute } from '@guardian/source/react-components' ;
55import { useCallback , useEffect , useRef , useState } from 'react' ;
66import {
@@ -18,6 +18,7 @@ import {
1818 customSelfHostedVideoPlayAudioEventName ,
1919 customYoutubePlayEventName ,
2020} from '../lib/video' ;
21+ import { palette } from '../palette' ;
2122import type { VideoPlayerFormat } from '../types/mainMedia' ;
2223import { CardPicture , type Props as CardPictureProps } from './CardPicture' ;
2324import { useConfig } from './ConfigContext' ;
@@ -29,9 +30,23 @@ import type {
2930import { SelfHostedVideoPlayer } from './SelfHostedVideoPlayer' ;
3031import { ophanTrackerWeb } from './YoutubeAtom/eventEmitters' ;
3132
32- const videoContainerStyles = css `
33+ const videoAndBackgroundStyles = css `
34+ position : relative;
35+ display : flex;
36+ justify-content : space-around;
3337 z-index : ${ getZIndex ( 'video-container' ) } ;
38+ background-color : ${ palette ( '--video-background' ) } ;
39+ ` ;
40+
41+ const videoContainerStyles = ( width : number , height : number ) => css `
3442 position : relative;
43+ height : 100% ;
44+ max-height : 100vh ;
45+ max-height : 100svh ;
46+ max-width : 100% ;
47+ ${ from . tablet } {
48+ max-width: ${ ( width / height ) * 80 } %;
49+ }
3550` ;
3651
3752const cinemagraphContainerStyles = css `
@@ -662,45 +677,47 @@ export const SelfHostedVideo = ({
662677 : undefined ;
663678
664679 return (
665- < figure
666- ref = { setNode }
667- css = { [
668- videoContainerStyles ,
669- isCinemagraph && cinemagraphContainerStyles ,
670- ] }
671- className = { `video-container ${ videoStyle . toLocaleLowerCase ( ) } ` }
672- data-component = "gu-video-loop"
673- >
674- < SelfHostedVideoPlayer
675- sources = { sources }
676- atomId = { atomId }
677- uniqueId = { uniqueId }
678- width = { width }
679- height = { height }
680- videoStyle = { videoStyle }
681- posterImage = { optimisedPosterImage }
682- FallbackImageComponent = { FallbackImageComponent }
683- currentTime = { currentTime }
684- setCurrentTime = { setCurrentTime }
685- ref = { vidRef }
686- isPlayable = { isPlayable }
687- playerState = { playerState }
688- isMuted = { isMuted }
689- handleLoadedMetadata = { handleLoadedMetadata }
690- handleLoadedData = { handleLoadedData }
691- handleCanPlay = { handleCanPlay }
692- handlePlayPauseClick = { handlePlayPauseClick }
693- handleAudioClick = { handleAudioClick }
694- handleKeyDown = { handleKeyDown }
695- handlePause = { handlePause }
696- onError = { onError }
697- AudioIcon = { hasAudio ? AudioIcon : null }
698- preloadPartialData = { preloadPartialData }
699- showPlayIcon = { showPlayIcon }
700- subtitleSize = { subtitleSize }
701- subtitleSource = { subtitleSource }
702- activeCue = { activeCue }
703- />
704- </ figure >
680+ < div css = { videoAndBackgroundStyles } className = "loop-video-container" >
681+ < figure
682+ ref = { setNode }
683+ css = { [
684+ videoContainerStyles ( width , height ) ,
685+ isCinemagraph && cinemagraphContainerStyles ,
686+ ] }
687+ className = { `video-container ${ videoStyle . toLocaleLowerCase ( ) } ` }
688+ data-component = "gu-video-loop"
689+ >
690+ < SelfHostedVideoPlayer
691+ sources = { sources }
692+ atomId = { atomId }
693+ uniqueId = { uniqueId }
694+ width = { width }
695+ height = { height }
696+ videoStyle = { videoStyle }
697+ posterImage = { optimisedPosterImage }
698+ FallbackImageComponent = { FallbackImageComponent }
699+ currentTime = { currentTime }
700+ setCurrentTime = { setCurrentTime }
701+ ref = { vidRef }
702+ isPlayable = { isPlayable }
703+ playerState = { playerState }
704+ isMuted = { isMuted }
705+ handleLoadedMetadata = { handleLoadedMetadata }
706+ handleLoadedData = { handleLoadedData }
707+ handleCanPlay = { handleCanPlay }
708+ handlePlayPauseClick = { handlePlayPauseClick }
709+ handleAudioClick = { handleAudioClick }
710+ handleKeyDown = { handleKeyDown }
711+ handlePause = { handlePause }
712+ onError = { onError }
713+ AudioIcon = { hasAudio ? AudioIcon : null }
714+ preloadPartialData = { preloadPartialData }
715+ showPlayIcon = { showPlayIcon }
716+ subtitleSource = { subtitleSource }
717+ subtitleSize = { subtitleSize }
718+ activeCue = { activeCue }
719+ />
720+ </ figure >
721+ </ div >
705722 ) ;
706723} ;
0 commit comments