-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathResizableSection.tsx
60 lines (56 loc) · 1.42 KB
/
ResizableSection.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { useState, type PropsWithChildren } from 'react';
import { Rnd } from 'react-rnd';
const ResizableSection = ({
minHeight,
height,
setHeight,
children,
}: PropsWithChildren<{
minHeight?: number;
height: number;
setHeight?: React.Dispatch<React.SetStateAction<number>>;
}>) => {
const [baseHeight, setBaseHeight] = useState(height);
const [sectionHeight, setSectionHeight] = useState(baseHeight);
return (
<div className="resizable-section" style={{ height: sectionHeight }}>
<Rnd
default={{
x: 0,
y: 0,
width: '100%',
height: sectionHeight,
}}
size={{
width: '100%',
height: sectionHeight,
}}
minHeight={minHeight}
disableDragging
enableResizing={{
top: false,
topLeft: false,
topRight: false,
bottomLeft: false,
bottomRight: false,
bottom: true,
left: false,
right: false,
}}
resizeHandleClasses={{
bottom: 'resizable-section-handle',
}}
onResizeStart={() => {
setBaseHeight(sectionHeight);
}}
onResize={(_e, _dir, _refToElement, delta) => {
setSectionHeight(baseHeight + delta.height);
setHeight?.(baseHeight + delta.height);
}}
>
{children}
</Rnd>
</div>
);
};
export default ResizableSection;