Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component: VideoOnClick #3

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
],
"dependencies": {
"@dailybruin/gatsby-source-kerckhoff": "^1.1.1",
"@dailybruin/lux": "1.5.4",
"@dailybruin/lux": "^1.7.0",
"@material-ui/core": "^3.5.1",
"@material-ui/icons": "^3.0.1",
"@types/react": "16.4.18",
"emotion": "^9.2.12",
"emotion-server": "^9.2.12",
Expand All @@ -35,7 +37,8 @@
"react-helmet": "5.2.0",
"react-typography": "0.16.13",
"slugify": "^1.3.2",
"typography": "0.16.17"
"typography": "0.16.17",
"video-react": "^0.13.1"
},
"devDependencies": {
"prettier": "1.14.3"
Expand Down
1 change: 1 addition & 0 deletions src/components/VideoOnClick/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'video-react';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

158 changes: 158 additions & 0 deletions src/components/VideoOnClick/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import * as React from 'react'
import { Player, BigPlayButton, ControlBar } from 'video-react'
import { css } from 'react-emotion'
import IconButton from '@material-ui/core/IconButton'
import Pause from '@material-ui/icons/Pause'
import PlayArrow from '@material-ui/icons/PlayArrow'
import VolumeUp from '@material-ui/icons/VolumeUp'
import VolumeOff from '@material-ui/icons/VolumeOff'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already use font awesome icons for most things, any chance we could use font awesome icons for these?


import 'video-react/dist/video-react.css'

interface VideoOnClickState {
video: boolean
mute: boolean
}

interface VideoOnClickProps {
videoURL: string
imageURL: string
}

class VideoOnClick extends React.Component<
VideoOnClickProps,
VideoOnClickState
> {
state = {
video: false,
mute: false,
}

toggleMuted = () => {
this.setState(prevState => ({ mute: !prevState.mute }))
}

toggle = () => {
this.setState(prevState => ({ video: !prevState.video }))
}

render() {
console.log(this.props)
return (
<div
className={css`
height: 300px;
width: 400px;
`}
>
{this.state.video && (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we're rendering components when we both have video and not, let's use a ternary

<div
className={css`
position: relative;
`}
>
<div
className={css`
position: absolute;
top: 0;
right: 0;
z-index: 100;
color: white;
`}
>
<IconButton onClick={this.toggle}>
<Pause
fontSize="small"
className={css`
color: white;
`}
/>
</IconButton>
</div>
<div
onClick={this.toggleMuted}
className={css`
position: absolute;
bottom: 0;
right: 0;
z-index: 100;
color: white;
`}
>
<IconButton>
{this.state.mute ? (
<VolumeOff
fontSize="small"
className={css`
color: white;
`}
/>
) : (
<VolumeUp
fontSize="small"
className={css`
color: white;
`}
/>
)}
</IconButton>
</div>
<Player
playsInline
autoPlay
poster="/assets/poster.png"
muted={this.state.mute}
src={this.props.videoURL}
>
<BigPlayButton position="center" />
<ControlBar disableCompletely className="my-class" />
</Player>
</div>
)}
{!this.state.video && (
<div
className={css`
position: relative;
filter: none;
-webkit-filter: grayscale(100%);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need vendor prefixes, emotion handles that automatically

-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
transition: 0.2s;
&:hover {
filter: none;
-webkit-filter: grayscale(0%);
-moz-filter: grayscale(0%);
-ms-filter: grayscale(0%);
-o-filter: grayscale(0%);
cursor: pointer;
}
`}
>
<div
className={css`
position: absolute;
top: 0;
right: 0;
z-index: 100;
color: white;
`}
>
<IconButton onClick={this.toggle}>
<PlayArrow
fontSize="small"
className={css`
color: white;
`}
/>
</IconButton>
</div>
<img src={this.props.imageURL} className={css``} />
legitmaxwu marked this conversation as resolved.
Show resolved Hide resolved
</div>
)}
</div>
)
}
}

export default VideoOnClick
5 changes: 5 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import { graphql } from 'gatsby'
import { Article, CoverPhoto, Footer, Head } from '@dailybruin/lux'
import HoverVideo from '../components/VideoOnClick'

export const query = graphql`
query {
Expand Down Expand Up @@ -33,6 +34,10 @@ const IndexPage = ({ data }) => (
/>
<Article dropcap={true} content={data.kerckhoffArticle.content} />
<Footer developers="Nathan Smith" copyrightYear={2018} />
<HoverVideo
imageURL="https://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg"
videoURL="https://media.w3.org/2010/05/sintel/trailer_hd.mp4"
/>
</>
)

Expand Down
Loading