Skip to content

🎥 Make videos programmatically with React

keyboard shortcuts and title

Jonny Burgerfe0109387057
diff --git a/packages/cli/src/editor/components/CurrentComposition.tsx b/packages/cli/src/editor/components/CurrentComposition.tsx
index 03e1b276a9..ce14c9acfb 100644
--- a/packages/cli/src/editor/components/CurrentComposition.tsx
+++ b/packages/cli/src/editor/components/CurrentComposition.tsx
@@ -1,7 +1,9 @@
-import React, {useContext, useEffect} from 'react';
+import React, {useCallback, useContext, useEffect} from 'react';
import {Internals} from 'remotion';
import {BACKGROUND, BORDER_COLOR} from '../helpers/colors';
import {isCompositionStill} from '../helpers/is-composition-still';
+import {useKeybinding} from '../helpers/use-keybinding';
+import {ModalsContext} from '../state/modals';
import {renderFrame} from '../state/render-frame';
import {RichTimelineContext} from '../state/rich-timeline';
import {Spacing} from './layout';
@@ -45,6 +47,9 @@ const targetWidth = (targetHeight * 16) / 9;
export const CurrentComposition = () => {
const richTimelineContext = useContext(RichTimelineContext);
const video = Internals.useVideo();
+ const keybindings = useKeybinding();
+ const {setSelectedModal} = useContext(ModalsContext);
+ const isStill = isCompositionStill(video);
useEffect(() => {
if (!video) {
@@ -55,6 +60,32 @@ export const CurrentComposition = () => {
document.title = `${video.id} / ${window.remotion_projectName} - Remotion Preview`;
}, [video]);
+ const renderStill = useCallback(() => {
+ if (!video) {
+ return null;
+ }
+
+ setSelectedModal({type: 'render', composition: video});
+ }, [setSelectedModal, video]);
+
+ useEffect(() => {
+ if (!isStill) {
+ return;
+ }
+
+ const binding = keybindings.registerKeybinding({
+ event: 'keydown',
+ key: 'r',
+ commandCtrlKey: false,
+ callback: renderStill,
+ preventDefault: true,
+ });
+
+ return () => {
+ binding.unregister();
+ };
+ }, [isStill, keybindings, renderStill]);
+
if (!video) {
return <div style={container} />;
}
diff --git a/packages/cli/src/editor/components/ModalHeader.tsx b/packages/cli/src/editor/components/ModalHeader.tsx
index 961cb6e177..45530594d2 100644
--- a/packages/cli/src/editor/components/ModalHeader.tsx
+++ b/packages/cli/src/editor/components/ModalHeader.tsx
@@ -7,11 +7,16 @@ const container: React.CSSProperties = {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
- padding: 12,
+ padding: '12px 16px',
width: '100%',
borderBottom: '1px solid black',
};
+const titleStyle: React.CSSProperties = {
+ fontSize: 14,
+ color: 'white',
+};
+
const icon: React.CSSProperties = {
height: 20,
width: 20,
@@ -21,12 +26,14 @@ export const NewCompHeader: React.FC<{
title: string;
}> = ({title}) => {
const {setSelectedModal} = useContext(ModalsContext);
+
const onPress = useCallback(() => {
setSelectedModal(null);
}, [setSelectedModal]);
+
return (
<div style={container}>
- <div>{title}</div>
+ <div style={titleStyle}>{title}</div>
<Flex />
<CancelButton style={icon} onPress={onPress} />
</div>
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
index 600babe43c..5585e3b266 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
@@ -11,6 +11,7 @@ import React, {
import type {TCompMetadata} from 'remotion';
import {getDefaultOutLocation} from '../../../get-default-out-name';
import {Button} from '../../../preview-server/error-overlay/remotion-overlay/Button';
+import {LIGHT_TEXT} from '../../helpers/colors';
import {useFileExistence} from '../../helpers/use-file-existence';
import {ModalsContext} from '../../state/modals';
import {Spacing} from '../layout';
@@ -71,21 +72,22 @@ const reducer = (state: State, action: Action): State => {
return state;
};
-const container: React.CSSProperties = {
- padding: 20,
-};
+const container: React.CSSProperties = {};
const optionRow: React.CSSProperties = {
display: 'flex',
flexDirection: 'row',
alignItems: 'flex-start',
minHeight: 40,
+ paddingLeft: 16,
+ paddingRight: 16,
};
const label: React.CSSProperties = {
width: 150,
fontSize: 14,
lineHeight: '40px',
+ color: LIGHT_TEXT,
};
const rightRow: React.CSSProperties = {
@@ -100,6 +102,11 @@ const buttonRow: React.CSSProperties = {
display: 'flex',
flexDirection: 'row',
justifyContent: 'flex-end',
+ borderTop: '1px solid black',
+ paddingTop: 8,
+ paddingBottom: 8,
+ paddingLeft: 16,
+ paddingRight: 16,
};
const input: React.CSSProperties = {
@@ -253,6 +260,7 @@ export const RenderModal: React.FC<{composition: TCompMetadata}> = ({
<ModalContainer onOutsideClick={onQuit} onEscape={onQuit}>
<NewCompHeader title={`Render ${composition.id}`} />
<div style={container}>
+ <Spacing block y={0.5} />
<div style={optionRow}>
<div style={label}>Format</div>
<div style={rightRow}>
@@ -264,27 +272,24 @@ export const RenderModal: React.FC<{composition: TCompMetadata}> = ({
</button>
</div>
</div>
- {imageFormat === 'jpeg' && (
- <>
- <Spacing block y={0.5} />
- <div style={optionRow}>
- <div style={label}>Quality</div>
- <div style={rightRow}>
- <InputDragger
- value={quality}
- onChange={onQualityChanged}
- placeholder="0-100"
- onValueChange={onQualityChangedDirectly}
- name="quality"
- step={1}
- min={MIN_QUALITY}
- max={MAX_QUALITY}
- />
- </div>
+ <div style={optionRow}>
+ <div style={label}>Output name</div>
+ <div style={rightRow}>
+ <div>
+ <RemotionInput
+ // TODO: Validate and reject folders or weird file names
+ warning={existence}
+ style={input}
+ type="text"
+ value={outName}
+ onChange={onValueChange}
+ />
+ {existence ? (
+ <ValidationMessage message="Will be overwritten" />
+ ) : null}
</div>
- </>
- )}
- <Spacing block y={0.5} />
+ </div>
+ </div>
<div style={optionRow}>
<div style={label}>Scale</div>
<div style={rightRow}>
@@ -302,25 +307,24 @@ export const RenderModal: React.FC<{composition: TCompMetadata}> = ({
/>
</div>
</div>
- <Spacing block y={0.5} />
- <div style={optionRow}>
- <div style={label}>Output name</div>
- <div style={rightRow}>
- <div>
- <RemotionInput
- // TODO: Validate and reject folders or weird file names
- warning={existence}
- style={input}
- type="text"
- value={outName}
- onChange={onValueChange}
+ {imageFormat === 'jpeg' && (
+ <div style={optionRow}>
+ <div style={label}>Quality</div>
+ <div style={rightRow}>
+ <InputDragger
+ value={quality}
+ onChange={onQualityChanged}
+ placeholder="0-100"
+ onValueChange={onQualityChangedDirectly}
+ name="quality"
+ step={1}
+ min={MIN_QUALITY}
+ max={MAX_QUALITY}
/>
- {existence ? (
- <ValidationMessage message="Will be overwritten" />
- ) : null}
</div>
</div>
- </div>
+ )}
+
<Spacing block y={0.5} />
<div style={buttonRow}>
<Button onClick={onClick} disabled={state.type === 'load'}>
diff --git a/packages/cli/src/editor/helpers/is-composition-still.ts b/packages/cli/src/editor/helpers/is-composition-still.ts
index 0db32a32f9..94fc4cba0b 100644
--- a/packages/cli/src/editor/helpers/is-composition-still.ts
+++ b/packages/cli/src/editor/helpers/is-composition-still.ts
@@ -1,5 +1,9 @@
import type {TComposition} from 'remotion';
-export const isCompositionStill = (comp: TComposition) => {
+export const isCompositionStill = (comp: TComposition | null) => {
+ if (!comp) {
+ return false;
+ }
+
return comp.durationInFrames === 1;
};