Skip to content

🎥 Make videos programmatically with React

progress

Jonny Burger06b770c4eef9
diff --git a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx b/packages/cli/src/editor/components/NewComposition/ComboBox.tsx
index 863bc105cb..aa3ef59e4b 100644
--- a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx
+++ b/packages/cli/src/editor/components/NewComposition/ComboBox.tsx
@@ -1,7 +1,12 @@
import {useElementSize} from '@remotion/player/src/utils/use-element-size';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import ReactDOM from 'react-dom';
-import {getBackgroundFromHoverState} from '../../helpers/colors';
+import {
+ INPUT_BACKGROUND,
+ INPUT_BORDER_COLOR_HOVERED,
+ INPUT_BORDER_COLOR_UNHOVERED,
+ SELECTED_BACKGROUND,
+} from '../../helpers/colors';
import {noop} from '../../helpers/noop';
import {HigherZIndex, useZIndex} from '../../state/z-index';
import {getPortal} from '../Menu/portals';
@@ -9,11 +14,11 @@ import {menuContainer, outerPortal} from '../Menu/styles';
import {MenuContent} from './MenuContent';
const container: React.CSSProperties = {
- padding: '6px 8px',
+ padding: '8px 10px',
display: 'inline-block',
- backgroundColor: 'rgba(255, 255, 255, 0.06)',
- fontSize: 15,
- borderWidth: 2,
+ backgroundColor: INPUT_BACKGROUND,
+ fontSize: 14,
+ borderWidth: 1,
borderStyle: 'solid',
};
@@ -57,18 +62,6 @@ export const Combobox: React.FC<{
setOpened(false);
}, []);
- const style = useMemo((): React.CSSProperties => {
- return {
- ...container,
- userSelect: 'none',
- color: 'white',
- borderColor: getBackgroundFromHoverState({
- hovered,
- selected: false,
- }),
- };
- }, [hovered]);
-
useEffect(() => {
const {current} = ref;
if (!current) {
@@ -107,6 +100,19 @@ export const Combobox: React.FC<{
const selected = values.find((v) => v.id === selectedId) as SelectionItem;
+ const style = useMemo((): React.CSSProperties => {
+ return {
+ ...container,
+ userSelect: 'none',
+ color: 'white',
+ borderColor: opened
+ ? SELECTED_BACKGROUND
+ : hovered
+ ? INPUT_BORDER_COLOR_HOVERED
+ : INPUT_BORDER_COLOR_UNHOVERED,
+ };
+ }, [hovered, opened]);
+
return (
<>
<button ref={ref} tabIndex={tabIndex} type="button" style={style}>
diff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
index 2a279e1a0c..db6c58c0eb 100644
--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
@@ -5,29 +5,34 @@ import React, {
useMemo,
useState,
} from 'react';
+import {Internals} from 'remotion';
import {Checkmark} from '../../icons/Checkmark';
import {ModalsContext} from '../../state/modals';
import {CopyButton} from '../CopyButton';
-import {Spacing} from '../layout';
+import {Row, Spacing} from '../layout';
import {ModalContainer} from '../ModalContainer';
import {NewCompHeader} from '../ModalHeader';
import {Combobox, ComboboxValue} from './ComboBox';
import {CompositionType, CompType} from './CompositionType';
-import {leftLabel} from './new-comp-layout';
+import {inputArea, leftLabel} from './new-comp-layout';
import {NewCompAspectRatio} from './NewCompAspectRatio';
import {getNewCompositionCode} from './NewCompCode';
import {NewCompDuration} from './NewCompDuration';
import {RemotionInput} from './RemInput';
+import {ValidationMessage} from './ValidationMessage';
const panelContent: React.CSSProperties = {
flexDirection: 'row',
display: 'flex',
+ width: 1100,
+ height: 450,
};
const left: React.CSSProperties = {
padding: 12,
paddingBottom: 80,
paddingRight: 12,
+ flex: 1,
};
const panelRight: React.CSSProperties = {
@@ -107,6 +112,8 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({
);
}, [onFpsChange, selectedFrameRate]);
+ const isValidCompName = Internals.isCompositionIdValid(name);
+
return (
<ModalContainer onOutsideClick={onQuit} onEscape={onQuit}>
<NewCompHeader title="New composition" />
@@ -116,13 +123,22 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({
<Spacing y={3} />
<form>
<label>
- <div style={leftLabel}>Name</div>
- <RemotionInput
- value={name}
- onChange={onNameChange}
- type="text"
- placeholder="Composition name"
- />
+ <Row align="center">
+ <div style={leftLabel}>Name</div>
+ <div style={inputArea}>
+ <RemotionInput
+ value={name}
+ onChange={onNameChange}
+ type="text"
+ placeholder="Composition name"
+ />
+ {isValidCompName ? null : (
+ <ValidationMessage
+ message={Internals.invalidCompositionErrorMessage}
+ />
+ )}
+ </div>
+ </Row>
</label>
<Spacing y={1} />
<div
@@ -135,26 +151,43 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({
<div>
<div>
<label>
- <div style={leftLabel}>Width</div>
- <RemotionInput
- type="number"
- value={width}
- placeholder="Width (px)"
- onChange={onWidthChanged}
- name="width"
- />
+ <Row align="center">
+ <div style={leftLabel}>Width</div>
+ <div style={inputArea}>
+ <RemotionInput
+ type="number"
+ value={width}
+ placeholder="Width (px)"
+ onChange={onWidthChanged}
+ name="width"
+ step={2}
+ min={2}
+ />
+ {Number(width) % 2 === 0 ? null : (
+ <ValidationMessage message="Dimension should be divisible by 2, since H264 codec doesn't support odd dimensions.." />
+ )}
+ </div>
+ </Row>
</label>
</div>
+ <div />
<Spacing y={1} />
+ <div />
<label>
- <div style={leftLabel}>Height</div>
- <RemotionInput
- type="number"
- value={height}
- onChange={onHeightChanged}
- placeholder="Height (px)"
- name="height"
- />
+ <Row align="center">
+ <div style={leftLabel}>Height</div>
+ <div style={inputArea}>
+ <RemotionInput
+ type="number"
+ value={height}
+ onChange={onHeightChanged}
+ placeholder="Height (px)"
+ name="height"
+ step={2}
+ min={2}
+ />
+ </div>
+ </Row>
</label>
</div>
<div>
@@ -164,6 +197,7 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({
/>
</div>
</div>
+ <div />
<Spacing y={1} />
{type === 'composition' ? (
<NewCompDuration
@@ -172,9 +206,12 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({
setDurationInFrames={setDurationInFrames}
/>
) : null}
-
+ <div />
+ <br />
+ <div />
{type === 'composition' ? (
<div>
+ <div />
<Spacing y={1} />
<label>
<div style={leftLabel}>Framerate</div>
diff --git a/packages/cli/src/editor/components/NewComposition/RemInput.tsx b/packages/cli/src/editor/components/NewComposition/RemInput.tsx
index 33366649af..4b6e19e862 100644
--- a/packages/cli/src/editor/components/NewComposition/RemInput.tsx
+++ b/packages/cli/src/editor/components/NewComposition/RemInput.tsx
@@ -7,8 +7,9 @@ import React, {
useState,
} from 'react';
import {
- BORDER_COLOR,
- CLEAR_HOVER,
+ INPUT_BACKGROUND,
+ INPUT_BORDER_COLOR_HOVERED,
+ INPUT_BORDER_COLOR_UNHOVERED,
SELECTED_BACKGROUND,
} from '../../helpers/colors';
import {FONT_FAMILY} from '../../helpers/font';
@@ -30,20 +31,20 @@ const RemInputForwardRef: React.ForwardRefRenderFunction<
const style = useMemo(() => {
return {
- backgroundColor: 'rgba(255, 255, 255, 0.06)',
- border: BORDER_COLOR,
+ backgroundColor: INPUT_BACKGROUND,
fontFamily: FONT_FAMILY,
- padding: '6px 8px',
+ padding: '8px 10px',
color: 'white',
outline: 'none',
borderStyle: 'solid',
- borderWidth: 2,
- fontSize: 15,
+ borderWidth: 1,
+ fontSize: 14,
+ appearance: 'textfield',
borderColor: isFocused
? SELECTED_BACKGROUND
: isHovered
- ? CLEAR_HOVER
- : 'transparent',
+ ? INPUT_BORDER_COLOR_HOVERED
+ : INPUT_BORDER_COLOR_UNHOVERED,
...(props.style ?? {}),
};
}, [isFocused, isHovered, props.style]);
diff --git a/packages/cli/src/editor/components/NewComposition/ValidationMessage.tsx b/packages/cli/src/editor/components/NewComposition/ValidationMessage.tsx
new file mode 100644
index 0000000000..281c77f300
--- /dev/null
+++ b/packages/cli/src/editor/components/NewComposition/ValidationMessage.tsx
@@ -0,0 +1,41 @@
+import React, {SVGProps} from 'react';
+import {Row, Spacing} from '../layout';
+
+const Triangle: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg viewBox="0 0 576 512" {...props}>
+ <path
+ fill="currentColor"
+ d="M248.747 204.705l6.588 112c.373 6.343 5.626 11.295 11.979 11.295h41.37a12 12 0 0 0 11.979-11.295l6.588-112c.405-6.893-5.075-12.705-11.979-12.705h-54.547c-6.903 0-12.383 5.812-11.978 12.705zM330 384c0 23.196-18.804 42-42 42s-42-18.804-42-42 18.804-42 42-42 42 18.804 42 42zm-.423-360.015c-18.433-31.951-64.687-32.009-83.154 0L6.477 440.013C-11.945 471.946 11.118 512 48.054 512H527.94c36.865 0 60.035-39.993 41.577-71.987L329.577 23.985zM53.191 455.002L282.803 57.008c2.309-4.002 8.085-4.002 10.394 0l229.612 397.993c2.308 4-.579 8.998-5.197 8.998H58.388c-4.617.001-7.504-4.997-5.197-8.997z"
+ />
+ </svg>
+ );
+};
+
+const style: React.CSSProperties = {
+ width: 11,
+ height: 11,
+};
+
+const container: React.CSSProperties = {
+ marginTop: 5,
+};
+
+const label: React.CSSProperties = {
+ fontSize: 13,
+ flex: 1,
+};
+
+export const ValidationMessage: React.FC<{
+ message: string;
+}> = ({message}) => {
+ return (
+ <div style={container}>
+ <Row align="center">
+ <Triangle style={style} color="#f1c40f" />
+ <Spacing x={1} />
+ <div style={label}>{message}</div>
+ </Row>
+ </div>
+ );
+};
diff --git a/packages/cli/src/editor/components/NewComposition/new-comp-layout.ts b/packages/cli/src/editor/components/NewComposition/new-comp-layout.ts
index 10726bbf27..c744ffb867 100644
--- a/packages/cli/src/editor/components/NewComposition/new-comp-layout.ts
+++ b/packages/cli/src/editor/components/NewComposition/new-comp-layout.ts
@@ -9,6 +9,10 @@ export const leftLabel: React.CSSProperties = {
color: '#ddd',
};
+export const inputArea: React.CSSProperties = {
+ width: 190,
+};
+
export const rightLabel: React.CSSProperties = {
fontSize: 13,
color: 'rgba(255, 255, 255, 0.5)',
diff --git a/packages/cli/src/editor/components/NewComposition/render-aspect-ratio.tsx b/packages/cli/src/editor/components/NewComposition/render-aspect-ratio.tsx
index ccf0b81749..23f443f76e 100644
--- a/packages/cli/src/editor/components/NewComposition/render-aspect-ratio.tsx
+++ b/packages/cli/src/editor/components/NewComposition/render-aspect-ratio.tsx
@@ -12,5 +12,12 @@ function gcd_two_numbers(x: number, y: number) {
export const aspectRatio = (width: number, height: number) => {
const commonDivisor = gcd_two_numbers(width, height);
- return width / commonDivisor + ':' + height / commonDivisor;
+ const widthDivisor = width / commonDivisor;
+ const heightDivisor = height / commonDivisor;
+
+ if (widthDivisor < 100) {
+ return widthDivisor + ':' + heightDivisor;
+ }
+
+ return (widthDivisor / heightDivisor).toFixed(2);
};
diff --git a/packages/cli/src/editor/helpers/colors.ts b/packages/cli/src/editor/helpers/colors.ts
index ed2ff44926..571928d3d1 100644
--- a/packages/cli/src/editor/helpers/colors.ts
+++ b/packages/cli/src/editor/helpers/colors.ts
@@ -1,9 +1,12 @@
-export const BACKGROUND = '#222';
+export const BACKGROUND = '#1f2428';
+export const INPUT_BACKGROUND = '#2f363d';
export const BORDER_COLOR = '#000';
export const SELECTED_BACKGROUND = 'hsla(0, 0%, 100%, 0.15)';
export const LIGHT_TEXT = 'rgba(255, 255, 255, 0.6)';
export const SELECTED_HOVER_BACKGROUND = 'hsla(0, 0%, 100%, 0.25)';
export const CLEAR_HOVER = 'rgba(255, 255, 255, 0.06)';
+export const INPUT_BORDER_COLOR_UNHOVERED = 'rgba(0, 0, 0, 0.6)';
+export const INPUT_BORDER_COLOR_HOVERED = 'rgba(255, 255, 255, 0.05)';
export const getBackgroundFromHoverState = ({
selected,
diff --git a/packages/cli/styles/styles.css b/packages/cli/styles/styles.css
index afef3746e1..6d3917f577 100644
--- a/packages/cli/styles/styles.css
+++ b/packages/cli/styles/styles.css
@@ -17,3 +17,9 @@ body {
.remotion-splitter-active {
background-color: var(--blue);
}
+
+input::-webkit-outer-spin-button,
+input::-webkit-inner-spin-button {
+ -webkit-appearance: none;
+ margin: 0;
+}
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsx
index 3afcf25c4b..3b6ad43aa9 100644
--- a/packages/core/src/Composition.tsx
+++ b/packages/core/src/Composition.tsx
@@ -8,6 +8,7 @@ import {
removeStaticComposition,
} from './register-root';
import {useLazyComponent} from './use-lazy-component';
+import {validateCompositionId} from './validation/validate-composition-id';
import {validateDimension} from './validation/validate-dimensions';
import {validateDurationInFrames} from './validation/validate-duration-in-frames';
import {validateFps} from './validation/validate-fps';
@@ -54,12 +55,7 @@ export const Composition = <T,>({
throw new Error('No id for composition passed.');
}
- if (!id.match(/^([a-zA-Z0-9-])+$/g)) {
- throw new Error(
- `Composition id can only contain a-z, A-Z, 0-9 and -. You passed ${id}`
- );
- }
-
+ validateCompositionId(id);
validateDimension(width, 'width', 'of the <Composition/> component');
validateDimension(height, 'height', 'of the <Composition/> component');
validateDurationInFrames(
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index 3a39d20885..e31d4861b4 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -94,6 +94,10 @@ import {truthy} from './truthy';
import {useLazyComponent} from './use-lazy-component';
import {useUnsafeVideoConfig} from './use-unsafe-video-config';
import {useVideo} from './use-video';
+import {
+ invalidCompositionErrorMessage,
+ isCompositionIdValid,
+} from './validation/validate-composition-id';
import {validateDimension} from './validation/validate-dimensions';
import {validateDurationInFrames} from './validation/validate-duration-in-frames';
import {validateFps} from './validation/validate-fps';
@@ -186,6 +190,8 @@ export const Internals = {
validateFrame,
setStillFrame,
getStillFrame,
+ invalidCompositionErrorMessage,
+ isCompositionIdValid,
};
export type {
diff --git a/packages/core/src/validation/validate-composition-id.ts b/packages/core/src/validation/validate-composition-id.ts
new file mode 100644
index 0000000000..0fa0d08be1
--- /dev/null
+++ b/packages/core/src/validation/validate-composition-id.ts
@@ -0,0 +1,15 @@
+export const validateCompositionId = (id: string) => {
+ if (!isCompositionIdValid(id)) {
+ throw new Error(
+ `Composition id can only contain a-z, A-Z, 0-9 and -. You passed ${id}`
+ );
+ }
+};
+
+const getRegex = () => /^([a-zA-Z0-9-])+$/g;
+
+export const isCompositionIdValid = (id: string) => id.match(getRegex());
+
+export const invalidCompositionErrorMessage = `Composition ID must match ${String(
+ getRegex()
+)}`;