Skip to content

🎥 Make videos programmatically with React

video adjust

Jonny Burger2da185b92b77
diff --git a/packages/docs/src/components/Demo/ActionRow.tsx b/packages/docs/src/components/Demo/ActionRow.tsx
index 6142f0f9dd..fb2e81df4f 100644
--- a/packages/docs/src/components/Demo/ActionRow.tsx
+++ b/packages/docs/src/components/Demo/ActionRow.tsx
@@ -2,8 +2,17 @@ import {useColorMode} from '@docusaurus/theme-common';
import React from 'react';
import styles from './action-row.module.css';
+const link: React.CSSProperties = {
+ color: 'var(--ifm-color-primary)',
+ cursor: 'pointer',
+};
+
export const ActionRow: React.FC = () => {
- const {colorMode} = useColorMode();
+ const {colorMode, setColorMode} = useColorMode();
+
+ const toggleTheme = () => {
+ setColorMode(colorMode === 'dark' ? 'light' : 'dark');
+ };
return (
<div className={styles.row}>
@@ -18,8 +27,10 @@ export const ActionRow: React.FC = () => {
{colorMode === 'dark' ? 'Light theme' : 'Dark theme'}
</h2>
<p>
- Switch to {colorMode === 'dark' ? 'light' : 'dark'} mode and see the
- video adjust!
+ <a style={link} onClick={toggleTheme}>
+ Switch to {colorMode === 'dark' ? 'light' : 'dark'} mode
+ </a>{' '}
+ and see the video adjust!
</p>
</div>
<div className={styles.action}>
diff --git a/packages/docs/src/components/Demo/Demo.tsx b/packages/docs/src/components/Demo/Demo.tsx
index 379d8b177e..248c9f51e9 100644
--- a/packages/docs/src/components/Demo/Demo.tsx
+++ b/packages/docs/src/components/Demo/Demo.tsx
@@ -10,12 +10,11 @@ import {ActionRow} from './ActionRow';
export const Demo: React.FC = () => {
const {colorMode} = useColorMode();
- const [location, setLocationAndTrending] =
- useState<LocationAndTrending | null>(null);
+ const [data, setData] = useState<LocationAndTrending | null>(null);
useEffect(() => {
- getDataAndProps().then((data) => {
- setLocationAndTrending(data);
+ getDataAndProps().then((d) => {
+ setData(d);
});
}, []);
@@ -27,7 +26,7 @@ export const Demo: React.FC = () => {
<br />
<br />
<h1>Try it out</h1>
- {location ? (
+ {data ? (
<Player
component={HomepageVideoComp}
compositionWidth={640}
@@ -45,7 +44,7 @@ export const Demo: React.FC = () => {
}}
inputProps={{
theme: colorMode,
- ...location,
+ ...data,
}}
loop
/>
diff --git a/packages/docs/src/remotion/HomepageVideo/Card.tsx b/packages/docs/src/remotion/HomepageVideo/Card.tsx
index 4882f61727..b111e86c4a 100644
--- a/packages/docs/src/remotion/HomepageVideo/Card.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/Card.tsx
@@ -1,5 +1,6 @@
import React, {createRef, useCallback, useRef, useState} from 'react';
import {AbsoluteFill, spring} from 'remotion';
+import type {Trending} from './Comp';
import {CurrentCountry} from './CurrentCountry';
import {Temperature} from './Temperature';
import {TrendingRepos} from './TrendingRepos';
@@ -302,7 +303,7 @@ export const Cards: React.FC<{
readonly indices: number[];
readonly theme: 'dark' | 'light';
readonly location: Location;
- readonly trending: string[];
+ readonly trending: Trending;
}> = ({onUpdate, indices, theme, location, trending}) => {
const [refs] = useState(() => {
return new Array(4).fill(true).map(() => {
@@ -321,7 +322,7 @@ export const Cards: React.FC<{
index === 0 ? (
<TrendingRepos trending={trending} theme={theme} />
) : index === 1 ? (
- <Temperature theme={theme} />
+ <Temperature city={location.city} theme={theme} />
) : index === 2 ? (
<CurrentCountry location={location} theme={theme} />
) : (
diff --git a/packages/docs/src/remotion/HomepageVideo/Comp.tsx b/packages/docs/src/remotion/HomepageVideo/Comp.tsx
index dc53e72cbf..c5dd2245e6 100644
--- a/packages/docs/src/remotion/HomepageVideo/Comp.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/Comp.tsx
@@ -5,15 +5,22 @@ import {z} from 'zod';
import {Cards} from './Card';
import type {Location} from './types';
+export type Trending = {
+ repos: string[];
+ date: string;
+};
+
export type LocationAndTrending = {
location: Location;
- trending: string[];
+ trending: Trending;
};
export const getDataAndProps = async () => {
- const trending = (await fetch('https://bugs.remotion.dev/trending')
+ const trending = await fetch('https://bugs.remotion.dev/trending')
.then((res) => res.json())
- .then((data) => data.repos.slice(0, 3))) as string[];
+ .then((data) => {
+ return {repos: data.repos.slice(0, 3), date: data.dateFetched};
+ });
const location = (await fetch(
'https://bugs-git-homepage-player-remotion.vercel.app/api/location',
@@ -42,7 +49,7 @@ export const calculateMetadata: CalculateMetadataFunction<
type Props = {
readonly location: Location;
- readonly trending: null | string[];
+ readonly trending: null | Trending;
};
export const schema = z.object({
diff --git a/packages/docs/src/remotion/HomepageVideo/Temperature.tsx b/packages/docs/src/remotion/HomepageVideo/Temperature.tsx
index f6e3a11a72..452eee11a6 100644
--- a/packages/docs/src/remotion/HomepageVideo/Temperature.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/Temperature.tsx
@@ -4,7 +4,8 @@ import {TemperatureNumber} from './TemperatureNumber';
export const Temperature: React.FC<{
readonly theme: 'dark' | 'light';
-}> = ({theme}) => {
+ readonly city: string;
+}> = ({theme, city}) => {
return (
<AbsoluteFill>
<AbsoluteFill
@@ -25,7 +26,7 @@ export const Temperature: React.FC<{
marginTop: 5,
}}
>
- Temperature
+ Temperature in {city}
</div>
<TemperatureNumber theme={theme} temperatureInCelsius={-9} />
diff --git a/packages/docs/src/remotion/HomepageVideo/TrendingRepos.tsx b/packages/docs/src/remotion/HomepageVideo/TrendingRepos.tsx
index ea92f52610..248abb5e04 100644
--- a/packages/docs/src/remotion/HomepageVideo/TrendingRepos.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/TrendingRepos.tsx
@@ -1,9 +1,10 @@
import React from 'react';
import {AbsoluteFill} from 'remotion';
+import type {Trending} from './Comp';
export const TrendingRepos: React.FC<{
readonly theme: 'dark' | 'light';
- readonly trending: string[];
+ readonly trending: Trending;
}> = ({theme, trending}) => {
const item: React.CSSProperties = {
lineHeight: 1.1,
@@ -33,7 +34,11 @@ export const TrendingRepos: React.FC<{
fontSize: 12,
}}
>
- Saturday, January 13th
+ {new Intl.DateTimeFormat('en-US', {
+ weekday: 'long',
+ month: 'long',
+ day: 'numeric',
+ }).format(new Date(trending.date))}
</div>
<div
style={{
@@ -46,9 +51,9 @@ export const TrendingRepos: React.FC<{
>
Trending repositories
</div>
- <div style={item}>1. {trending[0]}</div>
- <div style={item}>2. {trending[1]}</div>
- <div style={item}>3. {trending[2]}</div>
+ <div style={item}>1. {trending.repos[0]}</div>
+ <div style={item}>2. {trending.repos[1]}</div>
+ <div style={item}>3. {trending.repos[2]}</div>
</div>
</AbsoluteFill>
</AbsoluteFill>