import React, { useState, useRef, useCallback } from 'react' interface SplitterProps { direction: 'horizontal' | 'vertical' initialSize: number minSize?: number maxSize?: number children: [React.ReactNode, React.ReactNode] className?: string reverse?: boolean // İkinci panel için boyut kontrolü } export const Splitter: React.FC = ({ direction, initialSize, minSize = 200, maxSize = 800, children, className = '', reverse = false, }) => { const [size, setSize] = useState(initialSize) const [isDragging, setIsDragging] = useState(false) const splitterRef = useRef(null) const containerRef = useRef(null) const handleMouseDown = useCallback( (e: React.MouseEvent) => { e.preventDefault() setIsDragging(true) const handleMouseMove = (e: MouseEvent) => { if (!splitterRef.current || !containerRef.current) return const rect = containerRef.current.getBoundingClientRect() let newSize: number if (direction === 'horizontal') { if (reverse) { // İkinci panel için boyut kontrolü - sağdan ölçüm newSize = rect.right - e.clientX } else { // İlk panel için boyut kontrolü - soldan ölçüm newSize = e.clientX - rect.left } } else { if (reverse) { // İkinci panel için boyut kontrolü - alttan ölçüm newSize = rect.bottom - e.clientY } else { // İlk panel için boyut kontrolü - üstten ölçüm newSize = e.clientY - rect.top } } newSize = Math.max(minSize, Math.min(maxSize, newSize)) setSize(newSize) } const handleMouseUp = () => { setIsDragging(false) document.removeEventListener('mousemove', handleMouseMove) document.removeEventListener('mouseup', handleMouseUp) } document.addEventListener('mousemove', handleMouseMove) document.addEventListener('mouseup', handleMouseUp) }, [direction, minSize, maxSize, reverse], ) const isHorizontal = direction === 'horizontal' return (
{reverse ? ( <>
{children[0]}
{children[1]}
) : ( <>
{children[0]}
{children[1]}
)}
) }