1
1
import * as React from 'react' ;
2
- import type { GetContainer } from 'rc-util/lib/PortalWrapper ' ;
3
- import Portal from 'rc-util/lib/PortalWrapper ' ;
2
+ import Portal from '@ rc-component/portal ' ;
3
+ import type { PortalProps } from '@ rc-component/portal ' ;
4
4
import DrawerPopup from './DrawerPopup' ;
5
5
import type { DrawerPopupProps } from './DrawerPopup' ;
6
+ import { warnCheck } from './util' ;
6
7
7
8
export type Placement = 'left' | 'top' | 'right' | 'bottom' ;
8
9
@@ -12,27 +13,27 @@ export interface DrawerProps
12
13
13
14
open ?: boolean ;
14
15
onClose ?: ( e : React . MouseEvent | React . KeyboardEvent ) => void ;
15
- /** @deprecated Only work on Portal mode. You can replace with rootClassName instead */
16
- wrapperClassName ?: string ;
17
16
destroyOnClose ?: boolean ;
18
- getContainer ?: GetContainer | false ;
17
+ getContainer ?: PortalProps [ 'getContainer' ] ;
19
18
}
20
19
21
- const defaultGetContainer = ( ) => document . body ;
22
-
23
20
const Drawer : React . FC < DrawerProps > = props => {
24
21
const {
25
22
open,
26
23
getContainer,
27
24
forceRender,
28
- wrapperClassName,
29
25
prefixCls,
30
26
afterOpenChange,
31
27
destroyOnClose,
32
28
} = props ;
33
29
34
30
const [ animatedVisible , setAnimatedVisible ] = React . useState ( false ) ;
35
31
32
+ // ============================= Warn =============================
33
+ if ( process . env . NODE_ENV !== 'production' ) {
34
+ warnCheck ( props ) ;
35
+ }
36
+
36
37
// ============================= Open =============================
37
38
const internalAfterOpenChange : DrawerProps [ 'afterOpenChange' ] =
38
39
nextVisible => {
@@ -51,20 +52,14 @@ const Drawer: React.FC<DrawerProps> = props => {
51
52
afterOpenChange : internalAfterOpenChange ,
52
53
} ;
53
54
54
- if ( getContainer === false ) {
55
- return < DrawerPopup { ...sharedDrawerProps } inline /> ;
56
- }
57
-
58
55
return (
59
56
< Portal
60
- visible = { open }
61
- forceRender = { forceRender }
57
+ open = { open || forceRender || animatedVisible }
58
+ autoDestroy = { false }
62
59
getContainer = { getContainer }
63
- wrapperClassName = { wrapperClassName }
60
+ autoLock = { open || animatedVisible }
64
61
>
65
- { ( { scrollLocker } ) => (
66
- < DrawerPopup { ...sharedDrawerProps } scrollLocker = { scrollLocker } />
67
- ) }
62
+ < DrawerPopup { ...sharedDrawerProps } inline = { getContainer === false } />
68
63
</ Portal >
69
64
) ;
70
65
} ;
@@ -74,7 +69,6 @@ const Drawer: React.FC<DrawerProps> = props => {
74
69
// Let's maintain this in one place.
75
70
Drawer . defaultProps = {
76
71
open : false ,
77
- getContainer : defaultGetContainer ,
78
72
prefixCls : 'rc-drawer' ,
79
73
placement : 'right' ,
80
74
autoFocus : true ,
0 commit comments