Skip to content

🎥 Make videos programmatically with React

progress video

Jonny Burger80e71fd57d1f
diff --git a/packages/docs/src/remotion/HomepageVideo/Card.tsx b/packages/docs/src/remotion/HomepageVideo/Card.tsx
index 0db154372e..4882f61727 100644
--- a/packages/docs/src/remotion/HomepageVideo/Card.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/Card.tsx
@@ -184,6 +184,10 @@ const Card: React.FC<{
const startX = e.clientX;
const startY = e.clientY;
+ if (e.button === 2) {
+ return;
+ }
+
let translateX = 0;
let translateY = 0;
refToUse.current.classList.add(styles.active);
@@ -240,11 +244,6 @@ const Card: React.FC<{
x: cardLeft + translateX,
y: cardTop + translateY,
};
- console.log(
- 'release',
- positions.current[index].x,
- positions.current[index].y,
- );
refToUse.current.style.left = `${cardLeft + translateX}px`;
refToUse.current.style.top = `${cardTop + translateY}px`;
refToUse.current.style.transform = `translateX(0px) translateY(0px)`;
@@ -303,7 +302,8 @@ export const Cards: React.FC<{
readonly indices: number[];
readonly theme: 'dark' | 'light';
readonly location: Location;
-}> = ({onUpdate, indices, theme, location}) => {
+ readonly trending: string[];
+}> = ({onUpdate, indices, theme, location, trending}) => {
const [refs] = useState(() => {
return new Array(4).fill(true).map(() => {
return createRef<HTMLDivElement>();
@@ -319,7 +319,7 @@ export const Cards: React.FC<{
const index = indices[i];
const content =
index === 0 ? (
- <TrendingRepos theme={theme} />
+ <TrendingRepos trending={trending} theme={theme} />
) : index === 1 ? (
<Temperature theme={theme} />
) : index === 2 ? (
diff --git a/packages/docs/src/remotion/HomepageVideo/Comp.tsx b/packages/docs/src/remotion/HomepageVideo/Comp.tsx
index 5b17d620a0..0c27e5523d 100644
--- a/packages/docs/src/remotion/HomepageVideo/Comp.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/Comp.tsx
@@ -1,18 +1,43 @@
import React, {useCallback, useState} from 'react';
+import type {CalculateMetadataFunction} from 'remotion';
import {AbsoluteFill} from 'remotion';
import {z} from 'zod';
import {Cards} from './Card';
import type {Location} from './types';
+export const calculateMetadata: CalculateMetadataFunction<
+ z.infer<typeof schema> & Props
+> = async ({props}) => {
+ const trending = await fetch('https://bugs.remotion.dev/trending')
+ .then((res) => res.json())
+ .then((data) => data.repos.slice(0, 3));
+
+ return {
+ durationInFrames: 120,
+ fps: 30,
+ height: 360,
+ width: 640,
+ props: {
+ ...props,
+ trending,
+ },
+ };
+};
+
+type Props = {
+ readonly location: Location;
+ readonly trending: null | string[];
+};
+
export const schema = z.object({
theme: z.enum(['light', 'dark']),
});
-export const HomepageVideoComp: React.FC<
- z.infer<typeof schema> & {
- readonly location: Location;
- }
-> = ({theme, location}) => {
+export const HomepageVideoComp: React.FC<z.infer<typeof schema> & Props> = ({
+ theme,
+ location,
+ trending,
+}) => {
const [state, setRerenders] = useState({
rerenders: 0,
indices: [0, 1, 2, 3],
@@ -29,6 +54,10 @@ export const HomepageVideoComp: React.FC<
return null;
}
+ if (!trending) {
+ return null;
+ }
+
return (
<AbsoluteFill
style={{
@@ -41,6 +70,7 @@ export const HomepageVideoComp: React.FC<
indices={state.indices}
theme={theme}
location={location}
+ trending={trending}
/>
</AbsoluteFill>
);
diff --git a/packages/docs/src/remotion/HomepageVideo/TrendingRepos.tsx b/packages/docs/src/remotion/HomepageVideo/TrendingRepos.tsx
index 0fa191b660..ea92f52610 100644
--- a/packages/docs/src/remotion/HomepageVideo/TrendingRepos.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/TrendingRepos.tsx
@@ -3,7 +3,8 @@ import {AbsoluteFill} from 'remotion';
export const TrendingRepos: React.FC<{
readonly theme: 'dark' | 'light';
-}> = ({theme}) => {
+ readonly trending: string[];
+}> = ({theme, trending}) => {
const item: React.CSSProperties = {
lineHeight: 1.1,
fontFamily: 'GT Planar',
@@ -45,9 +46,9 @@ export const TrendingRepos: React.FC<{
>
Trending repositories
</div>
- <div style={item}>1. maybe-finance/maybe</div>
- <div style={item}>2. excalidraw/excalidraw</div>
- <div style={item}>3. atuinsh/atuin</div>
+ <div style={item}>1. {trending[0]}</div>
+ <div style={item}>2. {trending[1]}</div>
+ <div style={item}>3. {trending[2]}</div>
</div>
</AbsoluteFill>
</AbsoluteFill>
diff --git a/packages/docs/src/remotion/HomepageVideo/paths.tsx b/packages/docs/src/remotion/HomepageVideo/paths.tsx
index bed40b35c5..af62774ef7 100644
--- a/packages/docs/src/remotion/HomepageVideo/paths.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/paths.tsx
@@ -2098,7 +2098,3 @@ export const countriesPaths: Country[] = [
d: 'M 1994.4 606 1994 606.4 1993.2 607.5 1992.9 607.6 1992.2 608 1992 608.6 1991.6 608.8 1991.4 609.1 1991.3 609.3 1991.6 609.4 1992.2 609.1 1992.3 609 1992.6 608.7 1992.8 608.4 1993.4 608.1 1993.7 607.8 1994.3 607.5 1994.3 607.8 1993.8 608.5 1993.6 608.6 1993.7 609.2 1993.4 609.5 1993.1 609.2 1992.7 609.2 1992.2 609.3 1991.8 609.6 1991.1 609.7 1990.1 609.7 1990.6 609.2 1990.2 609 1989.6 609.2 1989.2 609.4 1989.2 609.6 1988.9 609.7 1988.7 609.8 1988.6 610.2 1988.4 610.5 1988.1 610.4 1988.1 610.2 1987.7 610.1 1987.3 610.3 1987.1 610.8 1986.8 611 1986.5 611 1986.5 610.7 1986.5 610.3 1986.3 609.9 1986.4 609.7 1986.3 609.6 1985.7 609.8 1985.7 609.4 1986.1 609.1 1986.2 609.1 1986.1 608.6 1986.4 608.5 1986.9 608.8 1987.5 608.4 1987.7 608.4 1988 608.1 1988.2 608.1 1988.5 607.8 1988.5 607.6 1989.3 607.5 1990.2 607.2 1990.5 607.1 1990.9 607.2 1991.4 607 1991.6 606.6 1991.8 606.6 1992 606.2 1992.4 606.3 1992.5 606.1 1992.7 606.2 1993.7 605.7 1993.8 606 1994 605.9 1994.2 606 1994.5 605.7 1995 605.5 1995.1 605.6 1994.6 606 1994.4 606 Z',
},
];
-
-const uniqueClasses = [...new Set(countriesPaths.map((c) => c.class))];
-
-console.log(uniqueClasses);
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 9fa4d6577a..6587756da3 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -6,7 +6,11 @@ import {experts} from '../data/experts';
import {AllTemplates} from './AllTemplates';
import {Article} from './Article';
import {Expert} from './Expert';
-import {HomepageVideoComp, schema} from './HomepageVideo/Comp';
+import {
+ HomepageVideoComp,
+ calculateMetadata,
+ schema,
+} from './HomepageVideo/Comp';
import {TemplateComp} from './Template';
export const RemotionRoot: React.FC = () => {
@@ -79,8 +83,10 @@ export const RemotionRoot: React.FC = () => {
country: 'US',
city: 'New York',
},
+ trending: null,
}}
schema={schema}
+ calculateMetadata={calculateMetadata}
/>
</>
);