Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/parameters.md
1---2name: parameters3description: Make a video parametrizable by adding a Zod schema4metadata:5tags: parameters, zod, schema6---78To make a video parametrizable, a Zod schema can be added to a composition.910First, `zod` must be installed .1112Search the project for lockfiles and run the correct command depending on the package manager:1314If `package-lock.json` is found, use the following command:1516```bash17npm i zod18```1920If `bun.lockb` is found, use the following command:2122```bash23bun i zod24```2526If `yarn.lock` is found, use the following command:2728```bash29yarn add zod30```3132If `pnpm-lock.yaml` is found, use the following command:3334```bash35pnpm i zod36```3738Then, a Zod schema can be defined alongside the component:3940```tsx title="src/MyComposition.tsx"41import { z } from "zod";4243export const MyCompositionSchema = z.object({44title: z.string(),45});4647const MyComponent: React.FC<z.infer<typeof MyCompositionSchema>> = () => {48return (49<div>50<h1>{props.title}</h1>51</div>52);53};54```5556In the root file, the schema can be passed to the composition:5758```tsx title="src/Root.tsx"59import { Composition } from "remotion";60import { MycComponent, MyCompositionSchema } from "./MyComposition";6162export const RemotionRoot = () => {63return (64<Composition65id="MyComposition"66component={MyComponent}67durationInFrames={100}68fps={30}69width={1080}70height={1080}71defaultProps={{ title: "Hello World" }}72schema={MyCompositionSchema}73/>74);75};76```7778Now, the user can edit the parameter visually in the sidebar.7980All schemas that are supported by Zod are supported by Remotion.8182Remotion requires that the top-level type is a z.object(), because the collection of props of a React component is always an object.8384## Color picker8586For adding a color picker, use `zColor()` from `@remotion/zod-types`.8788If it is not installed, use the following command:8990```bash91npx remotion add @remotion/zod-types # If project uses npm92bunx remotion add @remotion/zod-types # If project uses bun93yarn remotion add @remotion/zod-types # If project uses yarn94pnpm exec remotion add @remotion/zod-types # If project uses pnpm95```9697Then import `zColor` from `@remotion/zod-types`:9899```tsx100import { zColor } from "@remotion/zod-types";101```102103Then use it in the schema:104105```tsx106export const MyCompositionSchema = z.object({107color: zColor(),108});109```110