-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathSplitPanel.tsx
More file actions
41 lines (35 loc) · 975 Bytes
/
SplitPanel.tsx
File metadata and controls
41 lines (35 loc) · 975 Bytes
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
import clsx from 'clsx';
import React, { PropsWithChildren } from 'react';
import Split from 'react-split';
import { useStorage, updateDragStatus} from 'tailchat-shared';
import './SplitPanel.less';
/**
* Reference: https://split.js.org/#/
*/
interface SplitPanelProps extends PropsWithChildren {
className?: string;
}
export const SplitPanel: React.FC<SplitPanelProps> = React.memo((props) => {
const [sizes, { save: saveSizes }] = useStorage('pin-sizes', [90, 10]);
const updateStatus = updateDragStatus()
const handleDragEnd = (sizes: number[]) => {
saveSizes(sizes);
updateStatus(false)
};
const handleDragEnter = ()=>{
updateStatus(true)
}
return (
<Split
className={clsx('split', props.className)}
sizes={sizes}
minSize={250}
expandToMin={true}
onDragEnd={handleDragEnd}
onDragStart={handleDragEnter}
>
{props.children}
</Split>
);
});
SplitPanel.displayName = 'SplitPanel';