Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-modal-video

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-modal-video

Modal Video Viewer

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
74K
increased by16.96%
Maintainers
1
Weekly downloads
 
Created
Source

react-modal-video

React Modal Video Component

Features

  • Not affected by dom structure.
  • Beautiful transition
  • Accessible for keyboard navigation and screen readers.
  • Rich options for youtube API and Vimeo API

Demo

https://unpkg.com/react-modal-video@latest/test/index.html

Install

npm

npm install react-modal-video

Usage

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"
				youtube={{ mute: 0, autoplay: 0 }}
				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

propertiesdefault
channel'youtube'
youtubeautoplay1
cc_load_policy1
colornull
controls1
disablekb0
enablejsapi0
endnull
fs1
h1null
iv_load_policy1
listnull
listTypenull
loop0
modestbrandingnull
originnull
playlistnull
playsinlinenull
rel0
showinfo1
start0
wmode'transparent'
theme'dark'
mute0
vimeoapifalse
autopausetrue
autoplaytrue
bylinetrue
callbacknull
colornull
heightnull
loopfalse
maxheightnull
maxwidthnull
player_idnull
portraittrue
titletrue
widthnull
xhtmlfalse
youkuautoplay1
show_related0
customurlMP4 URL / iframe URL
ratio'16:9'
allowFullScreentrue
animationSpeed300
classNamesmodalVideo'modal-video'
modalVideoClose'modal-video-close'
modalVideoBody'modal-video-body'
modalVideoInner'modal-video-inner'
modalVideoIframeWrap'modal-video-movie-wrap'
modalVideoCloseBtn'modal-video-close-btn'
ariaopenMessage'You just opened the modal video'
dismissBtnMessage'Close the modal by clicking here'

FAQ

How to track YouTube videos playing in modal-video by GA4?

  1. Enable JS API. Turn enablejsapi property to 1.
  2. Load YouTube Iframe API. Add <script src="https://www.youtube.com/iframe_api"></script> in HTML file.

Licence

MIT

FAQs

Package last updated on 21 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc