Skip to content

🎥 Make videos programmatically with React

responsiveness

Jonny Burger7f053d1a1a5c
diff --git a/packages/docs/src/components/VideoPreview.tsx b/packages/docs/src/components/VideoPreview.tsx
index 9f60f3f4af..626708cfac 100644
--- a/packages/docs/src/components/VideoPreview.tsx
+++ b/packages/docs/src/components/VideoPreview.tsx
@@ -5,6 +5,11 @@ 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 = {
@@ -23,6 +28,7 @@ export const VideoPreview: React.FC<
title: string;
description: React.ReactNode;
onClick: () => void;
+ mobileLayout: boolean;
}
> = ({ title, description, onClick, muxId }) => {
const [hover, setHover] = useState(false);
diff --git a/packages/docs/src/helpers/chunk.ts b/packages/docs/src/helpers/chunk.ts
new file mode 100644
index 0000000000..129919a2fe
--- /dev/null
+++ b/packages/docs/src/helpers/chunk.ts
@@ -0,0 +1,6 @@
+export function chunk<T>(array: T[], chunkSize: number): T[][] {
+ const R = [];
+ for (let i = 0, len = array.length; i < len; i += chunkSize)
+ R.push(array.slice(i, i + chunkSize));
+ return R;
+}
diff --git a/packages/docs/src/pages/showcase/header.module.css b/packages/docs/src/pages/showcase/header.module.css
index 21d2ab6b26..7efe94dc33 100644
--- a/packages/docs/src/pages/showcase/header.module.css
+++ b/packages/docs/src/pages/showcase/header.module.css
@@ -5,15 +5,3 @@
font-weight: 700;
line-height: 1.2;
}
-
-.row {
- display: flex;
- flex-direction: row;
- text-align: left;
-}
-
-@media screen and (max-width: 1200px) {
- .row {
- flex-direction: column;
- }
-}
diff --git a/packages/docs/src/pages/showcase/index.tsx b/packages/docs/src/pages/showcase/index.tsx
index ba88e893b2..c0ad9b1cc3 100644
--- a/packages/docs/src/pages/showcase/index.tsx
+++ b/packages/docs/src/pages/showcase/index.tsx
@@ -4,6 +4,8 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
import { VideoPlayer } from "../../components/VideoPlayer";
import { VideoPreview } from "../../components/VideoPreview";
import { ShowcaseVideo, showcaseVideos } from "../../data/showcase-videos";
+import { chunk } from "../../helpers/chunk";
+import { useElementSize } from "../../helpers/use-el-size";
import headerStyles from "./header.module.css";
import styles from "./styles.module.css";
@@ -21,7 +23,14 @@ const PageHeader: React.FC = () => {
);
};
+const flex1: React.CSSProperties = {
+ flex: 1,
+};
+
const Showcase = () => {
+ const containerSize = useElementSize(document.body);
+ const mobileLayout = (containerSize?.width ?? Infinity) < 1200;
+
const [video, setVideo] = useState<ShowcaseVideo | null>(() => {
if (!window.location.hash) {
return null;
@@ -77,6 +86,24 @@ const Showcase = () => {
setVideo(null);
}, []);
+ const layoutStyle: React.CSSProperties = useMemo(() => {
+ if (mobileLayout) {
+ return {
+ display: "flex",
+ flexDirection: "column",
+ textAlign: "left",
+ };
+ }
+
+ return {
+ display: "flex",
+ flexDirection: "row",
+ textAlign: "left",
+ };
+ }, [mobileLayout]);
+
+ const chunks = chunk(showcaseVideos, 3);
+
return (
<Layout
title="Showcase"
@@ -99,17 +126,27 @@ const Showcase = () => {
<main>
<section className={styles.videos}>
<div className="container">
- <div className="row">
- {showcaseVideos.map((vid) => (
- <VideoPreview
- key={vid.muxId}
- onClick={() => {
- setVideo(vid);
- }}
- {...vid}
- />
- ))}
- </div>
+ {chunks.map((c) => {
+ return (
+ <div key={c.map((c_) => c_.muxId).join("")} style={layoutStyle}>
+ {c.map((vid) => {
+ return (
+ <div key={vid.muxId} style={flex1}>
+ <VideoPreview
+ onClick={() => {
+ setVideo(vid);
+ }}
+ mobileLayout={mobileLayout}
+ {...vid}
+ />
+ </div>
+ );
+ })}
+ {c.length < 3 ? <div style={flex1} /> : null}
+ {c.length < 2 ? <div style={flex1} /> : null}
+ </div>
+ );
+ })}
</div>
</section>
</main>