Skip to content

🎥 Make videos programmatically with React

collapse toggle

Jonny Burgerd05a35169b77
diff --git a/packages/cli/src/editor/components/Timeline/TimelineCollapseToggle.tsx b/packages/cli/src/editor/components/Timeline/TimelineCollapseToggle.tsx
new file mode 100644
index 0000000000..4c924ae5c9
--- /dev/null
+++ b/packages/cli/src/editor/components/Timeline/TimelineCollapseToggle.tsx
@@ -0,0 +1,28 @@
+import React, {SVGProps} from 'react';
+import styled from 'styled-components';
+
+const Container = styled.div`
+ height: 10px;
+ width: 10px;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+`;
+
+const Icon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg viewBox="0 0 8 10" {...props} style={{height: 10, width: 8}}>
+ <path d="M 0 0 L 8 5 L 0 10 z" fill="#ddd" />
+ </svg>
+ );
+};
+
+export const TimelineCollapseToggle: React.FC<{
+ collapsed: boolean;
+}> = ({collapsed}) => {
+ return (
+ <Container style={!collapsed ? {transform: 'rotate(90deg)'} : {}}>
+ <Icon />
+ </Container>
+ );
+};
diff --git a/packages/cli/src/editor/components/Timeline/TimelineListItem.tsx b/packages/cli/src/editor/components/Timeline/TimelineListItem.tsx
index 65aab3f313..4084cde9f6 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineListItem.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineListItem.tsx
@@ -6,6 +6,7 @@ import {
TIMELINE_PADDING,
} from '../../helpers/timeline-layout';
import {TimelineActionState} from './timeline-state-reducer';
+import {TimelineCollapseToggle} from './TimelineCollapseToggle';
const HOOK_WIDTH = 7;
const BORDER_BOTTOM_LEFT_RADIUS = 2;
@@ -46,7 +47,9 @@ const smallSpace: React.CSSProperties = {
};
const collapser: React.CSSProperties = {
- width: 20,
+ width: 8,
+ userSelect: 'none',
+ marginRight: 10,
};
export const TimelineListItem: React.FC<{
@@ -79,7 +82,7 @@ export const TimelineListItem: React.FC<{
const padder = useMemo((): React.CSSProperties => {
return {
- width: leftOffset * (nestedDepth - 1),
+ width: leftOffset * nestedDepth,
};
}, [leftOffset, nestedDepth]);
@@ -99,14 +102,14 @@ export const TimelineListItem: React.FC<{
return (
<div style={outer}>
+ <div style={padder} />
{canCollapse ? (
<div style={collapser} onClick={toggleCollapse}>
- {collapsed ? '+' : '-'}
+ <TimelineCollapseToggle collapsed={collapsed} />
</div>
) : (
<div style={collapser} />
)}
- <div style={padder} />
{sequence.parent && nestedDepth > 0 ? (
<>
<div style={smallSpace} />
diff --git a/packages/cli/src/editor/components/Timeline/TimelineTracks.tsx b/packages/cli/src/editor/components/Timeline/TimelineTracks.tsx
index 2aefa86a03..be74536a7e 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineTracks.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineTracks.tsx
@@ -4,6 +4,7 @@ import {
TIMELINE_BORDER,
TIMELINE_LAYER_HEIGHT,
TIMELINE_PADDING,
+ TrackWithHash,
} from '../../helpers/timeline-layout';
import {isCollapsed} from './is-collapsed';
import {TimelineViewState} from './timeline-state-reducer';
diff --git a/packages/cli/src/editor/components/Timeline/is-collapsed.ts b/packages/cli/src/editor/components/Timeline/is-collapsed.ts
index d9f42d7f68..724c9c4df9 100644
--- a/packages/cli/src/editor/components/Timeline/is-collapsed.ts
+++ b/packages/cli/src/editor/components/Timeline/is-collapsed.ts
@@ -11,7 +11,8 @@ export const isCollapsed = (
}
const parent = allTracks.find((t) => t.sequence.id === track.sequence.parent);
if (!parent) {
- throw new Error('did not find parent');
+ // TODO: Tighten up, when toggling rich timeline this case can happen right now
+ return false;
}
if (viewState.collapsed[parent.hash]) {
return true;