-
-
Save lpirir/d0e2603c80bcc17fd6fe4af8bb688001 to your computer and use it in GitHub Desktop.
Revisions
-
bzerangue revised this gist
Dec 27, 2019 . No changes.There are no files selected for viewing
-
bzerangue created this gist
Dec 27, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,73 @@ import React from 'react' const VideoEmbedPreview = ({ value }) => { const url = value.url const responsiveVideoContainer = { padding: "56.25% 0 0 0", position: "relative" } const responsiveVideoPlayer = { position: "absolute", top: 0, left: 0, width: "100%", height: "100%" } if (url) { // install https://www.npmjs.com/package/get-video-id, to get Vimeo or YouTube IDs const getVideoId = require('get-video-id') const id = getVideoId(url).id const service = getVideoId(url).service const vimeoEmbedUrl = 'https://player.vimeo.com/video/' + id const youtubeEmbedUrl = 'https://www.youtube.com/embed/' + id if (!id) { return <div>Missing YouTube or Vimeo URL</div> } if (service === 'vimeo') { return ( <div style={responsiveVideoContainer}> <iframe src={vimeoEmbedUrl} style={responsiveVideoPlayer} frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe> </div> ) } if (service === 'youtube') { return ( <div style={responsiveVideoContainer}> <iframe src={youtubeEmbedUrl} style={responsiveVideoPlayer} frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </div> ) } } return <div></div> } export default { name: 'videoEmbed', type: 'object', title: 'Video Embed', fields: [ { name: 'url', type: 'url', title: 'URL' } ], preview: { select: { url: 'url' }, component: VideoEmbedPreview } }