Skip to content

🎥 Make videos programmatically with React

mobile showcase

Jonny Burgerb7f15b905822
diff --git a/packages/docs/src/components/VideoPreview.tsx b/packages/docs/src/components/VideoPreview.tsx
index 909af6b44e..5ac2cff099 100644
--- a/packages/docs/src/components/VideoPreview.tsx
+++ b/packages/docs/src/components/VideoPreview.tsx
@@ -2,16 +2,6 @@ import clsx from "clsx";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { ShowcaseVideo } from "../data/showcase-videos";
-const a: React.CSSProperties = {
- color: "inherit",
- cursor: "pointer",
- margin: "auto",
- width: 300,
- maxWidth: 300,
- display: "block",
- flex: 1,
-};
-
const videoStyle: React.CSSProperties = {
display: "flex",
alignItems: "center",
@@ -23,14 +13,18 @@ const videoTitle: React.CSSProperties = {
marginTop: "1rem",
};
+const padding: React.CSSProperties = {
+ padding: "0 var(--ifm-spacing-horizontal)",
+};
export const VideoPreview: React.FC<
ShowcaseVideo & {
title: string;
description: React.ReactNode;
onClick: () => void;
mobileLayout: boolean;
+ mobileHeight: number;
}
-> = ({ title, description, onClick, muxId }) => {
+> = ({ title, description, onClick, muxId, mobileLayout, mobileHeight }) => {
const [hover, setHover] = useState(false);
const container = useRef<HTMLAnchorElement>(null);
@@ -61,15 +55,27 @@ export const VideoPreview: React.FC<
};
}, []);
+ const a: React.CSSProperties = useMemo(() => {
+ return {
+ color: "inherit",
+ cursor: "pointer",
+ margin: "auto",
+ width: mobileLayout ? mobileHeight : 300,
+ maxWidth: mobileLayout ? mobileHeight : 300,
+ display: "block",
+ flex: 1,
+ };
+ }, [mobileHeight, mobileLayout]);
+
const style = useMemo(() => {
return {
- width: 300,
- height: 300,
+ width: mobileLayout ? mobileHeight : 300,
+ height: mobileLayout ? mobileHeight : 300,
backgroundImage: `url(${hover ? animated : thumbnail})`,
backgroundSize: "cover",
backgroundPosition: "50% 50%",
};
- }, [animated, hover, thumbnail]);
+ }, [animated, hover, mobileHeight, mobileLayout, thumbnail]);
const placeholder: React.CSSProperties = useMemo(() => {
return {
@@ -87,8 +93,10 @@ export const VideoPreview: React.FC<
<div className="text--center" style={placeholder}>
<div style={style} />
</div>
- <h3 style={videoTitle}>{title}</h3>
- <p>{description}</p>
+ <div style={padding}>
+ <h3 style={videoTitle}>{title}</h3>
+ <p>{description}</p>
+ </div>
</a>
);
};
diff --git a/packages/docs/src/pages/showcase/index.tsx b/packages/docs/src/pages/showcase/index.tsx
index 0e51eed010..7a976a50bb 100644
--- a/packages/docs/src/pages/showcase/index.tsx
+++ b/packages/docs/src/pages/showcase/index.tsx
@@ -28,11 +28,18 @@ const flex1: React.CSSProperties = {
flex: 1,
};
+const container: React.CSSProperties = {
+ maxWidth: "var(--ifm-container-width)",
+ width: "100%",
+ margin: "auto",
+};
+
const Showcase = () => {
const containerSize = useElementSize(
typeof document === "undefined" ? null : document.body
);
const mobileLayout = (containerSize?.width ?? Infinity) < 1200;
+ const mobileHeight = mobileLayout ? containerSize.width : null;
const [userHasInteractedWithPage, setUserHasInteractedWithPage] = useState(
false
@@ -138,7 +145,7 @@ const Showcase = () => {
<main>
<section className={styles.videos}>
- <div className="container">
+ <div style={container}>
{chunks.map((c) => {
return (
<div key={c.map((c_) => c_.muxId).join("")} style={layoutStyle}>
@@ -146,6 +153,7 @@ const Showcase = () => {
return (
<div key={vid.muxId} style={flex1}>
<VideoPreview
+ mobileHeight={mobileHeight}
onClick={() => {
setVideo(vid);
setUserHasInteractedWithPage(true);
diff --git a/packages/docs/src/pages/showcase/styles.module.css b/packages/docs/src/pages/showcase/styles.module.css
index 29eaa9c916..9e8b6d8827 100644
--- a/packages/docs/src/pages/showcase/styles.module.css
+++ b/packages/docs/src/pages/showcase/styles.module.css
@@ -15,10 +15,8 @@
.videos {
display: flex;
align-items: center;
- padding: 2rem 0;
width: 100%;
}
.container * {
- color: white;
}