@@ -13,24 +13,53 @@ const horizontalCss = css`
13
13
width : 100% ;
14
14
height : 0 ;
15
15
` ;
16
- const StyledDiv = styled . div < { isVertical : boolean ; shouldAnimate : boolean ; timeout : number } > `
16
+ const coverCss = css `
17
+ position : absolute;
18
+ top : 0 ;
19
+ bottom : 0 ;
20
+ left : 0 ;
21
+ right : 0 ;
22
+ ` ;
23
+
24
+ interface PaneRootProps {
25
+ $isVertical : boolean ;
26
+ $shouldAnimate : boolean ;
27
+ $timeout : number ;
28
+ }
29
+ const PaneRoot = styled . div < PaneRootProps > `
17
30
position: relative;
18
31
outline: none;
19
32
border: 0;
20
33
overflow: hidden;
21
34
display: flex;
22
35
flex-grow: 1;
23
36
flex-shrink: 1;
24
- ${ props => ( props . isVertical ? verticalCss : horizontalCss ) }
25
- ${ props => props . shouldAnimate && `transition: flex-basis ${ props . timeout } ms ease-in-out` }
37
+ ${ props => ( props . $ isVertical ? verticalCss : horizontalCss ) }
38
+ ${ props => props . $ shouldAnimate && `transition: flex-basis ${ props . $ timeout} ms ease-in-out` }
26
39
` ;
27
- const CollapseOverlay = styled . div `
28
- position: absolute;
29
- top: 0;
30
- bottom: 0;
31
- left: 0;
32
- right: 0;
40
+ const WidthPreserver = styled . div < { $isCollapsed : boolean } > `
41
+ ${ coverCss }
42
+ ${ props =>
43
+ props . $isCollapsed &&
44
+ css `
45
+ * {
46
+ z-index : 0 ;
47
+ }
48
+ z-index : 0 ;
49
+ ` }
50
+ ` ;
51
+
52
+ const CollapseOverlay = styled . div < { $timeout : number ; $isCollapsed : boolean } > `
53
+ ${ props => props . $isCollapsed && coverCss }
54
+ ${ props =>
55
+ props . $isCollapsed &&
56
+ css `
57
+ z-index : 1 ;
58
+ ` } ;
59
+ opacity: ${ props => ( props . $isCollapsed ? 1 : 0 ) } ;
60
+ transition: opacity ${ props => props . $timeout } ms ease-in-out;
33
61
` ;
62
+
34
63
export interface PaneProps {
35
64
size : number ;
36
65
minSize : number ;
@@ -59,7 +88,7 @@ const UnMemoizedPane = ({
59
88
const timeout = useMemo ( ( ) => transitionTimeout ?? DEFAULT_COLLAPSE_TRANSITION_TIMEOUT , [
60
89
transitionTimeout ,
61
90
] ) ;
62
- const [ shouldAnimate , setShouldAnimate ] = useState < boolean > ( false ) ;
91
+ const [ shouldAnimate , setShouldAnimate ] = useState ( false ) ;
63
92
64
93
const didMount = useRef ( false ) ;
65
94
@@ -78,21 +107,23 @@ const UnMemoizedPane = ({
78
107
( ) => ( split === 'vertical' ? { minWidth : minSize } : { minHeight : minSize } ) ,
79
108
[ minSize , split ]
80
109
) ;
81
- const userSelect : React . CSSProperties = { userSelect : 'none' } ;
82
- const collapseOverlayStyle : React . CSSProperties = isCollapsed
83
- ? { ...collapseOverlayCss , ...minStyle , ...userSelect }
110
+ const widthPreserverStyle : React . CSSProperties = isCollapsed
111
+ ? { ...minStyle , userSelect : 'none' }
84
112
: minStyle ;
85
113
return (
86
- < StyledDiv
87
- isVertical = { split === 'vertical' }
114
+ < PaneRoot
115
+ $isVertical = { split === 'vertical' }
116
+ $shouldAnimate = { timeout !== 0 && shouldAnimate }
117
+ $timeout = { timeout }
88
118
className = { classes }
89
119
ref = { forwardRef }
90
120
style = { { flexBasis : size } }
91
- shouldAnimate = { timeout !== 0 && shouldAnimate }
92
- timeout = { timeout }
93
121
>
94
- < CollapseOverlay style = { collapseOverlayStyle } > { children } </ CollapseOverlay >
95
- </ StyledDiv >
122
+ < CollapseOverlay $isCollapsed = { isCollapsed } $timeout = { timeout } style = { collapseOverlayCss } />
123
+ < WidthPreserver $isCollapsed = { isCollapsed } style = { widthPreserverStyle } >
124
+ { children }
125
+ </ WidthPreserver >
126
+ </ PaneRoot >
96
127
) ;
97
128
} ;
98
129
0 commit comments