Skip to content

🎥 Make videos programmatically with React

more ui elements

Jonny Burger319e681ee067
diff --git a/packages/cli/src/editor/components/NewComposition/CancelButton.tsx b/packages/cli/src/editor/components/NewComposition/CancelButton.tsx
index 1d23957f2d..cd883370b2 100644
--- a/packages/cli/src/editor/components/NewComposition/CancelButton.tsx
+++ b/packages/cli/src/editor/components/NewComposition/CancelButton.tsx
@@ -1,10 +1,24 @@
import React, {SVGProps} from 'react';
-export const CancelButton: React.FC<SVGProps<SVGSVGElement>> = (props) => (
- <svg viewBox="0 0 320 512" {...props}>
- <path
- fill="currentColor"
- d="M207.6 256l107.72-107.72c6.23-6.23 6.23-16.34 0-22.58l-25.03-25.03c-6.23-6.23-16.34-6.23-22.58 0L160 208.4 52.28 100.68c-6.23-6.23-16.34-6.23-22.58 0L4.68 125.7c-6.23 6.23-6.23 16.34 0 22.58L112.4 256 4.68 363.72c-6.23 6.23-6.23 16.34 0 22.58l25.03 25.03c6.23 6.23 16.34 6.23 22.58 0L160 303.6l107.72 107.72c6.23 6.23 16.34 6.23 22.58 0l25.03-25.03c6.23-6.23 6.23-16.34 0-22.58L207.6 256z"
- />
- </svg>
+const style: React.CSSProperties = {
+ appearance: 'none',
+ border: 'none',
+ backgroundColor: 'transparent',
+ color: 'white',
+ cursor: 'pointer',
+};
+
+export const CancelButton: React.FC<
+ SVGProps<SVGSVGElement> & {
+ onPress: () => void;
+ }
+> = ({onPress, ...props}) => (
+ <button style={style} type="button" onClick={onPress}>
+ <svg viewBox="0 0 320 512" {...props}>
+ <path
+ fill="currentColor"
+ d="M207.6 256l107.72-107.72c6.23-6.23 6.23-16.34 0-22.58l-25.03-25.03c-6.23-6.23-16.34-6.23-22.58 0L160 208.4 52.28 100.68c-6.23-6.23-16.34-6.23-22.58 0L4.68 125.7c-6.23 6.23-6.23 16.34 0 22.58L112.4 256 4.68 363.72c-6.23 6.23-6.23 16.34 0 22.58l25.03 25.03c6.23 6.23 16.34 6.23 22.58 0L160 303.6l107.72 107.72c6.23 6.23 16.34 6.23 22.58 0l25.03-25.03c6.23-6.23 6.23-16.34 0-22.58L207.6 256z"
+ />
+ </svg>
+ </button>
);
diff --git a/packages/cli/src/editor/components/NewComposition/CompositionType.tsx b/packages/cli/src/editor/components/NewComposition/CompositionType.tsx
index d7a55d1740..83e1cffddb 100644
--- a/packages/cli/src/editor/components/NewComposition/CompositionType.tsx
+++ b/packages/cli/src/editor/components/NewComposition/CompositionType.tsx
@@ -2,12 +2,7 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {getBackgroundFromHoverState} from '../../helpers/colors';
import {FilmIcon} from '../../icons/film';
import {StillIcon} from '../../icons/still';
-import {Spacing} from '../Spacing';
-
-const row: React.CSSProperties = {
- display: 'flex',
- flexDirection: 'row',
-};
+import {Row, Spacing} from '../layout';
const panel: React.CSSProperties = {
flex: 1,
@@ -78,13 +73,13 @@ export const CompositionType: React.FC<{
onSelected: (type: CompType) => void;
}> = ({onSelected, type}) => {
return (
- <div style={row}>
+ <Row>
<Panel
onSelected={onSelected}
type="composition"
selected={type === 'composition'}
/>
<Panel onSelected={onSelected} type="still" selected={type === 'still'} />
- </div>
+ </Row>
);
};
diff --git a/packages/cli/src/editor/components/NewComposition/NewCompHeader.tsx b/packages/cli/src/editor/components/NewComposition/NewCompHeader.tsx
index e7ef428f0a..38c637583a 100644
--- a/packages/cli/src/editor/components/NewComposition/NewCompHeader.tsx
+++ b/packages/cli/src/editor/components/NewComposition/NewCompHeader.tsx
@@ -1,21 +1,32 @@
-import React from 'react';
+import React, {useCallback, useContext} from 'react';
+import {ModalsContext} from '../../state/modals';
+import {Flex} from '../layout';
import {CancelButton} from './CancelButton';
const container: React.CSSProperties = {
display: 'flex',
flexDirection: 'row',
+ alignItems: 'center',
padding: 12,
- textAlign: 'center',
width: '100%',
borderBottom: '1px solid black',
};
+const icon: React.CSSProperties = {
+ height: 20,
+ width: 20,
+};
+
export const NewCompHeader: React.FC = () => {
+ const {setSelectedModal} = useContext(ModalsContext);
+ const onPress = useCallback(() => {
+ setSelectedModal(null);
+ }, [setSelectedModal]);
return (
<div style={container}>
<div>New composition</div>
- <div style={{flex: 1}} />
- <CancelButton style={{height: 20, width: 20}} />
+ <Flex />
+ <CancelButton style={icon} onPress={onPress} />
</div>
);
};
diff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
index 732d8b9010..9717a9b5d5 100644
--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
@@ -1,7 +1,15 @@
-import React, {ChangeEventHandler, useCallback, useMemo, useState} from 'react';
+import React, {
+ ChangeEventHandler,
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useState,
+} from 'react';
import {BACKGROUND} from '../../helpers/colors';
import {FONT_FAMILY} from '../../helpers/font';
-import {Spacing} from '../Spacing';
+import {ModalsContext} from '../../state/modals';
+import {Spacing} from '../layout';
import {Combobox, ComboboxValue} from './ComboBox';
import {CompositionType, CompType} from './CompositionType';
import {leftLabel} from './new-comp-layout';
@@ -63,6 +71,7 @@ export const NewComposition: React.FC = () => {
const [width, setWidth] = useState('1280');
const [height, setHeight] = useState('720');
const [durationInFrames, setDurationInFrames] = useState('150');
+ const {setSelectedModal} = useContext(ModalsContext);
const onTypeChanged = useCallback((newType: CompType) => {
setType(newType);
@@ -105,6 +114,19 @@ export const NewComposition: React.FC = () => {
);
}, [onFpsChange]);
+ useEffect(() => {
+ const onKeyPress = (e: KeyboardEvent) => {
+ if (e.key === 'Escape') {
+ setSelectedModal(null);
+ }
+ };
+
+ window.addEventListener('keyup', onKeyPress);
+ return () => {
+ window.removeEventListener('keyup', onKeyPress);
+ };
+ }, [setSelectedModal]);
+
return (
<div style={backgroundOverlay}>
<div style={panel}>
diff --git a/packages/cli/src/editor/components/Spacing.tsx b/packages/cli/src/editor/components/layout.tsx
similarity index 57%
rename from packages/cli/src/editor/components/Spacing.tsx
rename to packages/cli/src/editor/components/layout.tsx
index 73ba32869d..b0f44b5b9a 100644
--- a/packages/cli/src/editor/components/Spacing.tsx
+++ b/packages/cli/src/editor/components/layout.tsx
@@ -16,3 +16,14 @@ export const Spacing: React.FC<{
return <div style={style} />;
};
+
+const flex: React.CSSProperties = {flex: 1};
+
+export const Flex = () => <div style={flex} />;
+
+const row: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'row',
+};
+
+export const Row: React.FC = ({children}) => <div style={row}>{children}</div>;