Skip to content

🎥 Make videos programmatically with React

lock icon

Jonny Burgerb1faa1de02ba
diff --git a/packages/cli/src/editor/components/NewComposition/NewCompAspectRatio.tsx b/packages/cli/src/editor/components/NewComposition/NewCompAspectRatio.tsx
index 652b0f5e75..5f539d73e1 100644
--- a/packages/cli/src/editor/components/NewComposition/NewCompAspectRatio.tsx
+++ b/packages/cli/src/editor/components/NewComposition/NewCompAspectRatio.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import {rightLabel} from './new-comp-layout';
import {aspectRatio} from './render-aspect-ratio';
+import {ToggleAspectRatio} from './ToggleAspectRatio';
const GUIDE_HEIGHT = 55;
const GUIDE_WIDTH = 10;
@@ -8,7 +9,9 @@ const GUIDE_WIDTH = 10;
export const NewCompAspectRatio: React.FC<{
width: number;
height: number;
-}> = ({width, height}) => {
+ aspectRatioLocked: boolean;
+ setAspectRatioLocked: React.Dispatch<React.SetStateAction<boolean>>;
+}> = ({width, height, aspectRatioLocked, setAspectRatioLocked}) => {
return (
<div>
<div
@@ -27,6 +30,10 @@ export const NewCompAspectRatio: React.FC<{
stroke="rgba(255, 255, 255, 0.2)"
/>
</svg>
+ <ToggleAspectRatio
+ aspectRatioLocked={aspectRatioLocked}
+ setAspectRatioLocked={setAspectRatioLocked}
+ />
<div style={rightLabel}>
Aspect ratio {aspectRatio(Number(width), Number(height))}
</div>
diff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
index c102372746..2250288f30 100644
--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
@@ -62,6 +62,7 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({
const [width, setWidth] = useState('1280');
const [height, setHeight] = useState('720');
const [durationInFrames, setDurationInFrames] = useState('150');
+ const [aspectRatioLocked, setAspectRatioLocked] = useState(false);
const {setSelectedModal} = useContext(ModalsContext);
const onQuit = useCallback(() => {
@@ -208,6 +209,8 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({
<NewCompAspectRatio
width={Number(width)}
height={Number(height)}
+ aspectRatioLocked={aspectRatioLocked}
+ setAspectRatioLocked={setAspectRatioLocked}
/>
</div>
</div>
diff --git a/packages/cli/src/editor/components/NewComposition/ToggleAspectRatio.tsx b/packages/cli/src/editor/components/NewComposition/ToggleAspectRatio.tsx
new file mode 100644
index 0000000000..008fc5e278
--- /dev/null
+++ b/packages/cli/src/editor/components/NewComposition/ToggleAspectRatio.tsx
@@ -0,0 +1,32 @@
+import React, {MouseEventHandler, useCallback} from 'react';
+import {BACKGROUND} from '../../helpers/colors';
+import {LockIcon, UnlockIcon} from '../../icons/lock';
+
+const buttonStyle: React.CSSProperties = {
+ backgroundColor: BACKGROUND,
+ border: 'none',
+ position: 'absolute',
+};
+
+const iconStyle: React.CSSProperties = {
+ width: 14,
+ color: 'white',
+};
+
+export const ToggleAspectRatio: React.FC<{
+ aspectRatioLocked: boolean;
+ setAspectRatioLocked: React.Dispatch<React.SetStateAction<boolean>>;
+}> = ({aspectRatioLocked, setAspectRatioLocked}) => {
+ const onClick: MouseEventHandler = useCallback(() => {
+ setAspectRatioLocked((a) => !a);
+ }, [setAspectRatioLocked]);
+ return (
+ <button type="button" onClick={onClick} style={buttonStyle}>
+ {aspectRatioLocked ? (
+ <LockIcon style={iconStyle} />
+ ) : (
+ <UnlockIcon style={iconStyle} />
+ )}
+ </button>
+ );
+};
diff --git a/packages/cli/src/editor/icons/lock.tsx b/packages/cli/src/editor/icons/lock.tsx
new file mode 100644
index 0000000000..17bd264f76
--- /dev/null
+++ b/packages/cli/src/editor/icons/lock.tsx
@@ -0,0 +1,23 @@
+import React, {SVGProps} from 'react';
+
+export const LockIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg viewBox="0 0 448 512" {...props}>
+ <path
+ fill="currentColor"
+ d="M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"
+ />
+ </svg>
+ );
+};
+
+export const UnlockIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg viewBox="0 0 448 512" {...props}>
+ <path
+ fill="currentColor"
+ d="M400 256H152V152.9c0-39.6 31.7-72.5 71.3-72.9 40-.4 72.7 32.1 72.7 72v16c0 13.3 10.7 24 24 24h32c13.3 0 24-10.7 24-24v-16C376 68 307.5-.3 223.5 0 139.5.3 72 69.5 72 153.5V256H48c-26.5 0-48 21.5-48 48v160c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V304c0-26.5-21.5-48-48-48z"
+ />
+ </svg>
+ );
+};
diff --git a/packages/cli/src/editor/state/z-index.tsx b/packages/cli/src/editor/state/z-index.tsx
index 2a9989c9e0..f85a32e104 100644
--- a/packages/cli/src/editor/state/z-index.tsx
+++ b/packages/cli/src/editor/state/z-index.tsx
@@ -58,7 +58,9 @@ export const HigherZIndex: React.FC<{
if (
outsideClick &&
highestContext.highestIndex === currentIndex &&
- !getClickLock()
+ !getClickLock() &&
+ // Don't trigger if that click removed that node
+ document.contains(e.target as Node)
) {
e.stopPropagation();
onOutsideClick();