Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
react-lite-youtube-embed
Advanced tools
> 📺 A faster and cleaner YouTube embed component for __React__: 1.4kB minified, 699B minified + gzipped
📺 A faster and cleaner YouTube embed component for React: 1.4kB minified, 699B minified + gzipped
Port of Paul Irish's Lite YouTube Embed to a React Component. Provide videos with a supercharged focus on visual performance. The gain is not the same as the web component of the original implementation but saves some requests and gives you more control of the embed visual. An "Adaptive Loading" way to handle iframes for YouTube.
To play nice with new frameworks like NextJS, we now don't import the .css
necessary. Instead in order to use now you have three options:
Manual import our file in your React application this way:
Place the necessary CSS in your Global CSS file
.yt-lite {
background-color: #000;
position: relative;
display: block;
contain: content;
background-position: center center;
background-size: cover;
cursor: pointer;
}
/* gradient */
.yt-lite::before {
content: '';
display: block;
position: absolute;
top: 0;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADGCAYAAAAT+OqFAAAAdklEQVQoz42QQQ7AIAgEF/T/D+kbq/RWAlnQyyazA4aoAB4FsBSA/bFjuF1EOL7VbrIrBuusmrt4ZZORfb6ehbWdnRHEIiITaEUKa5EJqUakRSaEYBJSCY2dEstQY7AuxahwXFrvZmWl2rh4JZ07z9dLtesfNj5q0FU3A5ObbwAAAABJRU5ErkJggg==);
background-position: top;
background-repeat: repeat-x;
height: 60px;
padding-bottom: 50px;
width: 100%;
transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);
}
/* responsive iframe with a 16:9 aspect ratio
thanks https://css-tricks.com/responsive-iframes/
*/
.yt-lite::after {
content: "";
display: block;
padding-bottom: calc(100% / (16 / 9));
}
.yt-lite > iframe {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
/* play button */
.yt-lite > .lty-playbtn {
width: 70px;
height: 46px;
background-color: #212121;
z-index: 1;
opacity: 0.8;
border-radius: 14%; /* TODO: Consider replacing this with YT's actual svg. Eh. */
transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);
}
.yt-lite:hover > .lty-playbtn {
background-color: #f00;
opacity: 1;
}
/* play button triangle */
.yt-lite > .lty-playbtn:before {
content: '';
border-style: solid;
border-width: 11px 0 11px 19px;
border-color: transparent transparent transparent #fff;
}
.yt-lite > .lty-playbtn,
.yt-lite > .lty-playbtn:before {
position: absolute;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 0);
}
/* Post-click styles */
.yt-lite.lyt-activated {
cursor: unset;
}
.yt-lite.lyt-activated::before,
.yt-lite.lyt-activated > .lty-playbtn {
opacity: 0;
pointer-events: none;
}
Using your CSS-In-JS tool of choice encapsulate this component and use the css provided as a guide.
Use your favorite package manager:
yarn add react-lite-youtube-embed
npm install react-lite-youtube-embed -S
import React from "react";
import { render } from "react-dom";
import { LiteYouTubeEmbed } from "react-lite-youtube-embed";
const App = () => (
<div>
<LiteYouTubeEmbed
id="L2vS_050c-M"
title="What’s new in Material Design for the web (Chrome Dev Summit 2019)"
/>
</div>
);
render(<App />, document.getElementById("root"));
And that's it.
const App = () => (
<div>
<LiteYouTubeEmbed
id="L2vS_050c-M" // Default none, id of the video or playlist
adNetwork={true} // Default true, to preconnect or not to doubleclick addresses called by YouTube iframe (the adnetwork from Google)
playlist={false} // Use true when your ID be from a playlist
poster="hqdefault" // Defines the image size to call on first render as poster image. Possible values are "default","mqdefault", "hqdefault", "sddefault" and "maxresdefault". Default value for this prop is "hqdefault". Please be aware that "sddefault" and "maxresdefault", high resolution images are not always avaialble for every video. See: https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
title="YouTube Embed" // a11y, always provide a title for iFrames: https://dequeuniversity.com/tips/provide-iframe-titles Help the web be accessible ;)
noCookie={true} //Default false, connect to YouTube via the Privacy-Enhanced Mode using https://www.youtube-nocookie.com
/>
</div>
);
React Lite YouTube Embed is packaged with all original styles from Paul Irish's Lite YouTube Embed but you can customize them as you wish passing as a props.
const App = () => (
<div>
<LiteYouTubeEmbed
id="L2vS_050c-M"
activeClass="lyt-activated" // Default as "lyt-activated", gives control to wrapper once clicked
iframeClass="" // Default none, gives control to add a class to iframe element itself
playerClass="lty-playbtn" // Default as "lty-playbtn" to control player button styles
wrapperClass="yt-lite" // Default as "yt-lite" for the div wrapping the area, it is the most important class and needs extra attention, please refer to LiteYouTubeEmbed.css for a reference.
/>
</div>
);
Please feel free to open an issue!
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Botho (elbotho)
Paul Irish (paulirish) for Lite YouTube Embed
Acauã Sperl de Faria (acaua) for code review
Addy Osmani (addyosmani) for the Adaptive Loading ideas
React Quicklink: Faster subsequent page-loads by prefetching in-viewport links during idle time for React
FAQs
A private by default, faster and cleaner YouTube embed component for React applications
The npm package react-lite-youtube-embed receives a total of 29,801 weekly downloads. As such, react-lite-youtube-embed popularity was classified as popular.
We found that react-lite-youtube-embed demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.