import React, { useEffect, useRef } from 'react' import { useInView } from '../../../_utils/useInView' import { SectionContentSize } from '../../../layout/section/baseSection' import { StyledVideoSection } from './VideoSection.style' export type VideoSectionProps = Readonly<{ title: string sources: Array children: React.ReactNode className?: string }> /** * A specialized section which shows a tutorial video alongside some descriptive content. */ export const VideoSection: React.SFC = ({ children, sources, title, className = '', }: VideoSectionProps) => { const videoRef = useRef() const inViewport = useInView(videoRef, { threshold: 1, }) // Automatically play the video when the container is visible on screen useEffect(() => { if (inViewport) { videoRef.current.play() } else if (!videoRef.current.paused) { videoRef.current.pause() } }, [inViewport]) return ( {title} {sources.map(source => ( ))} {children} ) }