🎥 Make videos programmatically with React
Add previews to the Studio effect picker
JonnyBurger28dcbc6d2780
diff --git a/packages/studio/src/components/EffectPickerModal.tsx b/packages/studio/src/components/EffectPickerModal.tsxindex 3890ca09b8..f6aad61e1b 100644--- a/packages/studio/src/components/EffectPickerModal.tsx+++ b/packages/studio/src/components/EffectPickerModal.tsx@@ -1,6 +1,8 @@import {EFFECT_CATALOG,getEffectDocumentationLink,+ getEffectPreviewAlt,+ getEffectPreviewSource,type EffectCatalogItem,} from '@remotion/studio-shared';import React, {@@ -18,7 +20,6 @@ import {WHITE_ALPHA_06,} from '../helpers/colors';import {useKeybinding} from '../helpers/use-keybinding';-import {EffectsIcon} from '../icons/effects';import {ExternalLinkIcon} from '../icons/external-link';import {type AddEffectModalState,@@ -27,7 +28,6 @@ import {import {ContextMenu} from './ContextMenu';import {addEffectToSequence} from './effect-drag-and-drop';import {filterEffectCatalog} from './effect-picker-search';-import {Spacing} from './layout';import {VERTICAL_SCROLLBAR_CLASSNAME} from './Menu/is-menu-item';import type {ComboboxValue} from './NewComposition/ComboBox';import {DismissableModal} from './NewComposition/DismissableModal';@@ -39,7 +39,7 @@ import {} from './QuickSwitcher/shared';const container: React.CSSProperties = {- width: 400,+ width: 440,};const panelStyle: React.CSSProperties = {@@ -98,9 +98,13 @@ const aboutEffectsIcon: React.CSSProperties = {};const resultList: React.CSSProperties = {- height: 320,+ height: 420,+ display: 'grid',+ gridTemplateColumns: 'repeat(3, minmax(0, 1fr))',+ alignContent: 'start',+ gap: 4,overflowY: 'auto',- paddingBottom: 10,+ padding: '0 12px 10px',};const noResults: React.CSSProperties = {@@ -112,41 +116,33 @@ const noResults: React.CSSProperties = {const resultContainer: React.CSSProperties = {cursor: 'default',display: 'flex',- flexDirection: 'row',- alignItems: 'center',- paddingLeft: 16,- paddingRight: 16,- marginBottom: 1,- marginLeft: 4,- marginRight: 4,+ flexDirection: 'column',+ gap: 3,+ padding: 6,+ minWidth: 0,borderRadius: 4,};-const iconStyle: React.CSSProperties = {- width: 18,- height: 18,- flexShrink: 0,-};--const labelContainer: React.CSSProperties = {- flex: 1,- minWidth: 0,+const previewFrame: React.CSSProperties = {+ width: '100%',+ aspectRatio: '3 / 2',+ position: 'relative',+ backgroundColor: WHITE_ALPHA_06,+ borderRadius: 3,overflow: 'hidden',- paddingTop: 5,- paddingBottom: 5,};-const label: React.CSSProperties = {- fontSize: QUICK_SWITCHER_RESULT_LABEL_FONT_SIZE,- overflow: 'hidden',- textOverflow: 'ellipsis',- whiteSpace: 'nowrap',+const preview: React.CSSProperties = {+ position: 'absolute',+ inset: 0,+ width: '100%',+ height: '100%',+ objectFit: 'cover',};-const category: React.CSSProperties = {- color: LIGHT_TEXT,- fontSize: 11,- flexShrink: 0,+const label: React.CSSProperties = {+ fontSize: QUICK_SWITCHER_RESULT_LABEL_FONT_SIZE - 2,+ overflowWrap: 'anywhere',};const EffectPickerResult: React.FC<{@@ -155,6 +151,7 @@ const EffectPickerResult: React.FC<{readonly onSelected: (item: EffectCatalogItem) => void;}> = ({item, selected, onSelected}) => {const [hovered, setHovered] = useState(false);+ const [previewLoaded, setPreviewLoaded] = useState(false);const ref = useRef<HTMLDivElement>(null);useScrollIntoViewOnSelected(ref, selected);@@ -207,16 +204,19 @@ const EffectPickerResult: React.FC<{onMouseEnter={() => setHovered(true)}onMouseLeave={() => setHovered(false)}>- <EffectsIcon- color={selected || hovered ? WHITE : LIGHT_TEXT}- style={iconStyle}- />- <Spacing x={1} />- <div style={labelContainer}>- <div style={labelStyle}>{item.label}</div>+ <div style={previewFrame}>+ <img+ src={`https://www.remotion.dev${getEffectPreviewSource(item)}`}+ alt={getEffectPreviewAlt(item)}+ style={{+ ...preview,+ visibility: previewLoaded ? 'visible' : 'hidden',+ }}+ loading="lazy"+ onLoad={() => setPreviewLoaded(true)}+ /></div>- <Spacing x={1} />- <div style={category}>{item.category}</div>+ <div style={labelStyle}>{item.label}</div></div></ContextMenu>);@@ -252,13 +252,19 @@ const EffectPickerContent: React.FC<{[setSelectedModal, state.clientId, state.fileName, state.nodePath],);- const onArrowDown = useCallback(() => {- setSelectedIndex((i) => i + 1);- }, []);+ const moveSelection = useCallback(+ (offset: number) => {+ if (results.length === 0) {+ return;+ }- const onArrowUp = useCallback(() => {- setSelectedIndex((i) => i - 1);- }, []);+ setSelectedIndex(+ (i) =>+ (((i + offset) % results.length) + results.length) % results.length,+ );+ },+ [results.length],+ );const onEnter = useCallback(() => {if (selectedIndexRounded === -1) {@@ -271,7 +277,7 @@ const EffectPickerContent: React.FC<{useEffect(() => {const downBinding = keybindings.registerKeybinding({key: 'ArrowDown',- callback: onArrowDown,+ callback: () => moveSelection(3),commandCtrlKey: false,event: 'keydown',preventDefault: true,@@ -280,7 +286,25 @@ const EffectPickerContent: React.FC<{});const upBinding = keybindings.registerKeybinding({key: 'ArrowUp',- callback: onArrowUp,+ callback: () => moveSelection(-3),+ commandCtrlKey: false,+ event: 'keydown',+ preventDefault: true,+ triggerIfInputFieldFocused: true,+ keepRegisteredWhenNotHighestContext: false,+ });+ const rightBinding = keybindings.registerKeybinding({+ key: 'ArrowRight',+ callback: () => moveSelection(1),+ commandCtrlKey: false,+ event: 'keydown',+ preventDefault: true,+ triggerIfInputFieldFocused: true,+ keepRegisteredWhenNotHighestContext: false,+ });+ const leftBinding = keybindings.registerKeybinding({+ key: 'ArrowLeft',+ callback: () => moveSelection(-1),commandCtrlKey: false,event: 'keydown',preventDefault: true,@@ -300,9 +324,11 @@ const EffectPickerContent: React.FC<{return () => {downBinding.unregister();upBinding.unregister();+ rightBinding.unregister();+ leftBinding.unregister();enterBinding.unregister();};- }, [keybindings, onArrowDown, onArrowUp, onEnter]);+ }, [keybindings, moveSelection, onEnter]);const onTextChange: React.ChangeEventHandler<HTMLInputElement> = useCallback((e) => {