Skip to content

🎥 Make videos programmatically with React

Show longer timeline labels when property chevron is hidden

Jonny Burgerc179f0b6fb39
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
index 9050e5555c..66d44bebad 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
@@ -146,61 +146,122 @@ type SequenceReorderDragData = {
readonly fileName: string;
};
-type TimelineSequenceExpandArrowProps = {
+type TimelineSequenceLabelProps = {
readonly disabled: boolean;
readonly isExpanded: boolean;
- readonly nodePathInfo: SequenceNodePathInfo;
+ readonly nodePathInfo: SequenceNodePathInfo | null;
readonly selectedItems: readonly TimelineSelection[];
readonly sequence: TSequence;
+ readonly canHaveExpandableContent: boolean;
+ readonly displayName: string;
+ readonly fallbackDisplayName: string;
+ readonly selected: boolean;
+ readonly containsSelection: boolean;
+ readonly editing: boolean;
+ readonly onCancelEditing: () => void;
+ readonly onSaveName: (name: string) => Promise<void>;
+ readonly numberOfHiddenDuplicates: number;
};
-const TimelineSequenceExpandArrowInner: React.FC<
- TimelineSequenceExpandArrowProps
-> = ({disabled, isExpanded, nodePathInfo, selectedItems, sequence}) => {
+const TimelineSequenceLabelInner: React.FC<TimelineSequenceLabelProps> = ({
+ disabled,
+ isExpanded,
+ nodePathInfo,
+ selectedItems,
+ sequence,
+ canHaveExpandableContent,
+ displayName,
+ fallbackDisplayName,
+ selected,
+ containsSelection,
+ editing,
+ onCancelEditing,
+ onSaveName,
+ numberOfHiddenDuplicates,
+}) => {
const {toggleTrack} = useContext(ExpandedTracksSetterContext);
const hasExpandableContent = useTimelineSequenceHasExpandableContent({
sequence,
nodePathInfo,
selectedItems,
});
- const onToggleExpand = useCallback(
- () => toggleTrack(nodePathInfo),
- [nodePathInfo, toggleTrack],
- );
-
- if (!hasExpandableContent) {
- return <TimelineExpandArrowSpacer />;
- }
+ const showChevronSlot = canHaveExpandableContent && nodePathInfo !== null;
+ const showChevron = showChevronSlot && hasExpandableContent;
+ const onToggleExpand = useCallback(() => {
+ if (nodePathInfo !== null) {
+ toggleTrack(nodePathInfo);
+ }
+ }, [nodePathInfo, toggleTrack]);
return (
- <TimelineExpandArrowButton
- isExpanded={isExpanded}
- onClick={onToggleExpand}
- label="track properties"
- disabled={disabled}
- />
+ <>
+ <TimelineSequenceName
+ displayName={displayName}
+ fallbackDisplayName={fallbackDisplayName}
+ selected={selected}
+ containsSelection={containsSelection}
+ editing={editing}
+ onCancelEditing={onCancelEditing}
+ onSaveName={onSaveName}
+ chevronSlot={
+ showChevronSlot && !editing && numberOfHiddenDuplicates === 0
+ ? showChevron
+ ? 'occupied'
+ : 'empty'
+ : 'none'
+ }
+ />
+ {numberOfHiddenDuplicates > 0 ? (
+ <>
+ <Spacing x={0.5} />
+ <TimelineDuplicateCount count={numberOfHiddenDuplicates} />
+ </>
+ ) : null}
+ {showChevronSlot ? (
+ <>
+ <Spacing x={0.5} />
+ {showChevron ? (
+ <TimelineExpandArrowButton
+ isExpanded={isExpanded}
+ onClick={onToggleExpand}
+ label="track properties"
+ disabled={disabled}
+ />
+ ) : (
+ <TimelineExpandArrowSpacer />
+ )}
+ </>
+ ) : null}
+ </>
);
};
-const areTimelineSequenceExpandArrowPropsEqual = (
- first: TimelineSequenceExpandArrowProps,
- second: TimelineSequenceExpandArrowProps,
-) => {
- return (
+const TimelineSequenceLabel = React.memo(
+ TimelineSequenceLabelInner,
+ (first, second) =>
first.disabled === second.disabled &&
first.isExpanded === second.isExpanded &&
first.selectedItems === second.selectedItems &&
+ first.canHaveExpandableContent === second.canHaveExpandableContent &&
+ first.displayName === second.displayName &&
+ first.fallbackDisplayName === second.fallbackDisplayName &&
+ first.selected === second.selected &&
+ first.containsSelection === second.containsSelection &&
+ first.editing === second.editing &&
+ first.onCancelEditing === second.onCancelEditing &&
+ first.onSaveName === second.onSaveName &&
+ first.numberOfHiddenDuplicates === second.numberOfHiddenDuplicates &&
first.sequence.controls?.schema === second.sequence.controls?.schema &&
first.sequence.controls?.runtimeValues ===
second.sequence.controls?.runtimeValues &&
first.sequence.effects === second.sequence.effects &&
- areSequenceNodePathInfosEqual(first.nodePathInfo, second.nodePathInfo)
- );
-};
-
-const TimelineSequenceExpandArrow = React.memo(
- TimelineSequenceExpandArrowInner,
- areTimelineSequenceExpandArrowPropsEqual,
+ (first.nodePathInfo === second.nodePathInfo ||
+ (first.nodePathInfo !== null &&
+ second.nodePathInfo !== null &&
+ areSequenceNodePathInfosEqual(
+ first.nodePathInfo,
+ second.nodePathInfo,
+ ))),
);
const sequenceReorderWrapper: React.CSSProperties = {
@@ -1488,7 +1549,7 @@ const TimelineSequenceItemInner: React.FC<{
<Spacing x={0.5} />
</>
) : null}
- <TimelineSequenceName
+ <TimelineSequenceLabel
displayName={timelineDisplayName}
fallbackDisplayName={fallbackDisplayName}
selected={selected}
@@ -1496,25 +1557,14 @@ const TimelineSequenceItemInner: React.FC<{
editing={isRenaming}
onCancelEditing={onCancelRenaming}
onSaveName={onSaveName}
+ numberOfHiddenDuplicates={numberOfHiddenDuplicates}
+ canHaveExpandableContent={hasExpandableContent}
+ disabled={!previewInteractive}
+ isExpanded={isExpanded}
+ nodePathInfo={nodePathInfo}
+ selectedItems={selectedItems}
+ sequence={sequence}
/>
- {numberOfHiddenDuplicates > 0 ? (
- <>
- <Spacing x={0.5} />
- <TimelineDuplicateCount count={numberOfHiddenDuplicates} />
- </>
- ) : null}
- {hasExpandableContent && nodePathInfo !== null ? (
- <>
- <Spacing x={0.5} />
- <TimelineSequenceExpandArrow
- disabled={!previewInteractive}
- isExpanded={isExpanded}
- nodePathInfo={nodePathInfo}
- selectedItems={selectedItems}
- sequence={sequence}
- />
- </>
- ) : null}
{mediaSrc ? (
<>
<Spacing x={0.5} /> <TimelineMediaInfo src={mediaSrc} />
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceName.tsx b/packages/studio/src/components/Timeline/TimelineSequenceName.tsx
index 4177681ec1..6ec5c6848f 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceName.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceName.tsx
@@ -9,6 +9,9 @@ import {
const MAX_DISPLAY_NAME_LENGTH = 1000;
const MAX_RENAME_INPUT_WIDTH = 240;
const RENAME_INPUT_CLASS_NAME = 'remotion-timeline-sequence-name-input';
+const LABEL_FONT_FAMILY = 'Arial, Helvetica, sans-serif';
+// 4px gap + 12px chevron + 4px chevron margin.
+const CHEVRON_SLOT_WIDTH = 20;
const getTruncatedDisplayName = (displayName: string): string => {
if (displayName.length > MAX_DISPLAY_NAME_LENGTH) {
@@ -26,6 +29,7 @@ export const TimelineSequenceName: React.FC<{
readonly editing: boolean;
readonly onCancelEditing: () => void;
readonly onSaveName: (name: string) => Promise<void>;
+ readonly chevronSlot: 'none' | 'empty' | 'occupied';
}> = ({
displayName,
fallbackDisplayName,
@@ -34,6 +38,7 @@ export const TimelineSequenceName: React.FC<{
editing,
onCancelEditing,
onSaveName,
+ chevronSlot,
}) => {
const inputRef = useRef<HTMLInputElement>(null);
const [draftName, setDraftName] = useState(displayName);
@@ -45,11 +50,12 @@ export const TimelineSequenceName: React.FC<{
...getTimelineSelectedLabelStyle(selected, false),
display: 'inline-flex',
flexShrink: 1,
- fontFamily: 'inherit',
+ fontFamily: LABEL_FONT_FAMILY,
fontSize: 12,
lineHeight: 'normal',
minWidth: 0,
- overflow: 'hidden',
+ overflow: chevronSlot === 'none' ? 'hidden' : 'visible',
+ position: chevronSlot === 'none' ? undefined : 'relative',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
color: getTimelineColor(selected, false),
@@ -61,7 +67,7 @@ export const TimelineSequenceName: React.FC<{
? `inset 0 0 0 2px ${TIMELINE_SELECTED_LABEL_BACKGROUND}`
: undefined,
};
- }, [selected, containsSelection]);
+ }, [selected, containsSelection, chevronSlot]);
const inputStyle = useMemo((): React.CSSProperties => {
return {
@@ -69,7 +75,7 @@ export const TimelineSequenceName: React.FC<{
background: TRANSPARENT,
border: 0,
color: getTimelineColor(false, false),
- fontFamily: 'inherit',
+ fontFamily: LABEL_FONT_FAMILY,
fontSize: 12,
outline: 'none',
paddingBottom: 0,
@@ -151,6 +157,70 @@ export const TimelineSequenceName: React.FC<{
);
}
+ if (chevronSlot !== 'none') {
+ // Keep the name's flex width fixed while its visible text uses the empty slot.
+ return (
+ <div
+ title={text}
+ style={{...style, backgroundColor: undefined, boxShadow: undefined}}
+ >
+ <div
+ aria-hidden
+ style={{
+ fontFamily: LABEL_FONT_FAMILY,
+ fontSize: 12,
+ lineHeight: 'normal',
+ visibility: 'hidden',
+ }}
+ >
+ {text}
+ </div>
+ <div
+ style={{
+ ...style,
+ backgroundColor: undefined,
+ boxShadow: undefined,
+ boxSizing: 'border-box',
+ clipPath:
+ chevronSlot === 'occupied'
+ ? `inset(0 ${CHEVRON_SLOT_WIDTH}px 0 0)`
+ : undefined,
+ height: '100%',
+ left: 0,
+ overflow: 'hidden',
+ paddingLeft: 0,
+ paddingRight: 0,
+ pointerEvents: 'none',
+ position: 'absolute',
+ top: 0,
+ width: `calc(100% + ${CHEVRON_SLOT_WIDTH}px)`,
+ }}
+ >
+ <div
+ style={{
+ ...getTimelineSelectedLabelStyle(selected, false),
+ alignItems: 'center',
+ boxShadow: style.boxShadow,
+ boxSizing: 'border-box',
+ color: getTimelineColor(selected, false),
+ display: 'inline-flex',
+ fontFamily: LABEL_FONT_FAMILY,
+ fontSize: 12,
+ height: '100%',
+ lineHeight: 'normal',
+ maxWidth: '100%',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ }}
+ >
+ {text}
+ </div>
+ </div>
+ </div>
+ );
+ }
+
return (
<div title={text} style={style}>
{text}
diff --git a/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts b/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts
index f21aa04203..c051189191 100644
--- a/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts
+++ b/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts
@@ -27,7 +27,7 @@ export const useTimelineSequenceHasExpandableContent = ({
selectedItems,
}: {
readonly sequence: TSequence;
- readonly nodePathInfo: SequenceNodePathInfo;
+ readonly nodePathInfo: SequenceNodePathInfo | null;
readonly selectedItems: readonly TimelineSelection[];
}) => {
const {propStatuses: visualModePropStatuses} = useContext(
@@ -42,6 +42,10 @@ export const useTimelineSequenceHasExpandableContent = ({
);
const selectHasExpandableContent = useCallback(
(runtimeValues: Readonly<Record<string, unknown>>) => {
+ if (nodePathInfo === null) {
+ return false;
+ }
+
const tree = buildTimelineTree({
sequence,
nodePathInfo,