npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-video

v1.5.3

Published

React component to load video from Vimeo or Youtube across any device

Downloads

557

Readme

React Video

Git release Travis license

A pretty good and effective way to create a video placeholder from Youtube or Vimeo using a high-res image. If you don't know, when an <iframe> is rendered from browser, it blocks its parse because it isn't a non-blocking script. This isn't so good to your user, no?. With this react component, the <iframe> just will be loaded when the user click on play.

Install

Installing this component is very easy and it has just one dependency: React. So, you have a lot of options to do that:

  • Using NPM ~the quickest way~
  $ npm install --save react-video
  • Using Bower
  $ bower install --save react-video

NOTICE: You need just one thing to make the component work. Put the base component style at the <header> tag. If you don't wanna use the .css extension, you can get the .styl or .scss extension at the folder ./lib.

Then you're done! :smile_cat:

Usage

Using the component is simpler than installing. See an example with browserify to bundle your script:

  var Video = require('react-video');

  // Video from Youtube
  React.render(
    <Video from='youtube' videoId={videoId} />,
    $mountNode
  );

  // Video from Vimeo
  React.render(
    <Video from='vimeo' videoId={videoId} />,
    $mountNode
  );

The property videoId is optional, so you can use it or not. If you don't pass the property, the component will select your type of video based on your id.

  React.render(
    <Video videoId={videoId} />
    document.querySelector('#your-div')
  );

To handle errors when something happens, like your video can't be loaded, you can pass a callback with a prop onError in the component:

  var _onError = function(err) {
    console.log(err);
  };

  React.render(
    <Video onError={_onError} videoId={videoId} />
    document.querySelector('#your-div')
  );

If you decide to use just Javascript without any module loader, you can get the global variable window.ReactVideo (or just ReactVideo):

  /** @jsx React.DOM */

  var Video = ReactVideo;

Behind the Scene

There are some things that you should know about the component. The first one is the structure created inside by the component if you wish to stylize it.

So, the semantic HTML structure will be something like this:

  <div class='video'>
    <div class='video-loading'>
      <svg>...</svg>
    </div>
    <div class='video-image'>
      <button type='button' class='video-play-button'>
        <svg>...</svg>
      </button>
    </div>
    <div class='video-embed'>
      <iframe>...</iframe>
    </div>
  </div>

This is a very simple structure to stylize however you want. So, if you are lost, don't panic, there is a real functional example that you can follow.

For more details, check out the API below.

Component API

<Video> component:

Property | Type | Default | Required | Description -------- | ---- | ------- | -------- |----------- from | String | none | no | Video source: youtube or vimeo. Leave empty and the service will be detected for you by looking a the id. videoId | String | none | no | The video ID onError | Function | yes | no | Callback function if the video can't be loaded

Contributing

Anyone can help make this project better - check out the Contributing guide!

License

See the License file.