@@ -20,7 +20,7 @@ class Drawer extends React.PureComponent {
20
20
openClassName : PropTypes . string ,
21
21
iconChild : PropTypes . any ,
22
22
onChange : PropTypes . func ,
23
- onIconClick : PropTypes . func ,
23
+ onSwitch : PropTypes . func ,
24
24
}
25
25
static defaultProps = {
26
26
className : 'drawer' ,
@@ -31,7 +31,8 @@ class Drawer extends React.PureComponent {
31
31
level : 'all' ,
32
32
levelTransition : 'transform .3s cubic-bezier(0.78, 0.14, 0.15, 0.86)' ,
33
33
onChange : ( ) => { } ,
34
- onIconClick : ( ) => { } ,
34
+ onSwitch : ( ) => { } ,
35
+ iconChild : ( < i className = "drawer-button-icon" /> ) ,
35
36
}
36
37
37
38
levelDom = [ ] ;
@@ -47,11 +48,10 @@ class Drawer extends React.PureComponent {
47
48
open : props . open !== undefined ? props . open : ! ! props . defaultOpen ,
48
49
} ;
49
50
}
50
-
51
51
componentDidMount ( ) {
52
+ this . container = this . props . parent ? this . defaultGetContainer ( ) : ReactDOM . findDOMNode ( this ) ;
52
53
this . getParentAndLevelDom ( ) ;
53
- this . container = this . defaultGetContainer ( ) ;
54
- this . componentDidUpdate ( ) ;
54
+ this . forceUpdate ( ) ;
55
55
}
56
56
57
57
componentWillReceiveProps ( nextProps ) {
@@ -64,17 +64,18 @@ class Drawer extends React.PureComponent {
64
64
}
65
65
}
66
66
67
- componentDidUpdate ( ) {
68
- this . renderPickerComponent ( this . getChildToRender ( ) ) ;
69
- }
70
-
71
67
componentWillUnmount ( ) {
72
68
if ( this . container ) {
73
69
this . setLevelDomTransform ( false , true ) ;
74
- this . contextWrapDom . style . transform = '' ;
70
+ // 拦不住。。直接删除;
71
+ if ( this . props . parent ) {
72
+ this . container . parentNode . removeChild ( this . container ) ;
73
+ }
74
+ /* this.contextWrapDom.style.transform = '';
75
75
this.container.style.opacity = 0;
76
76
this.container.style.pointerEvents = 'none';
77
- this . container . style . transition = 'opacity .3s' ;
77
+ this.container.style.transition = 'opacity 11.3s';
78
+ console.log(this.container)
78
79
const removeElemetFunc = () => {
79
80
this.container.removeEventListener(transitionEnd, removeElemetFunc);
80
81
this.levelDom.forEach(dom => {
@@ -84,7 +85,7 @@ class Drawer extends React.PureComponent {
84
85
this.container.parentNode.removeChild(this.container);
85
86
this.container = null;
86
87
};
87
- this . container . addEventListener ( transitionEnd , removeElemetFunc ) ;
88
+ this.container.addEventListener(transitionEnd, removeElemetFunc); */
88
89
}
89
90
}
90
91
@@ -94,7 +95,7 @@ class Drawer extends React.PureComponent {
94
95
}
95
96
const { level, parent } = this . props ;
96
97
this . levelDom = [ ] ;
97
- this . parent = document . querySelectorAll ( parent ) [ 0 ] ;
98
+ this . parent = parent && document . querySelectorAll ( parent ) [ 0 ] || this . container . parentNode ;
98
99
if ( level === 'all' ) {
99
100
const children = Array . prototype . slice . call ( this . parent . children ) ;
100
101
children . forEach ( child => {
@@ -105,7 +106,7 @@ class Drawer extends React.PureComponent {
105
106
this . levelDom . push ( child ) ;
106
107
}
107
108
} ) ;
108
- } else {
109
+ } else if ( level ) {
109
110
dataToArray ( this . props . level ) . forEach ( key => {
110
111
document . querySelectorAll ( key )
111
112
. forEach ( item => {
@@ -122,7 +123,7 @@ class Drawer extends React.PureComponent {
122
123
}
123
124
124
125
onTouchEnd = ( e , close ) => {
125
- this . props . onIconClick ( e ) ;
126
+ this . props . onSwitch ( e ) ;
126
127
if ( this . props . open !== undefined ) {
127
128
return ;
128
129
}
@@ -262,7 +263,7 @@ class Drawer extends React.PureComponent {
262
263
if ( this . isOpenChange === undefined || this . isOpenChange ) {
263
264
this . setLevelDomTransform ( open ) ;
264
265
}
265
- let iconChildToRender = ( < i className = { ` ${ className } -button-icon` } /> ) ;
266
+ let iconChildToRender ;
266
267
if ( iconChild ) {
267
268
if ( Array . isArray ( iconChild ) ) {
268
269
if ( iconChild . length === 2 ) {
@@ -298,12 +299,14 @@ class Drawer extends React.PureComponent {
298
299
>
299
300
{ children }
300
301
</ div >
301
- < div
302
- className = { `${ className } -button` }
303
- onClick = { ( e ) => { this . onTouchEnd ( e ) ; } }
304
- >
305
- { iconChildToRender }
306
- </ div >
302
+ { iconChildToRender && (
303
+ < div
304
+ className = { `${ className } -button` }
305
+ onClick = { ( e ) => { this . onTouchEnd ( e ) ; } }
306
+ >
307
+ { iconChildToRender }
308
+ </ div >
309
+ ) }
307
310
</ div >
308
311
</ div >
309
312
) ;
@@ -318,12 +321,17 @@ class Drawer extends React.PureComponent {
318
321
return container ;
319
322
} ;
320
323
321
- renderPickerComponent = ( children ) => {
322
- ReactDOM . unstable_renderSubtreeIntoContainer ( this , children , this . container ) ;
323
- }
324
-
325
324
render ( ) {
326
- return null ;
325
+ const children = this . getChildToRender ( ) ;
326
+ if ( ! this . props . parent ) {
327
+ return ( < div className = { this . props . wrapperClassName } >
328
+ { children }
329
+ </ div > ) ;
330
+ }
331
+ if ( ! this . container ) {
332
+ return null ;
333
+ }
334
+ return ReactDOM . createPortal ( children , this . container ) ;
327
335
}
328
336
}
329
337
0 commit comments