11'use client'
2- import { type HTMLProps , useEffect , useRef , useState } from 'react'
2+ import { type HTMLProps , useEffect , useRef } from 'react'
33import videojs from 'video.js'
44import 'video.js/dist/video-js.css'
55import type Player from 'video.js/dist/types/player'
6+ import { twMerge } from '@/lib/twMerge/twMerge'
67import useVideojsAnalytics from './useVideojsAnalytics'
78
89//Needed?
@@ -46,15 +47,15 @@ export const Video: React.FC<VideoProps> = ({
4647 options,
4748 onReady,
4849 useBrandTheme = false ,
49- containVideo = false ,
50+ // containVideo = false,
51+ className = '' ,
5052} ) => {
5153 const videoRef = useRef < HTMLDivElement > ( null )
5254 const playerRef = useRef < Player > ( null )
5355 const videoElementRef = useRef < HTMLElement | null > ( null )
5456 const onReadyRef = useRef < VideoProps [ 'onReady' ] > ( onReady )
5557 const sourceKeyRef = useRef ( '' )
56- const [ isReady , setIsReady ] = useState ( false )
57- const { src, title, autoplay = false , fill, aspectRatio } = options
58+ const { src, title, autoplay = false } = options
5859
5960 const getSourceKey = ( source : unknown ) : string => {
6061 if ( typeof source === 'string' ) {
@@ -107,29 +108,24 @@ export const Video: React.FC<VideoProps> = ({
107108 videoElement . classList . add ( 'vjs-envis-brand' )
108109 }
109110 if ( variant === 'fullwidth' ) {
110- videoElement . classList . add ( 'vjs-fullwidth' )
111- }
112- if (
113- ! containVideo &&
114- ( fill || aspectRatio === '10:3' || aspectRatio === '21:9' )
115- ) {
116- videoElement . classList . add ( 'vjs-fill' , 'lg:[&>video]:object-cover' )
117- }
118- if ( aspectRatio === '16:9' ) {
119- videoElement . classList . add ( 'vjs-16-9' )
120- }
121- if ( aspectRatio === '4:3' ) {
122- videoElement . classList . add ( 'vjs-4-3' )
123- }
124- if ( aspectRatio === '9:16' ) {
125- videoElement . classList . add ( 'vjs-9-16' )
111+ videoElement . classList . add (
112+ 'vjs-fullwidth' ,
113+ 'vjs-fill' ,
114+ 'lg:[&>video]:object-cover' ,
115+ )
116+ } else {
117+ videoElement . classList . add (
118+ 'pt-0!' ,
119+ 'w-full!' ,
120+ 'h-full!' ,
121+ '[&>video]:object-contain' ,
122+ '[&>video]:relative!' ,
123+ )
126124 }
127125
128126 videoRef . current ?. appendChild ( videoElement )
129- setIsReady ( false )
130127
131128 const markReady = ( ) => {
132- setIsReady ( true )
133129 videoElement . classList . add ( 'vjs-ready' )
134130 }
135131
@@ -150,17 +146,7 @@ export const Video: React.FC<VideoProps> = ({
150146 return ( ) => {
151147 window . clearTimeout ( readyTimeout )
152148 }
153- } , [
154- aspectRatio ,
155- autoplay ,
156- containVideo ,
157- fill ,
158- options ,
159- sourceKey ,
160- src ,
161- useBrandTheme ,
162- variant ,
163- ] )
149+ } , [ autoplay , options , sourceKey , src , useBrandTheme , variant ] )
164150
165151 useEffect ( ( ) => {
166152 const player = playerRef . current
@@ -171,11 +157,9 @@ export const Video: React.FC<VideoProps> = ({
171157 player . autoplay ( autoplay )
172158
173159 if ( sourceKey && sourceKeyRef . current !== sourceKey ) {
174- setIsReady ( false )
175160 videoElementRef . current ?. classList . remove ( 'vjs-ready' )
176161
177162 const markReady = ( ) => {
178- setIsReady ( true )
179163 videoElementRef . current ?. classList . add ( 'vjs-ready' )
180164 }
181165 const readyTimeout = window . setTimeout ( markReady , 350 )
@@ -202,14 +186,7 @@ export const Video: React.FC<VideoProps> = ({
202186 }
203187 } , [ ] )
204188
205- return (
206- < div
207- className = { `video-player h-full w-full transition-opacity duration-300 ${ isReady ? 'video-player--ready opacity-100' : 'opacity-0' } ` }
208- data-vjs-player
209- >
210- < div ref = { videoRef } className = { `h-full w-full` } />
211- </ div >
212- )
189+ return < div ref = { videoRef } className = { twMerge ( `h-full w-full` , className ) } />
213190}
214191
215192export default Video
0 commit comments