import React, { Component } from 'react'; import { Text } from '@rebass/emotion'; import { fontSizes, lineHeights, space, BREAKPOINT_VALUES } from 'utils/theme'; import typography from 'utils/typography'; import { VideoModuleProps } from './video-module.types'; import { FluidContainer } from 'utils/styles/mixins'; import * as Styles from './video-module.styles'; class VideoModule extends Component { renderCopy = (title: string, copy: string) => { return ( <> { title && {title} } { copy && {copy} } ) } renderVideoPlayer = (url: string, loop: boolean): JSX.Element | null => { const isVimeo = url.indexOf('vimeo') > -1 const urlSplit = url.split('/'); const videoId = urlSplit[urlSplit.length - 1] return isVimeo ? ( ) : null } render() { const { data: { video: { url }, title, copy, loop } } = this.props const screenWidth = (typeof window !== 'undefined' && window !== null) ? window.innerWidth : BREAKPOINT_VALUES.MEDIUM; const isWindowAvailable: boolean = (typeof window !== 'undefined' && window !== null); const video: JSX.Element | null = this.renderVideoPlayer(url, loop); const videoContent = isWindowAvailable ? ( {video} ) : ( {video} ); return ( {(title || copy) && this.renderCopy(title, copy)} {videoContent} ) } } export default VideoModule