Skip to content

🎥 Make videos programmatically with React

fix(studio): align timeline field values across nesting depths

Jonny Burger5b1c40676298
diff --git a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
index e836e5edba..bf1ceb3ec8 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
@@ -8,13 +8,13 @@ import type {EffectSchemaFieldInfo} from '../../helpers/timeline-layout';
import {EXPANDED_SECTION_PADDING_RIGHT} from '../../helpers/timeline-layout';
import {callApi} from '../call-api';
import {enqueueSavePropChange} from './save-prop-queue';
+import {getTimelineFieldLabelRowStyle} from './timeline-field-row-layout';
import {TimelineExpandArrowSpacer} from './TimelineExpandArrowButton';
import {TimelineLayerEyeSpacer} from './TimelineLayerEye';
import {TimelineRowChrome} from './TimelineRowChrome';
import {TimelineFieldValue, UnsupportedStatus} from './TimelineSchemaField';
const fieldRowBase: React.CSSProperties = {
- gap: 8,
paddingRight: EXPANDED_SECTION_PADDING_RIGHT,
};
@@ -24,14 +24,6 @@ const fieldName: React.CSSProperties = {
userSelect: 'none',
};
-const fieldLabelRow: React.CSSProperties = {
- flex: '0 0 50%',
- display: 'flex',
- flexDirection: 'row',
- alignItems: 'center',
- gap: 6,
-};
-
const Value: React.FC<{
readonly field: EffectSchemaFieldInfo;
readonly nodePath: SequencePropsSubscriptionKey;
@@ -227,6 +219,11 @@ export const TimelineEffectFieldRow: React.FC<{
};
}, [field.rowHeight]);
+ const labelRowStyle = useMemo(
+ () => getTimelineFieldLabelRowStyle(rowDepth),
+ [rowDepth],
+ );
+
return (
<TimelineRowChrome
depth={rowDepth}
@@ -234,7 +231,7 @@ export const TimelineEffectFieldRow: React.FC<{
arrow={<TimelineExpandArrowSpacer />}
style={style}
>
- <div style={fieldLabelRow}>
+ <div style={labelRowStyle}>
<span style={fieldName}>{field.description ?? field.key}</span>
</div>
<Value
diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
index b751ffe73c..198bcf37cc 100644
--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
@@ -14,6 +14,7 @@ import type {
} from '../../helpers/timeline-layout';
import {EXPANDED_SECTION_PADDING_RIGHT} from '../../helpers/timeline-layout';
import {saveSequenceProp} from './save-sequence-prop';
+import {getTimelineFieldLabelRowStyle} from './timeline-field-row-layout';
import {TimelineExpandArrowSpacer} from './TimelineExpandArrowButton';
import {TimelineLayerEyeSpacer} from './TimelineLayerEye';
import {TimelineRowChrome} from './TimelineRowChrome';
@@ -23,7 +24,6 @@ import {
} from './TimelineSchemaField';
const fieldRowBase: React.CSSProperties = {
- gap: 8,
paddingRight: EXPANDED_SECTION_PADDING_RIGHT,
};
@@ -33,14 +33,6 @@ const fieldName: React.CSSProperties = {
userSelect: 'none',
};
-const fieldLabelRow: React.CSSProperties = {
- flex: '0 0 50%',
- display: 'flex',
- flexDirection: 'row',
- alignItems: 'center',
- gap: 6,
-};
-
const Value: React.FC<{
readonly field: SchemaFieldInfo;
readonly nodePath: SequencePropsSubscriptionKey;
@@ -180,6 +172,11 @@ export const TimelineFieldRow: React.FC<{
};
}, [field.rowHeight]);
+ const labelRowStyle = useMemo(
+ () => getTimelineFieldLabelRowStyle(rowDepth),
+ [rowDepth],
+ );
+
if (codeValue === null) {
return null;
}
@@ -191,7 +188,7 @@ export const TimelineFieldRow: React.FC<{
arrow={<TimelineExpandArrowSpacer />}
style={style}
>
- <div style={fieldLabelRow}>
+ <div style={labelRowStyle}>
<span style={fieldName}>{field.description ?? field.key}</span>
</div>
{codeValue.canUpdate ? (
diff --git a/packages/studio/src/components/Timeline/timeline-field-row-layout.ts b/packages/studio/src/components/Timeline/timeline-field-row-layout.ts
new file mode 100644
index 0000000000..15f22873e3
--- /dev/null
+++ b/packages/studio/src/components/Timeline/timeline-field-row-layout.ts
@@ -0,0 +1,14 @@
+import type React from 'react';
+import {getTimelineFieldLabelFlexBasis} from './timeline-row-layout';
+
+export const getTimelineFieldLabelRowStyle = (
+ depth: number,
+): React.CSSProperties => {
+ return {
+ flex: `0 0 ${getTimelineFieldLabelFlexBasis(depth)}`,
+ display: 'flex',
+ flexDirection: 'row',
+ alignItems: 'center',
+ gap: 6,
+ };
+};
diff --git a/packages/studio/src/components/Timeline/timeline-row-layout.ts b/packages/studio/src/components/Timeline/timeline-row-layout.ts
index fa4d4f046c..9ec64537d5 100644
--- a/packages/studio/src/components/Timeline/timeline-row-layout.ts
+++ b/packages/studio/src/components/Timeline/timeline-row-layout.ts
@@ -1,11 +1,26 @@
import {TIMELINE_INDENT} from './timeline-indent';
export const TIMELINE_ROW_BASE_PADDING = 5;
+export const TIMELINE_EYE_COLUMN_WIDTH = 22;
+export const TIMELINE_ARROW_COLUMN_WIDTH = 16;
export const getTimelineRowIndentWidth = (depth: number): number => {
return depth * TIMELINE_INDENT;
};
+export const getTimelineRowLeftChromeWidth = (depth: number): number => {
+ return (
+ TIMELINE_ROW_BASE_PADDING +
+ TIMELINE_EYE_COLUMN_WIDTH +
+ getTimelineRowIndentWidth(depth) +
+ TIMELINE_ARROW_COLUMN_WIDTH
+ );
+};
+
+export const getTimelineFieldLabelFlexBasis = (depth: number): string => {
+ return `calc(50% - ${getTimelineRowLeftChromeWidth(depth)}px)`;
+};
+
export const getExpandedRowDepth = ({
nestedDepth,
treeDepth,
diff --git a/packages/studio/src/test/timeline-tree-layout.test.ts b/packages/studio/src/test/timeline-tree-layout.test.ts
index 0fd57c45f7..d99b0a4e40 100644
--- a/packages/studio/src/test/timeline-tree-layout.test.ts
+++ b/packages/studio/src/test/timeline-tree-layout.test.ts
@@ -6,7 +6,9 @@ import type {
} from 'remotion';
import {
getExpandedRowDepth,
+ getTimelineFieldLabelFlexBasis,
getTimelineRowIndentWidth,
+ getTimelineRowLeftChromeWidth,
} from '../components/Timeline/timeline-row-layout';
import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';
import {
@@ -134,3 +136,9 @@ test('getExpandedRowDepth combines composition and tree depth', () => {
).toBe(4);
expect(getTimelineRowIndentWidth(4)).toBe(40);
});
+
+test('getTimelineFieldLabelFlexBasis subtracts left chrome width', () => {
+ expect(getTimelineRowLeftChromeWidth(0)).toBe(43);
+ expect(getTimelineRowLeftChromeWidth(4)).toBe(83);
+ expect(getTimelineFieldLabelFlexBasis(4)).toBe('calc(50% - 83px)');
+});