2.0.0 • Published 3 years ago
react-modal-video-new v2.0.0
react-modal-video-new
React Modal Video Component forked from appleple/react-modal-video to support react 18
Features
- Not affected by dom structure.
- Beautiful transition
- Accessible for keyboard navigation and screen readers.
- Rich options for youtube API and Vimeo API
Demo
http://rawgit.com/appleple/react-modal-video/master/test/
Install
npm
npm install react-modal-videoUsage
import sass file to your project
@import 'node_modules/react-modal-video/scss/modal-video.scss';Functional Implementation with Hooks
import React,{useState} from 'react'
import ReactDOM from 'react-dom'
import ModalVideo from 'react-modal-video'
const App = () => {
	const [isOpen, setOpen] = useState(false)
	return (
		<React.Fragment>
			<ModalVideo channel='youtube' autoplay isOpen={isOpen} videoId="L61p2uyiMSo" onClose={() => setOpen(false)} />
			<button className="btn-primary" onClick={()=> setOpen(true)}>VIEW DEMO</button>
		</React.Fragment>
	)
}
ReactDOM.render(
  <App />,
    document.getElementById('root')
)Class Implementation
change "isOpen" property to open and close the modal-video
import React from 'react'
import ReactDOM from 'react-dom'
import ModalVideo from 'react-modal-video'
class App extends React.Component {
  constructor () {
    super()
    this.state = {
      isOpen: false
    }
    this.openModal = this.openModal.bind(this)
  }
  openModal () {
    this.setState({isOpen: true})
  }
  render () {
    return (
      <React.Fragment>
        <ModalVideo channel='youtube' isOpen={this.state.isOpen} videoId='L61p2uyiMSo' onClose={() => this.setState({isOpen: false})} />
        <button onClick={this.openModal}>Open</button>
      </React.Fragment>
    )
  }
}
ReactDOM.render(
  <App />,
    document.getElementById('root')
)Options
- About YouTube options, please refer to https://developers.google.com/youtube/player_parameters?hl=en
- About Vimeo options, please refer to https://developer.vimeo.com/apis/oembed
FAQ
How to track YouTube videos playing in modal-video by GA4?
- Enable JS API. Turn enablejsapiproperty to1.
- Load YouTube Iframe API. Add <script src="https://www.youtube.com/iframe_api"></script>in HTML file.
Licence
2.0.0
3 years ago