|
1 | | -import React from 'react'; |
| 1 | +import React, { useRef, useEffect } from 'react'; |
| 2 | +import { useTimelineStore } from '../../store/timelineStore'; |
2 | 3 |
|
3 | 4 | interface TimelineAxisProps { |
4 | 5 | ticks: number[]; |
5 | 6 | maxEndTime: number; |
6 | 7 | } |
7 | 8 |
|
8 | 9 | export const TimelineAxis: React.FC<TimelineAxisProps> = ({ ticks, maxEndTime }) => { |
| 10 | + const { flowColumnWidth, setFlowColumnWidth } = useTimelineStore(); |
| 11 | + const draggingRef = useRef<boolean>(false); |
| 12 | + const startXRef = useRef<number>(0); |
| 13 | + const startWidthRef = useRef<number>(0); |
| 14 | + |
| 15 | + useEffect(() => { |
| 16 | + const handlePointerMove = (e: PointerEvent) => { |
| 17 | + if (!draggingRef.current) return; |
| 18 | + |
| 19 | + const delta = e.pageX - startXRef.current; |
| 20 | + const newWidth = Math.max(100, Math.min(600, startWidthRef.current + delta)); |
| 21 | + setFlowColumnWidth(newWidth); |
| 22 | + }; |
| 23 | + |
| 24 | + const handlePointerUp = () => { |
| 25 | + if (draggingRef.current) { |
| 26 | + draggingRef.current = false; |
| 27 | + document.body.style.cursor = ''; |
| 28 | + } |
| 29 | + }; |
| 30 | + |
| 31 | + window.addEventListener('pointermove', handlePointerMove); |
| 32 | + window.addEventListener('pointerup', handlePointerUp); |
| 33 | + return () => { |
| 34 | + window.removeEventListener('pointermove', handlePointerMove); |
| 35 | + window.removeEventListener('pointerup', handlePointerUp); |
| 36 | + }; |
| 37 | + }, [setFlowColumnWidth]); |
| 38 | + |
9 | 39 | return ( |
10 | 40 | <div className="flex bg-gray-50 border-b border-gray-200 sticky top-0 z-10"> |
11 | | - <div className="w-48 shrink-0 bg-gray-100 border-r border-gray-200 flex items-center p-2 text-gray-700 font-semibold sticky left-0 z-20 shadow-[1px_0_0_rgba(0,0,0,0.1)]"> |
12 | | - Flows |
| 41 | + <div |
| 42 | + className="shrink-0 bg-gray-100 border-r border-gray-200 flex items-center p-2 text-gray-700 font-semibold sticky left-0 z-20 shadow-[1px_0_0_rgba(0,0,0,0.1)] relative" |
| 43 | + style={{ width: flowColumnWidth, minWidth: flowColumnWidth, maxWidth: flowColumnWidth }} |
| 44 | + > |
| 45 | + <span>Flows</span> |
| 46 | + <div |
| 47 | + className="absolute top-0 right-0 bottom-0 w-2 cursor-col-resize hover:bg-blue-400 z-30 opacity-50 transition-colors translate-x-1/2" |
| 48 | + onPointerDown={(e) => { |
| 49 | + e.preventDefault(); |
| 50 | + draggingRef.current = true; |
| 51 | + startXRef.current = e.pageX; |
| 52 | + startWidthRef.current = flowColumnWidth; |
| 53 | + document.body.style.cursor = 'col-resize'; |
| 54 | + }} |
| 55 | + /> |
13 | 56 | </div> |
14 | 57 | <div className="flex-grow relative h-10 min-w-[600px]"> |
15 | 58 | {ticks.map((tick) => ( |
|
0 commit comments