Giter Site home page Giter Site logo

appleple / react-modal-video Goto Github PK

View Code? Open in Web Editor NEW
177.0 10.0 86.0 2.9 MB

Accessible React Modal Video Component

Home Page: https://appleple.github.io/react-modal-video/

License: MIT License

JavaScript 80.00% HTML 1.24% SCSS 9.65% CSS 9.11%
es6 react ui-components modal youtube vimeo accessibility

react-modal-video's Introduction

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

properties default
channel 'youtube'
youtube autoplay 1
cc_load_policy 1
color null
controls 1
disablekb 0
enablejsapi 0
end null
fs 1
h1 null
iv_load_policy 1
list null
listType null
loop 0
modestbranding null
origin null
playlist null
playsinline null
rel 0
showinfo 1
start 0
wmode 'transparent'
theme 'dark'
mute 0
vimeo api false
autopause true
autoplay true
byline true
callback null
color null
height null
loop false
maxheight null
maxwidth null
player_id null
portrait true
title true
width null
xhtml false
youku autoplay 1
show_related 0
custom url MP4 URL / iframe URL
ratio '16:9'
allowFullScreen true
animationSpeed 300
classNames modalVideo 'modal-video'
modalVideoClose 'modal-video-close'
modalVideoBody 'modal-video-body'
modalVideoInner 'modal-video-inner'
modalVideoIframeWrap 'modal-video-movie-wrap'
modalVideoCloseBtn 'modal-video-close-btn'
aria openMessage '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

react-modal-video's People

Contributors

1000-x-t30 avatar abhinavrana avatar albertinator avatar ankit307 avatar atsu666 avatar aulisius avatar dependabot[bot] avatar fabiodiceglie avatar joanargarrido avatar llbbl avatar meabed avatar michaeljscript avatar mkasumi avatar msftenhanceprovenance avatar steelydylan avatar uidev1116 avatar vlladdrakk avatar yoshi0207 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-modal-video's Issues

Issues with updated react transition dependency commit

When the timeout prop was removed in commit cd406da it created propType errors:

Failed prop type: The prop timeout is marked as required in CSSTransition, but its value is undefined.

I am not super familiar with react-transition-group, but when I looked at the documentation, I only see references to the timeout prop, not the newly added transitionEnterTimeout and transitionLeaveTimeout, I believe these are removed from newer versions.

Am I missing something here?

Version update

Hey,

Can you update the version and publish the new one on npm! :D

Thanks,
Faizaan.

ModalVideo not closing in mobile view.

The video plays fine in all the views. It closes when i click the close button or the (overlay) shaded part. But the close option doesn't work in mobile view.
When logging the videoOpen variable that controls the display or closing of the modal, it is set to true when clicking the close option.
Any help on fixing this or am I missing something?

Here's the code
<ModalVideo channel='youtube' isOpen={this.state.videoOpen} videoId={this.props.data.video} onClose={() => this.setState({videoOpen: false})} />

Override style classes

Ehy, I'm trying to override default style but no luck.. can you provide a code snippet please?

!!Multiple video link getting only the last link... Any solution?

import React, { Component } from 'react'

import ModalVideo from 'react-modal-video'

class Video extends React.Component {
   constructor () {
      super()
      this.state = {
        isOpen: false
      }
      this.openModal = this.openModal.bind(this)
    }
  
    openModal () {
      this.setState({isOpen: true})
    }
  
    render() {

      
    
        return (
          
            <div>
      
      <div class="container">

              
               <ModalVideo channel='youtube' isOpen={this.state.isOpen} videoId='L61p2uyiMSo' onClose={() => this.setState({isOpen: false})} />
            <a href="javascript:void(0)" class="thumb  multimedia-icon-video big js-video-button" onClick={this.openModal}>
                     <picture title="Pipes on Road">
                   
                  
                        <img src="assets/images/world-news02.jpg" alt="Pipes on Road" title="Pipes on Road"/>
                     </picture>
                  </a>
     
                  
        
            </div>

            <div class="col-12"> 
               <ModalVideo channel='vimeo' isOpen={this.state.isOpen} videoId='132793529' onClose={() => this.setState({isOpen: false})} />
              <a href="javascript:void(0)" class="thumb multimedia-icon-video js-video-button" onClick={this.openModal} >
                 <img class="image-style-medium-v" src="assets/images/world-news03.jpg" alt="বৈসাবি"/>
                 </a> 

</div>
</div>



         </div>
        )
    }
}

export default Video

!!Multiple video link getting only the last link... Any solution?

Player not working in Chrome v79.x /Mac OS

Hi all,

We are implementing this component for showcasing a video on our homepage. Initially it seems the player works great, but there is a problem with the playback on Chrome on Mac (not sure if the problem is on windows machines too)

Steps to reproduce;

  1. Open Chrome (79.xx) on Mac
  2. Go to: https://5df78e1025d5380007230c3f--employes.netlify.com/
  3. Click on the play-button to play the video
  4. Start video
  5. BUG: sounds is playing but video is stuck after short period of time

Also the autoplay does not work on Chrome. Our website is built in GatsbyJS v2.

Does anyone know what the problem could be?

Incorrect iframe url

Hi! Thanks for the lib!
I am using this inside a chrome extension. And the final iframe that the ModalVideo component produces looks like this:
"//www.youtube.com/embed/P37IDOQ8jkI?autoplay=1&amp;cc_load_policy=1&amp;controls=1&amp;disablekb=0&amp;enablejsapi=0&amp;fs=1&amp;iv_load_policy=1&amp;loop=0&amp;rel=0&amp;showinfo=1&amp;start=0&amp;wmode=transparent&amp;theme=dark"
I had to manually add 'https:' here

return '//www.youtube.com/embed/' + videoId + '?' + query
to make it work.

Fix - Remove Outdated stringify Package Due to Security Vulnerability

Description:
The stringify package in our repository is outdated, not utilized, and poses a potential security risk due to an identified vulnerability. Specifically, the package is no longer in use and contains a known vulnerability, the "kangax html-minifier REDoS vulnerability". This vulnerability, discovered in kangax html-minifier 4.0.0, exposes our system to Regular Expression Denial of Service (ReDoS) attacks via the candidate variable in htmlminifier.js.

Considering that the package serves no active purpose in our codebase and presents a security concern, it's imperative to remove it from the repository to mitigate any potential risks.

Action Plan:

  1. Removal of the stringify Package:
    • We propose removing the stringify package from this repository entirely.
    • This action will not impact any existing functionality as the package is not in use.

Autoplay documentation

Hi!

I have been working with definitely typed with this package. And, I don't see the actual code that implements the prop autoplay as is used in the Functional Component snippet documentation.

In every vendor autoplay prop is passed in as a query param contructor inside it's own interface props.youtube: {autoplay:1} like so not props.autoplay.

So I'm not sure about this, because it might happen that I actually miss the line (it happens =D), but probably worth to check it up.
Have a nice day!

Clean up dependencies

Move eslint configs, sass etc. to devDependecies. It's causing peer dependency errors when installing.

[Nextjs] ReferenceError: window is not defined

Hello, thank you for this great lib.

When using this lib with Nextjs we got this error :

ReferenceError: window is not defined

Call Stack
new ModalVideo
file:///Users/jeremy/Documents/Dev/SITES/twitchsocial/node_modules/react-modal-video/lib/index.js (35:76)

Any idea ? Thanks

start option for youtube is mis-typed.

The YouTube API documentation says that the start parameter should be able to be any positive integer value, but it is currently typed that it can only be 0 or 1. Here are some screenshots of the YouTube API docs and the current code.

Current Code
Screenshot 2023-09-12 111924
YouTube API Docs
Screenshot 2023-09-12 112055

No option to close pop up in mobile landscape mode.

I have tested this in various devices, issue I found is in landscape mode for mobiles only. In Portrait mode video can be closed by tapping anywhere outside the video which is normal default behavior for mobile videos, but on landscape mode, it takes whole screen so there is no room to tap outside video.

Links and clickable elements that update the state of other components activate modal video.

I have a grid of videos which when clicked set the state of the React-modal-video to isOpen:true.

I also have a header component, separate from the grid of videos, that when clicked is activating the React modal video too. This header component is a menu that expands in and out, and modifies its own state with an onClick function.

How can we prevent your video grid from activating when other buttons modify their own state (menuIsOpen)?

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided (<URL>) does not match the recipient window's origin <URL>.

Hi,

www-widgetapi.js:148 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://www.youtube.com') does not match the recipient window's origin ('https://www.leadershipneverstops.org').

I am getting this error if I open the video modal on the real website. But it works fine on the localhost. Do you have any idea?

<ModalVideo channel='youtube' isOpen={modalOpen} videoId='U5gf51-wG18' onClose={toggleModal}/>
Thanks

not working

this is not working on react version 18.2.0. bring a solution

Unclear documentation on using properties

Hey there,

Looking over the docs, I'm not 100% sure how I am supposed to use some of the sub-property props.

I.e. "youtube show info" or "youtube controls = 0"

Am I missing something?

Load cannot follow more than 20 redirections with "http" instead of "https"

Not sure how this error occurs.

Here is my code.

"use client";

import React from "react";
import ModalVideo from "react-modal-video";

import "react-modal-video/scss/modal-video.scss";

import useGlobalContext from "@/hooks/useGlobalContext";

const VideoPopup = ({ videoId }) => {
  const popupValue = useGlobalContext();
  const { isOpen, setIsOpen } = popupValue;

  return (
    <>
      <ModalVideo
        channel="youtube"
        youtube={{ mute: 0, autoplay: 0 }}
        isOpen={isOpen}
        videoId={videoId}
        onClose={() => setIsOpen(false)}
      />
    </>
  );
};

export default VideoPopup;

When I run the modal, it gave me an error something like

  • Load cannot follow more than 20 redirections
  • http://www.youtube.com/embed/qEI33ptjd98?mute=0&autoplay=0

With "http" not "https"


package.json

"next": "14.0.4",
"react": "^18",
"react-modal-video": "^2.0.1"
Screen Shot 2024-01-05 at 02 14 11

video cropped on low height

when height is < 540px it is cropped. tested on demo website with vimeo & youtube.

expected behaviour: modal video should not overflow window, height should equal window height and width should be reduced to keep aspect ratio.

Not working in React 18

react-modal-video is not getting installed in React 18, so kindly update react-modal-video to work in latest version of React.

Affected by DOM structure?

Am i missing some css or...?

This is my VideoModal component:

import React, { useState } from "react";
import ModalVideo from "react-modal-video";
import styled from "styled-components";

import video_mockup from "../../resources/video_mockup.png";

function VideoModal(props) {
  const [videoIsOpen, setVideoIsOpen] = useState(false);
  return (
    <>
      <ModalVideo
        channel="youtube"
        autoplay
        isOpen={videoIsOpen}
        videoId="L61p2uyiMSo"
        onClose={() => setVideoIsOpen(false)}
      />

      <Mockup
        src={video_mockup}
        alt="mockup1"
        onClick={() => setVideoIsOpen(true)}
      />
    </>
  );
}

const Mockup = styled.img`
  width: 100%;
`;

export default VideoModal;

and this is what i get:

Screenshot 2021-08-12 at 14 46 39

autoplay NOT working in mobile browser

Issue: When trying to view the video in a mobile browser (safari or chrome) video does not auto play. Also after clicking play the video takes 10-15s to load.

What I tried: Different devices different network (WIFI and Data)

Youtube autoplay is no longer working

Using ?autoplay=1 no longer seems to work with YouTube videos.

I managed to get it working by removing any config from the videoId prop and hacking a version of this library so that the iFrame element has this attribute:

 allow="autoplay; encrypted-media"

I think the way to fix this would be to have a new prop such as youtubeAutoplay so that the above attribute is added to the iframe.

Related issue on Stack Overflow:
https://stackoverflow.com/questions/48086769/youtube-iframe-api-allow-autoplay-chrome-65

ReferenceError: window is not defined on NextJS Build

I have come across an issue when compiling NextJS into a published build. When you compile using next build, it comes up with an issue ReferenceError: window is not defined.

I have worked out a fix for this which would be useful for those using the Next JS Framework. Is there a way to add this to your code?

Legacy context API warning

index.js:1 Warning: Legacy context API has been detected within a strict-mode tree.

The old API will be supported in all 16.x releases, but applications using it should migrate to the new version.

Please update the following components: Transition

Device Orientation warning

Hi there,

I am using the React-Modal-Video package to play a vimeo video. Everything works great but I am getting a warning from chrome - 'The deviceorientation events are blocked by feature policy. See https://github.com/WICG/feature-policy/blob/gh-pages/features.md#sensor-features' -- at 'VM4884 player.js:2'. Is there a way of stopping this warning?

I have tried setting portrait to false - as this was the only parameter I could see that related to orientation but no luck.

Cheers

Properties have no effect for vimeo channel

When passing any of the options provided in the README, nothing changes.

Here's my code:
<ModalVideo channel='vimeo' autopause={false} autoplay={true} title={true} isOpen={this.state.isVideoOpen} videoId={${this.state.videoID}} onClose={() => this.setState({ isVideoOpen: false })} />

Unable to play unlisted Vimeo videos

On Vimeo, unlisted videos may be played using the URL format https://vimeo.com/[video_id]/[unlisted_hash]. It would would be great if an unlisted_hash could be passed in to allow for this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.