Skip to content

🎥 Make videos programmatically with React

info bubble

Jonny Burger48cab4cf3838
diff --git a/packages/cli/src/editor/components/Menu/styles.ts b/packages/cli/src/editor/components/Menu/styles.ts
index c8469e8854..e9eb55cffc 100644
--- a/packages/cli/src/editor/components/Menu/styles.ts
+++ b/packages/cli/src/editor/components/Menu/styles.ts
@@ -12,14 +12,17 @@ const menuContainer: React.CSSProperties = {
minWidth: 200,
};
+export const SHADOW_TOWARDS_BOTTOM = '0 2px 8px rgba(0, 0, 0, 0.5)';
+export const SHADOW_TOWARDS_TOP = '0 -2px 8px rgba(0, 0, 0, 0.5)';
+
export const menuContainerTowardsBottom: React.CSSProperties = {
...menuContainer,
- boxShadow: '0 2px 8px rgba(0, 0, 0, 0.5)',
+ boxShadow: SHADOW_TOWARDS_BOTTOM,
};
export const menuContainerTowardsTop: React.CSSProperties = {
...menuContainer,
- boxShadow: '0 -2px 8px rgba(0, 0, 0, 0.5)',
+ boxShadow: SHADOW_TOWARDS_TOP,
};
export const outerPortal: React.CSSProperties = {
diff --git a/packages/cli/src/editor/components/RenderModal/InfoBubble.tsx b/packages/cli/src/editor/components/RenderModal/InfoBubble.tsx
new file mode 100644
index 0000000000..c92e44b391
--- /dev/null
+++ b/packages/cli/src/editor/components/RenderModal/InfoBubble.tsx
@@ -0,0 +1,152 @@
+import {PlayerInternals} from '@remotion/player';
+import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
+import ReactDOM from 'react-dom';
+import {LIGHT_TEXT} from '../../helpers/colors';
+import {HigherZIndex, useZIndex} from '../../state/z-index';
+import {getPortal} from '../Menu/portals';
+import {outerPortal} from '../Menu/styles';
+import {InfoTooltip} from './InfoTooltip';
+
+const icon: React.CSSProperties = {
+ color: LIGHT_TEXT,
+ height: 15,
+};
+
+const container: React.CSSProperties = {
+ display: 'inline-block',
+ border: 'none',
+ fontSize: 14,
+ verticalAlign: 'text-bottom',
+};
+
+export const InfoBubble: React.FC<{
+ title: string;
+ children: React.ReactNode;
+}> = ({title, children}) => {
+ const [hovered, setIsHovered] = useState(false);
+ const [opened, setOpened] = useState(false);
+ const ref = useRef<HTMLButtonElement>(null);
+ const {tabIndex, currentZIndex} = useZIndex();
+ const size = PlayerInternals.useElementSize(ref, {
+ triggerOnWindowResize: true,
+ shouldApplyCssTransforms: true,
+ });
+
+ const refresh = size?.refresh;
+
+ const onHide = useCallback(() => {
+ setOpened(false);
+ }, []);
+
+ useEffect(() => {
+ const {current} = ref;
+ if (!current) {
+ return;
+ }
+
+ const onMouseEnter = () => setIsHovered(true);
+ const onMouseLeave = () => setIsHovered(false);
+ const onPointerDown = (e: MouseEvent) => {
+ e.stopPropagation();
+ return setOpened((o) => {
+ if (!o) {
+ refresh?.();
+ }
+
+ return !o;
+ });
+ };
+
+ const onClick = (e: MouseEvent | PointerEvent) => {
+ e.stopPropagation();
+ const isKeyboardInitiated = e.detail === 0;
+ if (!isKeyboardInitiated) {
+ return;
+ }
+
+ return setOpened((o) => {
+ return !o;
+ });
+ };
+
+ current.addEventListener('mouseenter', onMouseEnter);
+ current.addEventListener('mouseleave', onMouseLeave);
+ current.addEventListener('pointerdown', onPointerDown);
+ current.addEventListener('click', onClick);
+
+ return () => {
+ current.removeEventListener('mouseenter', onMouseEnter);
+ current.removeEventListener('mouseleave', onMouseLeave);
+ current.removeEventListener('pointerdown', onPointerDown);
+ current.removeEventListener('click', onClick);
+ };
+ }, [refresh]);
+
+ const portalStyle = useMemo((): React.CSSProperties | null => {
+ if (!opened || !size) {
+ return null;
+ }
+
+ const spaceToBottom = size.windowSize.height - (size.top + size.height);
+ const spaceToTop = size.top;
+
+ const layout = spaceToTop > spaceToBottom ? 'bottom' : 'top';
+
+ return {
+ ...(layout === 'top'
+ ? {
+ position: 'fixed',
+ top: size.top + size.height,
+ }
+ : {
+ position: 'fixed',
+ bottom: size.windowSize.height - size.top,
+ }),
+ left: size.left,
+ };
+ }, [opened, size]);
+
+ const style = useMemo((): React.CSSProperties => {
+ return {
+ ...container,
+ userSelect: 'none',
+ color: 'white',
+ display: 'inline-flex',
+ flexDirection: 'row',
+ alignItems: 'center',
+ };
+ }, []);
+
+ // TODO: Can click two info bubbles at the same time
+
+ return (
+ <>
+ <button
+ ref={ref}
+ tabIndex={tabIndex}
+ style={style}
+ title={title}
+ type="button"
+ >
+ <svg style={icon} viewBox="0 0 512 512">
+ <path
+ fill={hovered ? 'white' : LIGHT_TEXT}
+ d="M256 48a208 208 0 1 1 0 416 208 208 0 1 1 0-416zm0 464A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336c-13.3 0-24 10.7-24 24s10.7 24 24 24h80c13.3 0 24-10.7 24-24s-10.7-24-24-24h-8V248c0-13.3-10.7-24-24-24H216c-13.3 0-24 10.7-24 24s10.7 24 24 24h24v64H216zm40-144a32 32 0 1 0 0-64 32 32 0 1 0 0 64z"
+ />
+ </svg>
+ </button>
+ {portalStyle
+ ? ReactDOM.createPortal(
+ <div style={outerPortal} className="css-reset">
+ <HigherZIndex onOutsideClick={onHide} onEscape={onHide}>
+ <div style={portalStyle}>
+ <InfoTooltip>{children}</InfoTooltip>
+ </div>
+ </HigherZIndex>
+ </div>,
+ getPortal(currentZIndex)
+ )
+ : null}
+ </>
+ );
+};
diff --git a/packages/cli/src/editor/components/RenderModal/InfoTooltip.tsx b/packages/cli/src/editor/components/RenderModal/InfoTooltip.tsx
new file mode 100644
index 0000000000..cba9ade9fe
--- /dev/null
+++ b/packages/cli/src/editor/components/RenderModal/InfoTooltip.tsx
@@ -0,0 +1,43 @@
+import React from 'react';
+import {BACKGROUND, BORDER_COLOR} from '../../helpers/colors';
+import {SHADOW_TOWARDS_TOP} from '../Menu/styles';
+
+const container: React.CSSProperties = {
+ padding: '10px 12px',
+ // TODO: Depending on direction
+ boxShadow: SHADOW_TOWARDS_TOP,
+ background: BACKGROUND,
+ color: 'white',
+ border: '0.5px solid ' + BORDER_COLOR,
+ maxHeight: 200,
+ overflow: 'auto',
+};
+
+const arrow: React.CSSProperties = {
+ height: 7,
+ display: 'block',
+ overflow: 'visible',
+ marginTop: -0.5,
+ marginLeft: 7,
+};
+
+export const InfoTooltip: React.FC<{
+ children: React.ReactNode;
+}> = ({children}) => {
+ return (
+ // TODO: Down arrow
+ // TODO: not scrolling with portal
+ <>
+ <div style={container}>{children}</div>
+ <svg viewBox="0 0 14 7" style={arrow}>
+ <path
+ d={`M 14 0 L 7 7 L 0 0`}
+ fill={BACKGROUND}
+ strokeLinecap="butt"
+ stroke={BORDER_COLOR}
+ strokeWidth={0.5}
+ />
+ </svg>
+ </>
+ );
+};
diff --git a/packages/cli/src/editor/components/RenderModal/NumberSetting.tsx b/packages/cli/src/editor/components/RenderModal/NumberSetting.tsx
index dbcf754b4d..b377b0a9b5 100644
--- a/packages/cli/src/editor/components/RenderModal/NumberSetting.tsx
+++ b/packages/cli/src/editor/components/RenderModal/NumberSetting.tsx
@@ -1,7 +1,11 @@
+import {BrowserSafeApis} from '@remotion/renderer/client';
import React, {useCallback} from 'react';
+import {Spacing} from '../layout';
import {InputDragger} from '../NewComposition/InputDragger';
import {RightAlignInput} from '../NewComposition/RemInput';
+import {InfoBubble} from './InfoBubble';
import {label, optionRow, rightRow} from './layout';
+import {OptionExplainer} from './OptionExplainer';
export const NumberSetting: React.FC<{
name: string;
@@ -33,9 +37,15 @@ export const NumberSetting: React.FC<{
[onValueChanged]
);
+ // TODO: Scale option hardcoded, should be passed in
return (
<div style={optionRow}>
- <div style={label}>{name}</div>
+ <div style={label}>
+ {name} <Spacing x={0.25} />{' '}
+ <InfoBubble title="Learn more about this option">
+ <OptionExplainer option={BrowserSafeApis.options.scaleOption} />
+ </InfoBubble>
+ </div>
<div style={rightRow}>
<RightAlignInput>
<InputDragger
diff --git a/packages/cli/src/editor/components/RenderModal/OptionExplainer.tsx b/packages/cli/src/editor/components/RenderModal/OptionExplainer.tsx
new file mode 100644
index 0000000000..60f983a101
--- /dev/null
+++ b/packages/cli/src/editor/components/RenderModal/OptionExplainer.tsx
@@ -0,0 +1,34 @@
+import type {RemotionOption} from '@remotion/renderer';
+import {Spacing} from '../layout';
+import {MenuDivider} from '../Menu/MenuDivider';
+
+const container: React.CSSProperties = {
+ fontSize: 14,
+};
+
+const title: React.CSSProperties = {
+ fontSize: 14,
+};
+
+const description: React.CSSProperties = {
+ fontSize: 14,
+ maxWidth: 200,
+};
+
+// TODO: No style of <code>
+export const OptionExplainer: React.FC<{
+ option: RemotionOption;
+}> = ({option}) => {
+ return (
+ <div style={container}>
+ <div>
+ <strong style={title}>{option.name}</strong>
+ </div>
+ <div style={description}>{option.description}</div>
+ <Spacing block y={0.5} />
+ <MenuDivider />
+ <div style={description}>CLI flag: {option.cliFlag}</div>
+ <div style={description}>Node.JS option: {option.ssrName}</div>
+ </div>
+ );
+};
diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.ts
index 358a078c65..7e728f45fc 100644
--- a/packages/renderer/src/index.ts
+++ b/packages/renderer/src/index.ts
@@ -91,6 +91,7 @@ export type {LogLevel} from './log-level';
export {CancelSignal, makeCancelSignal} from './make-cancel-signal';
export {openBrowser} from './open-browser';
export type {ChromiumOptions} from './open-browser';
+export {RemotionOption} from './options/option';
export {PixelFormat} from './pixel-format';
export {ProResProfile} from './prores-profile';
export {renderFrames} from './render-frames';
@@ -107,7 +108,6 @@ export {SymbolicatedStackFrame} from './symbolicate-stacktrace';
export {OnStartData, RenderFramesOutput} from './types';
export {OpenGlRenderer} from './validate-opengl-renderer';
export {validateOutputFilename} from './validate-output-filename';
-
export const RenderInternals = {
ensureLocalBrowser,
getActualConcurrency,
diff --git a/packages/renderer/src/options/scale.tsx b/packages/renderer/src/options/scale.tsx
index 89363f56f0..4895234084 100644
--- a/packages/renderer/src/options/scale.tsx
+++ b/packages/renderer/src/options/scale.tsx
@@ -1,7 +1,7 @@
import type {RemotionOption} from './option';
export const scaleOption: RemotionOption = {
- name: 'scale',
+ name: 'Scale',
cliFlag: '--scale',
description: (
<>