🎥 Make videos programmatically with React
center + full size
Jonny Burgerdb89c17a55e9
diff --git a/packages/docs/src/components/VideoPreview.tsx b/packages/docs/src/components/VideoPreview.tsxindex 3d672dca73..3f9429c48d 100644--- a/packages/docs/src/components/VideoPreview.tsx+++ b/packages/docs/src/components/VideoPreview.tsx@@ -27,7 +27,6 @@ const padding: React.CSSProperties = {};const containerTitleDescription: React.CSSProperties = {- width: "300px",display: "flex",flexDirection: "column",alignItems: "center",@@ -39,19 +38,8 @@ export const VideoPreview: React.FC<title: string;description: React.ReactNode;onClick: () => void;- mobileLayout: boolean;- mobileHeight: number;}-> = ({- title,- description,- onClick,- muxId,- mobileLayout,- mobileHeight,- width,- height,-}) => {+> = ({ title, description, onClick, muxId, width, height }) => {const [hover, setHover] = useState(false);const container = useRef<HTMLAnchorElement>(null);@@ -82,52 +70,36 @@ export const VideoPreview: React.FC<};}, []);- const givenAspectRatio = width / height;- const maxFrameSize = 300;-- const frameWidth = Math.min(maxFrameSize, maxFrameSize * givenAspectRatio);- const frameHeight = frameWidth / givenAspectRatio;-const a: React.CSSProperties = useMemo(() => {return {color: "inherit",cursor: "pointer",margin: "auto",- width: mobileLayout ? mobileHeight * givenAspectRatio : frameWidth,- maxWidth: mobileLayout ? mobileHeight * givenAspectRatio : frameWidth,display: "block",flex: 1,};- }, [mobileHeight, mobileLayout, givenAspectRatio, frameWidth]);+ }, []);const style = useMemo(() => {return {- width: mobileLayout ? mobileHeight * givenAspectRatio : frameWidth,- height: mobileLayout ? mobileHeight : frameHeight,+ width: "100%",+ aspectRatio: `${width} / ${height}`,backgroundImage: `url(${hover ? animated : thumbnail})`,backgroundSize: "cover",backgroundPosition: "50% 50%",};- }, [- animated,- hover,- mobileHeight,- mobileLayout,- thumbnail,- givenAspectRatio,- frameWidth,- frameHeight,- ]);+ }, [width, height, hover, animated, thumbnail]);const placeholder: React.CSSProperties = useMemo(() => {return {backgroundColor: "rgba(0, 0, 0, 0.05)",+ aspectRatio: `${width} / ${height}`,};- }, []);+ }, [height, width]);return (<a ref={container} style={a} className={clsx(videoStyle)} onClick={onClick}>- <div className="text--center" style={placeholder}>+ <div style={placeholder}><div style={style} /></div><div style={{ ...padding, ...containerTitleDescription }}>diff --git a/packages/docs/src/pages/showcase/index.tsx b/packages/docs/src/pages/showcase/index.tsxindex 0fb74755b1..a1b840f6f5 100644--- a/packages/docs/src/pages/showcase/index.tsx+++ b/packages/docs/src/pages/showcase/index.tsx@@ -11,7 +11,6 @@ import {} from "../../data/showcase-videos";import { chunk } from "../../helpers/chunk";import { useMobileLayout } from "../../helpers/mobile-layout";-import { useElementSize } from "../../helpers/use-el-size";import headerStyles from "./header.module.css";import styles from "./styles.module.css";@@ -41,11 +40,7 @@ const container: React.CSSProperties = {};const Showcase = () => {- const containerSize = useElementSize(- typeof document === "undefined" ? null : document.body,- );const mobileLayout = useMobileLayout();- const mobileHeight = mobileLayout ? containerSize.width : null;const [userHasInteractedWithPage, setUserHasInteractedWithPage] =useState(false);@@ -124,7 +119,7 @@ const Showcase = () => {flexDirection: mobileLayout ? "column" : "row",textAlign: "left",justifyContent: "center",- alignItems: "center",+ gap: 10,};}, [mobileLayout]);@@ -164,12 +159,10 @@ const Showcase = () => {return (<div key={vid.muxId} style={flex1}><VideoPreview- mobileHeight={mobileHeight}onClick={() => {setVideo(vid);setUserHasInteractedWithPage(true);}}- mobileLayout={mobileLayout}{...vid}/></div>