• Stars
    star
    176
  • Rank 216,923 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Accessible React Modal Video Component

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

More Repositories

1

SmartPhoto

The most easy to use responsive image viewer especially for mobile devices
JavaScript
904
star
2

scroll-hint

A JS library to suggest that the elements are scrollable horizontally, with the pointer icon.
JavaScript
338
star
3

smartblock

intuitive block based wysiwyg editor built with React and ProseMirror
TypeScript
307
star
4

lookforward

A small library that helps you to create smooth transitions between pages with the easiest way
JavaScript
303
star
5

modal-video

JavaScript
267
star
6

lite-editor

A Modern WYSIWYG Editor especially for inline elements
JavaScript
176
star
7

form-storage

A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again.
JavaScript
164
star
8

pretty-scroll

A modern JS library to make an element follow you as you scroll
JavaScript
143
star
9

a-table.js

Simple Table UI for generating table html
JavaScript
83
star
10

hiraku

jQuery Offcanvas Menu Plugin
JavaScript
76
star
11

hiraku2

Vanilla JavaScript library to make drawer menus
JavaScript
69
star
12

document-outliner

HTML5 outliner
TypeScript
20
star
13

yahoo-map-cluster

Yahoo! Map Cluster
TypeScript
19
star
14

multi-menu

JavaScript for multi level menu
TypeScript
19
star
15

backpax

Simple JavaScript Library to add parallax image to background-image
TypeScript
16
star
16

responsive-auto-height

JavaScript library to equalize elements's height
JavaScript
11
star
17

acms-utsuwa

HTML
10
star
18

a-template.js

Simple Template Engine
JavaScript
9
star
19

a-starter-kit

アップルップルの受託案件用スターターキット
HTML
8
star
20

appleple.github.io

HTML
6
star
21

nice-spy

A library used to update classnames of links based on scroll position
JavaScript
5
star
22

acms-slack

Slack app for a-blog cms
PHP
5
star
23

guideline

アップルップルのガイドライン
5
star
24

acms-zoho

a-blog cmsのフォームと連携することによってお客様が入力した情報をZoho CRM 上に蓄積することができます。
PHP
5
star
25

wp-smartphoto

SmartPhoto plugin for WordPress
PHP
4
star
26

acms-recaptcha

a-blog cms の 拡張アプリ「reCAPTCHA for a-blog cms」を使うと、GoogleのreCAPTCHAを使用してボットからの フォームアクセスを防御することが出来るようになります。
PHP
4
star
27

geo-picker

JavaScript
4
star
28

react-device-mode

TypeScript
4
star
29

ui-expand

Just a simple UI helper to expand elements to full screen
HTML
4
star
30

custom-field-maker

JavaScript
4
star
31

assign-holiday

Simple library for adding class attributes to holiday elements in a calendar
JavaScript
3
star
32

acms-google-translate

Google Translation for a-blog cms
PHP
3
star
33

acms-easy-setup

より簡単に、ご利用の環境に合わせて a-blog cms をインストール、アップデートできるパッケージです。
PHP
3
star
34

scroll-up

This library is for a fixed scroll to top button.
JavaScript
3
star
35

acms-google-sheets

Google Sheets API と連携し、お問い合わせフォームなどで送信された内容を任意のGoogle スプレッドシートの最後の行に追記することができます。
PHP
3
star
36

a-dispatcher

Just a simple url-dispatcher you can use with regex
JavaScript
3
star
37

yahoo-map-loader

Just a simple yahoo map loader for Webpack/Browserify
JavaScript
3
star
38

lite-editor-emoji-picker-plugin

Emoji Picker plugin for Lite Editor
CSS
3
star
39

acms-base

HTML
2
star
40

ablogcms-docker

Shell
2
star
41

acms-chatwork

a-blog cms のフォームからの送信データをchatworkで通知します
PHP
2
star
42

react-ui-expand

Just a simple UI helper to expand elements
HTML
2
star
43

acms-image-placeholder

Image placeholder for a-blog cms.
PHP
2
star
44

PhotoCollage

HTML
2
star
45

ScrollScale

JavaScript
1
star
46

react-icon-picker

Just a simple icon picker for React
TypeScript
1
star
47

fold-menu

TypeScript
1
star
48

acms-tiny-png

PHP
1
star
49

lang-select

JavaScript
1
star
50

cfg-csv

JavaScript
1
star
51

dom-content-loaded

JavaScript
1
star
52

react-hiragana-picker

React Component to pick Japanese Character (Hiragana)
TypeScript
1
star
53

lazy-hover

delay appear effect and leave effect when mousein mouseout
CSS
1
star
54

react-car-number-picker

TypeScript
1
star
55

acms-google-calendar

Google Calendar API と連携し、お問い合わせフォームなどで送信された内容を任意のGoogleカレンダーに登録できます。
PHP
1
star