import React, { VideoHTMLAttributes, forwardRef, useRef, useState, useEffect } from 'react'; import classNames from 'classnames'; import { Box, IconButton, Icon, Icons, Tooltip, TooltipProvider, Text } from 'folds'; import * as css from './media.css'; import * as videoCss from './videoControls.css'; type VideoProps = VideoHTMLAttributes & { disableControls?: boolean; onExpand?: () => void; }; export const Video = forwardRef( ({ className, disableControls, onExpand, ...props }, ref) => { const videoRef = useRef(null); const [showControls, setShowControls] = useState(false); useEffect(() => { if (typeof ref === 'function') { ref(videoRef.current); } else if (ref) { ref.current = videoRef.current; } }, [ref]); useEffect(() => { if (!onExpand) return; const video = videoRef.current; if (!video) return; const handleFullscreenRequest = (evt: Event) => { evt.preventDefault(); evt.stopImmediatePropagation(); onExpand(); }; video.addEventListener('webkitbeginfullscreen', handleFullscreenRequest); return () => { video.removeEventListener('webkitbeginfullscreen', handleFullscreenRequest); }; }, [onExpand]); if (disableControls) { return ( // eslint-disable-next-line jsx-a11y/media-has-caption