@@ -4,15 +4,24 @@ import Paper from '@mui/material/Paper';
44import { useTheme } from '@mui/material/styles' ;
55import styled from '@mui/system/styled' ;
66import { detailsPanelId } from '@clients/common/constants' ;
7- import { detailsPanelWidth } from './constants' ;
7+ import classnames from 'classnames' ;
8+ import { defaultDetailsPanelWidth } from './constants' ;
89
910const StyledPaper = styled ( Paper ) ( ( { theme } ) => ( {
1011 display : 'flex' ,
1112 flex : '1 1 100%' ,
1213 maxHeight : '100%' ,
1314 paddingBottom : theme . spacing ( 2 ) ,
1415 pointerEvents : 'initial' ,
15- width : detailsPanelWidth ,
16+ '& .dragger' : {
17+ width : '3px' ,
18+ cursor : 'ew-resize' ,
19+ position : 'absolute' ,
20+ top : 0 ,
21+ left : 0 ,
22+ bottom : 0 ,
23+ zIndex : 100 ,
24+ } ,
1625} ) ) ;
1726
1827interface DetailsPanelProps {
@@ -29,6 +38,24 @@ export const DetailsPanel: React.FC<PropsWithChildren<DetailsPanelProps>> = ({
2938 open = false ,
3039} ) => {
3140 const theme = useTheme ( ) ;
41+
42+ const [ panelWidth , setPanelWidth ] = React . useState ( defaultDetailsPanelWidth ) ;
43+
44+ const handleMouseDown = ( e : React . MouseEvent ) => {
45+ document . addEventListener ( 'mouseup' , handleMouseUp , true ) ;
46+ document . addEventListener ( 'mousemove' , handleMouseMove , true ) ;
47+ } ;
48+
49+ const handleMouseUp = ( e : React . MouseEvent ) => {
50+ document . removeEventListener ( 'mouseup' , handleMouseUp , true ) ;
51+ document . removeEventListener ( 'mousemove' , handleMouseMove , true ) ;
52+ } ;
53+
54+ const handleMouseMove = React . useCallback ( ( e : React . MouseEvent ) => {
55+ const newWidth = document . body . offsetWidth - e . clientX ;
56+ setPanelWidth ( newWidth ) ;
57+ } , [ ] ) ;
58+
3259 return (
3360 < Drawer
3461 anchor = "right"
@@ -50,7 +77,8 @@ export const DetailsPanel: React.FC<PropsWithChildren<DetailsPanelProps>> = ({
5077 open = { open }
5178 key = "detailsPanel"
5279 >
53- < StyledPaper id = { detailsPanelId } square >
80+ < StyledPaper id = { detailsPanelId } square sx = { { width : panelWidth } } >
81+ < div onMouseDown = { ( e ) => handleMouseDown ( e ) } className = { classnames ( 'dragger' ) } />
5482 { children }
5583 </ StyledPaper >
5684 </ Drawer >
0 commit comments