Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<DrawerProps> = props => {
Expand Down
25 changes: 16 additions & 9 deletions src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -319,9 +321,14 @@ const DrawerPopup: React.ForwardRefRenderFunction<
// =========================== Resize ===========================
const wrapperRef = React.useRef<HTMLDivElement>(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({
Expand All @@ -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 ===========================
Expand Down Expand Up @@ -394,7 +401,7 @@ const DrawerPopup: React.ForwardRefRenderFunction<
}}
{...pickAttrs(props, { data: true })}
>
{resizable && <div {...dragElementProps} />}
{isResizable && <div {...dragElementProps} />}
{drawerRender ? drawerRender(content) : content}
</div>
);
Expand Down