Improving video sections.

This commit is contained in:
Dom Masters
2018-05-08 06:55:22 +10:00
parent 462006ab0a
commit 86e66b48fb
4 changed files with 37 additions and 9 deletions

View File

@ -24,6 +24,7 @@
import React from 'react'; import React from 'react';
import Page from './../Page'; import Page from './../Page';
import VideoSection from './../../section/video/VideoSection'; import VideoSection from './../../section/video/VideoSection';
import Section from './../../section/Section';
class Homepage extends React.Component { class Homepage extends React.Component {
constructor(props) { constructor(props) {
@ -36,6 +37,10 @@ class Homepage extends React.Component {
<VideoSection full mp4={ require('./../../videos/about/programming/programming.mp4') }> <VideoSection full mp4={ require('./../../videos/about/programming/programming.mp4') }>
Test Test
</VideoSection> </VideoSection>
<Section full>
Lorem
</Section>
</Page> </Page>
); );
} }

View File

@ -37,6 +37,8 @@ class VideoSection extends React.Component {
className="c-video-section__video" className="c-video-section__video"
autoPlay autoPlay
loop loop
fill
sources={ this.props.sources ? this.props.sources : this.props }
/> />
{ this.props.children } { this.props.children }

View File

@ -2,7 +2,7 @@
* Video * Video
* Video Object, with general fallbacks and smarter controls for better * Video Object, with general fallbacks and smarter controls for better
* cross-browser compatibility. * cross-browser compatibility.
* *
* Also allows for better and more styled controls. * Also allows for better and more styled controls.
* *
* Dependencies: * Dependencies:
@ -11,8 +11,17 @@
* 1.0.0 - 2018/05/07 * 1.0.0 - 2018/05/07
*/ */
.o-video { .o-video {
position: relative;
&__video { &__video {
&.is-full {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit:cover;
}
} }
} }

View File

@ -23,9 +23,10 @@
import React from 'react'; import React from 'react';
//Adjust the order to adjust the load position
const VALID_SOURCES = [ const VALID_SOURCES = [
"mp4",
"webm", "webm",
"mp4",
"ogg" "ogg"
] ]
@ -37,6 +38,8 @@ class Video extends React.Component {
render() { render() {
//TODO: Add image fallback support. //TODO: Add image fallback support.
//TODO: Add state support, as well as functional controls. //TODO: Add state support, as well as functional controls.
//Sources
let sources = []; let sources = [];
let sourceProps = this.props.sources ? this.props.sources : this.props; let sourceProps = this.props.sources ? this.props.sources : this.props;
@ -46,6 +49,7 @@ class Video extends React.Component {
sources.push(<source type={"video/"+s} src={sourceProps[s]} key={s} />); sources.push(<source type={"video/"+s} src={sourceProps[s]} key={s} />);
} }
//Classes
let clazz = "o-video"; let clazz = "o-video";
if(this.props.className) clazz += " " + this.props.className; if(this.props.className) clazz += " " + this.props.className;
if(sourceProps.image) clazz += " has-image"; if(sourceProps.image) clazz += " has-image";
@ -53,19 +57,27 @@ class Video extends React.Component {
if(this.props.autoplay) clazz += " is-autoplaying"; if(this.props.autoplay) clazz += " is-autoplaying";
if(this.props.loop) clazz += " is-looping"; if(this.props.loop) clazz += " is-looping";
let videoClass = "o-video__video";
if(this.props.fill) videoClass += " is-full";
//Fallback.
let fallback;
return ( return (
<div class={clazz}> <div className={clazz}>
{ /* Video Element (And sources) */ } { /* Video Element (And sources) */ }
<video className="o-video__video" autoPlay={this.props.autoPlay} loop={this.props.loop} > <video
className={ videoClass }
autoPlay={this.props.autoPlay}
loop={this.props.loop}
controls={false /* Explicitly no controls */}
>
{ sources } { sources }
</video> </video>
{ /* Fallback Picture */ } { /* Fallback Picture */ }
{ { fallback }
if(sourceProps.image) {
<img src={sourceProps.image} className="o-video__image" />
}
}
</div> </div>
); );
} }