import { DEFAULT_SIDEBAR_WIDTH, MAX_SIDEBAR_WIDTH, MIN_SIDEBAR_WIDTH, Path, } from "@/app/constant"; import useDrag from "@/app/hooks/useDrag"; import useMobileScreen from "@/app/hooks/useMobileScreen"; import { updateGlobalCSSVars } from "@/app/utils/client"; import { ComponentType, useRef, useState } from "react"; import { useAppConfig } from "@/app/store/config"; export interface MenuWrapperInspectProps { setExternalProps?: (v: Record) => void; setShowPanel?: (v: boolean) => void; showPanel?: boolean; [k: string]: any; } export default function MenuLayout< ListComponentProps extends MenuWrapperInspectProps, PanelComponentProps extends MenuWrapperInspectProps, >( ListComponent: ComponentType, PanelComponent: ComponentType, ) { return function MenuHood(props: ListComponentProps & PanelComponentProps) { const [showPanel, setShowPanel] = useState(false); const [externalProps, setExternalProps] = useState({}); const config = useAppConfig(); const isMobileScreen = useMobileScreen(); const startDragWidth = useRef(config.sidebarWidth ?? DEFAULT_SIDEBAR_WIDTH); // drag side bar const { onDragStart } = useDrag({ customToggle: () => { config.update((config) => { config.sidebarWidth = DEFAULT_SIDEBAR_WIDTH; }); }, customDragMove: (nextWidth: number) => { const { menuWidth } = updateGlobalCSSVars(nextWidth); document.documentElement.style.setProperty( "--menu-width", `${menuWidth}px`, ); config.update((config) => { config.sidebarWidth = nextWidth; }); }, customLimit: (x: number) => Math.max( MIN_SIDEBAR_WIDTH, Math.min(MAX_SIDEBAR_WIDTH, startDragWidth.current + x), ), }); return (
{!isMobileScreen && (
{ startDragWidth.current = config.sidebarWidth; onDragStart(e as any); }} >
 
)}
); }; }