@@ -4,6 +4,8 @@ import CSSMotion from 'rc-motion';
4
4
import type { CSSMotionProps } from 'rc-motion' ;
5
5
import DrawerPanel from './DrawerPanel' ;
6
6
import type ScrollLocker from 'rc-util/lib/Dom/scrollLocker' ;
7
+ import DrawerContext from './context' ;
8
+ import type { DrawerContextProps } from './context' ;
7
9
8
10
export type Placement = 'left' | 'right' | 'top' | 'bottom' ;
9
11
@@ -12,6 +14,7 @@ export interface DrawerPopupProps {
12
14
open ?: boolean ;
13
15
placement ?: Placement ;
14
16
inline ?: boolean ;
17
+ push ?: { distance ?: number | string } ;
15
18
16
19
// MISC
17
20
scrollLocker ?: ScrollLocker ;
@@ -47,6 +50,7 @@ export default function DrawerPopup(props: DrawerPopupProps) {
47
50
open,
48
51
placement = 'left' ,
49
52
inline,
53
+ push,
50
54
51
55
// MISC
52
56
scrollLocker,
@@ -74,16 +78,40 @@ export default function DrawerPopup(props: DrawerPopupProps) {
74
78
onClose,
75
79
} = props ;
76
80
81
+ // ============================ Push ============================
82
+ const { distance } = push || { } ;
83
+ const [ pushed , setPushed ] = React . useState ( false ) ;
84
+
85
+ const parentContext = React . useContext ( DrawerContext ) ;
86
+ const pushDistance = distance ?? parentContext ?. pushDistance ?? 180 ;
87
+
88
+ const mergedContext = React . useMemo < DrawerContextProps > (
89
+ ( ) => ( {
90
+ pushDistance,
91
+ push : ( ) => {
92
+ setPushed ( true ) ;
93
+ } ,
94
+ pull : ( ) => {
95
+ setPushed ( false ) ;
96
+ } ,
97
+ } ) ,
98
+ [ pushDistance ] ,
99
+ ) ;
100
+
77
101
// ========================= ScrollLock =========================
78
102
React . useEffect ( ( ) => {
79
103
if ( open ) {
80
104
scrollLocker ?. lock ( ) ;
105
+ parentContext ?. push ?.( ) ;
106
+ } else {
107
+ parentContext ?. pull ?.( ) ;
81
108
}
82
109
} , [ open ] ) ;
83
110
84
111
React . useEffect (
85
112
( ) => ( ) => {
86
113
scrollLocker ?. unLock ( ) ;
114
+ parentContext ?. pull ?.( ) ;
87
115
} ,
88
116
[ ] ,
89
117
) ;
@@ -114,7 +142,12 @@ export default function DrawerPopup(props: DrawerPopupProps) {
114
142
const motionProps = typeof motion === 'function' ? motion ( placement ) : motion ;
115
143
116
144
const panelNode : React . ReactNode = (
117
- < div className = { classNames ( `${ prefixCls } -panel-wrapper` ) } >
145
+ < div
146
+ className = { classNames ( `${ prefixCls } -panel-wrapper` ) }
147
+ style = { {
148
+ transform : pushed ? `translateX(${ - pushDistance } px)` : '' ,
149
+ } }
150
+ >
118
151
< CSSMotion
119
152
key = "panel"
120
153
{ ...motionProps }
@@ -150,19 +183,21 @@ export default function DrawerPopup(props: DrawerPopupProps) {
150
183
151
184
// =========================== Render ===========================
152
185
return (
153
- < div
154
- className = { classNames (
155
- prefixCls ,
156
- `${ prefixCls } -${ placement } ` ,
157
- rootClassName ,
158
- {
159
- [ `${ prefixCls } -inline` ] : inline ,
160
- } ,
161
- ) }
162
- style = { rootStyle }
163
- >
164
- { maskNode }
165
- { panelNode }
166
- </ div >
186
+ < DrawerContext . Provider value = { mergedContext } >
187
+ < div
188
+ className = { classNames (
189
+ prefixCls ,
190
+ `${ prefixCls } -${ placement } ` ,
191
+ rootClassName ,
192
+ {
193
+ [ `${ prefixCls } -inline` ] : inline ,
194
+ } ,
195
+ ) }
196
+ style = { rootStyle }
197
+ >
198
+ { maskNode }
199
+ { panelNode }
200
+ </ div >
201
+ </ DrawerContext . Provider >
167
202
) ;
168
203
}
0 commit comments