🎥 Make videos programmatically with React
layout improvements
Jonny Burger3b0d26ce3aad
diff --git a/packages/docs/src/components/VideoPlayerContent.tsx b/packages/docs/src/components/VideoPlayerContent.tsxindex 50cc682f5c..a37d7f0e00 100644--- a/packages/docs/src/components/VideoPlayerContent.tsx+++ b/packages/docs/src/components/VideoPlayerContent.tsx@@ -41,6 +41,11 @@ const loadingContainer: React.CSSProperties = {display: "flex",};+export const PAGINATE_ICON_WIDTH = 24;+export const PAGINATE_ICON_PADDING = 20;+export const PAGINATE_BUTTONS_WIDTH =+ (PAGINATE_ICON_WIDTH + PAGINATE_ICON_PADDING * 2) * 2;+const getVideoToPlayUrl = (video: ShowcaseVideo) => {if (video.type === "mux_video") {return `https://stream.mux.com/${video.muxId}.m3u8`;@@ -59,11 +64,14 @@ export const VideoPlayerContent: React.FC<{ video: ShowcaseVideo }> = ({const containerSize = useElementSize(document.body);- const containerWidth = Math.min(containerSize?.width ?? 0, 1200) - 200;+ const possibleVideoWidth =+ Math.min(containerSize?.width ?? 0, 1200) -+ RESERVED_FOR_SIDEBAR -+ PAGINATE_BUTTONS_WIDTH;const containerHeight = Math.min(containerSize?.height ?? 0, 800);const heightRatio = (containerHeight ?? 0) / video.height;- const widthRatio = (containerWidth ?? 0) / video.width;+ const widthRatio = (possibleVideoWidth ?? 0) / video.width;const ratio = Math.min(heightRatio, widthRatio);diff --git a/packages/docs/src/components/VideoPreview.tsx b/packages/docs/src/components/VideoPreview.tsxindex 7ea27ac05e..9f60f3f4af 100644--- a/packages/docs/src/components/VideoPreview.tsx+++ b/packages/docs/src/components/VideoPreview.tsx@@ -1,5 +1,5 @@import clsx from "clsx";-import React, { useEffect, useRef, useState } from "react";+import React, { useEffect, useMemo, useRef, useState } from "react";import { ShowcaseVideo } from "../data/showcase-videos";const a: React.CSSProperties = {@@ -55,6 +55,16 @@ export const VideoPreview: React.FC<};}, []);+ const style = useMemo(() => {+ return {+ width: 300,+ height: 300,+ backgroundImage: `url(${hover ? animated : thumbnail})`,+ backgroundSize: "cover",+ backgroundPosition: "50% 50%",+ };+ }, [animated, hover, thumbnail]);+return (<aref={container}@@ -63,15 +73,7 @@ export const VideoPreview: React.FC<onClick={onClick}><div className="text--center">- <div- style={{- width: 300,- height: 300,- backgroundImage: `url(${hover ? animated : thumbnail})`,- backgroundSize: "cover",- backgroundPosition: "50% 50%",- }}- >+ <div style={style}><img width={300} height={300} /></div></div>diff --git a/packages/docs/src/pages/showcase/index.tsx b/packages/docs/src/pages/showcase/index.tsxindex c5e139f6fd..ba88e893b2 100644--- a/packages/docs/src/pages/showcase/index.tsx+++ b/packages/docs/src/pages/showcase/index.tsx@@ -45,6 +45,12 @@ const Showcase = () => {useEffect(() => {if (video) {window.location.hash = video.muxId;+ } else if (window.location.href.includes("#")) {+ window.history.replaceState(+ {},+ document.title,+ window.location.href.substr(0, window.location.href.indexOf("#"))+ );}}, [video]);diff --git a/packages/docs/src/pages/showcase/styles.module.css b/packages/docs/src/pages/showcase/styles.module.cssindex db81c698d8..29eaa9c916 100644--- a/packages/docs/src/pages/showcase/styles.module.css+++ b/packages/docs/src/pages/showcase/styles.module.css@@ -8,17 +8,10 @@.heroBanner {padding-top: 4rem;padding-bottom: 0;- text-align: center;position: relative;overflow: hidden;}-@media screen and (max-width: 966px) {- .heroBanner {- padding: 2rem;- }-}-.videos {display: flex;align-items: center;