@lax-wp/design-system 0.14.0 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/data-display/infinite-table/body/cell/InlineCurrencyField.cjs.js +1 -1
- package/dist/components/data-display/infinite-table/body/cell/InlineCurrencyField.cjs.js.map +1 -1
- package/dist/components/data-display/infinite-table/body/cell/InlineCurrencyField.es.js +25 -25
- package/dist/components/data-display/infinite-table/body/cell/InlineCurrencyField.es.js.map +1 -1
- package/dist/components/data-display/modal/Modal.cjs.js +1 -1
- package/dist/components/data-display/modal/Modal.cjs.js.map +1 -1
- package/dist/components/data-display/modal/Modal.es.js +50 -47
- package/dist/components/data-display/modal/Modal.es.js.map +1 -1
- package/dist/components/data-display/resizable-sidebar/ResizableSidebar.cjs.js +1 -1
- package/dist/components/data-display/resizable-sidebar/ResizableSidebar.cjs.js.map +1 -1
- package/dist/components/data-display/resizable-sidebar/ResizableSidebar.d.ts +2 -0
- package/dist/components/data-display/resizable-sidebar/ResizableSidebar.es.js +124 -120
- package/dist/components/data-display/resizable-sidebar/ResizableSidebar.es.js.map +1 -1
- package/dist/components/modal/drawer/Drawer.cjs.js +1 -1
- package/dist/components/modal/drawer/Drawer.cjs.js.map +1 -1
- package/dist/components/modal/drawer/Drawer.es.js +40 -39
- package/dist/components/modal/drawer/Drawer.es.js.map +1 -1
- package/dist/hooks/useResponsiveWidth.cjs.js +2 -0
- package/dist/hooks/useResponsiveWidth.cjs.js.map +1 -0
- package/dist/hooks/useResponsiveWidth.d.ts +5 -0
- package/dist/hooks/useResponsiveWidth.es.js +24 -0
- package/dist/hooks/useResponsiveWidth.es.js.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +296 -293
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResizableSidebar.cjs.js","sources":["../../../../src/components/data-display/resizable-sidebar/ResizableSidebar.tsx"],"sourcesContent":["import cn from \"classnames\";\nimport { AnimatePresence, motion } from \"framer-motion\";\nimport { forwardRef, useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { Resizable } from \"re-resizable\";\n\n/**\n * Sidebar placement options\n */\nexport type ResizableSidebarPlacement = \"left\" | \"right\";\n\n/**\n * Props for the ResizableSidebar component\n */\nexport interface ResizableSidebarProps {\n /** Whether the sidebar is open */\n isOpen: boolean;\n /** Content to display in the sidebar */\n children: React.ReactNode;\n /** Whether to display in full screen mode */\n fullScreen?: boolean;\n /** Callback when drag/resize ends */\n onDragEnd?: (() => void) | null;\n /** Callback when resize occurs */\n onResize?: (width: number) => void;\n /** Additional CSS classes for the wrapper */\n className?: string;\n /** Default size of the sidebar */\n defaultSize?: string;\n /** Minimum width of the sidebar */\n minWidth?: number;\n /** Placement of the sidebar */\n placement?: ResizableSidebarPlacement;\n /** Parent container ID for portal rendering */\n parentContainer?: string;\n /** Header content */\n header?: React.ReactNode;\n /** Unique ID for the sidebar */\n id?: string;\n /** Additional CSS classes for the container */\n containerClassName?: string;\n /** Whether to ignore parent container height */\n ignoreParentContainerHeight?: boolean;\n /** Custom height */\n height?: string;\n /** Whether the main sidebar is expanded (affects max width calculation) */\n isMainSidebarExpanded?: boolean;\n /** Width of the main sidebar when expanded */\n mainSidebarExpandedWidth?: number;\n /** Width of the main sidebar when collapsed */\n mainSidebarCollapsedWidth?: number;\n /** Height offset for navbar */\n navbarHeight?: number;\n}\n\n/**\n * Drag handle component for the resizable sidebar\n */\nconst DragHandle = () => {\n return (\n <div className=\"cursor-ew-resize flex items-center justify-center rounded-full bg-[#1018288F] bg-opacity-55 w-8 h-8 shadow-200 border-[1.5px] border-[#FFFFFF3D]\">\n <svg\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 20 20\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <mask id=\"mask0_36675_12\" maskUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width=\"20\" height=\"20\">\n <rect y=\"20\" width=\"20\" height=\"20\" transform=\"rotate(-90 0 20)\" fill=\"#D9D9D9\" />\n </mask>\n <g mask=\"url(#mask0_36675_12)\">\n <path\n d=\"M15.9583 10L12.7292 6.77084C12.5625 6.60418 12.4792 6.40973 12.4792 6.18751C12.4792 5.96529 12.5625 5.77084 12.7292 5.60418C12.8958 5.43751 13.0938 5.35418 13.3229 5.35418C13.5521 5.35418 13.75 5.43751 13.9167 5.60418L17.1458 8.81251C17.4653 9.13195 17.625 9.52779 17.625 10C17.625 10.4722 17.4653 10.8681 17.1458 11.1875L13.9167 14.4167C13.75 14.5833 13.5521 14.6632 13.3229 14.6563C13.0938 14.6493 12.8958 14.5625 12.7292 14.3958C12.5625 14.2292 12.4792 14.0313 12.4792 13.8021C12.4792 13.5729 12.5625 13.375 12.7292 13.2083L15.9583 10ZM4.04167 10L7.25 13.2083C7.41667 13.375 7.49653 13.5695 7.48958 13.7917C7.48264 14.0139 7.40278 14.2083 7.25 14.375C7.08333 14.5417 6.88542 14.6285 6.65625 14.6354C6.42708 14.6424 6.22917 14.5625 6.0625 14.3958L2.85417 11.1875C2.53472 10.8681 2.375 10.4722 2.375 10C2.375 9.52779 2.53472 9.13195 2.85417 8.81251L6.0625 5.60418C6.22917 5.43751 6.42708 5.35765 6.65625 5.36459C6.88542 5.37154 7.08333 5.45834 7.25 5.62501C7.40278 5.79168 7.48264 5.98612 7.48958 6.20834C7.49653 6.43057 7.41667 6.62501 7.25 6.79168L4.04167 10Z\"\n fill=\"white\"\n />\n </g>\n </svg>\n </div>\n );\n};\n\n/**\n * ResizableSidebar component displays a resizable sidebar panel\n *\n * @example\n * ```tsx\n * <ResizableSidebar\n * isOpen={isOpen}\n * onClose={() => setIsOpen(false)}\n * placement=\"right\"\n * minWidth={300}\n * >\n * <div>Sidebar content</div>\n * </ResizableSidebar>\n * ```\n */\n// Helper functions to reduce cognitive complexity\nconst findParentContainer = (parentContainer: string, setPortalTarget: (target: HTMLElement | null) => void) => {\n const el = document.getElementById(parentContainer);\n if (el) {\n setPortalTarget(el);\n } else {\n requestAnimationFrame(() => {\n const retryEl = document.getElementById(parentContainer);\n if (retryEl) setPortalTarget(retryEl);\n });\n }\n};\n\nconst handleFullScreenToggle = (resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>, fullScreen: boolean) => {\n if (!resizableRef.current) return;\n\n if (fullScreen) {\n localStorage.setItem(\"resizable-sidebar-width-before-fullscreen\", String(resizableRef.current.size?.width));\n } else {\n const width = localStorage.getItem(\"resizable-sidebar-width-before-fullscreen\");\n if (width) {\n resizableRef.current.updateSize({ width: width, height: \"100%\" });\n return;\n }\n }\n resizableRef.current.updateSize({\n width: fullScreen ? \"100vw\" : \"\",\n height: \"100%\",\n });\n};\n\nconst useSidebarEffects = (\n parentContainer: string | undefined,\n isOpen: boolean,\n fullScreen: boolean,\n onResize: ((width: number) => void) | undefined,\n resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>,\n _minWidth: number\n) => {\n const [shouldRenderSidebar, setShouldRenderSidebar] = useState(false);\n const [portalTarget, setPortalTarget] = useState<HTMLElement | null>(null);\n\n useEffect(() => {\n if (!parentContainer || typeof window === \"undefined\") {\n setPortalTarget(null);\n return;\n }\n findParentContainer(parentContainer, setPortalTarget);\n }, [parentContainer]);\n\n useEffect(() => {\n handleFullScreenToggle(resizableRef, fullScreen);\n }, [fullScreen]);\n\n useEffect(() => {\n if (parentContainer && isOpen) {\n const frame = requestAnimationFrame(() => {\n setShouldRenderSidebar(true);\n });\n return () => {\n cancelAnimationFrame(frame);\n setShouldRenderSidebar(false);\n };\n }\n\n if (!parentContainer) {\n setShouldRenderSidebar(true);\n }\n\n if (!isOpen) {\n setShouldRenderSidebar(false);\n }\n }, [isOpen, parentContainer]);\n\n useEffect(() => {\n if (resizableRef.current?.size?.width && onResize) {\n onResize(resizableRef.current.size.width);\n }\n }, [resizableRef.current?.size?.width, onResize]);\n\n return { shouldRenderSidebar, portalTarget };\n};\n\nconst SidebarContent = ({\n isOpen,\n header,\n id,\n ref,\n className,\n containerClassName,\n widthStyle,\n heightStyle,\n motionVariants,\n resizableRef,\n fullScreen,\n maxResizableWidth,\n minWidth,\n handleKey,\n onDragEnd,\n onResize,\n children,\n}: {\n isOpen: boolean;\n header?: React.ReactNode;\n id?: string;\n ref: React.Ref<HTMLDivElement>;\n className?: string;\n containerClassName?: string;\n widthStyle?: string;\n heightStyle: string;\n motionVariants: any;\n resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>;\n fullScreen: boolean;\n maxResizableWidth: number;\n minWidth: number;\n handleKey: string;\n onDragEnd?: (() => void) | null;\n onResize?: (width: number) => void;\n children: React.ReactNode;\n}) => (\n <AnimatePresence>\n {isOpen && (\n <motion.div\n ref={ref}\n id={id}\n initial={motionVariants.initial}\n animate={motionVariants.animate}\n exit={motionVariants.exit}\n transition={{ type: \"tween\", duration: 0.3 }}\n className={cn(\n \"flex-shrink-0 z-50 relative bg-white border-neutral-200 dark:bg-black-800 dark:border-black-700\",\n fullScreen ? \"fixed w-full transition translate-x-4 duration-300\" : \"sticky\",\n className,\n )}\n style={{\n width: widthStyle,\n height: heightStyle,\n }}\n >\n <Resizable\n onResize={(e) => {\n e.stopPropagation();\n const width = resizableRef.current?.size?.width;\n if (onResize) {\n onResize(width || minWidth);\n }\n }}\n onResizeStart={(e) => {\n e.stopPropagation();\n }}\n ref={resizableRef}\n maxWidth={fullScreen ? maxResizableWidth : maxResizableWidth * 0.75}\n minWidth={minWidth}\n minHeight={heightStyle}\n maxHeight={heightStyle}\n enable={fullScreen ? {} : { [handleKey]: true }}\n handleClasses={{\n [handleKey]: cn(\n \"relative w-6 -left-1 flex items-center justify-center bg-transparent transition-colors cursor-ew-resize group z-[9999] hover:bg-neutral-200 dark:hover:bg-neutral-700\",\n ),\n }}\n handleComponent={{\n [handleKey]: (\n <div\n className={cn(\n \"absolute -left-2.5 top-1/2 -translate-y-1/2 flex items-center justify-center w-8 h-12 cursor-ew-resize opacity-0 group-hover:opacity-100 hover:opacity-100 active:opacity-100 transition-opacity z-[9999]\",\n handleKey === \"left\" && \"-right-2.5 -left-auto\",\n )}\n >\n <DragHandle />\n </div>\n ),\n }}\n className=\"!h-full\"\n onResizeStop={onDragEnd || undefined}\n >\n <div\n className={cn(\n \"h-full w-full flex flex-col overflow-hidden @container/sidebar border-b border-neutral-200 dark:border-black-700 bg-white dark:bg-black-800 dark:border\",\n containerClassName,\n )}\n >\n {header ? <div className=\"py-4 px-6\">{header || null}</div> : null}\n <div className=\"flex-1 overflow-y-auto overflow-x-hidden\">{children}</div>\n </div>\n </Resizable>\n </motion.div>\n )} \n </AnimatePresence>\n);\n\nexport const ResizableSidebar = forwardRef<HTMLDivElement, ResizableSidebarProps>(\n (\n {\n isOpen,\n children,\n fullScreen = false,\n defaultSize = undefined,\n minWidth = 400,\n onDragEnd = null,\n onResize,\n className,\n placement = \"right\",\n parentContainer,\n header,\n id,\n containerClassName,\n ignoreParentContainerHeight = false,\n height,\n isMainSidebarExpanded = false,\n mainSidebarExpandedWidth = 280,\n mainSidebarCollapsedWidth = 80,\n navbarHeight = 64,\n },\n ref\n ) => {\n const mainSidebarWidth = isMainSidebarExpanded ? mainSidebarExpandedWidth : mainSidebarCollapsedWidth;\n const resizableRef = useRef<React.ElementRef<typeof Resizable>>(null);\n const { shouldRenderSidebar, portalTarget } = useSidebarEffects(\n parentContainer,\n isOpen,\n fullScreen,\n onResize,\n resizableRef,\n minWidth\n );\n\n const maxResizableWidth = typeof window !== \"undefined\" ? window.innerWidth - mainSidebarWidth : 0;\n\n const widthStyle = defaultSize;\n const isRight = placement === \"right\";\n const heightStyle = height || (parentContainer && !ignoreParentContainerHeight ? \"100%\" : `calc(100vh - ${navbarHeight}px)`);\n\n const motionVariants = {\n initial: { x: isRight ? \"100%\" : \"-100%\" },\n animate: { x: 0 },\n exit: { x: isRight ? \"100%\" : \"-100%\" },\n };\n\n const handleKey = isRight ? \"left\" : \"right\";\n\n const sidebarContent = (\n <SidebarContent\n isOpen={isOpen}\n header={header}\n id={id}\n ref={ref}\n className={className}\n containerClassName={containerClassName}\n widthStyle={widthStyle}\n heightStyle={heightStyle}\n motionVariants={motionVariants}\n resizableRef={resizableRef}\n fullScreen={fullScreen}\n maxResizableWidth={maxResizableWidth}\n minWidth={minWidth}\n handleKey={handleKey}\n onDragEnd={onDragEnd}\n onResize={onResize}\n >\n {children}\n </SidebarContent>\n );\n\n if (parentContainer) {\n if (!shouldRenderSidebar || !portalTarget) return null;\n return ReactDOM.createPortal(sidebarContent, portalTarget);\n }\n\n if (!shouldRenderSidebar) return null;\n\n return sidebarContent;\n }\n);\n\nResizableSidebar.displayName = \"ResizableSidebar\";\n"],"names":["DragHandle","jsx","jsxs","findParentContainer","parentContainer","setPortalTarget","el","retryEl","handleFullScreenToggle","resizableRef","fullScreen","width","useSidebarEffects","isOpen","onResize","_minWidth","shouldRenderSidebar","setShouldRenderSidebar","useState","portalTarget","useEffect","frame","SidebarContent","header","id","ref","className","containerClassName","widthStyle","heightStyle","motionVariants","maxResizableWidth","minWidth","handleKey","onDragEnd","children","AnimatePresence","motion","cn","Resizable","e","ResizableSidebar","forwardRef","defaultSize","placement","ignoreParentContainerHeight","height","isMainSidebarExpanded","mainSidebarExpandedWidth","mainSidebarCollapsedWidth","navbarHeight","mainSidebarWidth","useRef","isRight","sidebarContent","ReactDOM"],"mappings":"gQA0DMA,EAAa,IAEfC,EAAAA,IAAC,MAAA,CAAI,UAAU,mJACb,SAAAC,EAAAA,KAAC,MAAA,CACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,MAAM,6BAEN,SAAA,CAAAD,EAAAA,IAAC,OAAA,CAAK,GAAG,iBAAiB,UAAU,iBAAiB,EAAE,IAAI,EAAE,IAAI,MAAM,KAAK,OAAO,KACjF,SAAAA,EAAAA,IAAC,OAAA,CAAK,EAAE,KAAK,MAAM,KAAK,OAAO,KAAK,UAAU,mBAAmB,K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W1C,GAAmB,CAACyC,EAA8B,OAAS,gBAAgBK,CAAY,OAEhHpB,EAAiB,CACrB,QAAS,CAAE,EAAGuB,EAAU,OAAS,OAAA,EACjC,QAAS,CAAE,EAAG,CAAA,EACd,KAAM,CAAE,EAAGA,EAAU,OAAS,OAAA,CAAQ,EAGlCpB,EAAYoB,EAAU,OAAS,QAE/BC,EACJrD,EAAAA,IAACqB,EAAA,CACC,OAAAT,EACA,OAAAU,EACA,GAAAC,EACA,IAAAC,EACA,UAAAC,EACA,mBAAAC,EACA,WAAAC,EACA,YAAAC,EACA,eAAAC,EACA,aAAArB,EACA,WAAAC,EACA,kBAAAqB,EACA,SAAAC,EACA,UAAAC,EACA,UAAAC,EACA,SAAApB,EAEC,SAAAqB,CAAA,CAAA,EAIL,OAAI/B,EACE,CAACY,GAAuB,CAACG,EAAqB,KAC3CoC,EAAS,aAAaD,EAAgBnC,CAAY,EAGtDH,EAEEsC,EAF0B,IAGnC,CACF,EAEAb,EAAiB,YAAc"}
|
|
1
|
+
{"version":3,"file":"ResizableSidebar.cjs.js","sources":["../../../../src/components/data-display/resizable-sidebar/ResizableSidebar.tsx"],"sourcesContent":["import cn from \"classnames\";\nimport { AnimatePresence, motion } from \"framer-motion\";\nimport { forwardRef, useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { Resizable } from \"re-resizable\";\n\nimport { useResponsiveWidth } from \"../../../hooks/useResponsiveWidth\";\n\n/**\n * Sidebar placement options\n */\nexport type ResizableSidebarPlacement = \"left\" | \"right\";\n\n/**\n * Props for the ResizableSidebar component\n */\nexport interface ResizableSidebarProps {\n /** Whether the sidebar is open */\n isOpen: boolean;\n /** Content to display in the sidebar */\n children: React.ReactNode;\n /** Whether to display in full screen mode */\n fullScreen?: boolean;\n /** Callback when drag/resize ends */\n onDragEnd?: (() => void) | null;\n /** Callback when resize occurs */\n onResize?: (width: number) => void;\n /** Additional CSS classes for the wrapper */\n className?: string;\n /** Default size of the sidebar */\n defaultSize?: string;\n /** Minimum width of the sidebar */\n minWidth?: number;\n /** Placement of the sidebar */\n placement?: ResizableSidebarPlacement;\n /** Parent container ID for portal rendering */\n parentContainer?: string;\n /** Header content */\n header?: React.ReactNode;\n /** Unique ID for the sidebar */\n id?: string;\n /** Additional CSS classes for the container */\n containerClassName?: string;\n /** Additional CSS classes for the header wrapper */\n headerClassName?: string;\n /** Whether to ignore parent container height */\n ignoreParentContainerHeight?: boolean;\n /** Custom height */\n height?: string;\n /** Whether the main sidebar is expanded (affects max width calculation) */\n isMainSidebarExpanded?: boolean;\n /** Width of the main sidebar when expanded */\n mainSidebarExpandedWidth?: number;\n /** Width of the main sidebar when collapsed */\n mainSidebarCollapsedWidth?: number;\n /** Height offset for navbar */\n navbarHeight?: number;\n}\n\n/**\n * Drag handle component for the resizable sidebar\n */\nconst DragHandle = () => {\n return (\n <div className=\"cursor-ew-resize flex items-center justify-center rounded-full bg-[#1018288F] bg-opacity-55 w-8 h-8 shadow-200 border-[1.5px] border-[#FFFFFF3D]\">\n <svg\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 20 20\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <mask id=\"mask0_36675_12\" maskUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width=\"20\" height=\"20\">\n <rect y=\"20\" width=\"20\" height=\"20\" transform=\"rotate(-90 0 20)\" fill=\"#D9D9D9\" />\n </mask>\n <g mask=\"url(#mask0_36675_12)\">\n <path\n d=\"M15.9583 10L12.7292 6.77084C12.5625 6.60418 12.4792 6.40973 12.4792 6.18751C12.4792 5.96529 12.5625 5.77084 12.7292 5.60418C12.8958 5.43751 13.0938 5.35418 13.3229 5.35418C13.5521 5.35418 13.75 5.43751 13.9167 5.60418L17.1458 8.81251C17.4653 9.13195 17.625 9.52779 17.625 10C17.625 10.4722 17.4653 10.8681 17.1458 11.1875L13.9167 14.4167C13.75 14.5833 13.5521 14.6632 13.3229 14.6563C13.0938 14.6493 12.8958 14.5625 12.7292 14.3958C12.5625 14.2292 12.4792 14.0313 12.4792 13.8021C12.4792 13.5729 12.5625 13.375 12.7292 13.2083L15.9583 10ZM4.04167 10L7.25 13.2083C7.41667 13.375 7.49653 13.5695 7.48958 13.7917C7.48264 14.0139 7.40278 14.2083 7.25 14.375C7.08333 14.5417 6.88542 14.6285 6.65625 14.6354C6.42708 14.6424 6.22917 14.5625 6.0625 14.3958L2.85417 11.1875C2.53472 10.8681 2.375 10.4722 2.375 10C2.375 9.52779 2.53472 9.13195 2.85417 8.81251L6.0625 5.60418C6.22917 5.43751 6.42708 5.35765 6.65625 5.36459C6.88542 5.37154 7.08333 5.45834 7.25 5.62501C7.40278 5.79168 7.48264 5.98612 7.48958 6.20834C7.49653 6.43057 7.41667 6.62501 7.25 6.79168L4.04167 10Z\"\n fill=\"white\"\n />\n </g>\n </svg>\n </div>\n );\n};\n\n/**\n * ResizableSidebar component displays a resizable sidebar panel\n *\n * @example\n * ```tsx\n * <ResizableSidebar\n * isOpen={isOpen}\n * onClose={() => setIsOpen(false)}\n * placement=\"right\"\n * minWidth={300}\n * >\n * <div>Sidebar content</div>\n * </ResizableSidebar>\n * ```\n */\n// Helper functions to reduce cognitive complexity\nconst findParentContainer = (parentContainer: string, setPortalTarget: (target: HTMLElement | null) => void) => {\n const el = document.getElementById(parentContainer);\n if (el) {\n setPortalTarget(el);\n } else {\n requestAnimationFrame(() => {\n const retryEl = document.getElementById(parentContainer);\n if (retryEl) setPortalTarget(retryEl);\n });\n }\n};\n\nconst handleFullScreenToggle = (resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>, fullScreen: boolean) => {\n if (!resizableRef.current) return;\n\n if (fullScreen) {\n localStorage.setItem(\"resizable-sidebar-width-before-fullscreen\", String(resizableRef.current.size?.width));\n } else {\n const width = localStorage.getItem(\"resizable-sidebar-width-before-fullscreen\");\n if (width) {\n resizableRef.current.updateSize({ width: width, height: \"100%\" });\n return;\n }\n }\n resizableRef.current.updateSize({\n width: fullScreen ? \"100vw\" : \"\",\n height: \"100%\",\n });\n};\n\nconst useSidebarEffects = (\n parentContainer: string | undefined,\n isOpen: boolean,\n fullScreen: boolean,\n onResize: ((width: number) => void) | undefined,\n resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>,\n _minWidth: number\n) => {\n const [shouldRenderSidebar, setShouldRenderSidebar] = useState(false);\n const [portalTarget, setPortalTarget] = useState<HTMLElement | null>(null);\n\n useEffect(() => {\n if (!parentContainer || typeof window === \"undefined\") {\n setPortalTarget(null);\n return;\n }\n findParentContainer(parentContainer, setPortalTarget);\n }, [parentContainer]);\n\n useEffect(() => {\n handleFullScreenToggle(resizableRef, fullScreen);\n }, [fullScreen]);\n\n useEffect(() => {\n if (parentContainer && isOpen) {\n const frame = requestAnimationFrame(() => {\n setShouldRenderSidebar(true);\n });\n return () => {\n cancelAnimationFrame(frame);\n setShouldRenderSidebar(false);\n };\n }\n\n if (!parentContainer) {\n setShouldRenderSidebar(true);\n }\n\n if (!isOpen) {\n setShouldRenderSidebar(false);\n }\n }, [isOpen, parentContainer]);\n\n useEffect(() => {\n if (resizableRef.current?.size?.width && onResize) {\n onResize(resizableRef.current.size.width);\n }\n }, [resizableRef.current?.size?.width, onResize]);\n\n return { shouldRenderSidebar, portalTarget };\n};\n\nconst SidebarContent = ({\n isOpen,\n header,\n id,\n ref,\n className,\n containerClassName,\n headerClassName,\n widthStyle,\n heightStyle,\n motionVariants,\n resizableRef,\n fullScreen,\n maxResizableWidth,\n minWidth,\n handleKey,\n onDragEnd,\n onResize,\n children,\n}: {\n isOpen: boolean;\n header?: React.ReactNode;\n id?: string;\n ref: React.Ref<HTMLDivElement>;\n className?: string;\n containerClassName?: string;\n headerClassName?: string;\n widthStyle?: string | number;\n heightStyle: string;\n motionVariants: any;\n resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>;\n fullScreen: boolean;\n maxResizableWidth: number;\n minWidth: number;\n handleKey: string;\n onDragEnd?: (() => void) | null;\n onResize?: (width: number) => void;\n children: React.ReactNode;\n}) => (\n <AnimatePresence>\n {isOpen && (\n <motion.div\n ref={ref}\n id={id}\n initial={motionVariants.initial}\n animate={motionVariants.animate}\n exit={motionVariants.exit}\n transition={{ type: \"tween\", duration: 0.3 }}\n className={cn(\n \"flex-shrink-0 z-50 relative bg-white border-neutral-200 dark:bg-black-800 dark:border-black-700\",\n fullScreen ? \"fixed w-full transition translate-x-4 duration-300\" : \"sticky\",\n className,\n )}\n style={{\n width: widthStyle,\n height: heightStyle,\n }}\n >\n <Resizable\n onResize={(e) => {\n e.stopPropagation();\n const width = resizableRef.current?.size?.width;\n if (onResize) {\n onResize(width || minWidth);\n }\n }}\n onResizeStart={(e) => {\n e.stopPropagation();\n }}\n ref={resizableRef}\n maxWidth={fullScreen ? maxResizableWidth : maxResizableWidth * 0.75}\n minWidth={minWidth}\n minHeight={heightStyle}\n maxHeight={heightStyle}\n enable={fullScreen ? {} : { [handleKey]: true }}\n handleClasses={{\n [handleKey]: cn(\n \"relative w-6 -left-1 flex items-center justify-center bg-transparent transition-colors cursor-ew-resize group z-[9999] hover:bg-neutral-200 dark:hover:bg-neutral-700\",\n ),\n }}\n handleComponent={{\n [handleKey]: (\n <div\n className={cn(\n \"absolute -left-2.5 top-1/2 -translate-y-1/2 flex items-center justify-center w-8 h-12 cursor-ew-resize opacity-0 group-hover:opacity-100 hover:opacity-100 active:opacity-100 transition-opacity z-[9999]\",\n handleKey === \"left\" && \"-right-2.5 -left-auto\",\n )}\n >\n <DragHandle />\n </div>\n ),\n }}\n className=\"!h-full\"\n onResizeStop={onDragEnd || undefined}\n >\n <div\n className={cn(\n \"h-full w-full flex flex-col overflow-hidden @container/sidebar border-b border-neutral-200 dark:border-black-700 bg-white dark:bg-black-800 dark:border\",\n containerClassName,\n )}\n >\n {header ? <div className={cn(\"py-4 px-6\", headerClassName)}>{header || null}</div> : null}\n <div className=\"flex-1 overflow-y-auto overflow-x-hidden\">{children}</div>\n </div>\n </Resizable>\n </motion.div>\n )} \n </AnimatePresence>\n);\n\nexport const ResizableSidebar = forwardRef<HTMLDivElement, ResizableSidebarProps>(\n (\n {\n isOpen,\n children,\n fullScreen = false,\n defaultSize = undefined,\n minWidth = 400,\n onDragEnd = null,\n onResize,\n className,\n placement = \"right\",\n parentContainer,\n header,\n id,\n containerClassName,\n headerClassName,\n ignoreParentContainerHeight = false,\n height,\n isMainSidebarExpanded = false,\n mainSidebarExpandedWidth = 280,\n mainSidebarCollapsedWidth = 80,\n navbarHeight = 64,\n },\n ref\n ) => {\n const mainSidebarWidth = isMainSidebarExpanded ? mainSidebarExpandedWidth : mainSidebarCollapsedWidth;\n const resizableRef = useRef<React.ElementRef<typeof Resizable>>(null);\n const { shouldRenderSidebar, portalTarget } = useSidebarEffects(\n parentContainer,\n isOpen,\n fullScreen,\n onResize,\n resizableRef,\n minWidth\n );\n\n const maxResizableWidth = typeof window !== \"undefined\" ? window.innerWidth - mainSidebarWidth : 0;\n\n // Passed sizes are the desktop maximum; both the drag floor and the open\n // width shrink by viewport breakpoint.\n const responsiveMinWidth = useResponsiveWidth(minWidth);\n const responsiveDefaultSize = useResponsiveWidth(defaultSize);\n\n const widthStyle = responsiveDefaultSize;\n const isRight = placement === \"right\";\n const heightStyle = height || (parentContainer && !ignoreParentContainerHeight ? \"100%\" : `calc(100vh - ${navbarHeight}px)`);\n\n const motionVariants = {\n initial: { x: isRight ? \"100%\" : \"-100%\" },\n animate: { x: 0 },\n exit: { x: isRight ? \"100%\" : \"-100%\" },\n };\n\n const handleKey = isRight ? \"left\" : \"right\";\n\n const sidebarContent = (\n <SidebarContent\n isOpen={isOpen}\n header={header}\n id={id}\n ref={ref}\n className={className}\n containerClassName={containerClassName}\n headerClassName={headerClassName}\n widthStyle={widthStyle}\n heightStyle={heightStyle}\n motionVariants={motionVariants}\n resizableRef={resizableRef}\n fullScreen={fullScreen}\n maxResizableWidth={maxResizableWidth}\n minWidth={responsiveMinWidth}\n handleKey={handleKey}\n onDragEnd={onDragEnd}\n onResize={onResize}\n >\n {children}\n </SidebarContent>\n );\n\n if (parentContainer) {\n if (!shouldRenderSidebar || !portalTarget) return null;\n return ReactDOM.createPortal(sidebarContent, portalTarget);\n }\n\n if (!shouldRenderSidebar) return null;\n\n return sidebarContent;\n }\n);\n\nResizableSidebar.displayName = \"ResizableSidebar\";\n"],"names":["DragHandle","jsx","jsxs","findParentContainer","parentContainer","setPortalTarget","el","retryEl","handleFullScreenToggle","resizableRef","fullScreen","width","useSidebarEffects","isOpen","onResize","_minWidth","shouldRenderSidebar","setShouldRenderSidebar","useState","portalTarget","useEffect","frame","SidebarContent","header","id","ref","className","containerClassName","headerClassName","widthStyle","heightStyle","motionVariants","maxResizableWidth","minWidth","handleKey","onDragEnd","children","AnimatePresence","motion","cn","Resizable","e","ResizableSidebar","forwardRef","defaultSize","placement","ignoreParentContainerHeight","height","isMainSidebarExpanded","mainSidebarExpandedWidth","mainSidebarCollapsedWidth","navbarHeight","mainSidebarWidth","useRef","responsiveMinWidth","useResponsiveWidth","isRight","sidebarContent","ReactDOM"],"mappings":"sTA8DMA,EAAa,IAEfC,EAAAA,IAAC,MAAA,CAAI,UAAU,mJACb,SAAAC,EAAAA,KAAC,MAAA,CACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,MAAM,6BAEN,SAAA,CAAAD,EAAAA,IAAC,OAAA,CAAK,GAAG,iBAAiB,UAAU,iBAAiB,EAAE,IAAI,EAAE,IAAI,MAAM,KAAK,OAAO,KACjF,SAAAA,EAAAA,IAAC,OAAA,CAAK,EAAE,KAAK,MAAM,KAAK,OAAO,KAAK,UAAU,mBAAmB,KAAK,SAAA,CAAU,CAAA,CAClF,EACAA,EAAAA,IAAC,IAAA,CAAE,KAAK,uBACN,SAAAA,EAAAA,IAAC,OAAA,CACC,EAAE,yiCACF,KAAK,OAAA,CAAA,CACP,CACF,CAAA,CAAA,CAAA,EAEJ,EAoBEE,EAAsB,CAACC,EAAyBC,IAA0D,CAC9G,MAAMC,EAAK,SAAS,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,OAAS,OAAA,EACjC,QAAS,CAAE,EAAG,CAAA,EACd,KAAM,CAAE,EAAGA,EAAU,OAAS,OAAA,CAAQ,EAGlCtB,EAAYsB,EAAU,OAAS,QAE/BC,EACJxD,EAAAA,IAACqB,EAAA,CACC,OAAAT,EACA,OAAAU,EACA,GAAAC,EACA,IAAAC,EACA,UAAAC,EACA,mBAAAC,EACA,gBAAAC,EACA,WAAAC,EACA,YAAAC,EACA,eAAAC,EACA,aAAAtB,EACA,WAAAC,EACA,kBAAAsB,EACA,SAAUsB,EACV,UAAApB,EACA,UAAAC,EACA,SAAArB,EAEC,SAAAsB,CAAA,CAAA,EAIL,OAAIhC,EACE,CAACY,GAAuB,CAACG,EAAqB,KAC3CuC,EAAS,aAAaD,EAAgBtC,CAAY,EAGtDH,EAEEyC,EAF0B,IAGnC,CACF,EAEAf,EAAiB,YAAc"}
|
|
@@ -32,6 +32,8 @@ export interface ResizableSidebarProps {
|
|
|
32
32
|
id?: string;
|
|
33
33
|
/** Additional CSS classes for the container */
|
|
34
34
|
containerClassName?: string;
|
|
35
|
+
/** Additional CSS classes for the header wrapper */
|
|
36
|
+
headerClassName?: string;
|
|
35
37
|
/** Whether to ignore parent container height */
|
|
36
38
|
ignoreParentContainerHeight?: boolean;
|
|
37
39
|
/** Custom height */
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { AnimatePresence as
|
|
4
|
-
import { forwardRef as B, useRef as H, useState as L, useEffect as
|
|
5
|
-
import
|
|
6
|
-
import { Resizable as
|
|
7
|
-
|
|
1
|
+
import { jsx as r, jsxs as W } from "react/jsx-runtime";
|
|
2
|
+
import m from "../../../_virtual/index.es.js";
|
|
3
|
+
import { AnimatePresence as M, motion as R } from "framer-motion";
|
|
4
|
+
import { forwardRef as B, useRef as H, useState as L, useEffect as v } from "react";
|
|
5
|
+
import T from "react-dom";
|
|
6
|
+
import { Resizable as q } from "re-resizable";
|
|
7
|
+
import { useResponsiveWidth as N } from "../../../hooks/useResponsiveWidth.es.js";
|
|
8
|
+
const U = () => /* @__PURE__ */ r("div", { className: "cursor-ew-resize flex items-center justify-center rounded-full bg-[#1018288F] bg-opacity-55 w-8 h-8 shadow-200 border-[1.5px] border-[#FFFFFF3D]", children: /* @__PURE__ */ W(
|
|
8
9
|
"svg",
|
|
9
10
|
{
|
|
10
11
|
width: "20",
|
|
@@ -13,8 +14,8 @@ const T = () => /* @__PURE__ */ i("div", { className: "cursor-ew-resize flex ite
|
|
|
13
14
|
fill: "none",
|
|
14
15
|
xmlns: "http://www.w3.org/2000/svg",
|
|
15
16
|
children: [
|
|
16
|
-
/* @__PURE__ */
|
|
17
|
-
/* @__PURE__ */
|
|
17
|
+
/* @__PURE__ */ r("mask", { id: "mask0_36675_12", maskUnits: "userSpaceOnUse", x: "0", y: "0", width: "20", height: "20", children: /* @__PURE__ */ r("rect", { y: "20", width: "20", height: "20", transform: "rotate(-90 0 20)", fill: "#D9D9D9" }) }),
|
|
18
|
+
/* @__PURE__ */ r("g", { mask: "url(#mask0_36675_12)", children: /* @__PURE__ */ r(
|
|
18
19
|
"path",
|
|
19
20
|
{
|
|
20
21
|
d: "M15.9583 10L12.7292 6.77084C12.5625 6.60418 12.4792 6.40973 12.4792 6.18751C12.4792 5.96529 12.5625 5.77084 12.7292 5.60418C12.8958 5.43751 13.0938 5.35418 13.3229 5.35418C13.5521 5.35418 13.75 5.43751 13.9167 5.60418L17.1458 8.81251C17.4653 9.13195 17.625 9.52779 17.625 10C17.625 10.4722 17.4653 10.8681 17.1458 11.1875L13.9167 14.4167C13.75 14.5833 13.5521 14.6632 13.3229 14.6563C13.0938 14.6493 12.8958 14.5625 12.7292 14.3958C12.5625 14.2292 12.4792 14.0313 12.4792 13.8021C12.4792 13.5729 12.5625 13.375 12.7292 13.2083L15.9583 10ZM4.04167 10L7.25 13.2083C7.41667 13.375 7.49653 13.5695 7.48958 13.7917C7.48264 14.0139 7.40278 14.2083 7.25 14.375C7.08333 14.5417 6.88542 14.6285 6.65625 14.6354C6.42708 14.6424 6.22917 14.5625 6.0625 14.3958L2.85417 11.1875C2.53472 10.8681 2.375 10.4722 2.375 10C2.375 9.52779 2.53472 9.13195 2.85417 8.81251L6.0625 5.60418C6.22917 5.43751 6.42708 5.35765 6.65625 5.36459C6.88542 5.37154 7.08333 5.45834 7.25 5.62501C7.40278 5.79168 7.48264 5.98612 7.48958 6.20834C7.49653 6.43057 7.41667 6.62501 7.25 6.79168L4.04167 10Z",
|
|
@@ -23,20 +24,20 @@ const T = () => /* @__PURE__ */ i("div", { className: "cursor-ew-resize flex ite
|
|
|
23
24
|
) })
|
|
24
25
|
]
|
|
25
26
|
}
|
|
26
|
-
) }),
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
) }), Z = (e, t) => {
|
|
28
|
+
const i = document.getElementById(e);
|
|
29
|
+
i ? t(i) : requestAnimationFrame(() => {
|
|
29
30
|
const n = document.getElementById(e);
|
|
30
31
|
n && t(n);
|
|
31
32
|
});
|
|
32
|
-
},
|
|
33
|
+
}, $ = (e, t) => {
|
|
33
34
|
if (e.current) {
|
|
34
35
|
if (t)
|
|
35
36
|
localStorage.setItem("resizable-sidebar-width-before-fullscreen", String(e.current.size?.width));
|
|
36
37
|
else {
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
e.current.updateSize({ width:
|
|
38
|
+
const i = localStorage.getItem("resizable-sidebar-width-before-fullscreen");
|
|
39
|
+
if (i) {
|
|
40
|
+
e.current.updateSize({ width: i, height: "100%" });
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -45,176 +46,179 @@ const T = () => /* @__PURE__ */ i("div", { className: "cursor-ew-resize flex ite
|
|
|
45
46
|
height: "100%"
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
|
-
},
|
|
49
|
-
const [
|
|
50
|
-
return
|
|
49
|
+
}, G = (e, t, i, n, s, w) => {
|
|
50
|
+
const [d, a] = L(!1), [l, o] = L(null);
|
|
51
|
+
return v(() => {
|
|
51
52
|
if (!e || typeof window > "u") {
|
|
52
|
-
|
|
53
|
+
o(null);
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
}, [e]),
|
|
57
|
-
|
|
58
|
-
}, [
|
|
56
|
+
Z(e, o);
|
|
57
|
+
}, [e]), v(() => {
|
|
58
|
+
$(s, i);
|
|
59
|
+
}, [i]), v(() => {
|
|
59
60
|
if (e && t) {
|
|
60
|
-
const
|
|
61
|
-
|
|
61
|
+
const c = requestAnimationFrame(() => {
|
|
62
|
+
a(!0);
|
|
62
63
|
});
|
|
63
64
|
return () => {
|
|
64
|
-
cancelAnimationFrame(
|
|
65
|
+
cancelAnimationFrame(c), a(!1);
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
|
-
e ||
|
|
68
|
-
}, [t, e]),
|
|
69
|
-
|
|
70
|
-
}, [
|
|
71
|
-
},
|
|
68
|
+
e || a(!0), t || a(!1);
|
|
69
|
+
}, [t, e]), v(() => {
|
|
70
|
+
s.current?.size?.width && n && n(s.current.size.width);
|
|
71
|
+
}, [s.current?.size?.width, n]), { shouldRenderSidebar: d, portalTarget: l };
|
|
72
|
+
}, J = ({
|
|
72
73
|
isOpen: e,
|
|
73
74
|
header: t,
|
|
74
|
-
id:
|
|
75
|
+
id: i,
|
|
75
76
|
ref: n,
|
|
76
|
-
className:
|
|
77
|
-
containerClassName:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
className: s,
|
|
78
|
+
containerClassName: w,
|
|
79
|
+
headerClassName: d,
|
|
80
|
+
widthStyle: a,
|
|
81
|
+
heightStyle: l,
|
|
82
|
+
motionVariants: o,
|
|
83
|
+
resizableRef: c,
|
|
84
|
+
fullScreen: u,
|
|
85
|
+
maxResizableWidth: g,
|
|
86
|
+
minWidth: b,
|
|
85
87
|
handleKey: h,
|
|
86
88
|
onDragEnd: x,
|
|
87
|
-
onResize:
|
|
88
|
-
children:
|
|
89
|
-
}) => /* @__PURE__ */
|
|
90
|
-
|
|
89
|
+
onResize: p,
|
|
90
|
+
children: y
|
|
91
|
+
}) => /* @__PURE__ */ r(M, { children: e && /* @__PURE__ */ r(
|
|
92
|
+
R.div,
|
|
91
93
|
{
|
|
92
94
|
ref: n,
|
|
93
|
-
id:
|
|
94
|
-
initial:
|
|
95
|
-
animate:
|
|
96
|
-
exit:
|
|
95
|
+
id: i,
|
|
96
|
+
initial: o.initial,
|
|
97
|
+
animate: o.animate,
|
|
98
|
+
exit: o.exit,
|
|
97
99
|
transition: { type: "tween", duration: 0.3 },
|
|
98
|
-
className:
|
|
100
|
+
className: m(
|
|
99
101
|
"flex-shrink-0 z-50 relative bg-white border-neutral-200 dark:bg-black-800 dark:border-black-700",
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
u ? "fixed w-full transition translate-x-4 duration-300" : "sticky",
|
|
103
|
+
s
|
|
102
104
|
),
|
|
103
105
|
style: {
|
|
104
|
-
width:
|
|
105
|
-
height:
|
|
106
|
+
width: a,
|
|
107
|
+
height: l
|
|
106
108
|
},
|
|
107
|
-
children: /* @__PURE__ */
|
|
108
|
-
|
|
109
|
+
children: /* @__PURE__ */ r(
|
|
110
|
+
q,
|
|
109
111
|
{
|
|
110
|
-
onResize: (
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
112
|
+
onResize: (f) => {
|
|
113
|
+
f.stopPropagation();
|
|
114
|
+
const k = c.current?.size?.width;
|
|
115
|
+
p && p(k || b);
|
|
114
116
|
},
|
|
115
|
-
onResizeStart: (
|
|
116
|
-
|
|
117
|
+
onResizeStart: (f) => {
|
|
118
|
+
f.stopPropagation();
|
|
117
119
|
},
|
|
118
|
-
ref:
|
|
119
|
-
maxWidth:
|
|
120
|
-
minWidth:
|
|
121
|
-
minHeight:
|
|
122
|
-
maxHeight:
|
|
123
|
-
enable:
|
|
120
|
+
ref: c,
|
|
121
|
+
maxWidth: u ? g : g * 0.75,
|
|
122
|
+
minWidth: b,
|
|
123
|
+
minHeight: l,
|
|
124
|
+
maxHeight: l,
|
|
125
|
+
enable: u ? {} : { [h]: !0 },
|
|
124
126
|
handleClasses: {
|
|
125
|
-
[h]:
|
|
127
|
+
[h]: m(
|
|
126
128
|
"relative w-6 -left-1 flex items-center justify-center bg-transparent transition-colors cursor-ew-resize group z-[9999] hover:bg-neutral-200 dark:hover:bg-neutral-700"
|
|
127
129
|
)
|
|
128
130
|
},
|
|
129
131
|
handleComponent: {
|
|
130
|
-
[h]: /* @__PURE__ */
|
|
132
|
+
[h]: /* @__PURE__ */ r(
|
|
131
133
|
"div",
|
|
132
134
|
{
|
|
133
|
-
className:
|
|
135
|
+
className: m(
|
|
134
136
|
"absolute -left-2.5 top-1/2 -translate-y-1/2 flex items-center justify-center w-8 h-12 cursor-ew-resize opacity-0 group-hover:opacity-100 hover:opacity-100 active:opacity-100 transition-opacity z-[9999]",
|
|
135
137
|
h === "left" && "-right-2.5 -left-auto"
|
|
136
138
|
),
|
|
137
|
-
children: /* @__PURE__ */
|
|
139
|
+
children: /* @__PURE__ */ r(U, {})
|
|
138
140
|
}
|
|
139
141
|
)
|
|
140
142
|
},
|
|
141
143
|
className: "!h-full",
|
|
142
144
|
onResizeStop: x || void 0,
|
|
143
|
-
children: /* @__PURE__ */
|
|
145
|
+
children: /* @__PURE__ */ W(
|
|
144
146
|
"div",
|
|
145
147
|
{
|
|
146
|
-
className:
|
|
148
|
+
className: m(
|
|
147
149
|
"h-full w-full flex flex-col overflow-hidden @container/sidebar border-b border-neutral-200 dark:border-black-700 bg-white dark:bg-black-800 dark:border",
|
|
148
|
-
|
|
150
|
+
w
|
|
149
151
|
),
|
|
150
152
|
children: [
|
|
151
|
-
t ? /* @__PURE__ */
|
|
152
|
-
/* @__PURE__ */
|
|
153
|
+
t ? /* @__PURE__ */ r("div", { className: m("py-4 px-6", d), children: t || null }) : null,
|
|
154
|
+
/* @__PURE__ */ r("div", { className: "flex-1 overflow-y-auto overflow-x-hidden", children: y })
|
|
153
155
|
]
|
|
154
156
|
}
|
|
155
157
|
)
|
|
156
158
|
}
|
|
157
159
|
)
|
|
158
160
|
}
|
|
159
|
-
) }),
|
|
161
|
+
) }), Q = B(
|
|
160
162
|
({
|
|
161
163
|
isOpen: e,
|
|
162
164
|
children: t,
|
|
163
|
-
fullScreen:
|
|
165
|
+
fullScreen: i = !1,
|
|
164
166
|
defaultSize: n = void 0,
|
|
165
|
-
minWidth:
|
|
166
|
-
onDragEnd:
|
|
167
|
-
onResize:
|
|
168
|
-
className:
|
|
169
|
-
placement:
|
|
170
|
-
parentContainer:
|
|
171
|
-
header:
|
|
172
|
-
id:
|
|
173
|
-
containerClassName:
|
|
167
|
+
minWidth: s = 400,
|
|
168
|
+
onDragEnd: w = null,
|
|
169
|
+
onResize: d,
|
|
170
|
+
className: a,
|
|
171
|
+
placement: l = "right",
|
|
172
|
+
parentContainer: o,
|
|
173
|
+
header: c,
|
|
174
|
+
id: u,
|
|
175
|
+
containerClassName: g,
|
|
176
|
+
headerClassName: b,
|
|
174
177
|
ignoreParentContainerHeight: h = !1,
|
|
175
178
|
height: x,
|
|
176
|
-
isMainSidebarExpanded:
|
|
177
|
-
mainSidebarExpandedWidth:
|
|
178
|
-
mainSidebarCollapsedWidth:
|
|
179
|
-
navbarHeight:
|
|
180
|
-
},
|
|
181
|
-
const
|
|
182
|
-
|
|
179
|
+
isMainSidebarExpanded: p = !1,
|
|
180
|
+
mainSidebarExpandedWidth: y = 280,
|
|
181
|
+
mainSidebarCollapsedWidth: f = 80,
|
|
182
|
+
navbarHeight: k = 64
|
|
183
|
+
}, j) => {
|
|
184
|
+
const E = p ? y : f, S = H(null), { shouldRenderSidebar: z, portalTarget: F } = G(
|
|
185
|
+
o,
|
|
183
186
|
e,
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
),
|
|
188
|
-
|
|
187
|
+
i,
|
|
188
|
+
d,
|
|
189
|
+
S
|
|
190
|
+
), P = typeof window < "u" ? window.innerWidth - E : 0, _ = N(s), A = N(n), C = l === "right", I = x || (o && !h ? "100%" : `calc(100vh - ${k}px)`), D = /* @__PURE__ */ r(
|
|
191
|
+
J,
|
|
189
192
|
{
|
|
190
193
|
isOpen: e,
|
|
191
|
-
header:
|
|
192
|
-
id:
|
|
193
|
-
ref:
|
|
194
|
-
className:
|
|
195
|
-
containerClassName:
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
header: c,
|
|
195
|
+
id: u,
|
|
196
|
+
ref: j,
|
|
197
|
+
className: a,
|
|
198
|
+
containerClassName: g,
|
|
199
|
+
headerClassName: b,
|
|
200
|
+
widthStyle: A,
|
|
201
|
+
heightStyle: I,
|
|
198
202
|
motionVariants: {
|
|
199
|
-
initial: { x:
|
|
203
|
+
initial: { x: C ? "100%" : "-100%" },
|
|
200
204
|
animate: { x: 0 },
|
|
201
|
-
exit: { x:
|
|
205
|
+
exit: { x: C ? "100%" : "-100%" }
|
|
202
206
|
},
|
|
203
|
-
resizableRef:
|
|
204
|
-
fullScreen:
|
|
205
|
-
maxResizableWidth:
|
|
206
|
-
minWidth:
|
|
207
|
-
handleKey:
|
|
208
|
-
onDragEnd:
|
|
209
|
-
onResize:
|
|
207
|
+
resizableRef: S,
|
|
208
|
+
fullScreen: i,
|
|
209
|
+
maxResizableWidth: P,
|
|
210
|
+
minWidth: _,
|
|
211
|
+
handleKey: C ? "left" : "right",
|
|
212
|
+
onDragEnd: w,
|
|
213
|
+
onResize: d,
|
|
210
214
|
children: t
|
|
211
215
|
}
|
|
212
216
|
);
|
|
213
|
-
return
|
|
217
|
+
return o ? !z || !F ? null : T.createPortal(D, F) : z ? D : null;
|
|
214
218
|
}
|
|
215
219
|
);
|
|
216
|
-
|
|
220
|
+
Q.displayName = "ResizableSidebar";
|
|
217
221
|
export {
|
|
218
|
-
|
|
222
|
+
Q as ResizableSidebar
|
|
219
223
|
};
|
|
220
224
|
//# sourceMappingURL=ResizableSidebar.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResizableSidebar.es.js","sources":["../../../../src/components/data-display/resizable-sidebar/ResizableSidebar.tsx"],"sourcesContent":["import cn from \"classnames\";\nimport { AnimatePresence, motion } from \"framer-motion\";\nimport { forwardRef, useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { Resizable } from \"re-resizable\";\n\n/**\n * Sidebar placement options\n */\nexport type ResizableSidebarPlacement = \"left\" | \"right\";\n\n/**\n * Props for the ResizableSidebar component\n */\nexport interface ResizableSidebarProps {\n /** Whether the sidebar is open */\n isOpen: boolean;\n /** Content to display in the sidebar */\n children: React.ReactNode;\n /** Whether to display in full screen mode */\n fullScreen?: boolean;\n /** Callback when drag/resize ends */\n onDragEnd?: (() => void) | null;\n /** Callback when resize occurs */\n onResize?: (width: number) => void;\n /** Additional CSS classes for the wrapper */\n className?: string;\n /** Default size of the sidebar */\n defaultSize?: string;\n /** Minimum width of the sidebar */\n minWidth?: number;\n /** Placement of the sidebar */\n placement?: ResizableSidebarPlacement;\n /** Parent container ID for portal rendering */\n parentContainer?: string;\n /** Header content */\n header?: React.ReactNode;\n /** Unique ID for the sidebar */\n id?: string;\n /** Additional CSS classes for the container */\n containerClassName?: string;\n /** Whether to ignore parent container height */\n ignoreParentContainerHeight?: boolean;\n /** Custom height */\n height?: string;\n /** Whether the main sidebar is expanded (affects max width calculation) */\n isMainSidebarExpanded?: boolean;\n /** Width of the main sidebar when expanded */\n mainSidebarExpandedWidth?: number;\n /** Width of the main sidebar when collapsed */\n mainSidebarCollapsedWidth?: number;\n /** Height offset for navbar */\n navbarHeight?: number;\n}\n\n/**\n * Drag handle component for the resizable sidebar\n */\nconst DragHandle = () => {\n return (\n <div className=\"cursor-ew-resize flex items-center justify-center rounded-full bg-[#1018288F] bg-opacity-55 w-8 h-8 shadow-200 border-[1.5px] border-[#FFFFFF3D]\">\n <svg\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 20 20\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <mask id=\"mask0_36675_12\" maskUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width=\"20\" height=\"20\">\n <rect y=\"20\" width=\"20\" height=\"20\" transform=\"rotate(-90 0 20)\" fill=\"#D9D9D9\" />\n </mask>\n <g mask=\"url(#mask0_36675_12)\">\n <path\n d=\"M15.9583 10L12.7292 6.77084C12.5625 6.60418 12.4792 6.40973 12.4792 6.18751C12.4792 5.96529 12.5625 5.77084 12.7292 5.60418C12.8958 5.43751 13.0938 5.35418 13.3229 5.35418C13.5521 5.35418 13.75 5.43751 13.9167 5.60418L17.1458 8.81251C17.4653 9.13195 17.625 9.52779 17.625 10C17.625 10.4722 17.4653 10.8681 17.1458 11.1875L13.9167 14.4167C13.75 14.5833 13.5521 14.6632 13.3229 14.6563C13.0938 14.6493 12.8958 14.5625 12.7292 14.3958C12.5625 14.2292 12.4792 14.0313 12.4792 13.8021C12.4792 13.5729 12.5625 13.375 12.7292 13.2083L15.9583 10ZM4.04167 10L7.25 13.2083C7.41667 13.375 7.49653 13.5695 7.48958 13.7917C7.48264 14.0139 7.40278 14.2083 7.25 14.375C7.08333 14.5417 6.88542 14.6285 6.65625 14.6354C6.42708 14.6424 6.22917 14.5625 6.0625 14.3958L2.85417 11.1875C2.53472 10.8681 2.375 10.4722 2.375 10C2.375 9.52779 2.53472 9.13195 2.85417 8.81251L6.0625 5.60418C6.22917 5.43751 6.42708 5.35765 6.65625 5.36459C6.88542 5.37154 7.08333 5.45834 7.25 5.62501C7.40278 5.79168 7.48264 5.98612 7.48958 6.20834C7.49653 6.43057 7.41667 6.62501 7.25 6.79168L4.04167 10Z\"\n fill=\"white\"\n />\n </g>\n </svg>\n </div>\n );\n};\n\n/**\n * ResizableSidebar component displays a resizable sidebar panel\n *\n * @example\n * ```tsx\n * <ResizableSidebar\n * isOpen={isOpen}\n * onClose={() => setIsOpen(false)}\n * placement=\"right\"\n * minWidth={300}\n * >\n * <div>Sidebar content</div>\n * </ResizableSidebar>\n * ```\n */\n// Helper functions to reduce cognitive complexity\nconst findParentContainer = (parentContainer: string, setPortalTarget: (target: HTMLElement | null) => void) => {\n const el = document.getElementById(parentContainer);\n if (el) {\n setPortalTarget(el);\n } else {\n requestAnimationFrame(() => {\n const retryEl = document.getElementById(parentContainer);\n if (retryEl) setPortalTarget(retryEl);\n });\n }\n};\n\nconst handleFullScreenToggle = (resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>, fullScreen: boolean) => {\n if (!resizableRef.current) return;\n\n if (fullScreen) {\n localStorage.setItem(\"resizable-sidebar-width-before-fullscreen\", String(resizableRef.current.size?.width));\n } else {\n const width = localStorage.getItem(\"resizable-sidebar-width-before-fullscreen\");\n if (width) {\n resizableRef.current.updateSize({ width: width, height: \"100%\" });\n return;\n }\n }\n resizableRef.current.updateSize({\n width: fullScreen ? \"100vw\" : \"\",\n height: \"100%\",\n });\n};\n\nconst useSidebarEffects = (\n parentContainer: string | undefined,\n isOpen: boolean,\n fullScreen: boolean,\n onResize: ((width: number) => void) | undefined,\n resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>,\n _minWidth: number\n) => {\n const [shouldRenderSidebar, setShouldRenderSidebar] = useState(false);\n const [portalTarget, setPortalTarget] = useState<HTMLElement | null>(null);\n\n useEffect(() => {\n if (!parentContainer || typeof window === \"undefined\") {\n setPortalTarget(null);\n return;\n }\n findParentContainer(parentContainer, setPortalTarget);\n }, [parentContainer]);\n\n useEffect(() => {\n handleFullScreenToggle(resizableRef, fullScreen);\n }, [fullScreen]);\n\n useEffect(() => {\n if (parentContainer && isOpen) {\n const frame = requestAnimationFrame(() => {\n setShouldRenderSidebar(true);\n });\n return () => {\n cancelAnimationFrame(frame);\n setShouldRenderSidebar(false);\n };\n }\n\n if (!parentContainer) {\n setShouldRenderSidebar(true);\n }\n\n if (!isOpen) {\n setShouldRenderSidebar(false);\n }\n }, [isOpen, parentContainer]);\n\n useEffect(() => {\n if (resizableRef.current?.size?.width && onResize) {\n onResize(resizableRef.current.size.width);\n }\n }, [resizableRef.current?.size?.width, onResize]);\n\n return { shouldRenderSidebar, portalTarget };\n};\n\nconst SidebarContent = ({\n isOpen,\n header,\n id,\n ref,\n className,\n containerClassName,\n widthStyle,\n heightStyle,\n motionVariants,\n resizableRef,\n fullScreen,\n maxResizableWidth,\n minWidth,\n handleKey,\n onDragEnd,\n onResize,\n children,\n}: {\n isOpen: boolean;\n header?: React.ReactNode;\n id?: string;\n ref: React.Ref<HTMLDivElement>;\n className?: string;\n containerClassName?: string;\n widthStyle?: string;\n heightStyle: string;\n motionVariants: any;\n resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>;\n fullScreen: boolean;\n maxResizableWidth: number;\n minWidth: number;\n handleKey: string;\n onDragEnd?: (() => void) | null;\n onResize?: (width: number) => void;\n children: React.ReactNode;\n}) => (\n <AnimatePresence>\n {isOpen && (\n <motion.div\n ref={ref}\n id={id}\n initial={motionVariants.initial}\n animate={motionVariants.animate}\n exit={motionVariants.exit}\n transition={{ type: \"tween\", duration: 0.3 }}\n className={cn(\n \"flex-shrink-0 z-50 relative bg-white border-neutral-200 dark:bg-black-800 dark:border-black-700\",\n fullScreen ? \"fixed w-full transition translate-x-4 duration-300\" : \"sticky\",\n className,\n )}\n style={{\n width: widthStyle,\n height: heightStyle,\n }}\n >\n <Resizable\n onResize={(e) => {\n e.stopPropagation();\n const width = resizableRef.current?.size?.width;\n if (onResize) {\n onResize(width || minWidth);\n }\n }}\n onResizeStart={(e) => {\n e.stopPropagation();\n }}\n ref={resizableRef}\n maxWidth={fullScreen ? maxResizableWidth : maxResizableWidth * 0.75}\n minWidth={minWidth}\n minHeight={heightStyle}\n maxHeight={heightStyle}\n enable={fullScreen ? {} : { [handleKey]: true }}\n handleClasses={{\n [handleKey]: cn(\n \"relative w-6 -left-1 flex items-center justify-center bg-transparent transition-colors cursor-ew-resize group z-[9999] hover:bg-neutral-200 dark:hover:bg-neutral-700\",\n ),\n }}\n handleComponent={{\n [handleKey]: (\n <div\n className={cn(\n \"absolute -left-2.5 top-1/2 -translate-y-1/2 flex items-center justify-center w-8 h-12 cursor-ew-resize opacity-0 group-hover:opacity-100 hover:opacity-100 active:opacity-100 transition-opacity z-[9999]\",\n handleKey === \"left\" && \"-right-2.5 -left-auto\",\n )}\n >\n <DragHandle />\n </div>\n ),\n }}\n className=\"!h-full\"\n onResizeStop={onDragEnd || undefined}\n >\n <div\n className={cn(\n \"h-full w-full flex flex-col overflow-hidden @container/sidebar border-b border-neutral-200 dark:border-black-700 bg-white dark:bg-black-800 dark:border\",\n containerClassName,\n )}\n >\n {header ? <div className=\"py-4 px-6\">{header || null}</div> : null}\n <div className=\"flex-1 overflow-y-auto overflow-x-hidden\">{children}</div>\n </div>\n </Resizable>\n </motion.div>\n )} \n </AnimatePresence>\n);\n\nexport const ResizableSidebar = forwardRef<HTMLDivElement, ResizableSidebarProps>(\n (\n {\n isOpen,\n children,\n fullScreen = false,\n defaultSize = undefined,\n minWidth = 400,\n onDragEnd = null,\n onResize,\n className,\n placement = \"right\",\n parentContainer,\n header,\n id,\n containerClassName,\n ignoreParentContainerHeight = false,\n height,\n isMainSidebarExpanded = false,\n mainSidebarExpandedWidth = 280,\n mainSidebarCollapsedWidth = 80,\n navbarHeight = 64,\n },\n ref\n ) => {\n const mainSidebarWidth = isMainSidebarExpanded ? mainSidebarExpandedWidth : mainSidebarCollapsedWidth;\n const resizableRef = useRef<React.ElementRef<typeof Resizable>>(null);\n const { shouldRenderSidebar, portalTarget } = useSidebarEffects(\n parentContainer,\n isOpen,\n fullScreen,\n onResize,\n resizableRef,\n minWidth\n );\n\n const maxResizableWidth = typeof window !== \"undefined\" ? window.innerWidth - mainSidebarWidth : 0;\n\n const widthStyle = defaultSize;\n const isRight = placement === \"right\";\n const heightStyle = height || (parentContainer && !ignoreParentContainerHeight ? \"100%\" : `calc(100vh - ${navbarHeight}px)`);\n\n const motionVariants = {\n initial: { x: isRight ? \"100%\" : \"-100%\" },\n animate: { x: 0 },\n exit: { x: isRight ? \"100%\" : \"-100%\" },\n };\n\n const handleKey = isRight ? \"left\" : \"right\";\n\n const sidebarContent = (\n <SidebarContent\n isOpen={isOpen}\n header={header}\n id={id}\n ref={ref}\n className={className}\n containerClassName={containerClassName}\n widthStyle={widthStyle}\n heightStyle={heightStyle}\n motionVariants={motionVariants}\n resizableRef={resizableRef}\n fullScreen={fullScreen}\n maxResizableWidth={maxResizableWidth}\n minWidth={minWidth}\n handleKey={handleKey}\n onDragEnd={onDragEnd}\n onResize={onResize}\n >\n {children}\n </SidebarContent>\n );\n\n if (parentContainer) {\n if (!shouldRenderSidebar || !portalTarget) return null;\n return ReactDOM.createPortal(sidebarContent, portalTarget);\n }\n\n if (!shouldRenderSidebar) return null;\n\n return sidebarContent;\n }\n);\n\nResizableSidebar.displayName = \"ResizableSidebar\";\n"],"names":["DragHandle","jsx","jsxs","findParentContainer","parentContainer","setPortalTarget","el","retryEl","handleFullScreenToggle","resizableRef","fullScreen","width","useSidebarEffects","isOpen","onResize","_minWidth","shouldRenderSidebar","setShouldRenderSidebar","useState","portalTarget","useEffect","frame","SidebarContent","header","id","ref","className","containerClassName","widthStyle","heightStyle","motionVariants","maxResizableWidth","minWidth","handleKey","onDragEnd","children","AnimatePresence","motion","cn","Resizable","e","ResizableSidebar","forwardRef","defaultSize","placement","ignoreParentContainerHeight","height","isMainSidebarExpanded","mainSidebarExpandedWidth","mainSidebarCollapsedWidth","navbarHeight","mainSidebarWidth","useRef","isRight","sidebarContent","ReactDOM"],"mappings":";;;;;;AA0DA,MAAMA,IAAa,MAEf,gBAAAC,EAAC,OAAA,EAAI,WAAU,oJACb,UAAA,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,OAAM;AAAA,IACN,QAAO;AAAA,IACP,SAAQ;AAAA,IACR,MAAK;AAAA,IACL,OAAM;AAAA,IAEN,UAAA;AAAA,MAAA,gBAAAD,EAAC,QAAA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A,QACA,gBAlBmB;AAAA,UACrB,SAAS,EAAE,GAAGwB,IAAU,SAAS,QAAA;AAAA,UACjC,SAAS,EAAE,GAAG,EAAA;AAAA,UACd,MAAM,EAAE,GAAGA,IAAU,SAAS,QAAA;AAAA,QAAQ;AAAA,QAgBpC,cAAA5C;AAAA,QACA,YAAAC;AAAA,QACA,mBAAAqB;AAAA,QACA,UAAAC;AAAA,QACA,WAjBcqB,IAAU,SAAS;AAAA,QAkBjC,WAAAnB;AAAA,QACA,UAAApB;AAAA,QAEC,UAAAqB;AAAA,MAAA;AAAA,IAAA;AAIL,WAAI/B,IACE,CAACY,KAAuB,CAACG,IAAqB,OAC3CoC,EAAS,aAAaD,GAAgBnC,CAAY,IAGtDH,IAEEsC,IAF0B;AAAA,EAGnC;AACF;AAEAb,EAAiB,cAAc;"}
|
|
1
|
+
{"version":3,"file":"ResizableSidebar.es.js","sources":["../../../../src/components/data-display/resizable-sidebar/ResizableSidebar.tsx"],"sourcesContent":["import cn from \"classnames\";\nimport { AnimatePresence, motion } from \"framer-motion\";\nimport { forwardRef, useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { Resizable } from \"re-resizable\";\n\nimport { useResponsiveWidth } from \"../../../hooks/useResponsiveWidth\";\n\n/**\n * Sidebar placement options\n */\nexport type ResizableSidebarPlacement = \"left\" | \"right\";\n\n/**\n * Props for the ResizableSidebar component\n */\nexport interface ResizableSidebarProps {\n /** Whether the sidebar is open */\n isOpen: boolean;\n /** Content to display in the sidebar */\n children: React.ReactNode;\n /** Whether to display in full screen mode */\n fullScreen?: boolean;\n /** Callback when drag/resize ends */\n onDragEnd?: (() => void) | null;\n /** Callback when resize occurs */\n onResize?: (width: number) => void;\n /** Additional CSS classes for the wrapper */\n className?: string;\n /** Default size of the sidebar */\n defaultSize?: string;\n /** Minimum width of the sidebar */\n minWidth?: number;\n /** Placement of the sidebar */\n placement?: ResizableSidebarPlacement;\n /** Parent container ID for portal rendering */\n parentContainer?: string;\n /** Header content */\n header?: React.ReactNode;\n /** Unique ID for the sidebar */\n id?: string;\n /** Additional CSS classes for the container */\n containerClassName?: string;\n /** Additional CSS classes for the header wrapper */\n headerClassName?: string;\n /** Whether to ignore parent container height */\n ignoreParentContainerHeight?: boolean;\n /** Custom height */\n height?: string;\n /** Whether the main sidebar is expanded (affects max width calculation) */\n isMainSidebarExpanded?: boolean;\n /** Width of the main sidebar when expanded */\n mainSidebarExpandedWidth?: number;\n /** Width of the main sidebar when collapsed */\n mainSidebarCollapsedWidth?: number;\n /** Height offset for navbar */\n navbarHeight?: number;\n}\n\n/**\n * Drag handle component for the resizable sidebar\n */\nconst DragHandle = () => {\n return (\n <div className=\"cursor-ew-resize flex items-center justify-center rounded-full bg-[#1018288F] bg-opacity-55 w-8 h-8 shadow-200 border-[1.5px] border-[#FFFFFF3D]\">\n <svg\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 20 20\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <mask id=\"mask0_36675_12\" maskUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width=\"20\" height=\"20\">\n <rect y=\"20\" width=\"20\" height=\"20\" transform=\"rotate(-90 0 20)\" fill=\"#D9D9D9\" />\n </mask>\n <g mask=\"url(#mask0_36675_12)\">\n <path\n d=\"M15.9583 10L12.7292 6.77084C12.5625 6.60418 12.4792 6.40973 12.4792 6.18751C12.4792 5.96529 12.5625 5.77084 12.7292 5.60418C12.8958 5.43751 13.0938 5.35418 13.3229 5.35418C13.5521 5.35418 13.75 5.43751 13.9167 5.60418L17.1458 8.81251C17.4653 9.13195 17.625 9.52779 17.625 10C17.625 10.4722 17.4653 10.8681 17.1458 11.1875L13.9167 14.4167C13.75 14.5833 13.5521 14.6632 13.3229 14.6563C13.0938 14.6493 12.8958 14.5625 12.7292 14.3958C12.5625 14.2292 12.4792 14.0313 12.4792 13.8021C12.4792 13.5729 12.5625 13.375 12.7292 13.2083L15.9583 10ZM4.04167 10L7.25 13.2083C7.41667 13.375 7.49653 13.5695 7.48958 13.7917C7.48264 14.0139 7.40278 14.2083 7.25 14.375C7.08333 14.5417 6.88542 14.6285 6.65625 14.6354C6.42708 14.6424 6.22917 14.5625 6.0625 14.3958L2.85417 11.1875C2.53472 10.8681 2.375 10.4722 2.375 10C2.375 9.52779 2.53472 9.13195 2.85417 8.81251L6.0625 5.60418C6.22917 5.43751 6.42708 5.35765 6.65625 5.36459C6.88542 5.37154 7.08333 5.45834 7.25 5.62501C7.40278 5.79168 7.48264 5.98612 7.48958 6.20834C7.49653 6.43057 7.41667 6.62501 7.25 6.79168L4.04167 10Z\"\n fill=\"white\"\n />\n </g>\n </svg>\n </div>\n );\n};\n\n/**\n * ResizableSidebar component displays a resizable sidebar panel\n *\n * @example\n * ```tsx\n * <ResizableSidebar\n * isOpen={isOpen}\n * onClose={() => setIsOpen(false)}\n * placement=\"right\"\n * minWidth={300}\n * >\n * <div>Sidebar content</div>\n * </ResizableSidebar>\n * ```\n */\n// Helper functions to reduce cognitive complexity\nconst findParentContainer = (parentContainer: string, setPortalTarget: (target: HTMLElement | null) => void) => {\n const el = document.getElementById(parentContainer);\n if (el) {\n setPortalTarget(el);\n } else {\n requestAnimationFrame(() => {\n const retryEl = document.getElementById(parentContainer);\n if (retryEl) setPortalTarget(retryEl);\n });\n }\n};\n\nconst handleFullScreenToggle = (resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>, fullScreen: boolean) => {\n if (!resizableRef.current) return;\n\n if (fullScreen) {\n localStorage.setItem(\"resizable-sidebar-width-before-fullscreen\", String(resizableRef.current.size?.width));\n } else {\n const width = localStorage.getItem(\"resizable-sidebar-width-before-fullscreen\");\n if (width) {\n resizableRef.current.updateSize({ width: width, height: \"100%\" });\n return;\n }\n }\n resizableRef.current.updateSize({\n width: fullScreen ? \"100vw\" : \"\",\n height: \"100%\",\n });\n};\n\nconst useSidebarEffects = (\n parentContainer: string | undefined,\n isOpen: boolean,\n fullScreen: boolean,\n onResize: ((width: number) => void) | undefined,\n resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>,\n _minWidth: number\n) => {\n const [shouldRenderSidebar, setShouldRenderSidebar] = useState(false);\n const [portalTarget, setPortalTarget] = useState<HTMLElement | null>(null);\n\n useEffect(() => {\n if (!parentContainer || typeof window === \"undefined\") {\n setPortalTarget(null);\n return;\n }\n findParentContainer(parentContainer, setPortalTarget);\n }, [parentContainer]);\n\n useEffect(() => {\n handleFullScreenToggle(resizableRef, fullScreen);\n }, [fullScreen]);\n\n useEffect(() => {\n if (parentContainer && isOpen) {\n const frame = requestAnimationFrame(() => {\n setShouldRenderSidebar(true);\n });\n return () => {\n cancelAnimationFrame(frame);\n setShouldRenderSidebar(false);\n };\n }\n\n if (!parentContainer) {\n setShouldRenderSidebar(true);\n }\n\n if (!isOpen) {\n setShouldRenderSidebar(false);\n }\n }, [isOpen, parentContainer]);\n\n useEffect(() => {\n if (resizableRef.current?.size?.width && onResize) {\n onResize(resizableRef.current.size.width);\n }\n }, [resizableRef.current?.size?.width, onResize]);\n\n return { shouldRenderSidebar, portalTarget };\n};\n\nconst SidebarContent = ({\n isOpen,\n header,\n id,\n ref,\n className,\n containerClassName,\n headerClassName,\n widthStyle,\n heightStyle,\n motionVariants,\n resizableRef,\n fullScreen,\n maxResizableWidth,\n minWidth,\n handleKey,\n onDragEnd,\n onResize,\n children,\n}: {\n isOpen: boolean;\n header?: React.ReactNode;\n id?: string;\n ref: React.Ref<HTMLDivElement>;\n className?: string;\n containerClassName?: string;\n headerClassName?: string;\n widthStyle?: string | number;\n heightStyle: string;\n motionVariants: any;\n resizableRef: React.RefObject<React.ElementRef<typeof Resizable>>;\n fullScreen: boolean;\n maxResizableWidth: number;\n minWidth: number;\n handleKey: string;\n onDragEnd?: (() => void) | null;\n onResize?: (width: number) => void;\n children: React.ReactNode;\n}) => (\n <AnimatePresence>\n {isOpen && (\n <motion.div\n ref={ref}\n id={id}\n initial={motionVariants.initial}\n animate={motionVariants.animate}\n exit={motionVariants.exit}\n transition={{ type: \"tween\", duration: 0.3 }}\n className={cn(\n \"flex-shrink-0 z-50 relative bg-white border-neutral-200 dark:bg-black-800 dark:border-black-700\",\n fullScreen ? \"fixed w-full transition translate-x-4 duration-300\" : \"sticky\",\n className,\n )}\n style={{\n width: widthStyle,\n height: heightStyle,\n }}\n >\n <Resizable\n onResize={(e) => {\n e.stopPropagation();\n const width = resizableRef.current?.size?.width;\n if (onResize) {\n onResize(width || minWidth);\n }\n }}\n onResizeStart={(e) => {\n e.stopPropagation();\n }}\n ref={resizableRef}\n maxWidth={fullScreen ? maxResizableWidth : maxResizableWidth * 0.75}\n minWidth={minWidth}\n minHeight={heightStyle}\n maxHeight={heightStyle}\n enable={fullScreen ? {} : { [handleKey]: true }}\n handleClasses={{\n [handleKey]: cn(\n \"relative w-6 -left-1 flex items-center justify-center bg-transparent transition-colors cursor-ew-resize group z-[9999] hover:bg-neutral-200 dark:hover:bg-neutral-700\",\n ),\n }}\n handleComponent={{\n [handleKey]: (\n <div\n className={cn(\n \"absolute -left-2.5 top-1/2 -translate-y-1/2 flex items-center justify-center w-8 h-12 cursor-ew-resize opacity-0 group-hover:opacity-100 hover:opacity-100 active:opacity-100 transition-opacity z-[9999]\",\n handleKey === \"left\" && \"-right-2.5 -left-auto\",\n )}\n >\n <DragHandle />\n </div>\n ),\n }}\n className=\"!h-full\"\n onResizeStop={onDragEnd || undefined}\n >\n <div\n className={cn(\n \"h-full w-full flex flex-col overflow-hidden @container/sidebar border-b border-neutral-200 dark:border-black-700 bg-white dark:bg-black-800 dark:border\",\n containerClassName,\n )}\n >\n {header ? <div className={cn(\"py-4 px-6\", headerClassName)}>{header || null}</div> : null}\n <div className=\"flex-1 overflow-y-auto overflow-x-hidden\">{children}</div>\n </div>\n </Resizable>\n </motion.div>\n )} \n </AnimatePresence>\n);\n\nexport const ResizableSidebar = forwardRef<HTMLDivElement, ResizableSidebarProps>(\n (\n {\n isOpen,\n children,\n fullScreen = false,\n defaultSize = undefined,\n minWidth = 400,\n onDragEnd = null,\n onResize,\n className,\n placement = \"right\",\n parentContainer,\n header,\n id,\n containerClassName,\n headerClassName,\n ignoreParentContainerHeight = false,\n height,\n isMainSidebarExpanded = false,\n mainSidebarExpandedWidth = 280,\n mainSidebarCollapsedWidth = 80,\n navbarHeight = 64,\n },\n ref\n ) => {\n const mainSidebarWidth = isMainSidebarExpanded ? mainSidebarExpandedWidth : mainSidebarCollapsedWidth;\n const resizableRef = useRef<React.ElementRef<typeof Resizable>>(null);\n const { shouldRenderSidebar, portalTarget } = useSidebarEffects(\n parentContainer,\n isOpen,\n fullScreen,\n onResize,\n resizableRef,\n minWidth\n );\n\n const maxResizableWidth = typeof window !== \"undefined\" ? window.innerWidth - mainSidebarWidth : 0;\n\n // Passed sizes are the desktop maximum; both the drag floor and the open\n // width shrink by viewport breakpoint.\n const responsiveMinWidth = useResponsiveWidth(minWidth);\n const responsiveDefaultSize = useResponsiveWidth(defaultSize);\n\n const widthStyle = responsiveDefaultSize;\n const isRight = placement === \"right\";\n const heightStyle = height || (parentContainer && !ignoreParentContainerHeight ? \"100%\" : `calc(100vh - ${navbarHeight}px)`);\n\n const motionVariants = {\n initial: { x: isRight ? \"100%\" : \"-100%\" },\n animate: { x: 0 },\n exit: { x: isRight ? \"100%\" : \"-100%\" },\n };\n\n const handleKey = isRight ? \"left\" : \"right\";\n\n const sidebarContent = (\n <SidebarContent\n isOpen={isOpen}\n header={header}\n id={id}\n ref={ref}\n className={className}\n containerClassName={containerClassName}\n headerClassName={headerClassName}\n widthStyle={widthStyle}\n heightStyle={heightStyle}\n motionVariants={motionVariants}\n resizableRef={resizableRef}\n fullScreen={fullScreen}\n maxResizableWidth={maxResizableWidth}\n minWidth={responsiveMinWidth}\n handleKey={handleKey}\n onDragEnd={onDragEnd}\n onResize={onResize}\n >\n {children}\n </SidebarContent>\n );\n\n if (parentContainer) {\n if (!shouldRenderSidebar || !portalTarget) return null;\n return ReactDOM.createPortal(sidebarContent, portalTarget);\n }\n\n if (!shouldRenderSidebar) return null;\n\n return sidebarContent;\n }\n);\n\nResizableSidebar.displayName = \"ResizableSidebar\";\n"],"names":["DragHandle","jsx","jsxs","findParentContainer","parentContainer","setPortalTarget","el","retryEl","handleFullScreenToggle","resizableRef","fullScreen","width","useSidebarEffects","isOpen","onResize","_minWidth","shouldRenderSidebar","setShouldRenderSidebar","useState","portalTarget","useEffect","frame","SidebarContent","header","id","ref","className","containerClassName","headerClassName","widthStyle","heightStyle","motionVariants","maxResizableWidth","minWidth","handleKey","onDragEnd","children","AnimatePresence","motion","cn","Resizable","e","ResizableSidebar","forwardRef","defaultSize","placement","ignoreParentContainerHeight","height","isMainSidebarExpanded","mainSidebarExpandedWidth","mainSidebarCollapsedWidth","navbarHeight","mainSidebarWidth","useRef","responsiveMinWidth","useResponsiveWidth","isRight","sidebarContent","ReactDOM"],"mappings":";;;;;;;AA8DA,MAAMA,IAAa,MAEf,gBAAAC,EAAC,OAAA,EAAI,WAAU,oJACb,UAAA,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,OAAM;AAAA,IACN,QAAO;AAAA,IACP,SAAQ;AAAA,IACR,MAAK;AAAA,IACL,OAAM;AAAA,IAEN,UAAA;AAAA,MAAA,gBAAAD,EAAC,QAAA,EAAK,IAAG,kBAAiB,WAAU,kBAAiB,GAAE,KAAI,GAAE,KAAI,OAAM,MAAK,QAAO,MACjF,UAAA,gBAAAA,EAAC,QAAA,EAAK,GAAE,MAAK,OAAM,MAAK,QAAO,MAAK,WAAU,oBAAmB,MAAK,UAAA,CAAU,EAAA,CAClF;AAAA,MACA,gBAAAA,EAAC,KAAA,EAAE,MAAK,wBACN,UAAA,gBAAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,GAAE;AAAA,UACF,MAAK;AAAA,QAAA;AAAA,MAAA,EACP,CACF;AAAA,IAAA;AAAA,EAAA;AAAA,GAEJ,GAoBEE,IAAsB,CAACC,GAAyBC,MAA0D;AAC9G,QAAMC,IAAK,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B;AAAA,QACA,UAAArB;AAAA,QAEC,UAAAsB;AAAA,MAAA;AAAA,IAAA;AAIL,WAAIhC,IACE,CAACY,KAAuB,CAACG,IAAqB,OAC3CuC,EAAS,aAAaD,GAAgBtC,CAAY,IAGtDH,IAEEyC,IAF0B;AAAA,EAGnC;AACF;AAEAf,EAAiB,cAAc;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("react/jsx-runtime"),j=require("antd"),e=require("react"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("react/jsx-runtime"),j=require("antd"),e=require("react"),x=require("react-dom"),z=require("../../../hooks/useResponsiveWidth.cjs.js"),d=({id:h,children:v,onClose:b,open:a,title:g,parentContainer:w="full-screen-container",resizable:W,width:p=400,placement:t="right",closable:R=!1,mask:y,classNames:E,styles:D,getContainer:l,zIndex:k,footer:M,...q})=>{const r=e.useRef(!1),s=z.useResponsiveWidth(p),[L,n]=e.useState(s);e.useEffect(()=>{n(s)},[a,s]);const o=e.useCallback(u=>{if(r.current)if(t==="right"){const c=document.body.offsetWidth-(u.clientX-document.body.offsetLeft);c>256&&n(c)}else u.clientX>256&&n(u.clientX)},[t,n]),i=e.useCallback(()=>{r.current&&(r.current=!1)},[]);e.useEffect(()=>(document.addEventListener("mousemove",o),document.addEventListener("mouseup",i),()=>{document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",i)}),[o,i]);const f=typeof window<"u"?document.getElementById(w)||document.body:null;return f?x.createPortal(m.jsxs(j.Drawer,{id:h||"",closable:R,title:g,onClose:b,open:a,width:L,getContainer:l!==void 0?l:!1,placement:t,mask:y,classNames:E,styles:D,zIndex:k,footer:M,...q,children:[W&&m.jsx("div",{className:"cursor-ew-resize w-1 pl-[2px] absolute top-0 bottom-0 z-[2100] bg-transparent dark:bg-black-600 hover:bg-neutral-200 dark:hover:bg-black-700",onMouseDown:()=>{r.current=!0},style:t==="right"?{left:0}:{right:0}}),v]}),f):null};d.displayName="Drawer";exports.Drawer=d;exports.default=d;
|
|
2
2
|
//# sourceMappingURL=Drawer.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.cjs.js","sources":["../../../../src/components/modal/drawer/Drawer.tsx"],"sourcesContent":["import { Drawer as AntDrawer } from 'antd';\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\n\nexport type DrawerProps = {\n id?: string;\n children: React.ReactNode;\n onClose: () => void;\n open: boolean;\n title: React.ReactNode;\n parentContainer?: string;\n resizable?: boolean;\n width?: number | string;\n placement?: 'left' | 'right' | 'top' | 'bottom';\n closable?: boolean;\n mask?: boolean;\n getContainer?: false | HTMLElement | (() => HTMLElement);\n zIndex?: number;\n footer?: React.ReactNode;\n} & React.ComponentProps<typeof AntDrawer>;\n\n/**\n * Drawer component for sliding panels from screen edges\n *\n * @example\n * ```tsx\n * <Drawer\n * open={isOpen}\n * onClose={() => setIsOpen(false)}\n * title=\"Drawer Title\"\n * width={400}\n * >\n * <div>Drawer content</div>\n * </Drawer>\n * ```\n */\nexport const Drawer: React.FC<DrawerProps> = ({\n id,\n children,\n onClose,\n open,\n title,\n parentContainer = 'full-screen-container',\n resizable,\n width = 400,\n placement = 'right',\n closable = false,\n mask,\n classNames,\n styles,\n getContainer,\n zIndex,\n footer,\n ...props\n}) => {\n const isResizingRef = useRef(false);\n const [drawerWidth, setDrawerWidth] = useState(
|
|
1
|
+
{"version":3,"file":"Drawer.cjs.js","sources":["../../../../src/components/modal/drawer/Drawer.tsx"],"sourcesContent":["import { Drawer as AntDrawer } from 'antd';\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport { useResponsiveWidth } from '../../../hooks/useResponsiveWidth';\n\nexport type DrawerProps = {\n id?: string;\n children: React.ReactNode;\n onClose: () => void;\n open: boolean;\n title: React.ReactNode;\n parentContainer?: string;\n resizable?: boolean;\n width?: number | string;\n placement?: 'left' | 'right' | 'top' | 'bottom';\n closable?: boolean;\n mask?: boolean;\n getContainer?: false | HTMLElement | (() => HTMLElement);\n zIndex?: number;\n footer?: React.ReactNode;\n} & React.ComponentProps<typeof AntDrawer>;\n\n/**\n * Drawer component for sliding panels from screen edges\n *\n * @example\n * ```tsx\n * <Drawer\n * open={isOpen}\n * onClose={() => setIsOpen(false)}\n * title=\"Drawer Title\"\n * width={400}\n * >\n * <div>Drawer content</div>\n * </Drawer>\n * ```\n */\nexport const Drawer: React.FC<DrawerProps> = ({\n id,\n children,\n onClose,\n open,\n title,\n parentContainer = 'full-screen-container',\n resizable,\n width = 400,\n placement = 'right',\n closable = false,\n mask,\n classNames,\n styles,\n getContainer,\n zIndex,\n footer,\n ...props\n}) => {\n const isResizingRef = useRef(false);\n // The provided width is the desktop maximum; it shrinks by viewport breakpoint.\n // Drag overrides it until the next resize/open.\n const responsiveWidth = useResponsiveWidth(width);\n const [drawerWidth, setDrawerWidth] = useState<number | string | undefined>(responsiveWidth);\n\n useEffect(() => {\n setDrawerWidth(responsiveWidth);\n }, [open, responsiveWidth]);\n\n const handleMousemove = useCallback(\n (e: MouseEvent) => {\n if (!isResizingRef.current) return;\n if (placement === 'right') {\n const offsetRight = document.body.offsetWidth - (e.clientX - document.body.offsetLeft);\n const minWidth = 256;\n if (offsetRight > minWidth) {\n setDrawerWidth(offsetRight);\n }\n } else {\n const minWidth = 256;\n if (e.clientX > minWidth) {\n setDrawerWidth(e.clientX);\n }\n }\n },\n [placement, setDrawerWidth],\n );\n\n const onMouseUp = useCallback(() => {\n if (isResizingRef.current) {\n isResizingRef.current = false;\n }\n }, []);\n\n useEffect(() => {\n document.addEventListener('mousemove', handleMousemove);\n document.addEventListener('mouseup', onMouseUp);\n\n return () => {\n document.removeEventListener('mousemove', handleMousemove);\n document.removeEventListener('mouseup', onMouseUp);\n };\n }, [handleMousemove, onMouseUp]);\n\n const containerElement = typeof window !== 'undefined'\n ? (document.getElementById(parentContainer) || document.body)\n : null;\n\n if (!containerElement) {\n return null;\n }\n\n return createPortal(\n <AntDrawer\n id={id || ''}\n closable={closable}\n title={title}\n onClose={onClose}\n open={open}\n width={drawerWidth}\n getContainer={getContainer !== undefined ? getContainer : false}\n placement={placement}\n mask={mask}\n classNames={classNames}\n styles={styles}\n zIndex={zIndex}\n footer={footer}\n {...props}\n >\n {resizable && (\n <div\n className='cursor-ew-resize w-1 pl-[2px] absolute top-0 bottom-0 z-[2100] bg-transparent dark:bg-black-600 hover:bg-neutral-200 dark:hover:bg-black-700'\n onMouseDown={() => {\n isResizingRef.current = true;\n }}\n style={\n placement === 'right'\n ? { left: 0 }\n : {\n right: 0,\n }\n }\n />\n )}\n {children}\n </AntDrawer>,\n containerElement,\n );\n};\n\nDrawer.displayName = 'Drawer';\n\nexport default Drawer;\n\n\n\n"],"names":["Drawer","id","children","onClose","open","title","parentContainer","resizable","width","placement","closable","mask","classNames","styles","getContainer","zIndex","footer","props","isResizingRef","useRef","responsiveWidth","useResponsiveWidth","drawerWidth","setDrawerWidth","useState","useEffect","handleMousemove","useCallback","e","offsetRight","onMouseUp","containerElement","createPortal","jsxs","AntDrawer","jsx"],"mappings":"mQAsCaA,EAAgC,CAAC,CAC1C,GAAAC,EACA,SAAAC,EACA,QAAAC,EACA,KAAAC,EACA,MAAAC,EACA,gBAAAC,EAAkB,wBAClB,UAAAC,EACA,MAAAC,EAAQ,IACR,UAAAC,EAAY,QACZ,SAAAC,EAAW,GACX,KAAAC,EACA,WAAAC,EACA,OAAAC,EACA,aAAAC,EACA,OAAAC,EACA,OAAAC,EACA,GAAGC,CACP,IAAM,CACF,MAAMC,EAAgBC,EAAAA,OAAO,EAAK,EAG5BC,EAAkBC,EAAAA,mBAAmBb,CAAK,EAC1C,CAACc,EAAaC,CAAc,EAAIC,EAAAA,SAAsCJ,CAAe,EAE3FK,EAAAA,UAAU,IAAM,CACZ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