import { cn } from '@/ui/lib/utils' import { useEffect, useRef, useState } from 'react' interface ResizeHandleProps extends Omit< React.ComponentProps<'div'>, 'children' | 'onMouseDown' | 'onResize' > { onResize: (delta: number) => void hitAreaClassName?: string } export const ResizeHandle: React.FC = ({ onResize, hitAreaClassName, className = '', ...props }) => { const [isDragging, setIsDragging] = useState(false) const startXref = useRef(0) useEffect(() => { if (!isDragging) return const handleMouseMove = (e: MouseEvent) => { // Calculate how much the mouse has moved const delta = e.clientX - startXref.current // Update the reference point for the next frame startXref.current = e.clientX onResize(delta) } const handleMouseUp = () => { setIsDragging(false) document.body.style.cursor = '' // Reset cursor } // Attach global listeners document.addEventListener('mousemove', handleMouseMove) document.addEventListener('mouseup', handleMouseUp) // Force cursor style on body to prevent flickering during fast drags document.body.style.cursor = 'col-resize' return () => { document.removeEventListener('mousemove', handleMouseMove) document.removeEventListener('mouseup', handleMouseUp) document.body.style.cursor = '' } }, [isDragging, onResize]) const handleMouseDown = (e: React.MouseEvent) => { e.preventDefault() e.stopPropagation() setIsDragging(true) startXref.current = e.clientX } return (