🎥 Make videos programmatically with React
better behavior, can clear input field
Jonny Burger86bdaae2c7f1
diff --git a/packages/cli/src/editor/components/NewComposition/InputDragger.tsx b/packages/cli/src/editor/components/NewComposition/InputDragger.tsxindex 5ea1639426..6c77ddc05b 100644--- a/packages/cli/src/editor/components/NewComposition/InputDragger.tsx+++ b/packages/cli/src/editor/components/NewComposition/InputDragger.tsx@@ -12,6 +12,7 @@ import {inputBaseStyle, RemotionInput} from './RemInput';type Props = InputHTMLAttributes<HTMLInputElement> & {onValueChange: (newVal: number) => void;+ onTextChange: (newVal: string) => void;};export const InputDragger: React.FC<Props> = ({@@ -19,7 +20,7 @@ export const InputDragger: React.FC<Props> = ({min: _min,step: _step,value,- onChange,+ onTextChange,...props}) => {const [inputFallback, setInputFallback] = useState(false);@@ -57,14 +58,33 @@ export const InputDragger: React.FC<Props> = ({setInputFallback(true);}, []);- const onBlur = useCallback(() => {- if (fallbackRef.current) setInputFallback(false);+ const onEscape = useCallback(() => {+ setInputFallback(false);}, []);+ const onBlur = useCallback(() => {+ if (!fallbackRef.current) {+ return;+ }++ const newValue = fallbackRef.current.value;+ if (newValue.trim() === '') {+ onEscape();+ return;+ }++ if (fallbackRef.current.checkValidity()) {+ onTextChange?.(newValue);+ setInputFallback(false);+ } else {+ fallbackRef.current.reportValidity();+ }+ }, [onEscape, onTextChange]);+const onKeyPress: React.KeyboardEventHandler<HTMLInputElement> = useCallback((e) => {if (e.key === 'Enter') {- setInputFallback(false);+ fallbackRef.current?.blur();}},[]@@ -119,7 +139,7 @@ export const InputDragger: React.FC<Props> = ({if (inputFallback) {return (- <HigherZIndex onEscape={onBlur} onOutsideClick={noop}>+ <HigherZIndex onEscape={onEscape} onOutsideClick={noop}><RemotionInputref={fallbackRef}autoFocus@@ -127,6 +147,7 @@ export const InputDragger: React.FC<Props> = ({onBlur={onBlur}min={_min}step={_step}+ defaultValue={value}{...props}/></HigherZIndex>diff --git a/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx b/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsxindex 94a04bbc77..4efced94dc 100644--- a/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx+++ b/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx@@ -1,4 +1,3 @@-import type {ChangeEventHandler} from 'react';import React, {useCallback} from 'react';import {validateCompositionDuration} from '../../helpers/validate-new-comp-data';import {Row} from '../layout';@@ -11,13 +10,12 @@ export const NewCompDuration: React.FC<{fps: string;setDurationInFrames: React.Dispatch<React.SetStateAction<string>>;}> = ({durationInFrames, setDurationInFrames, fps}) => {- const onDurationInFramesChanged: ChangeEventHandler<HTMLInputElement> =- useCallback(- (e) => {- setDurationInFrames(String(Number(e.target.value)));- },- [setDurationInFrames]- );+ const onDurationInFramesChanged = useCallback(+ (newValue: string) => {+ setDurationInFrames(String(Number(newValue)));+ },+ [setDurationInFrames]+ );const onDurationChangedDirectly = useCallback((newVal: number) => {@@ -37,12 +35,14 @@ export const NewCompDuration: React.FC<{<InputDraggertype="number"value={durationInFrames}- onChange={onDurationInFramesChanged}+ onTextChange={onDurationInFramesChanged}placeholder="Duration (frames)"name="durationInFrames"min={1}step={1}- max={100000000}+ required+ // Hitting Promise.all() limit in Chrome+ max={300_000}onValueChange={onDurationChangedDirectly}/>{compDurationErrMessage ? (diff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsxindex 45b878eb5a..c06dd5dbda 100644--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx@@ -113,11 +113,11 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {setType(newType);}, []);- const onWidthChanged: ChangeEventHandler<HTMLInputElement> = useCallback(- (e) => {+ const onWidthChanged = useCallback(+ (newValue: string) => {setSize((s) => {const {height} = s;- const newWidth = Number(e.target.value);+ const newWidth = Number(newValue);return {height:lockedAspectRatio === null@@ -164,11 +164,11 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {[lockedAspectRatio]);- const onHeightChanged: ChangeEventHandler<HTMLInputElement> = useCallback(- (e) => {+ const onHeightChanged = useCallback(+ (newValue: string) => {setSize((s) => {const {width} = s;- const newHeight = Number(e.target.value);+ const newHeight = Number(newValue);return {width:lockedAspectRatio === null@@ -289,10 +289,11 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {type="number"value={size.width}placeholder="Width (px)"- onChange={onWidthChanged}+ onTextChange={onWidthChanged}name="width"step={2}min={2}+ requiredmax={100000000}onValueChange={onWidthDirectlyChanged}/>@@ -313,10 +314,11 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {<InputDraggertype="number"value={size.height}- onChange={onHeightChanged}+ onTextChange={onHeightChanged}placeholder="Height (px)"name="height"step={2}+ requiredmin={2}max={100000000}onValueChange={onHeightDirectlyChanged}