Skip to content

Commit 1f9af53

Browse files
cactuser-Luafc163gemini-code-assist[bot]
authored
feat: support boolean for resizable (#538)
* feat: support boolean for resizable * Update src/DrawerPopup.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: 路振凯 <l> Co-authored-by: afc163 <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent d84d7ac commit 1f9af53

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-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: 14 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,12 @@ const DrawerPopup: React.ForwardRefRenderFunction<
319321
// =========================== Resize ===========================
320322
const wrapperRef = React.useRef<HTMLDivElement>(null);
321323

324+
const isResizable = !!resizable;
325+
const resizeConfig = (typeof resizable === 'object' && resizable) || {};
326+
322327
const onInternalResize = useEvent((size: number) => {
323328
setCurrentSize(size);
324-
resizable?.onResize?.(size);
329+
resizeConfig.onResize?.(size);
325330
});
326331

327332
const { dragElementProps, isDragging } = useDrag({
@@ -333,8 +338,8 @@ const DrawerPopup: React.ForwardRefRenderFunction<
333338
containerRef: wrapperRef,
334339
currentSize: mergedSize,
335340
onResize: onInternalResize,
336-
onResizeStart: resizable?.onResizeStart,
337-
onResizeEnd: resizable?.onResizeEnd,
341+
onResizeStart: resizeConfig.onResizeStart,
342+
onResizeEnd: resizeConfig.onResizeEnd,
338343
});
339344

340345
// =========================== Events ===========================
@@ -394,7 +399,7 @@ const DrawerPopup: React.ForwardRefRenderFunction<
394399
}}
395400
{...pickAttrs(props, { data: true })}
396401
>
397-
{resizable && <div {...dragElementProps} />}
402+
{isResizable && <div {...dragElementProps} />}
398403
{drawerRender ? drawerRender(content) : content}
399404
</div>
400405
);

0 commit comments

Comments
 (0)