🎥 Make videos programmatically with React
let's go
Jonny Burgerb77eeee7084d
diff --git a/packages/cli/src/editor/components/CopyButton.tsx b/packages/cli/src/editor/components/CopyButton.tsxindex 2e7245ad08..c174d7cb62 100644--- a/packages/cli/src/editor/components/CopyButton.tsx+++ b/packages/cli/src/editor/components/CopyButton.tsx@@ -1,4 +1,8 @@-import React, {useCallback, useState} from 'react';+import React, {useCallback, useEffect, useState} from 'react';+import {+ INPUT_BACKGROUND,+ INPUT_BORDER_COLOR_UNHOVERED,+} from '../helpers/colors';import {copyCmd} from '../helpers/copy-text';import {Row, Spacing} from './layout';@@ -22,16 +26,16 @@ const copyIcon = ();const container: React.CSSProperties = {- border: `2px solid rgba(255, 255, 255, 0.2)`,- borderRadius: 4,padding: 10,cursor: 'pointer',+ fontSize: 14,};const button: React.CSSProperties = {- backgroundColor: 'transparent',+ border: `1px solid ${INPUT_BORDER_COLOR_UNHOVERED}`,+ borderRadius: 4,+ backgroundColor: INPUT_BACKGROUND,appearance: 'none',- border: 'none',fontFamily: 'inherit',fontSize: 16,color: 'white',@@ -42,18 +46,27 @@ export const CopyButton: React.FC<{label: string;labelWhenCopied: string;}> = ({textToCopy, label, labelWhenCopied}) => {- const [copied, setCopied] = useState(false);+ const [copied, setCopied] = useState<false | number>(false);const onClick = useCallback(() => {copyCmd(textToCopy);- setCopied(true);+ setCopied(Date.now());}, [textToCopy]);+ useEffect(() => {+ if (!copied) {+ return;+ }++ const to = setTimeout(() => setCopied(false), 2000);+ return () => clearTimeout(to);+ }, [copied]);+return (<button onClick={onClick} style={button} type="button"><Row style={container}>{copyIcon}- <Spacing x={1} /> {copied ? labelWhenCopied : label}+ <Spacing x={1.5} /> {copied ? labelWhenCopied : label}</Row></button>);diff --git a/packages/cli/src/editor/components/NewComposition/InputDragger.tsx b/packages/cli/src/editor/components/NewComposition/InputDragger.tsxindex 5a06b3cb05..5b6eaa3d3a 100644--- a/packages/cli/src/editor/components/NewComposition/InputDragger.tsx+++ b/packages/cli/src/editor/components/NewComposition/InputDragger.tsx@@ -10,9 +10,11 @@ import {interpolate} from 'remotion';import {getClickLock, setClickLock} from '../../state/input-dragger-click-lock';import {inputBaseStyle, RemotionInput} from './RemInput';-type Props = InputHTMLAttributes<HTMLInputElement>;+type Props = InputHTMLAttributes<HTMLInputElement> & {+ onValueChange: (newVal: number) => void;+};-export const InputDragger: React.FC<Props> = (props) => {+export const InputDragger: React.FC<Props> = ({onValueChange, ...props}) => {const [inputFallback, setInputFallback] = useState(false);const [editMode, setEditMode] = useState(false);@@ -36,7 +38,7 @@ export const InputDragger: React.FC<Props> = (props) => {);const onClick: MouseEventHandler<HTMLButtonElement> = useCallback((e) => {- if (!getClickLock) e.stopPropagation();+ if (!getClickLock()) e.stopPropagation();setInputFallback(true);}, []);@@ -74,7 +76,8 @@ export const InputDragger: React.FC<Props> = (props) => {[-step, 0, 0, 0, step]);const newValue = Math.max(min, Math.floor(Number(props.value) + diff));- console.log({newValue});+ const roundToStep = Math.floor(newValue / step) * step;+ onValueChange(roundToStep);};window.addEventListener('mousemove', moveListener);@@ -92,7 +95,7 @@ export const InputDragger: React.FC<Props> = (props) => {});},- [props.min, props.step, props.value]+ [onValueChange, props.min, props.step, props.value]);if (inputFallback) {diff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsxindex ddb8af8693..9528f19aad 100644--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx@@ -79,6 +79,14 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({[]);+ const onWidthDirectlyChanged = useCallback((newWidth: number) => {+ setWidth(String(newWidth));+ }, []);++ const onHeightDirectlyChanged = useCallback((newHeight: number) => {+ setHeight(String(newHeight));+ }, []);+const onHeightChanged: ChangeEventHandler<HTMLInputElement> = useCallback((e) => {setHeight(e.target.value);@@ -163,6 +171,7 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({name="width"step={2}min={2}+ onValueChange={onWidthDirectlyChanged}/>{Number(width) % 2 === 0 ? null : (<ValidationMessage message="Dimension should be divisible by 2, since H264 codec doesn't support odd dimensions.." />@@ -186,6 +195,7 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({name="height"step={2}min={2}+ onValueChange={onHeightDirectlyChanged}/>{Number(height) % 2 === 0 ? null : (<ValidationMessage message="Dimension should be divisible by 2, since H264 codec doesn't support odd dimensions.." />@@ -247,7 +257,7 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({><CopyButtonlabel="Copy code"- labelWhenCopied="Copied"+ labelWhenCopied="Copied!"textToCopy={getNewCompositionCode({type,diff --git a/packages/cli/src/editor/state/z-index.tsx b/packages/cli/src/editor/state/z-index.tsxindex 27845774f5..2a9989c9e0 100644--- a/packages/cli/src/editor/state/z-index.tsx+++ b/packages/cli/src/editor/state/z-index.tsx@@ -55,14 +55,12 @@ export const HigherZIndex: React.FC<{useEffect(() => {const listener = (e: MouseEvent) => {const outsideClick = !containerRef.current?.contains(e.target as Node);- console.log({containerRef: containerRef.current, target: e.target});if (outsideClick &&highestContext.highestIndex === currentIndex &&!getClickLock()) {e.stopPropagation();- console.log('outside click');onOutsideClick();}};diff --git a/packages/cli/styles/styles.css b/packages/cli/styles/styles.cssindex cd508b4283..c31d848577 100644--- a/packages/cli/styles/styles.css+++ b/packages/cli/styles/styles.css@@ -24,3 +24,11 @@ input::-webkit-inner-spin-button {-webkit-appearance: none;margin: 0;}++input:focus,+button:focus,+a:focus {+ outline: none;+ box-shadow: 0 0 1px 2px rgba(255, 255, 255, 0.35);+ border-radius: 3px;+}