🎥 Make videos programmatically with React
getting nice
Jonny Burger82e3da8f529f
diff --git a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx b/packages/cli/src/editor/components/NewComposition/ComboBox.tsxindex aa3ef59e4b..2e4532d935 100644--- a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx+++ b/packages/cli/src/editor/components/NewComposition/ComboBox.tsx@@ -8,7 +8,9 @@ import {SELECTED_BACKGROUND,} from '../../helpers/colors';import {noop} from '../../helpers/noop';+import {CaretDown} from '../../icons/caret';import {HigherZIndex, useZIndex} from '../../state/z-index';+import {Flex, Spacing} from '../layout';import {getPortal} from '../Menu/portals';import {menuContainer, outerPortal} from '../Menu/styles';import {MenuContent} from './MenuContent';@@ -49,7 +51,8 @@ export type ComboboxValue = DividerItem | SelectionItem;export const Combobox: React.FC<{values: ComboboxValue[];selectedId: string | number;-}> = ({values, selectedId}) => {+ style?: React.CSSProperties;+}> = ({values, selectedId, style: customStyle}) => {const [hovered, setIsHovered] = useState(false);const [opened, setOpened] = useState(false);const ref = useRef<HTMLButtonElement>(null);@@ -103,20 +106,24 @@ export const Combobox: React.FC<{const style = useMemo((): React.CSSProperties => {return {...container,+ ...(customStyle ?? {}),userSelect: 'none',color: 'white',+ display: 'inline-flex',+ flexDirection: 'row',+ alignItems: 'center',borderColor: opened? SELECTED_BACKGROUND: hovered? INPUT_BORDER_COLOR_HOVERED: INPUT_BORDER_COLOR_UNHOVERED,};- }, [hovered, opened]);+ }, [customStyle, hovered, opened]);return (<><button ref={ref} tabIndex={tabIndex} type="button" style={style}>- {selected.label}+ {selected.label} <Flex /> <Spacing x={1} /> <CaretDown /></button>{portalStyle? ReactDOM.createPortal(diff --git a/packages/cli/src/editor/components/NewComposition/InputDragger.tsx b/packages/cli/src/editor/components/NewComposition/InputDragger.tsxindex 5b6eaa3d3a..0edab19345 100644--- a/packages/cli/src/editor/components/NewComposition/InputDragger.tsx+++ b/packages/cli/src/editor/components/NewComposition/InputDragger.tsx@@ -38,7 +38,10 @@ export const InputDragger: React.FC<Props> = ({onValueChange, ...props}) => {);const onClick: MouseEventHandler<HTMLButtonElement> = useCallback((e) => {- if (!getClickLock()) e.stopPropagation();+ if (!getClickLock()) {+ e.stopPropagation();+ }+setInputFallback(true);}, []);diff --git a/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx b/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsxindex 65872df10f..9dd4e54d24 100644--- a/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx+++ b/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx@@ -1,6 +1,7 @@import React, {ChangeEventHandler, useCallback} from 'react';-import {leftLabel, rightLabel} from './new-comp-layout';-import {RemotionInput} from './RemInput';+import {Row} from '../layout';+import {InputDragger} from './InputDragger';+import {inputArea, leftLabel, rightLabel} from './new-comp-layout';const label: React.CSSProperties = {fontSize: 13,@@ -20,20 +21,33 @@ export const NewCompDuration: React.FC<{[setDurationInFrames]);+ const onDurationChangedDirectly = useCallback(+ (newVal: number) => {+ setDurationInFrames(String(newVal));+ },+ [setDurationInFrames]+ );+return (<div><label>- <div style={leftLabel}> Duration in frames</div>- <RemotionInput- type="number"- value={durationInFrames}- onChange={onDurationInFramesChanged}- placeholder="Duration (frames)"- name="height"- />- <span style={rightLabel}>- {(Number(durationInFrames) / Number(fps)).toFixed(2)}sec- </span>+ <Row align="center">+ <div style={leftLabel}> Duration in frames</div>+ <div style={inputArea}>+ <InputDragger+ type="number"+ value={durationInFrames}+ onChange={onDurationInFramesChanged}+ placeholder="Duration (frames)"+ name="height"+ min={1}+ onValueChange={onDurationChangedDirectly}+ />+ </div>+ <span style={rightLabel}>+ {(Number(durationInFrames) / Number(fps)).toFixed(2)}sec+ </span>+ </Row></label></div>);diff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsxindex 9528f19aad..c102372746 100644--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx@@ -229,7 +229,13 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({<Spacing y={1} /><label><div style={leftLabel}>Framerate</div>- <Combobox values={items} selectedId={selectedFrameRate} />+ <Combobox+ style={{+ width: inputArea.width,+ }}+ values={items}+ selectedId={selectedFrameRate}+ /></label></div>) : null}diff --git a/packages/cli/src/editor/components/NewComposition/RemInput.tsx b/packages/cli/src/editor/components/NewComposition/RemInput.tsxindex 3a9728b019..f1199dcc2a 100644--- a/packages/cli/src/editor/components/NewComposition/RemInput.tsx+++ b/packages/cli/src/editor/components/NewComposition/RemInput.tsx@@ -42,7 +42,7 @@ const RemInputForwardRef: React.ForwardRefRenderFunction<return {backgroundColor: INPUT_BACKGROUND,...inputBaseStyle,-+ width: '100%',borderColor: isFocused? SELECTED_BACKGROUND: isHovereddiff --git a/packages/cli/src/editor/icons/caret.tsx b/packages/cli/src/editor/icons/caret.tsxindex 1f1620e3b2..7759f91d44 100644--- a/packages/cli/src/editor/icons/caret.tsx+++ b/packages/cli/src/editor/icons/caret.tsx@@ -4,21 +4,26 @@ const caret: React.CSSProperties = {height: 12,};+const caretDown: React.CSSProperties = {+ width: 10,+};+export const Caret = () => (- <svg- aria-hidden="true"- focusable="false"- data-prefix="fas"- data-icon="caret-right"- className="svg-inline--fa fa-caret-right fa-w-6"- role="img"- xmlns="http://www.w3.org/2000/svg"- viewBox="0 0 192 512"- style={caret}- >+ <svg viewBox="0 0 192 512" style={caret}><pathfill="currentColor"d="M0 384.662V127.338c0-17.818 21.543-26.741 34.142-14.142l128.662 128.662c7.81 7.81 7.81 20.474 0 28.284L34.142 398.804C21.543 411.404 0 402.48 0 384.662z"/></svg>);++export const CaretDown = () => {+ return (+ <svg viewBox="0 0 320 512" style={caretDown}>+ <path+ fill="currentColor"+ d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"+ />+ </svg>+ );+};