Skip to content

🎥 Make videos programmatically with React

boolean editor

Jonny Burger41e4f315aa23
diff --git a/packages/cli/src/editor/components/Checkbox.tsx b/packages/cli/src/editor/components/Checkbox.tsx
index 8712d0dea3..3370bb79c8 100644
--- a/packages/cli/src/editor/components/Checkbox.tsx
+++ b/packages/cli/src/editor/components/Checkbox.tsx
@@ -23,6 +23,7 @@ const box: React.CSSProperties = {
top: 0,
left: 0,
pointerEvents: 'none',
+ color: 'white',
};
export const Checkbox: React.FC<{
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodBooleanEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodBooleanEditor.tsx
new file mode 100644
index 0000000000..783096a5c0
--- /dev/null
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodBooleanEditor.tsx
@@ -0,0 +1,68 @@
+import React, {useCallback} from 'react';
+import {Checkbox} from '../../Checkbox';
+import {narrowOption, optionRow} from '../layout';
+import {SchemaLabel} from './SchemaLabel';
+import type {JSONPath} from './zod-types';
+
+const fullWidth: React.CSSProperties = {
+ width: '100%',
+};
+
+export const ZodBooleanEditor: React.FC<{
+ jsonPath: JSONPath;
+ value: boolean;
+ setValue: React.Dispatch<React.SetStateAction<boolean>>;
+ compact: boolean;
+ defaultValue: boolean;
+ onSave: (updater: (oldNum: unknown) => boolean) => void;
+ onRemove: null | (() => void);
+ showSaveButton: boolean;
+}> = ({
+ jsonPath,
+ value,
+ setValue,
+ onSave,
+ compact,
+ defaultValue,
+ onRemove,
+ showSaveButton,
+}) => {
+ const onValueChange = useCallback(
+ (newValue: boolean) => {
+ setValue(newValue);
+ },
+ [setValue]
+ );
+
+ const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
+ (e) => {
+ onValueChange(e.target.checked);
+ },
+ [onValueChange]
+ );
+
+ const reset = useCallback(() => {
+ onValueChange(defaultValue);
+ }, [defaultValue, onValueChange]);
+
+ const save = useCallback(() => {
+ onSave(() => value);
+ }, [onSave, value]);
+
+ return (
+ <div style={compact ? narrowOption : optionRow}>
+ <SchemaLabel
+ isDefaultValue={value === defaultValue}
+ jsonPath={jsonPath}
+ onReset={reset}
+ onSave={save}
+ showSaveButton={showSaveButton}
+ compact={compact}
+ onRemove={onRemove}
+ />
+ <div style={fullWidth}>
+ <Checkbox checked={value} onChange={onChange} disabled={false} />
+ </div>
+ </div>
+ );
+};
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
index 4a68f4436d..5482a705bd 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
@@ -2,6 +2,7 @@ import React from 'react';
import {z} from 'remotion';
import type {JSONPath} from './zod-types';
import {ZodArrayEditor} from './ZodArrayEditor';
+import {ZodBooleanEditor} from './ZodBooleanEditor';
import {ZodEffectEditor} from './ZodEffectEditor';
import {ZodNumberEditor} from './ZodNumberEditor';
import {ZodObjectEditor} from './ZodObjectEditor';
@@ -90,6 +91,21 @@ export const ZodSwitch: React.FC<{
);
}
+ if (typeName === z.ZodFirstPartyTypeKind.ZodBoolean) {
+ return (
+ <ZodBooleanEditor
+ value={value as boolean}
+ setValue={setValue as React.Dispatch<React.SetStateAction<unknown>>}
+ jsonPath={jsonPath}
+ compact={compact}
+ defaultValue={defaultValue as boolean}
+ onSave={onSave}
+ showSaveButton={showSaveButton}
+ onRemove={onRemove}
+ />
+ );
+ }
+
if (typeName === z.ZodFirstPartyTypeKind.ZodArray) {
return (
<ZodArrayEditor
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsx
index a9b36866ab..93a9bada6c 100644
--- a/packages/example/src/Video.tsx
+++ b/packages/example/src/Video.tsx
@@ -697,9 +697,10 @@ export const Index: React.FC = () => {
.min(2),
array2: z.array(z.array(z.string())),
mynum: z.number(),
+ value: z.boolean().refine((v) => v === false || v === true),
})}
defaultProps={{
- vehicle: 'caa',
+ vehicle: 'bus',
other: 'hi',
abc: {def: {xyz: 'hu', pef: 'hu'}, jkl: 'sting', xyz: 'hi'},
array: [
@@ -708,6 +709,7 @@ export const Index: React.FC = () => {
],
array2: [['bbbbbb'], ['bbbbbb']],
mynum: 179,
+ value: false,
}}
durationInFrames={150}
/>