Skip to content

🎥 Make videos programmatically with React

no need to scroll between schema and JSON

Jonny Burger0fca0250c387
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx
index 1f6a6fbc41..fd78b9288b 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx
@@ -2,8 +2,6 @@ import React, {useCallback, useMemo, useState} from 'react';
import type {AnyComposition} from 'remotion';
import {BORDER_COLOR} from '../../helpers/colors';
-import {Spacing} from '../layout';
-import {VERTICAL_SCROLLBAR_CLASSNAME} from '../Menu/is-menu-item';
import {updateDefaultProps} from '../RenderQueue/actions';
import type {SegmentedControlItem} from '../SegmentedControl';
import {SegmentedControl} from '../SegmentedControl';
@@ -19,13 +17,6 @@ const outer: React.CSSProperties = {
overflow: 'hidden',
};
-const scrollable: React.CSSProperties = {
- padding: '8px 12px',
- display: 'flex',
- flexDirection: 'column',
- overflowY: 'auto',
-};
-
const controlContainer: React.CSSProperties = {
flexDirection: 'row',
display: 'flex',
@@ -48,8 +39,6 @@ export const RenderModalData: React.FC<{
return composition.schema.safeParse(inputProps);
}, [composition.schema, inputProps]);
- // TODO: Put Schema/JSON tab one component above, so no scrolling to reach them is needed
-
const modeItems = useMemo((): SegmentedControlItem[] => {
return [
{
@@ -91,29 +80,26 @@ export const RenderModalData: React.FC<{
<div style={controlContainer}>
<SegmentedControl items={modeItems} needsWrapping={false} />
</div>
- <div style={scrollable} className={VERTICAL_SCROLLBAR_CLASSNAME}>
- <Spacing y={2} block />
- {mode === 'schema' ? (
- <SchemaEditor
- value={inputProps}
- setValue={setInputProps}
- schema={composition.schema}
- zodValidationResult={zodValidationResult}
- compact={compact}
- defaultProps={composition.defaultProps}
- onSave={onSave}
- showSaveButton={showSaveButton}
- />
- ) : (
- <RenderModalJSONInputPropsEditor
- value={inputProps ?? {}}
- setValue={setInputProps}
- zodValidationResult={zodValidationResult}
- switchToSchema={switchToSchema}
- onSave={onUpdate}
- />
- )}
- </div>{' '}
+ {mode === 'schema' ? (
+ <SchemaEditor
+ value={inputProps}
+ setValue={setInputProps}
+ schema={composition.schema}
+ zodValidationResult={zodValidationResult}
+ compact={compact}
+ defaultProps={composition.defaultProps}
+ onSave={onSave}
+ showSaveButton={showSaveButton}
+ />
+ ) : (
+ <RenderModalJSONInputPropsEditor
+ value={inputProps ?? {}}
+ setValue={setInputProps}
+ zodValidationResult={zodValidationResult}
+ switchToSchema={switchToSchema}
+ onSave={onUpdate}
+ />
+ )}
</div>
);
};
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx
index 60ecaaa81d..1812fd8a10 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx
@@ -43,6 +43,13 @@ const schemaButton: React.CSSProperties = {
backgroundColor: 'transparent',
};
+const scrollable: React.CSSProperties = {
+ padding: '8px 12px',
+ display: 'flex',
+ flexDirection: 'column',
+ flex: 1,
+};
+
// TODO: Note if custom 'remotion-date:' pattern has been used
export const RenderModalJSONInputPropsEditor: React.FC<{
value: unknown;
@@ -91,7 +98,7 @@ export const RenderModalJSONInputPropsEditor: React.FC<{
// TODO: Don't show save button if no changes have been made
// TODO: Indicate saving progress
return (
- <>
+ <div style={scrollable}>
<RemTextarea
onChange={onChange}
value={localValue.str}
@@ -124,6 +131,6 @@ export const RenderModalJSONInputPropsEditor: React.FC<{
Save
</Button>
</Row>
- </>
+ </div>
);
};
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
index 433b19fd6b..e9dc579ccd 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
@@ -3,6 +3,7 @@ import {z} from 'remotion';
import {Button} from '../../../../preview-server/error-overlay/remotion-overlay/Button';
import {LIGHT_TEXT} from '../../../helpers/colors';
import {Spacing} from '../../layout';
+import {VERTICAL_SCROLLBAR_CLASSNAME} from '../../Menu/is-menu-item';
import {ZodErrorMessages} from './ZodErrorMessages';
import {ZodObjectEditor} from './ZodObjectEditor';
@@ -19,6 +20,13 @@ const codeSnippet: React.CSSProperties = {
fontFamily: 'monospace',
};
+const scrollable: React.CSSProperties = {
+ padding: '8px 12px',
+ display: 'flex',
+ flexDirection: 'column',
+ overflowY: 'auto',
+};
+
export const SchemaEditor: React.FC<{
schema: z.ZodTypeAny;
value: unknown;
@@ -46,13 +54,29 @@ export const SchemaEditor: React.FC<{
setValue(defaultProps);
}, [defaultProps, setValue]);
+ const openDocs = useCallback(() => {
+ window.open(
+ 'https://v4.remotion.dev/docs/parametrized-rendering#define-a-schema-'
+ );
+ }, []);
+
if (typeName === z.ZodFirstPartyTypeKind.ZodAny) {
return (
- <div style={errorExplanation}>
- The schema has an <code style={codeSnippet}>any</code> type.
- <br /> Tweak the schema by adding a{' '}
- <code style={codeSnippet}>schema</code> prop to the{' '}
- <code style={codeSnippet}>{'<Composition>'}</code> component.
+ <div
+ style={{
+ backgroundColor: 'red',
+ display: 'flex',
+ flex: 1,
+ flexDirection: 'column',
+ }}
+ >
+ <div style={errorExplanation}>
+ Make the props of this composition interactively editable by adding a{' '}
+ <code style={codeSnippet}>schema</code> prop to the{' '}
+ <code style={codeSnippet}>{'<Composition>'}</code> component.
+ </div>
+ <Spacing y={2} block />
+ <Button onClick={openDocs}>Learn how</Button>
</div>
);
}
@@ -122,23 +146,25 @@ export const SchemaEditor: React.FC<{
if (typeName === z.ZodFirstPartyTypeKind.ZodObject) {
return (
- <ZodObjectEditor
- value={value}
- setValue={setValue}
- jsonPath={[]}
- schema={schema}
- compact={compact}
- defaultValue={defaultProps}
- onSave={
- onSave as (
- newValue: (
- oldVal: Record<string, unknown>
- ) => Record<string, unknown>
- ) => void
- }
- showSaveButton={showSaveButton}
- onRemove={null}
- />
+ <div style={scrollable} className={VERTICAL_SCROLLBAR_CLASSNAME}>
+ <ZodObjectEditor
+ value={value}
+ setValue={setValue}
+ jsonPath={[]}
+ schema={schema}
+ compact={compact}
+ defaultValue={defaultProps}
+ onSave={
+ onSave as (
+ newValue: (
+ oldVal: Record<string, unknown>
+ ) => Record<string, unknown>
+ ) => void
+ }
+ showSaveButton={showSaveButton}
+ onRemove={null}
+ />
+ </div>
);
}