PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / admin / src / components / YouTubeEmbed.jsx

YouTubeEmbed.jsx in Tableberg – Simple Gutenberg Table Block 1.1.5, at admin/src/components/YouTubeEmbed.jsx

45 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useEffect, useState } from "react";
2
3 /**
4 * YouTube embed component.
5 *
6 * @param {Object} props component properties
7 * @param {string} props.videoId video id
8 * @param {number |null} props.width embed width
9 * @param {number |null} props.height embed height
10 * @class
11 */
12 function YouTubeEmbed({ videoId, width = null, height = null }) {
13 const [embedUrl, setEmbedUrl] = useState(null);
14
15 const defaults = {
16 width: "100",
17 height: "100",
18 };
19
20 /**
21 * useEffect hook.
22 */
23 useEffect(() => {
24 const generatedEmbedUrl = `https://www.youtube.com/embed/${videoId}`;
25 setEmbedUrl(generatedEmbedUrl);
26 }, []);
27
28 return (
29 <div className={"tableberg-youtube-embed"}>
30 <iframe
31 width={width || defaults.width}
32 height={height || defaults.height}
33 src={embedUrl}
34 title="YouTube video player"
35 allow="picture-in-picture; web-share; fullscreen"
36 ></iframe>
37 </div>
38 );
39 }
40
41 /**
42 * @module YouTubeEmbed
43 */
44 export default YouTubeEmbed;
45