🎥 Make videos programmatically with React
call it useVisualControls()
Jonny Burger2531a80c2f6b
diff --git a/packages/docs/docs/studio/use-visual-controls.mdx b/packages/docs/docs/studio/use-visual-controls.mdxnew file mode 100644index 0000000000..21c85503a0--- /dev/null+++ b/packages/docs/docs/studio/use-visual-controls.mdx@@ -0,0 +1,42 @@+---+title: useVisualControls()+crumb: '@remotion/studio'+---++# useVisualControls()++Creates a control in the right sidebar of the [Remotion Studio](/docs/studio) that allows you to change a value.++Useful for if you have a hardcoded constant that you want to find the optimal value for.++## Example++Consider you have a value `rotation` that you want to find the optimal value for:++```tsx twoslash title="Root.tsx"+import {useVideoConfig} from 'remotion';++const MyComp: React.FC = () => {+ const rotation = 180;++ return <div style={{rotate: `${rotation}deg`}}>Hello</div>;+};+```++Instead of changing the value of `rotation` in the code, you can create a control in the right sidebar of the [Remotion Studio](/docs/studio) that allows you to change the value:++```tsx twoslash title="Root.tsx"+import {useVisualControls} from '@remotion/studio';++const MyComp: React.FC = () => {+ const {visualControl} = useVisualControls();++ const rotation = visualControl('rotation', 180);++ return <div style={{rotate: `${rotation}deg`}}>Hello</div>;+};+```++## See also++- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/studio/src/api/use-visual-controls.ts)diff --git a/packages/example/package.json b/packages/example/package.jsonindex cf6172eaa7..26890d9731 100644--- a/packages/example/package.json+++ b/packages/example/package.json@@ -33,6 +33,7 @@"@react-three/fiber": "9.0.0-rc.6","@remotion/svg-3d-engine": "workspace:*","@remotion/animated-emoji": "workspace:*",+ "@remotion/animation-utils": "workspace:*","@remotion/babel-loader": "workspace:*","@remotion/webcodecs": "workspace:*","@remotion/bundler": "workspace:*",diff --git a/packages/example/src/VisualControls/index.tsx b/packages/example/src/VisualControls/index.tsxindex 3b00b71911..0a30ec0c66 100644--- a/packages/example/src/VisualControls/index.tsx+++ b/packages/example/src/VisualControls/index.tsx@@ -1,18 +1,24 @@-import {useVisualControl} from '@remotion/studio';+import {makeTransform, matrix3d} from '@remotion/animation-utils';+import {useVisualControls} from '@remotion/studio';import {zMatrix} from '@remotion/zod-types';import {AbsoluteFill} from 'remotion';export const VisualControls = () => {- const {visualControl} = useVisualControl();+ const {visualControl} = useVisualControls();const matrix = visualControl('william',- [1, 0, 0, 0, 1, 0, 0, 0, 1],+ [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] as const,zMatrix(),);return (- <AbsoluteFill className="bg-red-300 text-7xl">+ <AbsoluteFill+ className="bg-red-300 text-7xl flex flex-1 items-center justify-center"+ style={{+ transform: makeTransform([matrix3d(...matrix)]),+ }}+ ><p>{matrix.join(', ')}</p></AbsoluteFill>);diff --git a/packages/studio/src/api/use-visual-control.tsx b/packages/studio/src/api/use-visual-controls.tsxsimilarity index 93%rename from packages/studio/src/api/use-visual-control.tsxrename to packages/studio/src/api/use-visual-controls.tsxindex ce26a9597f..ab0a44cdce 100644--- a/packages/studio/src/api/use-visual-control.tsx+++ b/packages/studio/src/api/use-visual-controls.tsx@@ -11,14 +11,15 @@ import {getZodSchemaFromPrimitive} from './get-zod-schema-from-primitive';type VisualControl = <T>(key: string, value: T, schema?: z.ZodTypeAny) => T;-type UseVisualControl = {+type UseVisualControls = {visualControl: VisualControl;};-export const useVisualControl = (): UseVisualControl => {+export const useVisualControls = (): UseVisualControls => {const {addHook, removeHook, setControl, updateHandles} = useContext(SetVisualControlsContext,);+const {handles} = useContext(VisualControlsContext);const changed = useRef(false);@@ -79,6 +80,6 @@ export const useVisualControl = (): UseVisualControl => {return currentValue as T;},}),- [handles, hook, setControl, z],+ [hook, setControl, handles, z],);};diff --git a/packages/studio/src/components/Timeline/TimelineStack/get-stack.ts b/packages/studio/src/components/Timeline/TimelineStack/get-stack.tsindex 9754a680c0..c325d3be1e 100644--- a/packages/studio/src/components/Timeline/TimelineStack/get-stack.ts+++ b/packages/studio/src/components/Timeline/TimelineStack/get-stack.ts@@ -60,7 +60,7 @@ export const getOriginalLocationFromStack = async (const location =type === 'sequence'? getLocationOfSequence(stack)- : getLocationOfFunctionCall(stack, 'useVisualControl');+ : getLocationOfFunctionCall(stack, 'useVisualControls');if (!location) {return null;diff --git a/packages/studio/src/index.ts b/packages/studio/src/index.tsindex 354669a5fd..d32183f24f 100644--- a/packages/studio/src/index.ts+++ b/packages/studio/src/index.ts@@ -16,7 +16,7 @@ export {saveDefaultProps} from './api/save-default-props';export {seek} from './api/seek';export {toggle} from './api/toggle';export {updateDefaultProps} from './api/update-default-props';-export {useVisualControl} from './api/use-visual-control';+export {useVisualControls} from './api/use-visual-controls';export {watchPublicFolder} from './api/watch-public-folder';export {watchStaticFile} from './api/watch-static-file';export {writeStaticFile} from './api/write-static-file';diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex e52aaddea5..dbc6834ff7 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -962,6 +962,9 @@ importers:'@remotion/animated-emoji':specifier: workspace:*version: link:../animated-emoji+ '@remotion/animation-utils':+ specifier: workspace:*+ version: link:../animation-utils'@remotion/babel-loader':specifier: workspace:*version: link:../babel-loader