Skip to content

Commit

Permalink
feat: add onResizeStart prop (#347)
Browse files Browse the repository at this point in the history
* feat: add `onResizeStart` prop

* refactor: remove useState callbacks from deps
  • Loading branch information
ogonkov authored Jan 14, 2025
1 parent d0208f1 commit f9a9230
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/components/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export interface DrawerItemProps {
*/
width?: number;

/** Called at the start of resizing. */
onResizeStart?: VoidFunction;

/**
* Called at the end of resizing. Can be used to save the new width.
* @param width The new width of the drawer item
Expand Down Expand Up @@ -76,6 +79,7 @@ export const DrawerItem = React.forwardRef<HTMLDivElement, DrawerItemProps>(
width,
minResizeWidth,
maxResizeWidth,
onResizeStart,
onResize,
keepMounted = false,
} = props;
Expand All @@ -91,6 +95,7 @@ export const DrawerItem = React.forwardRef<HTMLDivElement, DrawerItemProps>(
width,
minResizeWidth,
maxResizeWidth,
onResizeStart,
onResize,
});

Expand Down
1 change: 1 addition & 0 deletions src/components/Drawer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ The Drawer module consists of two primary components: `Drawer` and `DrawerItem`.
| className | HTML `class` attribute | `string` | |
| resizable | Determines whether the drawer item can be resized | `boolean` | |
| width | The width of the resizable drawer item | `number` | |
| onResizeStart | Callback function called at the start of resizing. | `() => void` | |
| onResize | Callback function called at the end of resizing. Can be used to save the new width. | `(width: number) => void` | |
| minResizeWidth | The minimum width of the resizable drawer item | `number` | |
| maxResizeWidth | The maximum width of the resizable drawer item | `number` | |
Expand Down
7 changes: 5 additions & 2 deletions src/components/Drawer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface UseResizableDrawerItemParams {
width?: number;
minResizeWidth?: number;
maxResizeWidth?: number;
onResizeStart?: VoidFunction;
onResize?: OnResizeHandler;
}

Expand All @@ -98,6 +99,7 @@ export function useResizableDrawerItem(params: UseResizableDrawerItemParams) {
width,
minResizeWidth = DRAWER_ITEM_MIN_RESIZE_WIDTH,
maxResizeWidth = DRAWER_ITEM_MAX_RESIZE_WIDTH,
onResizeStart,
onResize,
} = params;

Expand All @@ -124,7 +126,8 @@ export function useResizableDrawerItem(params: UseResizableDrawerItemParams) {
const onStart = React.useCallback(() => {
setIsResizing(true);
setResizeDelta(0);
}, [setIsResizing, setResizeDelta]);
onResizeStart?.();
}, [onResizeStart]);

const onMove = React.useCallback((delta: number) => {
setResizeDelta(delta);
Expand All @@ -137,7 +140,7 @@ export function useResizableDrawerItem(params: UseResizableDrawerItemParams) {
setInternalWidth(newWidth);
onResize?.(newWidth);
},
[setIsResizing, setInternalWidth, getResizedWidth, onResize],
[getResizedWidth, onResize],
);

const displayWidth = isResizing
Expand Down

0 comments on commit f9a9230

Please sign in to comment.