-
Notifications
You must be signed in to change notification settings - Fork 273
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
feat: extend Video component / image/caption spacing fix #160
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d3f58cc
feat(video): add locally sourced video support
alisonjoseph a0a2da9
chore: update video example
alisonjoseph 3e77cda
fix(caption: fix caption and image spacing
alisonjoseph b07dfb0
chore: update video html
alisonjoseph bd3e762
fix: remove extra wrapper div
alisonjoseph e8bdcfa
chore: cleanup classnames
alisonjoseph 06948ed
chore: update component
alisonjoseph b7b1fea
Merge branch 'master' into Video
vpicone e947edb
chore: Add prop-type validation, vtt support, and use css modules
vpicone 78b2a4b
Merge branch 'Video' of github.com:alisonjoseph/gatsby-theme-carbon i…
vpicone b0af487
Merge branch 'master' into Video
vpicone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: Video | ||
--- | ||
|
||
<PageDescription> | ||
|
||
The `<Video>` component can render a Vimeo player or a html video player. | ||
|
||
</PageDescription> | ||
|
||
## Example | ||
|
||
#### Vimeo | ||
|
||
<Video title="Eyes" vimeoId="310583077" /> | ||
|
||
#### Video | ||
|
||
<Video src="/videos/hero-video.mp4" poster="/images/poster.png"> | ||
<track default src="/videos/vtt/hero-video.vtt" srcLang="en" /> | ||
</Video> | ||
|
||
## Code | ||
|
||
#### Vimeo | ||
|
||
``` | ||
<Video title="Eyes" vimeoId="310583077" /> | ||
``` | ||
|
||
#### Video | ||
|
||
``` | ||
<Video src="/videos/hero-video.mp4" poster="/images/poster.png"> | ||
<track default src="/videos/vtt/hero-video.vtt" srcLang="en" /> | ||
</Video> | ||
|
||
``` | ||
|
||
## Props | ||
|
||
| property | propType | required | default | description | | ||
| -------- | ---------------------------------------------------------------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| vimeoId | string | | | To find your `vimeoId`, go to the Vimeo page and find the video you want to put on your website. Once it is loaded, look at the URL and look for the numbers that come after the slash (/). | | ||
| src | string | | | Use the html `<video>` player with a local `.mp4` video | | ||
| title | string | | | Vimeo title | | ||
| poster | string | | | Provides an image to show before the video loads, only works with `src` | | ||
| children | [`<track>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track) | | | _non-vimeo only_ – Provide `.vtt` file in your static directory to make your videos more accessible. Then add a track element with a src pointing to it Check out [this simple tutorial](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API#Tutorial_on_how_to_write_a_WebVTT_file) for getting started with writing vtt files. | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
WEBVTT | ||
|
||
00:00:00.500 --> 00:00:02.000 | ||
This is a video text track (vtt) file. | ||
|
||
00:00:02.500 --> 00:00:04.300 | ||
Use it to give your videos captions for accessibility. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 54 additions & 26 deletions
80
packages/gatsby-theme-carbon/src/components/Video/Video.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,63 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { settings } from 'carbon-components'; | ||
import cx from 'classnames'; | ||
|
||
const { prefix } = settings; | ||
|
||
export default class Vimeo extends React.Component { | ||
static propTypes = { | ||
vimeoId: PropTypes.string.isRequired, | ||
title: PropTypes.string.isRequired, | ||
}; | ||
|
||
render() { | ||
const { vimeoId, title } = this.props; | ||
import { video, vimeo } from './Video.module.scss'; | ||
|
||
export const Video = ({ vimeoId, title, ...props }) => { | ||
if (vimeoId) { | ||
return ( | ||
<div className={`${prefix}--video`}> | ||
<div className="gatsby-resp-iframe-wrapper"> | ||
<div className="embedVideo-container"> | ||
<iframe | ||
title={title} | ||
src={`https://player.vimeo.com/video/${vimeoId}`} | ||
width="640" | ||
height="360" | ||
frameBorder="0" | ||
webkitallowfullscreen="true" | ||
mozallowfullscreen="true" | ||
allowFullScreen | ||
/> | ||
</div> | ||
<div className={cx(video, vimeo)}> | ||
<div className="embedVideo-container"> | ||
<iframe | ||
title={title} | ||
src={`https://player.vimeo.com/video/${vimeoId}`} | ||
width="640" | ||
height="360" | ||
frameBorder="0" | ||
webkitallowfullscreen="true" | ||
mozallowfullscreen="true" | ||
allowFullScreen | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
// eslint-disable-next-line jsx-a11y/media-has-caption | ||
<video className={video} controls type="video/mp4" {...props} /> | ||
); | ||
}; | ||
|
||
Video.propTypes = { | ||
vimeoId: PropTypes.string, | ||
children: PropTypes.element, | ||
src: PropTypes.string, | ||
title: PropTypes.string, | ||
poster: PropTypes.string, | ||
videoSourceValidator: props => { | ||
if (!props.vimeoId && !props.src) { | ||
return new Error( | ||
`The Video component requires either a 'vimeoId' Or a 'src' prop` | ||
); | ||
} | ||
if (props.vimeoId && props.src) { | ||
return new Error( | ||
`You can only specify one source for the Video component. Use either the 'vimeoId' OR the 'src' prop.` | ||
); | ||
} | ||
if (props.vimeoId && props.poster) { | ||
return new Error( | ||
`You can't specify a poster for vimeo videos. You can control the poster image from the Vimeo control panel` | ||
); | ||
} | ||
if (props.vimeoId && props.children) { | ||
return new Error( | ||
`You can't specify children/tracks for vimeo videos. You can control the captions from the Vimeo control panel` | ||
); | ||
} | ||
}, | ||
}; | ||
|
||
export default Video; |
7 changes: 5 additions & 2 deletions
7
...me-carbon/src/components/Video/video.scss → ...on/src/components/Video/Video.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this if we're targeting the
img
as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because the actual image tag is nested inside so we need to target this for the sibling selector to work