"use client" import * as React from 'react'; import * as ResizablePrimitive from 'react-resizable-panels'; import { DragHandleDots2Icon } from '@radix-ui/react-icons'; import { cn } from '../../../lib/utils'; // Context to share dragging state across panel group const ResizableDraggingContext = React.createContext<{ isDragging: boolean setIsDragging: (value: boolean) => void }>({ isDragging: false, setIsDragging: () => {} }) // Hook to check if panel group is being resized export const useResizableDragging = () => React.useContext(ResizableDraggingContext) const ResizablePanelGroup = ({ className, ...props }: React.ComponentProps) => { const [mounted, setMounted] = React.useState(false) const [isDragging, setIsDragging] = React.useState(false) React.useEffect(() => { setMounted(true) }, []) // SSR fallback - render static flex container if (!mounted) { return (
{props.children}
) } return ( ) } const ResizablePanel = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, defaultSize, minSize, maxSize, children, ...props }, ref) => { const [mounted, setMounted] = React.useState(false) React.useEffect(() => { setMounted(true) }, []) // SSR fallback - render static div with default size if (!mounted) { const direction = (props as any)['data-panel-group-direction'] const sizeStyle = defaultSize ? direction === 'vertical' ? { height: `${defaultSize}%` } : { width: `${defaultSize}%` } : { flex: 1 } return (
{children}
) } return ( {children} ) }) ResizablePanel.displayName = "ResizablePanel" export interface ResizableHandleProps extends React.ComponentProps { withHandle?: boolean; size?: 'sm' | 'md' | 'lg'; showIndicator?: boolean; indicatorHeight?: number; } const ResizableHandle = ({ withHandle, className, size = 'md', showIndicator = false, indicatorHeight = 32, onDragging, ...props }: ResizableHandleProps) => { const [mounted, setMounted] = React.useState(false) const { setIsDragging } = React.useContext(ResizableDraggingContext) React.useEffect(() => { setMounted(true) }, []) // Handle drag state change - update context and call user callback const handleDragging = React.useCallback((isDragging: boolean) => { setIsDragging(isDragging) onDragging?.(isDragging) }, [setIsDragging, onDragging]) // Size variants for hit area const sizeClasses = { sm: 'after:w-0.5', md: 'after:w-1', lg: 'after:w-1.5', } // SSR fallback - render static border if (!mounted) { return (
) } return ( {/* Optional pill indicator */} {showIndicator && (
)} {/* Optional dots handle */} {withHandle && (
)} ) } export { ResizablePanelGroup, ResizablePanel, ResizableHandle } // Re-export types from react-resizable-panels for imperative panel control export type { ImperativePanelHandle } from 'react-resizable-panels'