Skip to content

Commit 5e26e4e

Browse files
ogonkovRuminat
authored andcommitted
feat: add onResizeStart prop (#347)
* feat: add `onResizeStart` prop * refactor: remove useState callbacks from deps
1 parent 6b7362c commit 5e26e4e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/components/Drawer/Drawer.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export interface DrawerItemProps {
4545
*/
4646
width?: number;
4747

48+
/** Called at the start of resizing. */
49+
onResizeStart?: VoidFunction;
50+
4851
/**
4952
* Called at the end of resizing. Can be used to save the new width.
5053
* @param width The new width of the drawer item
@@ -76,6 +79,7 @@ export const DrawerItem = React.forwardRef<HTMLDivElement, DrawerItemProps>(
7679
width,
7780
minResizeWidth,
7881
maxResizeWidth,
82+
onResizeStart,
7983
onResize,
8084
keepMounted = false,
8185
} = props;
@@ -91,6 +95,7 @@ export const DrawerItem = React.forwardRef<HTMLDivElement, DrawerItemProps>(
9195
width,
9296
minResizeWidth,
9397
maxResizeWidth,
98+
onResizeStart,
9499
onResize,
95100
});
96101

src/components/Drawer/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ The Drawer module consists of two primary components: `Drawer` and `DrawerItem`.
7373
| className | HTML `class` attribute | `string` | |
7474
| resizable | Determines whether the drawer item can be resized | `boolean` | |
7575
| width | The width of the resizable drawer item | `number` | |
76+
| onResizeStart | Callback function called at the start of resizing. | `() => void` | |
7677
| onResize | Callback function called at the end of resizing. Can be used to save the new width. | `(width: number) => void` | |
7778
| minResizeWidth | The minimum width of the resizable drawer item | `number` | |
7879
| maxResizeWidth | The maximum width of the resizable drawer item | `number` | |

src/components/Drawer/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export interface UseResizableDrawerItemParams {
8989
width?: number;
9090
minResizeWidth?: number;
9191
maxResizeWidth?: number;
92+
onResizeStart?: VoidFunction;
9293
onResize?: OnResizeHandler;
9394
}
9495

@@ -98,6 +99,7 @@ export function useResizableDrawerItem(params: UseResizableDrawerItemParams) {
9899
width,
99100
minResizeWidth = DRAWER_ITEM_MIN_RESIZE_WIDTH,
100101
maxResizeWidth = DRAWER_ITEM_MAX_RESIZE_WIDTH,
102+
onResizeStart,
101103
onResize,
102104
} = params;
103105

@@ -124,7 +126,8 @@ export function useResizableDrawerItem(params: UseResizableDrawerItemParams) {
124126
const onStart = React.useCallback(() => {
125127
setIsResizing(true);
126128
setResizeDelta(0);
127-
}, [setIsResizing, setResizeDelta]);
129+
onResizeStart?.();
130+
}, [onResizeStart]);
128131

129132
const onMove = React.useCallback((delta: number) => {
130133
setResizeDelta(delta);
@@ -137,7 +140,7 @@ export function useResizableDrawerItem(params: UseResizableDrawerItemParams) {
137140
setInternalWidth(newWidth);
138141
onResize?.(newWidth);
139142
},
140-
[setIsResizing, setInternalWidth, getResizedWidth, onResize],
143+
[getResizedWidth, onResize],
141144
);
142145

143146
const displayWidth = isResizing

0 commit comments

Comments
 (0)