From 2aaae249d0a0054925da1bdcdc3e5b57de3bb3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E6=8C=AF=E5=87=AF?= Date: Mon, 22 Sep 2025 20:29:41 +0800 Subject: [PATCH 1/2] feat: support boolean for resizable --- src/Drawer.tsx | 14 ++++++++------ src/DrawerPopup.tsx | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/Drawer.tsx b/src/Drawer.tsx index 0150691..7515560 100644 --- a/src/Drawer.tsx +++ b/src/Drawer.tsx @@ -40,12 +40,14 @@ export interface DrawerProps maxSize?: number; /** Default size for uncontrolled resizable drawer */ defaultSize?: number | string; - /** Resizable configuration - object with optional callbacks */ - resizable?: { - onResize?: (size: number) => void; - onResizeStart?: () => void; - onResizeEnd?: () => void; - }; + /** Resizable configuration - boolean to enable/disable or object with optional callbacks */ + resizable?: + | boolean + | { + onResize?: (size: number) => void; + onResizeStart?: () => void; + onResizeEnd?: () => void; + }; } const Drawer: React.FC = props => { diff --git a/src/DrawerPopup.tsx b/src/DrawerPopup.tsx index ab63780..340ba3e 100644 --- a/src/DrawerPopup.tsx +++ b/src/DrawerPopup.tsx @@ -85,11 +85,13 @@ export interface DrawerPopupProps // resizable /** Default size for uncontrolled resizable drawer */ defaultSize?: number | string; - resizable?: { - onResize?: (size: number) => void; - onResizeStart?: () => void; - onResizeEnd?: () => void; - }; + resizable?: + | boolean + | { + onResize?: (size: number) => void; + onResizeStart?: () => void; + onResizeEnd?: () => void; + }; } const DrawerPopup: React.ForwardRefRenderFunction< @@ -319,9 +321,14 @@ const DrawerPopup: React.ForwardRefRenderFunction< // =========================== Resize =========================== const wrapperRef = React.useRef(null); + const isResizable = typeof resizable === 'boolean' ? resizable : !!resizable; + + const resizeConfig = + typeof resizable === 'object' && resizable !== null ? resizable : {}; + const onInternalResize = useEvent((size: number) => { setCurrentSize(size); - resizable?.onResize?.(size); + resizeConfig.onResize?.(size); }); const { dragElementProps, isDragging } = useDrag({ @@ -333,8 +340,8 @@ const DrawerPopup: React.ForwardRefRenderFunction< containerRef: wrapperRef, currentSize: mergedSize, onResize: onInternalResize, - onResizeStart: resizable?.onResizeStart, - onResizeEnd: resizable?.onResizeEnd, + onResizeStart: resizeConfig.onResizeStart, + onResizeEnd: resizeConfig.onResizeEnd, }); // =========================== Events =========================== @@ -394,7 +401,7 @@ const DrawerPopup: React.ForwardRefRenderFunction< }} {...pickAttrs(props, { data: true })} > - {resizable &&
} + {isResizable &&
} {drawerRender ? drawerRender(content) : content}
); From 3f75e07cf88e8901b1400f5b2ec8cfb396d54b31 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 22 Sep 2025 21:00:12 +0800 Subject: [PATCH 2/2] Update src/DrawerPopup.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/DrawerPopup.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/DrawerPopup.tsx b/src/DrawerPopup.tsx index 340ba3e..900a1a4 100644 --- a/src/DrawerPopup.tsx +++ b/src/DrawerPopup.tsx @@ -321,10 +321,8 @@ const DrawerPopup: React.ForwardRefRenderFunction< // =========================== Resize =========================== const wrapperRef = React.useRef(null); - const isResizable = typeof resizable === 'boolean' ? resizable : !!resizable; - - const resizeConfig = - typeof resizable === 'object' && resizable !== null ? resizable : {}; + const isResizable = !!resizable; + const resizeConfig = (typeof resizable === 'object' && resizable) || {}; const onInternalResize = useEvent((size: number) => { setCurrentSize(size);