Skip to content

🎥 Make videos programmatically with React

Button working

Patric Salvisbergac708ad41740
diff --git a/packages/cli/src/editor/components/MenuBuildIndicator.tsx b/packages/cli/src/editor/components/MenuBuildIndicator.tsx
index 16deb2c017..b6e9f9e2dd 100644
--- a/packages/cli/src/editor/components/MenuBuildIndicator.tsx
+++ b/packages/cli/src/editor/components/MenuBuildIndicator.tsx
@@ -1,8 +1,12 @@
import React, {useEffect, useState} from 'react';
+import {Spacing} from './layout';
+import {OpenEditorButton} from './OpenEditorButton';
const cwd: React.CSSProperties = {
fontSize: 13,
opacity: 0.8,
+ display: 'flex',
+ alignItems: 'center',
};
export const MenuBuildIndicator: React.FC = () => {
@@ -25,7 +29,9 @@ export const MenuBuildIndicator: React.FC = () => {
return (
<div style={cwd} title={window.remotion_cwd}>
+ <Spacing x={5} />
{isBuilding ? 'Building...' : window.remotion_projectName}
+ <OpenEditorButton />
</div>
);
};
diff --git a/packages/cli/src/editor/components/MenuToolbar.tsx b/packages/cli/src/editor/components/MenuToolbar.tsx
index cd498d84bf..06cbba4421 100644
--- a/packages/cli/src/editor/components/MenuToolbar.tsx
+++ b/packages/cli/src/editor/components/MenuToolbar.tsx
@@ -118,7 +118,6 @@ export const MenuToolbar: React.FC = () => {
})}
<UpdateCheck />
</div>
-
<div style={flex} />
<MenuBuildIndicator />
<div style={flex} />
diff --git a/packages/cli/src/editor/components/OpenEditorButton.tsx b/packages/cli/src/editor/components/OpenEditorButton.tsx
new file mode 100644
index 0000000000..d684e9108d
--- /dev/null
+++ b/packages/cli/src/editor/components/OpenEditorButton.tsx
@@ -0,0 +1,76 @@
+import {useCallback, useMemo, useState} from 'react';
+import {LIGHT_TEXT} from '../helpers/colors';
+import {openInEditor} from '../helpers/open-in-editor';
+import {sendErrorNotification} from './Notifications/NotificationCenter';
+
+const svgStyle: React.CSSProperties = {
+ width: '11px',
+ height: '11px',
+};
+
+const buttonStyle: React.CSSProperties = {
+ border: 'none',
+ width: '25px',
+ height: '25px',
+};
+export const OpenEditorButton: React.FC<{}> = () => {
+ const [hovered, setHovered] = useState<boolean>(false);
+
+ const svgFillColor = useMemo(() => {
+ return hovered ? 'white' : LIGHT_TEXT;
+ }, [hovered]);
+
+ const handleClick = async () => {
+ await openInEditor({
+ originalFileName: `${window.remotion_cwd}`,
+ originalLineNumber: 1,
+ originalColumnNumber: 1,
+ originalFunctionName: null,
+ originalScriptCode: null,
+ })
+ .then((res) => res.json())
+ .then(({success}) => {
+ if (!success) {
+ sendErrorNotification(`Could not open ${window.remotion_editorName}`);
+ }
+ })
+ .catch((err) => {
+ console.error(err);
+ sendErrorNotification(`Could not open ${window.remotion_editorName}`);
+ });
+ };
+
+ const buttonTooltip = `Open in ${window.remotion_editorName}`;
+ const openInEditorSvg = (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 512 512"
+ style={svgStyle}
+ >
+ <path
+ fill={svgFillColor}
+ d="M320 0c-17.7 0-32 14.3-32 32s14.3 32 32 32h82.7L201.4 265.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L448 109.3V192c0 17.7 14.3 32 32 32s32-14.3 32-32V32c0-17.7-14.3-32-32-32H320zM80 32C35.8 32 0 67.8 0 112V432c0 44.2 35.8 80 80 80H400c44.2 0 80-35.8 80-80V320c0-17.7-14.3-32-32-32s-32 14.3-32 32V432c0 8.8-7.2 16-16 16H80c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16H192c17.7 0 32-14.3 32-32s-14.3-32-32-32H80z"
+ />
+ </svg>
+ );
+ const onPointerEnter = useCallback(() => {
+ setHovered(true);
+ }, []);
+
+ const onPointerLeave = useCallback(() => {
+ setHovered(false);
+ }, []);
+
+ return (
+ <button
+ title={buttonTooltip}
+ type="button"
+ onPointerEnter={onPointerEnter}
+ onPointerLeave={onPointerLeave}
+ style={buttonStyle}
+ onClick={handleClick}
+ >
+ {openInEditorSvg}
+ </button>
+ );
+};
diff --git a/packages/cli/src/editor/components/RenderModal/CliCopyButton.tsx b/packages/cli/src/editor/components/RenderModal/CliCopyButton.tsx
index c70af78fae..9f83f9346d 100644
--- a/packages/cli/src/editor/components/RenderModal/CliCopyButton.tsx
+++ b/packages/cli/src/editor/components/RenderModal/CliCopyButton.tsx
@@ -15,6 +15,13 @@ const copiedStyle: React.CSSProperties = {
justifyContent: 'center',
};
+const buttonStyle: React.CSSProperties = {
+ width: '30px',
+ height: '30px',
+ border: 'none',
+ cursor: 'pointer',
+};
+
export const CliCopyButton: React.FC<{valueToCopy: string}> = ({
valueToCopy,
}) => {
@@ -86,12 +93,7 @@ export const CliCopyButton: React.FC<{valueToCopy: string}> = ({
type="button"
onPointerEnter={onPointerEnter}
onPointerLeave={onPointerLeave}
- style={{
- width: '30px',
- height: '30px',
- border: 'none',
- cursor: 'pointer',
- }}
+ style={buttonStyle}
onClick={() => {
navigator.clipboard.writeText(valueToCopy);
setCopied(true);