Code Monkey home page Code Monkey logo

ibrahimcesar / react-lite-youtube-embed Goto Github PK

View Code? Open in Web Editor NEW
240.0 4.0 40.0 3.55 MB

πŸ“Ί β€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Ž< A private by default, faster and cleaner YouTube embed component for React applications />

Home Page: https://www.npmjs.com/package/react-lite-youtube-embed

License: MIT License

CSS 26.66% TypeScript 73.34%
youtube react iframe-embeds reactjs reactjs-components adaptive-loading iframe a11y privacy responsive

react-lite-youtube-embed's Introduction

πŸ“Ί React Lite YouTube Embed

A private by default, faster and cleaner YouTube embed component for React applications

TypeScript

VersionΒ  Β Β  Β Total DownloadsΒ  Β Β  Β LicenseΒ  Β  Β GitHub issues by-label

Developed in πŸ‡§πŸ‡· Brazil

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.

iFrame example

πŸ”’ Up 2.0.0 Privacy by Default

The biggest change is, from 2.0.0 this component is private by default. Meaning that will not preconnect with the ad network from Google and connect to YouTube via the Privacy-Enhanced Mode using https://www.youtube-nocookie.com.

πŸš€ Install

Use your favorite package manager:

yarn add react-lite-youtube-embed
npm install react-lite-youtube-embed -S

πŸ•ΉοΈ Basic Usage

import React from "react";
import { render } from "react-dom";
import LiteYouTubeEmbed from 'react-lite-youtube-embed';
import 'react-lite-youtube-embed/dist/LiteYouTubeEmbed.css'

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.

πŸ’Ž Pro Usage

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)
       params="" // any params you want to pass to the URL, assume we already had '&' and pass your parameters string
       playlist={false} // Use true when your ID be from a playlist
       playlistCoverId="L2vS_050c-M" // The ids for playlists did not bring the cover in a pattern to render so you'll need pick up a video from the playlist (or in fact, whatever id) and use to render the cover. There's a programmatic way to get the cover from YouTube API v3 but the aim of this component is do not make any another call and reduce requests and bandwidth usage as much as possibe
       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
       ref={myRef} // Use this ref prop to programmatically access the underlying iframe element
    />
  </div>
);

🧰 Bring Your Own Styles

React Lite YouTube Embed comes 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, the most important class and needs extra attention, please refer to LiteYouTubeEmbed.css for a reference.
    />
  </div>
);

⚠️ After version 1.0.0 - BREAKING CHANGES ⚠️

To play nice with new frameworks like NextJS, we now don't import the .css necessary. Since version 2.0.9 you can pass custom aspect-ratio props, so be aware of any changes needed in the CSS options. Instead use now you have three options:

Option 1

Place the necessary CSS in your Global CSS file method of preference

Show me the code!
.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-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: 65px;
    height: 46px;
    z-index: 1;
    opacity: 0.8;
    border: none;
    background: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20version%3D%221.1%22%20id%3D%22YouTube_Icon%22%20x%3D%220px%22%20y%3D%220px%22%20viewBox%3D%220%200%201024%20721%22%20enable-background%3D%22new%200%200%201024%20721%22%20xml%3Aspace%3D%22preserve%22%3E%3Cscript%20xmlns%3D%22%22%3E%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20Object.defineProperty(navigator%2C%20%22globalPrivacyControl%22%2C%20%7B%0A%20%20%20%20%20%20%20%20value%3A%20false%2C%0A%20%20%20%20%20%20%20%20configurable%3A%20false%2C%0A%20%20%20%20%20%20%20%20writable%3A%20false%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20document.currentScript.parentElement.removeChild(document.currentScript)%3B%0A%20%20%20%20%7D%20catch(e)%20%7B%7D%3B%0A%20%20%20%20%20%20%3C%2Fscript%3E%0A%3Cpath%20id%3D%22Triangle%22%20fill%3D%22%23FFFFFF%22%20d%3D%22M407%2C493l276-143L407%2C206V493z%22%2F%3E%0A%3Cpath%20id%3D%22The_Sharpness%22%20opacity%3D%220.12%22%20fill%3D%22%23420000%22%20d%3D%22M407%2C206l242%2C161.6l34-17.6L407%2C206z%22%2F%3E%0A%3Cg%20id%3D%22Lozenge%22%3E%0A%09%3Cg%3E%0A%09%09%0A%09%09%09%3ClinearGradient%20id%3D%22SVGID_1_%22%20gradientUnits%3D%22userSpaceOnUse%22%20x1%3D%22512.5%22%20y1%3D%22719.7%22%20x2%3D%22512.5%22%20y2%3D%221.2%22%20gradientTransform%3D%22matrix(1%200%200%20-1%200%20721)%22%3E%0A%09%09%09%3Cstop%20offset%3D%220%22%20style%3D%22stop-color%3A%23E52D27%22%2F%3E%0A%09%09%09%3Cstop%20offset%3D%221%22%20style%3D%22stop-color%3A%23BF171D%22%2F%3E%0A%09%09%3C%2FlinearGradient%3E%0A%09%09%3Cpath%20fill%3D%22url(%23SVGID_1_)%22%20d%3D%22M1013%2C156.3c0%2C0-10-70.4-40.6-101.4C933.6%2C14.2%2C890%2C14%2C870.1%2C11.6C727.1%2C1.3%2C512.7%2C1.3%2C512.7%2C1.3%20%20%20%20h-0.4c0%2C0-214.4%2C0-357.4%2C10.3C135%2C14%2C91.4%2C14.2%2C52.6%2C54.9C22%2C85.9%2C12%2C156.3%2C12%2C156.3S1.8%2C238.9%2C1.8%2C321.6v77.5%20%20%20%20C1.8%2C481.8%2C12%2C564.4%2C12%2C564.4s10%2C70.4%2C40.6%2C101.4c38.9%2C40.7%2C89.9%2C39.4%2C112.6%2C43.7c81.7%2C7.8%2C347.3%2C10.3%2C347.3%2C10.3%20%20%20%20s214.6-0.3%2C357.6-10.7c20-2.4%2C63.5-2.6%2C102.3-43.3c30.6-31%2C40.6-101.4%2C40.6-101.4s10.2-82.7%2C10.2-165.3v-77.5%20%20%20%20C1023.2%2C238.9%2C1013%2C156.3%2C1013%2C156.3z%20M407%2C493V206l276%2C144L407%2C493z%22%2F%3E%0A%09%3C%2Fg%3E%0A%3C%2Fg%3E%0A%3C%2Fsvg%3E");
    transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);
}
.yt-lite:hover > .lty-playbtn {
    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;
}

For example, for NextJS:

<style jsx global>{`
        html,
        body {
          padding: 0;
          margin: 0;
          font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,
            Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue,
            sans-serif;
        }

        * {
          box-sizing: border-box;

        // CSS above

`}</style>

Option 2

Using your CSS-In-JS tool of choice encapsulate this component and use the css provided as a guide.

Option 3

Not work on every framework but you can import the css directly, check what works best with your bundler / framework.

Show me the code!
import 'react-lite-youtube-embed/dist/LiteYouTubeEmbed.css';

or in a *.css/scss etc:

@import "~react-lite-youtube-embed/dist/LiteYouTubeEmbed.css";

All our props belongs to you

The most minimalist implementation requires two props: id from the YouTube you want to render and title, for the iFrame.

Prop Type Description
id string id of the video or playlist
title string Here goes your video title. Always provide a title for iFrames: https://dequeuniversity.com/tips/provide-iframe-titles Help the web be accessible ;) #a11y
activeClass string Pass the string class for the active state
adNetwork boolean Default: false To preconnect or not to doubleclick addresses called by YouTube iframe (the adnetwork from Google)
announce string Default: Watch. This will added to the button announce to the final user as in Clickable Watch, ${title}, button , customize to match your own language #a11y #i18n
aspectHeight number Default: 9. Use this optional prop if you want a custom aspect-ratio. Please be aware of aspect height and width relation and also any custom CSS you are using.
aspectWidth number Default: 16. Use this optional prop if you want a custom aspect-ratio. Please be aware of aspect height and width relation and also any custom CSS you are using.
cookie boolean Default: false Connect to YouTube via the Privacy-Enhanced Mode using https://www.youtube-nocookie.com. You should opt-in to allow cookies
iframeClass string Pass the string class for the own iFrame
muted boolean If the video has sound or not. Required autoplay true to work
noCookie boolean Deprecated Default false use option cookie to opt-in
onIframeAdded function Callback that will fired when iframe loads
params string any params you want to pass to the URL in the iFrame. Two important points to notice: You need to add the params, we already setup for you, so you should write start=1150 and not ?start=1150 or &start=1150. You can place more params but it will need to fully form: start=1150&other=value&another=value. First, when you share a YouTube url the param of time is t, but the embed needs start.
playerClass string Pass the string class for the player, once you can customize it
playlist boolean Use true when your id be from a playlist
playlistCoverId string The ids for playlists did not bring the cover in a pattern to render so you'll need pick up a video from the playlist (or in fact, whatever id) and use to render the cover. There's a programmatic way to get the cover from YouTube API v3 but the aim of this component is do not make any another call and reduce requests and bandwidth usage as much as possible
poster string. One of default mqdefault hqdefault sddefault maxresdefault Defines the image size to call on first render as poster image. See: https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
rel string Default preload. allows for prefetch or preload of the link url
thumbnail string Pass an optional image url to override the default poster and set a custom poster image
webp boolean Default false. When set, uses the WebP format for poster images
wrapperClass string Pass the string class that wraps the iFrame
containerElement string Default article. Pass the element to be used for the container.
style object Pass the style object to be used for the container, overriding any root styles.

πŸ™‡β€β™‚οΈ Thanks

πŸ“ Read more

🈺 TODO

  • Add tests

MIT License

Copyright (c) 2021 β€” 2023 Ibrahim Cesar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

react-lite-youtube-embed's People

Contributors

afzalsayed96 avatar akx avatar avaleriani avatar batteredbunny avatar dependabot[bot] avatar elbotho avatar fox32 avatar functiondj avatar gstaykov avatar humet avatar ibrahimcesar avatar kaladivo avatar kylemocode avatar lichlord91 avatar n1ark avatar preya avatar rub1e avatar snyk-bot avatar theodorusclarence avatar tmcw avatar xepozz avatar zoul 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

react-lite-youtube-embed's Issues

Announce property is not optional

Describe the bug
TypeScript detected an error 'announce is declared here.
An additional implementation of the "announce" property was added in version 2.0.6, but README.md indicates that it is an optional property.

Screenshots
screenshot 2021-09-01 20 57 19

API control of 1 or more videos

Is your feature request related to a problem? Please describe.
I have a project which has multiple embedded videos, and I would like to control each one of them with the YouTube API, which seems impossible.

Describe the solution you'd like
I would love some additional parameters to the "LiteYoutubeEmbed" tag that would enable the API commands.

Add poster fallback quality

Problem
If maxresdefault or sddefault poster quality doesn`t exist the video gets no thumbnail.

Suggestion
Add fallback poster quality if the originally selected one is not available.
If the api call return a 404 the component could try again using the fallback quality.

Accessibilty issues.

Describe the bug
Currently, as per my testing, the div generated by the plugin is not focusable using the tab key. That means they are not accessible by screen-readers or keyboard users.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://react-lite-youtube-embed.ibrahimcesar.cloud/
  2. click on the Tab key on the keyboard.

Expected behavior
The div should get focus and on Enter, it should fetch the iFrame and play the video

Possible Fix
Changing the youtube play button to a button from div seems to fix it.

Desktop (please complete the following information):

  • OS: Windows
  • Browser Chrome, Mozilla

Trouble using both ref and onIframeAdded

Describe the bug

  • ref never seems to get populated.
  • onIFrameAdded doesn't seem to get called.

I'm relatively inexperienced with React and this is my first attempt at using ref so it's entirely possible this is my fault.

To Reproduce

Here's my code extracted for readability:

const videoRef = useRef<HTMLIFrameElement>(null);

useEffect(() => {
  if (videoRef.current) {
    console.log("videoRef.current is present");
  }
}, []);

<LiteYouTubeEmbed
  id={post.content.youtubeId}
  title={post.content.title}
  onIframeAdded={() => console.log("onIframeAdded")}
  ref={videoRef}
/>

Expected behavior

I would expect the console to contain logs showing "videoRef.current is present" and "onIframeAdded".

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version: 120

Additional context

I'm trying to add react-lite-youtube-embed to a Next.js app (v14). We have a number of event handlers we need to attach to the YouTube iframe and I was expecting to do that inside an effect.

you need to double click while using this on mobile

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Initially render with a low quality thumbnail for loading speeds, then load a higher res thumbnail when idle

Title pretty much says it all.
I was curious so i wrote this custom hook who's return value i pass to the poster prop:

const useKindaLazyYouTubeThumbnail = () => {
  const [imgRes, setImgRes] = useState<"mqdefault" | "maxresdefault">("mqdefault");

  useEffect(() => {
    setTimeout(() => {
      setImgRes("maxresdefault");
    }, 5000);
  }, []);

  return imgRes;
};

What do you guys think? I noticed that changing the poster will show a blank thumbnail for a brief moment because the new thumbnail needs to get downloaded. I've already tried putting a prefetch element into the , but couldn't get it to work yet (it doesn't create a request):

<link rel="prefetch" href={`https://i.ytimg.com/vi_webp/${id}/maxresdefault.webp`}/>

By the way i think it would be cool if the type for the poster prop was importable. You can technically get to it through Parameters<typeof LiteYouTubeEmbed>["0"]["poster"] but yeah i'll let it speak for itself lmao

I'll make a PR for that little export.

Ability to control the player by JS

Is your feature request related to a problem? Please describe.
Hello! very glad to know there is an import of lite-youtube-embed πŸ˜„ .
I wanted to create a custom player which can do double tap to seek. These, would require JS on the player.

Describe the solution you'd like
creating a Player object which can be added as props to LiteYouTubeEmbed and enable the ability to control the player.

Generated dist file uses .jsx ending, but not JSX syntax, making it difficult to import from Node

Describe the bug

The dist files of this module use the .jsx extension, which causes issues when importing it with Node's native ESM support (like in an implementation of epic-stack).

To Reproduce

  1. Import react-lite-youtube-embed with just Node's ESM support.

Expected behavior

This should load the file - it's just JavaScript, no JSX syntax in there, it should just load.

But you'll get something like

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".jsx" for /src/node_modules/react-lite-youtube-embed/dist/index.jsx
    at new NodeError (node:internal/errors:399:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11

In Node v20.

Screenshots

(This is a build-time issue)

Desktop (please complete the following information):

(This is a build-time issue)

Smartphone (please complete the following information):

(This is a build-time issue)


The fix for this would be to generate dist packages with .js extensions.

iframe doesn't exist when onIframeAdded is called

Describe the bug

The title pretty much says it all.
When you run document.querySelector("iframe") in the callback function / event handler, it's null.
I haven't looked at the source code but i can imagine that the callback is called together with the state update that will end up rendering the iframe, but the DOM update takes place after all state updates, and i think even after their callback functions.

If I parse LiteYouTubeEmbed as html on the server side, will it not work?

Thank you very much for developing this wonderful library.

In my app, it worked from displaying the video thumbnail and YouTube icon to the icon hover effect.
When I press the thumbnail, nothing happens and I can't play it.
I'm using Next.js to parse the article information retrieved from the CMS into html on the server side, is this the cause?

When I checked the html elements, it seemed that the following two types of link tags were missing when compared to demo.

  • <link rel="preconnect" href="https://www.youtube-nocookie.com">
  • <link rel="preconnect" href="https://www.google.com">

demo
demo

myApp
myApp

When I checked the behavior with CodeSandBox, the thumbnail display did not work, but the playback did, so I figured that the lack of playback might be due to server-side processing.

Title not showing up

The title of the video doesn't show up even after passing it as a prop.
image

Rendered:
image

Add custom thumbnail import

Is your feature request related to a problem? Please describe.
Cache-Control policy does not support external URLs. Google Lighthouse flags all static resources that aren't cached.

Describe the solution you'd like
Add prop to import local image.

The LiteYouTube interface export

Description
It is a bit limited to use this awesome library with Typescript, because the LiteYouTube interface is not exported, there is no possibility to import it, and all the props should be defined in the end consuming app. That can lead to the situation when the defined in the end application interface is not up to date with the LiteYouTube one. It would be great to have an opportunity to import it.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the consuming app, that is based on the Typescript
  2. Try to import the LiteYouTube interface

Expected behavior
You can import the interface

Desktop :

  • Browser [e.g. chrome, safari]

Screenshot 2022-09-28 at 12 09 23

usage of --aspect-ratio variable without fallback

I'm having trouble when I import the lib css, because postcss-custom-properties gives an annoying warning saying that --aspect-ratio variable is undefined and doesn't have a fallback.

Expected behavior
It would be good if the css had the aspect-ratio fallback so I could import the lib css without the warning, right now I have to copy the css to avoid the warning.

Screenshots
warning

Iframe/component should display decent view once video completes

Is your feature request related to a problem? Please describe.
When a video playing is complete, the iframe shows irrelevant video suggestions which are out of place for an embedding website.

Describe the solution you'd like
Embed APIs has events support. Based on the player state, we can give a better behavior when the video ends, say, showing a thumbnail or taking the video back to time=0.

Describe alternatives you've considered
Using playlist mitigates the issue, but it is not optimal for all cases. The problematic views still come up at the end of playlist.

Screenshot upon video completion:
sin-embed

Additional context

Add unit and integration tests

Right now, I only have a demo application in this folder that I use for all sorts of experiments and exploratory tests.

But would be easier and less error prone have some tests. I thinking at least of Cypress. But feel free to collaborate!

Have to press pay button twice on safari

Describe the bug
I have to press the play button trice to play the video on safari

To Reproduce
Steps to reproduce the behavior:
open: https://www.thisiscoin.com/watch
on safari
and click on the play button. you will see that it props you to play again

Expected behavior
should play only clicking once

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):
Safari Version 14.0.3 (16610.4.3.1.4)

Typescript error

I tried to use in a project with NextJs and typescript but got the following message "Cannot find module 'react-lite-youtube-embed' or its corresponding type declarations.ts(2307)"

Not sure if I am doing something wrong but I would appreciate if I could use your component :D

Add onIframeAdded callback

Is your feature request related to a problem? Please describe.
It would be nice to get a callback, when iframe is added.

Describe the solution you'd like
Add onIframeAdded: () => void to component param

Describe alternatives you've considered
Currently there is no alternative that I can think of...

Lazy load thumbnail image

Is your feature request related to a problem? Please describe.

Running a lighthouse audit on my side, I get the following suggestion:

Defer offscreen images

Consider lazy-loading offscreen and hidden images after all critical resources have finished loading to lower time to interactive. Learn more.

Describe the solution you'd like

I would like to lazy load the thumbnail image to save bandwidth and load time, especially if the video is embedded at the bottom of my page. Maybe the feature is configurable on the enabled.

Describe alternatives you've considered
None

Additional context
Right now a background image is used for the thumbnail. It's not possible to use the native lazy loading for background images. Maybe we have to switch too using an <img> tag instead. We could still stack the image, iframe and button over each other. The only problem I see is centering the image and keeping it's aspect ration, but that should be possible too.

Responsive Image

Currently the package loads the hqdefault image.

I am using your package and bootstrap to display the youtube on a website. Therefore it would be great if the choice of image could be based on the width of the frame (e.g. load mqdefault on mobile and maxresdefault on desktop).

EDIT: I just saw it is configurable. Just wonder if it is possible that it is automatic.

Vertical video - aspect ratio props don't seem to have an effect

If a video created for mobile first is used, setting aspectWidth={9) and aspectHeight={18} doesn't seem to have an effect.
Forcing the height via playerClass="min-h-96 w-full" seems to do the job, but the preview doesn't show the play button afterwards, while the loaded player works great:

Preview:

image

Loaded:

image

Am I misunderstanding the usage of the aspect ration props in this case and how the component should be adapted for vertical video?
What would the correct way of implementing vertical video embeds look like?

All the best and thank you for the great package!

Version: "^2.2.2",
Gatsby

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.