1
- import React , { useState } from 'react'
1
+ import React , { useState } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import classNames from 'classnames'
4
- import { omitByKeys } from '@coreui/utils/src'
5
- import { TransitionPropTypeKeys } from '../utils/helper.js'
6
4
import { Transition } from 'react-transition-group'
7
5
8
- const transitionStatusToClassHash = {
9
- entering : 'collapsing' ,
10
- entered : 'collapse show' ,
11
- exiting : 'collapsing' ,
12
- exited : 'collapse'
13
- } ;
14
-
15
- const getTransitionClass = status => {
16
- return transitionStatusToClassHash [ status ] || 'collapse'
17
- }
18
-
19
- const getHeight = node => {
20
- return node . scrollHeight ;
6
+ const getTransitionClass = s => {
7
+ return s === 'entering' ? 'collapsing' :
8
+ s === 'entered' ? 'collapse show' :
9
+ s === 'exiting' ? 'collapsing' : 'collapse'
21
10
}
22
11
23
12
//component - CoreUI / CCollapse
24
-
25
13
const CCollapse = props => {
26
14
27
15
const {
@@ -31,43 +19,40 @@ const CCollapse = props => {
31
19
innerRef,
32
20
show,
33
21
navbar,
34
- ...rest
35
- } = props ;
22
+ ...attributes
23
+ } = props
36
24
37
- const [ height , setHeight ] = useState ( null ) ;
25
+ const [ height , setHeight ] = useState ( )
38
26
39
- const onEntering = ( node , isAppearing ) => {
40
- setHeight ( getHeight ( node ) ) ;
41
- props . onEntering ( node , isAppearing ) ;
27
+ const onEntering = node => {
28
+ setHeight ( node . scrollHeight )
42
29
}
43
30
44
- const onEntered = ( node , isAppearing ) => {
45
- setHeight ( null ) ;
46
- props . onEntered ( node , isAppearing ) ;
31
+ const onEntered = ( ) => {
32
+ setHeight ( null )
47
33
}
48
34
49
- const onExit = node => {
50
- setHeight ( getHeight ( node ) ) ;
51
- props . onExit ( node ) ;
35
+ const onExit = node => {
36
+ setHeight ( node . scrollHeight )
52
37
}
53
38
54
- const onExiting = node => {
55
- const _unused = node . offsetHeight ; // eslint-disable-line no-unused-vars
56
- setHeight ( 0 ) ;
57
- props . onExiting ( node ) ;
39
+ const onExiting = node => {
40
+ const _unused = node . offsetHeight // eslint-disable-line no-unused-vars
41
+ setHeight ( 0 )
58
42
}
59
43
60
- const onExited = node => {
61
- setHeight ( null ) ;
62
- props . onExited ( node ) ;
44
+ const onExited = ( ) => {
45
+ setHeight ( null )
63
46
}
64
47
65
48
//render
66
- const childProps = omitByKeys ( rest , TransitionPropTypeKeys )
67
-
68
49
return (
69
50
< Transition
70
51
in = { show }
52
+ timeout = { 350 }
53
+ appear = { false }
54
+ enter = { true }
55
+ exit = { true }
71
56
onEntering = { onEntering }
72
57
onEntered = { onEntered }
73
58
onExit = { onExit }
@@ -80,12 +65,12 @@ const CCollapse = props => {
80
65
className ,
81
66
collapseClass ,
82
67
navbar && 'navbar-collapse'
83
- ) ;
68
+ )
84
69
const style = height === null ? null : { height }
85
70
return (
86
71
< div
87
- { ...childProps }
88
- style = { { ...childProps . style , ...style } }
72
+ { ...attributes }
73
+ style = { { ...attributes . style , ...style } }
89
74
className = { classes }
90
75
ref = { innerRef }
91
76
>
@@ -98,7 +83,6 @@ const CCollapse = props => {
98
83
}
99
84
100
85
CCollapse . propTypes = {
101
- ...Transition . propTypes ,
102
86
children : PropTypes . oneOfType ( [
103
87
PropTypes . arrayOf ( PropTypes . node ) ,
104
88
PropTypes . node
@@ -108,15 +92,10 @@ CCollapse.propTypes = {
108
92
innerRef : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . func , PropTypes . string ] ) ,
109
93
show : PropTypes . bool ,
110
94
navbar : PropTypes . bool
111
- } ;
95
+ }
112
96
113
97
CCollapse . defaultProps = {
114
- ...Transition . defaultProps ,
115
- show : false ,
116
- appear : false ,
117
- enter : true ,
118
- exit : true ,
119
- timeout : 350 ,
120
- } ;
98
+ show : false
99
+ }
121
100
122
101
export default CCollapse
0 commit comments