Skip to content

🎥 Make videos programmatically with React

error message aesthetics

Patric Salvisberg80e14b38f564
diff --git a/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx b/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx
index 2f1939cfcc..506234ef7b 100644
--- a/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx
+++ b/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx
@@ -49,6 +49,7 @@ export const NewCompDuration: React.FC<{
<ValidationMessage
align="flex-start"
message={compDurationErrMessage}
+ type="error"
/>
) : null}
</div>
diff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
index e400494309..1e97232d70 100644
--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
@@ -274,6 +274,7 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {
<ValidationMessage
align="flex-start"
message={compNameErrMessage}
+ type="error"
/>
) : null}
</div>
@@ -304,6 +305,7 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {
<ValidationMessage
align="flex-start"
message={compWidthErrMessage}
+ type="error"
/>
) : null}
</div>
@@ -334,6 +336,7 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {
<ValidationMessage
align="flex-start"
message={compHeightErrMessage}
+ type="error"
/>
) : null}
</div>
diff --git a/packages/cli/src/editor/components/NewComposition/RemInput.tsx b/packages/cli/src/editor/components/NewComposition/RemInput.tsx
index 347161bb05..71672d3e32 100644
--- a/packages/cli/src/editor/components/NewComposition/RemInput.tsx
+++ b/packages/cli/src/editor/components/NewComposition/RemInput.tsx
@@ -8,6 +8,7 @@ import React, {
useState,
} from 'react';
import {
+ FAIL_COLOR,
INPUT_BACKGROUND,
INPUT_BORDER_COLOR_HOVERED,
INPUT_BORDER_COLOR_UNHOVERED,
@@ -21,6 +22,7 @@ type Props = React.DetailedHTMLProps<
HTMLInputElement
> & {
warning?: boolean;
+ disabled?: boolean;
};
export const INPUT_HORIZONTAL_PADDING = 8;
@@ -44,7 +46,7 @@ export const inputBaseStyle: React.CSSProperties = {
const RemInputForwardRef: React.ForwardRefRenderFunction<
HTMLInputElement,
Props
-> = ({warning, ...props}, ref) => {
+> = ({warning, disabled, ...props}, ref) => {
const [isFocused, setIsFocused] = useState(false);
const [isHovered, setIsHovered] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);
@@ -57,6 +59,8 @@ const RemInputForwardRef: React.ForwardRefRenderFunction<
width: '100%',
borderColor: warning
? WARNING_COLOR
+ : disabled
+ ? FAIL_COLOR
: isFocused
? SELECTED_BACKGROUND
: isHovered
@@ -64,7 +68,7 @@ const RemInputForwardRef: React.ForwardRefRenderFunction<
: INPUT_BORDER_COLOR_UNHOVERED,
...(props.style ?? {}),
};
- }, [isFocused, isHovered, props.style, warning]);
+ }, [disabled, isFocused, isHovered, props.style, warning]);
useImperativeHandle(
ref,
diff --git a/packages/cli/src/editor/components/NewComposition/ValidationMessage.tsx b/packages/cli/src/editor/components/NewComposition/ValidationMessage.tsx
index 3d29f3fba3..b0c4f5b410 100644
--- a/packages/cli/src/editor/components/NewComposition/ValidationMessage.tsx
+++ b/packages/cli/src/editor/components/NewComposition/ValidationMessage.tsx
@@ -1,15 +1,12 @@
import type {SVGProps} from 'react';
import React from 'react';
-import {WARNING_COLOR} from '../../helpers/colors';
+import {FAIL_COLOR, WARNING_COLOR} from '../../helpers/colors';
import {Row, Spacing} from '../layout';
const WarningTriangle: React.FC<SVGProps<SVGSVGElement>> = (props) => {
return (
<svg viewBox="0 0 576 512" {...props}>
- <path
- fill={WARNING_COLOR}
- 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"
- />
+ <path 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>
);
};
@@ -30,11 +27,17 @@ const label: React.CSSProperties = {
export const ValidationMessage: React.FC<{
message: string;
align: 'flex-start' | 'flex-end';
-}> = ({message, align}) => {
+ type: 'warning' | 'error';
+}> = ({message, align, type}) => {
return (
<div style={container}>
<Row align="center" justify={align}>
- <WarningTriangle style={style} />
+ <WarningTriangle
+ style={{
+ ...style,
+ fill: type === 'warning' ? WARNING_COLOR : FAIL_COLOR,
+ }}
+ />
<Spacing x={1} />
<div style={label}>{message}</div>
</Row>
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
index ece35b15a4..2d131c6f58 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
@@ -238,6 +238,8 @@ export const RenderModal: React.FC<{
() => initialEnforceAudioTrack
);
+ const [renderDisabled, setRenderDisabled] = useState<boolean>(false);
+
const [renderMode, setRenderModeState] =
useState<RenderType>(initialRenderType);
const [quality, setQuality] = useState<number>(() => initialQuality);
@@ -740,8 +742,14 @@ export const RenderModal: React.FC<{
<Button
autoFocus
onClick={renderMode === 'still' ? onClickStill : onClickVideo}
- disabled={state.type === 'load'}
- style={buttonStyle}
+ disabled={state.type === 'load' || renderDisabled}
+ style={{
+ ...buttonStyle,
+ backgroundColor: renderDisabled
+ ? 'var(--blue-disabled)'
+ : 'var(--blue)',
+ opacity: renderDisabled ? 0.7 : 1,
+ }}
>
{state.type === 'idle' ? `Render ${renderMode}` : 'Rendering...'}
</Button>
@@ -829,6 +837,8 @@ export const RenderModal: React.FC<{
setStartFrame={setStartFrame}
startFrame={startFrame}
audioCodec={audioCodec}
+ setRenderDisabled={setRenderDisabled}
+ renderDisabled={renderDisabled}
/>
) : tab === 'picture' ? (
<RenderModalPicture
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalBasic.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalBasic.tsx
index 9756bde084..eb88eec9f7 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalBasic.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalBasic.tsx
@@ -36,6 +36,8 @@ export const RenderModalBasic: React.FC<{
startFrame: number;
endFrame: number;
setStartFrame: React.Dispatch<React.SetStateAction<number | null>>;
+ renderDisabled: boolean;
+ setRenderDisabled: React.Dispatch<React.SetStateAction<boolean>>;
}> = ({
renderMode,
imageFormatOptions,
@@ -53,6 +55,8 @@ export const RenderModalBasic: React.FC<{
endFrame,
setStartFrame,
startFrame,
+ setRenderDisabled,
+ renderDisabled,
}) => {
const existence = useFileExistence(outName);
const videoCodecOptions = useMemo((): ComboboxValue[] => {
@@ -198,6 +202,8 @@ export const RenderModalBasic: React.FC<{
onValueChange={onValueChange}
codec={codec}
audioCodec={audioCodec}
+ setRenderDisabled={setRenderDisabled}
+ renderDisabled={renderDisabled}
/>
</div>
);
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalInput.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalInput.tsx
index db81b0a245..2f44f9f03e 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalInput.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalInput.tsx
@@ -12,8 +12,20 @@ export const RenderModalInput: React.FC<{
codec: Codec;
audioCodec: AudioCodec;
onValueChange: React.ChangeEventHandler<HTMLInputElement>;
-}> = ({existence, inputStyle, outName, onValueChange, codec, audioCodec}) => {
+ renderDisabled: boolean;
+ setRenderDisabled: React.Dispatch<React.SetStateAction<boolean>>;
+}> = ({
+ existence,
+ inputStyle,
+ outName,
+ onValueChange,
+ codec,
+ audioCodec,
+ setRenderDisabled,
+ renderDisabled,
+}) => {
const checkInpuName = useMemo(() => {
+ setRenderDisabled(false);
const extension = outName.substring(outName.lastIndexOf('.') + 1);
const prefix = outName.substring(0, outName.lastIndexOf('.'));
const invalidChars = ['?', '*', '+', '%'];
@@ -31,39 +43,61 @@ export const RenderModalInput: React.FC<{
preferLossless: false,
});
} catch (e) {
+ setRenderDisabled(true);
console.log(e);
const errorMessage = 'Invalid file extension';
- return <ValidationMessage align="flex-end" message={errorMessage} />;
+ return (
+ <ValidationMessage
+ align="flex-end"
+ message={errorMessage}
+ type={'error'}
+ />
+ );
}
if (existence) {
return (
- <ValidationMessage align="flex-end" message="Will be overwritten" />
+ <ValidationMessage
+ align="flex-end"
+ message="Will be overwritten"
+ type={'warning'}
+ />
);
}
if (prefix.length < 1) {
- return <ValidationMessage align="flex-end" message="Empty file name" />;
+ setRenderDisabled(true);
+ return (
+ <ValidationMessage
+ align="flex-end"
+ message="Empty file name"
+ type={'error'}
+ />
+ );
}
if (prefix[0] === '.') {
+ setRenderDisabled(true);
return (
<ValidationMessage
align="flex-end"
message="Filename starts with '.'"
+ type={'error'}
/>
);
}
if (hasInvalidChar()) {
+ setRenderDisabled(true);
return (
<ValidationMessage
align="flex-end"
message="Filename can't contain the following characters: ?, *, +, %"
+ type={'error'}
/>
);
}
- }, [audioCodec, codec, existence, outName]);
+ }, [audioCodec, codec, existence, outName, setRenderDisabled]);
return (
<div style={optionRow}>
@@ -73,6 +107,7 @@ export const RenderModalInput: React.FC<{
<RemotionInput
// TODO: Validate and reject folders or weird file names
warning={existence}
+ disabled={renderDisabled}
style={inputStyle}
type="text"
value={outName}
diff --git a/packages/cli/styles/styles.css b/packages/cli/styles/styles.css
index 4b17c9cabe..42c9e3b0c0 100644
--- a/packages/cli/styles/styles.css
+++ b/packages/cli/styles/styles.css
@@ -1,5 +1,6 @@
html {
--blue: #0b84f3;
+ --blue-disabled: #284f73;
}
body {
@@ -30,7 +31,8 @@ input:focus,
button:focus,
a:focus {
outline: none;
- box-shadow: inset 1px 1px #555, inset -1px -1px #555, inset 1px -1px #555, inset -1px 1px #555;
+ box-shadow: inset 1px 1px #555, inset -1px -1px #555, inset 1px -1px #555,
+ inset -1px 1px #555;
border-radius: 0 !important;
}
@@ -38,5 +40,5 @@ input.no-focus-ring:focus,
button.no-focus-ring:focus,
a.no-focus-ring:focus {
box-shadow: none;
- border-radius: 0
+ border-radius: 0;
}