Skip to content

🎥 Make videos programmatically with React

@remotion/studio: Restore segmented source preview

Jonny Burgerc44669d37964
diff --git a/packages/studio/src/components/Timeline/TimelineAssetField.tsx b/packages/studio/src/components/Timeline/TimelineAssetField.tsx
index 17184d12e7..a4f99c4aca 100644
--- a/packages/studio/src/components/Timeline/TimelineAssetField.tsx
+++ b/packages/studio/src/components/Timeline/TimelineAssetField.tsx
@@ -2,7 +2,12 @@ import React, {createContext, useCallback, useContext, useMemo} from 'react';
import {staticFile, type CanUpdateSequencePropStatusStatic} from 'remotion';
import {NoReactInternals} from 'remotion/no-react';
import {writeStaticFile} from '../../api/write-static-file';
-import {LIGHT_TEXT, TRANSPARENT, WHITE} from '../../helpers/colors';
+import {
+ LIGHT_TEXT,
+ TRANSPARENT,
+ WHITE,
+ getBackgroundFromHoverState,
+} from '../../helpers/colors';
import {
FOCUS_VISIBLE_ONLY_CLASS_NAME,
HOVERABLE_CLASS_NAME,
@@ -59,33 +64,37 @@ const imageAssetField: React.CSSProperties = {
alignItems: 'center',
display: 'flex',
flex: 1,
- gap: 8,
+ gap: 4,
+ margin: '0 4px',
minWidth: 0,
- padding: '4px 12px',
+ padding: '4px 0',
};
-const imageAssetPreview: React.CSSProperties = {
- alignItems: 'center',
+const imageAssetPreviewContainer: React.CSSProperties = {
display: 'flex',
flex: 1,
- gap: 8,
minWidth: 0,
};
-const thumbnailButton: React.CSSProperties = {
- ...hoverableStyle({
- idleBackground: TRANSPARENT,
- hoverBackground: TRANSPARENT,
- idleColor: LIGHT_TEXT,
- hoverColor: WHITE,
- }),
+const imageAssetPreviewButton: React.CSSProperties = {
+ alignItems: 'center',
appearance: 'none',
border: 'none',
+ borderRadius: 4,
cursor: 'default',
- flexShrink: 0,
+ display: 'flex',
+ flex: 1,
+ gap: 8,
height: 40,
margin: 0,
- padding: 0,
+ minWidth: 0,
+ padding: '0 8px',
+ textAlign: 'left',
+};
+
+const thumbnailContainer: React.CSSProperties = {
+ flexShrink: 0,
+ height: 40,
width: 40,
};
@@ -97,22 +106,11 @@ const thumbnail: React.CSSProperties = {
};
const imageAssetInfo: React.CSSProperties = {
- ...hoverableStyle({
- idleBackground: TRANSPARENT,
- hoverBackground: TRANSPARENT,
- idleColor: LIGHT_TEXT,
- hoverColor: WHITE,
- }),
- appearance: 'none',
- border: 'none',
display: 'flex',
flex: 1,
flexDirection: 'column',
gap: 2,
- margin: 0,
minWidth: 0,
- padding: 0,
- textAlign: 'left',
};
const imageAssetName: React.CSSProperties = {
@@ -359,44 +357,47 @@ export const TimelineAssetField: React.FC<TimelineAssetFieldProps> = ({
const previewDisabled = opensSource
? inlineSourceAction.disabled
: window.remotion_isReadOnlyStudio;
+ const previewButtonStyle: React.CSSProperties = {
+ ...imageAssetPreviewButton,
+ ...hoverableStyle({
+ idleBackground: TRANSPARENT,
+ hoverBackground: previewDisabled
+ ? TRANSPARENT
+ : getBackgroundFromHoverState({hovered: true, selected: false}),
+ idleColor: LIGHT_TEXT,
+ hoverColor: previewDisabled ? LIGHT_TEXT : WHITE,
+ }),
+ };
const previewAction = (
- <>
- <button
- aria-label={previewLabel}
- className={`${HOVERABLE_CLASS_NAME} ${FOCUS_VISIBLE_ONLY_CLASS_NAME}`}
- disabled={previewDisabled}
- onClick={onPreviewClick}
- style={thumbnailButton}
- title={title}
- type="button"
- >
+ <button
+ aria-label={previewLabel}
+ className={`${HOVERABLE_CLASS_NAME} ${FOCUS_VISIBLE_ONLY_CLASS_NAME}`}
+ disabled={previewDisabled}
+ onClick={onPreviewClick}
+ style={previewButtonStyle}
+ title={title}
+ type="button"
+ >
+ <span style={thumbnailContainer}>
<img alt="" draggable={false} src={previewSrc} style={thumbnail} />
- </button>
- <button
- aria-label={previewLabel}
- className={`${HOVERABLE_CLASS_NAME} ${FOCUS_VISIBLE_ONLY_CLASS_NAME}`}
- disabled={previewDisabled}
- onClick={onPreviewClick}
- style={imageAssetInfo}
- title={title}
- type="button"
- >
+ </span>
+ <span style={imageAssetInfo}>
<span style={imageAssetName}>{name}</span>
{source === null ? null : (
<span style={imageAssetSource}>{source}</span>
)}
- </button>
- </>
+ </span>
+ </button>
);
return (
<div style={imageAssetField}>
{localAssetPath === null ? (
- <div style={imageAssetPreview}>{previewAction}</div>
+ <div style={imageAssetPreviewContainer}>{previewAction}</div>
) : (
<ContextMenu
getItems={getLocalAssetContextMenuItems}
- style={imageAssetPreview}
+ style={imageAssetPreviewContainer}
>
{previewAction}
</ContextMenu>
diff --git a/packages/studio/src/test/quick-switcher-asset-search.test.tsx b/packages/studio/src/test/quick-switcher-asset-search.test.tsx
index 1be162592e..e2c7c89ad6 100644
--- a/packages/studio/src/test/quick-switcher-asset-search.test.tsx
+++ b/packages/studio/src/test/quick-switcher-asset-search.test.tsx
@@ -225,11 +225,11 @@ test('an image asset field replaces a protocol-relative URL', () => {
const sourceButtons = screen.getAllByRole('button', {
name: 'Replace avatar.png',
});
- expect(sourceButtons).toHaveLength(2);
+ expect(sourceButtons).toHaveLength(1);
expect(document.querySelector('img')?.getAttribute('src')).toBe(
'https://cdn.example.com/images/avatar.png',
);
- fireEvent.click(sourceButtons[1]);
+ fireEvent.click(sourceButtons[0]);
const modal = selectedModal as ModalState | null;
if (modal?.type !== 'asset-selection' || modal.assetType !== 'image') {
@@ -315,13 +315,13 @@ test('a local image preview supports navigation and asset actions', async () =>
const previewButtons = screen.getAllByRole('button', {
name: 'Open logo.png',
});
- expect(previewButtons).toHaveLength(2);
+ expect(previewButtons).toHaveLength(1);
fireEvent.click(previewButtons[0]);
expect(navigationCount).toBe(1);
const previousMenuPortal = portals[0];
portals[0] = document.body;
try {
- fireEvent.contextMenu(previewButtons[1]);
+ fireEvent.contextMenu(previewButtons[0]);
expect(await screen.findByText('Copy file name')).toBeTruthy();
} finally {
portals[0] = previousMenuPortal;