import { type ReactNode, useLayoutEffect, useRef } from "react"; import { ResizableHandle, ResizablePanel, ResizablePanelGroup, type ImperativePanelHandle, } from "@/src/components/ui/resizable"; interface ResizableDesktopLayoutProps { mainContent: ReactNode; sidebarContent: ReactNode; open: boolean; defaultMainSize?: number; defaultSidebarSize?: number; minMainSize?: number; maxSidebarSize?: number; autoSaveId?: string; className?: string; sidebarPosition?: "left" | "right"; } /** * Reusable component to show/hide resizable panels with a consistent DOM tree. * Always renders the same DOM tree to prevent remounting children and preserve their state. */ export function ResizableDesktopLayout({ mainContent, sidebarContent, open, defaultMainSize = 70, defaultSidebarSize = 30, minMainSize = 30, maxSidebarSize = 60, autoSaveId, className = "flex h-full w-full", sidebarPosition = "right", }: ResizableDesktopLayoutProps) { const sidebarPanelRef = useRef(null); const mainPanelRef = useRef(null); useLayoutEffect(() => { if (open) { sidebarPanelRef.current?.resize(defaultSidebarSize); mainPanelRef.current?.resize(defaultMainSize); } else { sidebarPanelRef.current?.resize(0); mainPanelRef.current?.resize(100); } }, [open, defaultMainSize, defaultSidebarSize]); return ( {sidebarPosition === "left" && ( {sidebarContent} )} {open && }
{mainContent}
{sidebarPosition === "right" && ( {sidebarContent} )}
); }