Skip to content

Commit 2aaae24

Browse files
author
路振凯
committed
feat: support boolean for resizable
1 parent d84d7ac commit 2aaae24

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/Drawer.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ export interface DrawerProps
4040
maxSize?: number;
4141
/** Default size for uncontrolled resizable drawer */
4242
defaultSize?: number | string;
43-
/** Resizable configuration - object with optional callbacks */
44-
resizable?: {
45-
onResize?: (size: number) => void;
46-
onResizeStart?: () => void;
47-
onResizeEnd?: () => void;
48-
};
43+
/** Resizable configuration - boolean to enable/disable or object with optional callbacks */
44+
resizable?:
45+
| boolean
46+
| {
47+
onResize?: (size: number) => void;
48+
onResizeStart?: () => void;
49+
onResizeEnd?: () => void;
50+
};
4951
}
5052

5153
const Drawer: React.FC<DrawerProps> = props => {

src/DrawerPopup.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ export interface DrawerPopupProps
8585
// resizable
8686
/** Default size for uncontrolled resizable drawer */
8787
defaultSize?: number | string;
88-
resizable?: {
89-
onResize?: (size: number) => void;
90-
onResizeStart?: () => void;
91-
onResizeEnd?: () => void;
92-
};
88+
resizable?:
89+
| boolean
90+
| {
91+
onResize?: (size: number) => void;
92+
onResizeStart?: () => void;
93+
onResizeEnd?: () => void;
94+
};
9395
}
9496

9597
const DrawerPopup: React.ForwardRefRenderFunction<
@@ -319,9 +321,14 @@ const DrawerPopup: React.ForwardRefRenderFunction<
319321
// =========================== Resize ===========================
320322
const wrapperRef = React.useRef<HTMLDivElement>(null);
321323

324+
const isResizable = typeof resizable === 'boolean' ? resizable : !!resizable;
325+
326+
const resizeConfig =
327+
typeof resizable === 'object' && resizable !== null ? resizable : {};
328+
322329
const onInternalResize = useEvent((size: number) => {
323330
setCurrentSize(size);
324-
resizable?.onResize?.(size);
331+
resizeConfig.onResize?.(size);
325332
});
326333

327334
const { dragElementProps, isDragging } = useDrag({
@@ -333,8 +340,8 @@ const DrawerPopup: React.ForwardRefRenderFunction<
333340
containerRef: wrapperRef,
334341
currentSize: mergedSize,
335342
onResize: onInternalResize,
336-
onResizeStart: resizable?.onResizeStart,
337-
onResizeEnd: resizable?.onResizeEnd,
343+
onResizeStart: resizeConfig.onResizeStart,
344+
onResizeEnd: resizeConfig.onResizeEnd,
338345
});
339346

340347
// =========================== Events ===========================
@@ -394,7 +401,7 @@ const DrawerPopup: React.ForwardRefRenderFunction<
394401
}}
395402
{...pickAttrs(props, { data: true })}
396403
>
397-
{resizable && <div {...dragElementProps} />}
404+
{isResizable && <div {...dragElementProps} />}
398405
{drawerRender ? drawerRender(content) : content}
399406
</div>
400407
);

0 commit comments

Comments
 (0)