Skip to content

Visualize Your Ideas With Code

feat(ui): timeline dragging (#794)

Jacob248e4546367f
diff --git a/packages/ui/src/components/timeline/Timeline.tsx b/packages/ui/src/components/timeline/Timeline.tsx
index eff47ff4..671c7e46 100644
--- a/packages/ui/src/components/timeline/Timeline.tsx
+++ b/packages/ui/src/components/timeline/Timeline.tsx
@@ -186,8 +186,30 @@ export function Timeline() {
event.x - rect.x + newOffset
}px`;
}}
- onMouseMove={event => {
+ onPointerDown={event => {
+ if (event.button === 1) {
+ event.preventDefault();
+ event.currentTarget.setPointerCapture(event.pointerId);
+ containerRef.current.style.cursor = 'grabbing';
+ }
+ }}
+ onPointerMove={event => {
playheadRef.current.style.left = `${event.x - rect.x + offset}px`;
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) {
+ const newOffset = clamp(
+ 0,
+ sizes.playableLength,
+ offset - event.movementX,
+ );
+ setOffset(newOffset);
+ containerRef.current.scrollLeft = newOffset;
+ }
+ }}
+ onPointerUp={event => {
+ if (event.button === 1) {
+ event.currentTarget.releasePointerCapture(event.pointerId);
+ containerRef.current.style.cursor = '';
+ }
}}
>
<div