🎥 Make videos programmatically with React
better layout of combobox
Jonny Burger343cfea61d96
diff --git a/packages/cli/src/editor/components/Menu/MenuSubItem.tsx b/packages/cli/src/editor/components/Menu/MenuSubItem.tsxindex 82dd4f1322..67b1f99736 100644--- a/packages/cli/src/editor/components/Menu/MenuSubItem.tsx+++ b/packages/cli/src/editor/components/Menu/MenuSubItem.tsx@@ -5,7 +5,7 @@ import {CLEAR_HOVER, LIGHT_TEXT} from '../../helpers/colors';import {areKeyboardShortcutsDisabled} from '../../helpers/use-keybinding';import {CaretRight} from '../../icons/caret';import {useZIndex} from '../../state/z-index';-import {Flex, Row, Spacing} from '../layout';+import {Row, Spacing} from '../layout';import type {SubMenu} from '../NewComposition/ComboBox';import {MENU_ITEM_CLASSNAME} from './is-menu-item';import {getPortal} from './portals';@@ -27,6 +27,10 @@ export const MENU_SUBMENU_BUTTON_CLASS_NAME = 'remotion-submenu-button';const labelStyle: React.CSSProperties = {fontSize: 13,+ overflow: 'hidden',+ textOverflow: 'ellipsis',+ whiteSpace: 'nowrap',+ flex: 1,};const keyHintCss: React.CSSProperties = {@@ -145,7 +149,12 @@ export const MenuSubItem: React.FC<{<Spacing x={1} /></>) : null}- <div style={labelStyle}>{label}</div> <Flex />+ <div+ style={labelStyle}+ {...{title: typeof label === 'string' ? label : undefined}}+ >+ {label}+ </div>{' '}<Spacing x={2} />{subMenu ? <CaretRight /> : null}{keyHint && !areKeyboardShortcutsDisabled() ? (diff --git a/packages/cli/src/editor/components/Menu/styles.ts b/packages/cli/src/editor/components/Menu/styles.tsindex c2b9fa96d5..aae8ecdc58 100644--- a/packages/cli/src/editor/components/Menu/styles.ts+++ b/packages/cli/src/editor/components/Menu/styles.ts@@ -4,14 +4,13 @@ import {BACKGROUND} from '../../helpers/colors';export const MENU_VERTICAL_PADDING = 4;export const SUBMENU_LEFT_INSET = -8;+export const MAX_MENU_WIDTH = 400;+const menuContainer: React.CSSProperties = {backgroundColor: BACKGROUND,position: 'fixed',color: 'white',userSelect: 'none',- minWidth: 200,- maxHeight: 400,- overflow: 'auto',};export const SHADOW_TOWARDS_BOTTOM = '0 2px 8px rgba(0, 0, 0, 0.5)';diff --git a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx b/packages/cli/src/editor/components/NewComposition/ComboBox.tsxindex ba74707427..d4bc7418a6 100644--- a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx+++ b/packages/cli/src/editor/components/NewComposition/ComboBox.tsx@@ -14,6 +14,7 @@ import {Flex, Spacing} from '../layout';import {isMenuItem, MENU_INITIATOR_CLASSNAME} from '../Menu/is-menu-item';import {getPortal} from '../Menu/portals';import {+ MAX_MENU_WIDTH,menuContainerTowardsBottom,menuContainerTowardsTop,outerPortal,@@ -146,9 +147,8 @@ export const Combobox: React.FC<{};}, [refresh]);- // TODO: Limit width- // TODO: Align to left if more space on the right// TODO: Scroll to current value if there are a lot of values+ // TODO: If long value is selected, layout breaksconst portalStyle = useMemo((): React.CSSProperties | null => {if (!opened || !size) {@@ -158,10 +158,16 @@ export const Combobox: React.FC<{const spaceToBottom = size.windowSize.height - (size.top + size.height);const spaceToTop = size.top;- const layout = spaceToTop > spaceToBottom ? 'bottom' : 'top';+ const spaceToRight = size.windowSize.width - (size.left + size.width);++ const minSpaceToRightRequired = MAX_MENU_WIDTH;++ const verticalLayout = spaceToTop > spaceToBottom ? 'bottom' : 'top';+ const horizontalLayout =+ spaceToRight >= minSpaceToRightRequired ? 'left' : 'right';return {- ...(layout === 'top'+ ...(verticalLayout === 'top'? {...menuContainerTowardsBottom,top: size.top + size.height,@@ -170,7 +176,13 @@ export const Combobox: React.FC<{...menuContainerTowardsTop,bottom: size.windowSize.height - size.top,}),- left: size.left,+ ...(horizontalLayout === 'left'+ ? {+ left: size.left,+ }+ : {+ right: size.windowSize.width - size.left - size.width,+ }),};}, [opened, size]);diff --git a/packages/cli/src/editor/components/NewComposition/MenuContent.tsx b/packages/cli/src/editor/components/NewComposition/MenuContent.tsxindex 4234aef63a..f8a4000ba1 100644--- a/packages/cli/src/editor/components/NewComposition/MenuContent.tsx+++ b/packages/cli/src/editor/components/NewComposition/MenuContent.tsx@@ -2,11 +2,12 @@ import type {SetStateAction} from 'react';import React, {useCallback, useEffect, useRef, useState} from 'react';import {INPUT_BORDER_COLOR_UNHOVERED} from '../../helpers/colors';import {useKeybinding} from '../../helpers/use-keybinding';+import {VERTICAL_SCROLLBAR_CLASSNAME} from '../Menu/is-menu-item';import {MenuDivider} from '../Menu/MenuDivider';import type {MenuId} from '../Menu/MenuItem';import type {SubMenuActivated} from '../Menu/MenuSubItem';import {MenuSubItem} from '../Menu/MenuSubItem';-import {MENU_VERTICAL_PADDING} from '../Menu/styles';+import {MAX_MENU_WIDTH, MENU_VERTICAL_PADDING} from '../Menu/styles';import type {ComboboxValue} from './ComboBox';const BORDER_SIZE = 1;@@ -15,6 +16,11 @@ const container: React.CSSProperties = {paddingBottom: MENU_VERTICAL_PADDING,border: `${BORDER_SIZE}px solid ${INPUT_BORDER_COLOR_UNHOVERED}`,marginLeft: 0 - BORDER_SIZE,+ overflowY: 'auto',+ overflowX: 'hidden',+ minWidth: 200,+ maxWidth: MAX_MENU_WIDTH,+ maxHeight: 600,};export const MenuContent: React.FC<{@@ -270,7 +276,11 @@ export const MenuContent: React.FC<{}, [onHide, subMenuActivated]);return (- <div ref={containerRef} style={container}>+ <div+ ref={containerRef}+ style={container}+ className={VERTICAL_SCROLLBAR_CLASSNAME}+ >{values.map((item) => {if (item.type === 'divider') {return <MenuDivider key={item.id} />;diff --git a/packages/cli/src/editor/components/layout.tsx b/packages/cli/src/editor/components/layout.tsxindex 0ebb670981..ab1bfe7145 100644--- a/packages/cli/src/editor/components/layout.tsx+++ b/packages/cli/src/editor/components/layout.tsx@@ -19,19 +19,20 @@ export const Spacing: React.FC<{return <div style={style} />;};-const flex: React.CSSProperties = {flex: 1};+const flexCss: React.CSSProperties = {flex: 1};export const Flex: React.FC<{children?: React.ReactNode;-}> = ({children}) => <div style={flex}>{children}</div>;+}> = ({children}) => <div style={flexCss}>{children}</div>;export const Row: React.FC<{justify?: 'center' | 'flex-start' | 'flex-end';align?: 'center';style?: React.CSSProperties;+ flex?: number;className?: string;children: React.ReactNode;-}> = ({children, justify, className, align, style = {}}) => {+}> = ({children, justify, className, align, flex, style = {}}) => {const finalStyle: React.CSSProperties = useMemo(() => {return {...style,@@ -39,8 +40,9 @@ export const Row: React.FC<{flexDirection: 'row',justifyContent: justify ?? 'flex-start',alignItems: align ?? 'flex-start',+ flex: flex ?? undefined,};- }, [align, justify, style]);+ }, [align, flex, justify, style]);return (<div className={className} style={finalStyle}>{children}diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex 8dad529fad..2566932e1c 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -764,7 +764,7 @@ export const Index: React.FC = () => {values: 'a' as const,supersuperlongvalueabcdefghji: 'hi' as const,incompatible: null,- longEnum: 'a' as const,+ longEnum: 'k' as const,}}durationInFrames={150}/>