π₯ Make videos programmatically with React
cool
Jonny Burgerf2e1c87fb12c
diff --git a/packages/docs/src/remotion/HomepageVideo/Card.tsx b/packages/docs/src/remotion/HomepageVideo/Card.tsxindex 04846c66ef..b6ecdf31d5 100644--- a/packages/docs/src/remotion/HomepageVideo/Card.tsx+++ b/packages/docs/src/remotion/HomepageVideo/Card.tsx@@ -61,6 +61,7 @@ const Card: React.FC<{positions: React.MutableRefObject<Position[]>;shouldBePositions: React.MutableRefObject<Position[]>;indices: number[];+ theme: "dark" | "light";}> = ({positions,shouldBePositions,@@ -69,6 +70,7 @@ const Card: React.FC<{onUpdate,content,indices,+ theme,}) => {const refToUse = refsToUse[index];const stopPrevious = useRef<(() => void)[]>([]);@@ -258,7 +260,7 @@ const Card: React.FC<{}, []);const { x, y } = getPositionForIndex(index);-+ const color = theme === "light" ? " #EAEAEA" : "#333";return (<divref={refToUse}@@ -272,18 +274,18 @@ const Card: React.FC<{left: x,top: y,userSelect: "none",- border: "1px solid #EAEAEA",+ border: `1px solid ${color}`,borderRadius: 13,overflow: "hidden",}}><AbsoluteFillstyle={{- backgroundColor: "#EAEAEA",+ backgroundColor: color,}}className={styles.content}>- {content}{" "}+ {content}</AbsoluteFill></div>);@@ -292,7 +294,8 @@ const Card: React.FC<{export const Cards: React.FC<{onUpdate: (newIndices: number[]) => void;indices: number[];-}> = ({ onUpdate, indices }) => {+ theme: "dark" | "light";+}> = ({ onUpdate, indices, theme }) => {const [refs] = useState(() => {return new Array(4).fill(true).map(() => {return createRef<HTMLDivElement>();@@ -308,7 +311,7 @@ export const Cards: React.FC<{const index = indices[i];const content =index === 0 ? (- <CurrentCountry />+ <CurrentCountry theme={theme} />) : index === 1 ? ("π±") : i === 2 ? (@@ -327,6 +330,7 @@ export const Cards: React.FC<{positions={positions}shouldBePositions={shouldBePositions}indices={indices}+ theme={theme}/>);})}diff --git a/packages/docs/src/remotion/HomepageVideo/Comp.tsx b/packages/docs/src/remotion/HomepageVideo/Comp.tsxindex f2b9777974..20e58a9b9e 100644--- a/packages/docs/src/remotion/HomepageVideo/Comp.tsx+++ b/packages/docs/src/remotion/HomepageVideo/Comp.tsx@@ -1,8 +1,13 @@import React, { useCallback, useState } from "react";import { AbsoluteFill } from "remotion";+import { z } from "zod";import { Cards } from "./Card";-export const Comp: React.FC = () => {+export const schema = z.object({+ theme: z.enum(["light", "dark"]),+});++export const Comp: React.FC<z.infer<typeof schema>> = ({ theme }) => {const [state, setRerenders] = useState({rerenders: 0,indices: [0, 1, 2, 3],@@ -18,13 +23,14 @@ export const Comp: React.FC = () => {return (<AbsoluteFillstyle={{- backgroundColor: "white",+ backgroundColor: theme === "dark" ? "#222" : "white",}}><Cardskey={state.rerenders}onUpdate={onUpdate}indices={state.indices}+ theme={theme}/></AbsoluteFill>);diff --git a/packages/docs/src/remotion/HomepageVideo/CurrentCountry.tsx b/packages/docs/src/remotion/HomepageVideo/CurrentCountry.tsxindex 2315721aa5..1456dba7fc 100644--- a/packages/docs/src/remotion/HomepageVideo/CurrentCountry.tsx+++ b/packages/docs/src/remotion/HomepageVideo/CurrentCountry.tsx@@ -3,7 +3,9 @@ import React from "react";import { AbsoluteFill } from "remotion";import { countriesPaths, ISO_3166_ALPHA_2_MAPPINGS } from "./paths";-export const CurrentCountry: React.FC = () => {+export const CurrentCountry: React.FC<{+ theme: "dark" | "light";+}> = ({ theme }) => {const country = "FR";const paths = countriesPaths.filter((c) => c.class === country);const joined = paths.map((p) => p.d).join(" ");@@ -19,7 +21,7 @@ export const CurrentCountry: React.FC = () => {scale: "0.8",}}>- <path fill="#bbb" d={reset} />+ <path fill={theme === "light" ? "#bbb" : "#222"} d={reset} /></svg></AbsoluteFill><AbsoluteFill />@@ -49,6 +51,7 @@ export const CurrentCountry: React.FC = () => {textAlign: "center",fontWeight: "500",fontSize: 30,+ color: theme === "dark" ? "white" : "black",}}>{ISO_3166_ALPHA_2_MAPPINGS[country]}diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsxindex 0edb208102..3145648394 100644--- a/packages/docs/src/remotion/Root.tsx+++ b/packages/docs/src/remotion/Root.tsx@@ -6,7 +6,7 @@ import { experts } from "../data/experts";import { AllTemplates } from "./AllTemplates";import { Article } from "./Article";import { Expert } from "./Expert";-import { Comp } from "./HomepageVideo/Comp";+import { Comp, schema } from "./HomepageVideo/Comp";import { TemplateComp } from "./Template";export const RemotionRoot: React.FC = () => {@@ -73,6 +73,10 @@ export const RemotionRoot: React.FC = () => {height={360}durationInFrames={120}fps={30}+ defaultProps={{+ theme: "light",+ }}+ schema={schema}/></>);