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

feat(video): add autoPlay prop to set initial isPlaying state #553

Merged
merged 1 commit into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/example/src/pages/components/Video.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ The `<Video>` component can render a Vimeo player or a html video player.
| 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. |
| autoPlay | boolean | | | Whether or not the video should autoplay. |
10 changes: 8 additions & 2 deletions packages/gatsby-theme-carbon/src/components/Video/Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
videoIsPlaying,
} from './Video.module.scss';

const Video = ({ vimeoId, title, src, poster, ...props }) => {
const [isPlaying, setIsPlaying] = useState(false);
const Video = ({ autoPlay, vimeoId, title, src, poster, ...props }) => {
const [isPlaying, setIsPlaying] = useState(autoPlay);
const videoRef = useRef(null);
const iframeRef = useRef(null);
const buttonClassName = cx(videoButton, {
Expand Down Expand Up @@ -98,6 +98,7 @@ const Video = ({ vimeoId, title, src, poster, ...props }) => {
</div>
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
<video
autoPlay={autoPlay}
className={video}
type="video/mp4"
ref={videoRef}
Expand All @@ -111,6 +112,7 @@ const Video = ({ vimeoId, title, src, poster, ...props }) => {
};

Video.propTypes = {
autoPlay: PropTypes.bool,
vimeoId: PropTypes.string,
children: PropTypes.element,
src: PropTypes.string,
Expand Down Expand Up @@ -140,4 +142,8 @@ Video.propTypes = {
},
};

Video.defaultProps = {
autoPlay: false,
};

export default Video;