1
- import React , { useState } from 'react' ;
2
- import PropTypes from 'prop-types' ;
3
- import classNames from 'classnames' ;
4
- import {
5
- omit ,
6
- pick ,
7
- TransitionTimeouts ,
8
- TransitionPropTypeKeys ,
9
- TransitionStatuses
10
- } from './Shared/helper.js' ;
11
- import { Transition } from 'react-transition-group' ;
1
+ import React , { useState } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import classNames from 'classnames'
4
+ import { pickByKeys } from '@coreui/utils/src'
5
+ import { TransitionPropTypeKeys } from './Shared/helper.js'
6
+ import { Transition } from 'react-transition-group'
12
7
13
8
const transitionStatusToClassHash = {
14
- [ TransitionStatuses . ENTERING ] : 'collapsing' ,
15
- [ TransitionStatuses . ENTERED ] : 'collapse show' ,
16
- [ TransitionStatuses . EXITING ] : 'collapsing' ,
17
- [ TransitionStatuses . EXITED ] : 'collapse' ,
9
+ entering : 'collapsing' ,
10
+ entered : 'collapse show' ,
11
+ exiting : 'collapsing' ,
12
+ exited : 'collapse'
18
13
} ;
19
14
20
- const getTransitionClass = status => {
21
- return transitionStatusToClassHash [ status ] || 'collapse' ;
15
+ const getTransitionClass = status => {
16
+ return transitionStatusToClassHash [ status ] || 'collapse'
22
17
}
23
18
24
- const getHeight = node => {
19
+ const getHeight = node => {
25
20
return node . scrollHeight ;
26
21
}
27
22
28
23
//component - CoreUI / CCollapse
29
24
30
- const CCollapse = props => {
25
+ const CCollapse = props => {
31
26
32
27
const {
33
28
children,
@@ -36,7 +31,7 @@ const CCollapse = props=>{
36
31
innerRef,
37
32
show,
38
33
navbar,
39
- ...otherProps
34
+ ...rest
40
35
} = props ;
41
36
42
37
const [ height , setHeight ] = useState ( null ) ;
@@ -68,9 +63,11 @@ const CCollapse = props=>{
68
63
}
69
64
70
65
//render
71
-
72
- const transitionProps = pick ( otherProps , TransitionPropTypeKeys ) ;
73
- const childProps = omit ( otherProps , TransitionPropTypeKeys ) ;
66
+ const transitionProps = pickByKeys ( rest , TransitionPropTypeKeys )
67
+ const childPropKeys = Object . keys ( rest ) . filter ( attr => {
68
+ return ! TransitionPropTypeKeys . includes ( attr )
69
+ } )
70
+ const childProps = pickByKeys ( rest , childPropKeys )
74
71
75
72
return (
76
73
< Transition
@@ -83,13 +80,13 @@ const CCollapse = props=>{
83
80
onExited = { onExited }
84
81
>
85
82
{ ( status ) => {
86
- let collapseClass = getTransitionClass ( status ) ;
83
+ let collapseClass = getTransitionClass ( status )
87
84
const classes = classNames (
88
85
className ,
89
86
collapseClass ,
90
87
navbar && 'navbar-collapse'
91
88
) ;
92
- const style = height === null ? null : { height } ;
89
+ const style = height === null ? null : { height }
93
90
return (
94
91
< div
95
92
{ ...childProps }
@@ -99,11 +96,10 @@ const CCollapse = props=>{
99
96
>
100
97
{ children }
101
98
</ div >
102
- ) ;
99
+ )
103
100
} }
104
101
</ Transition >
105
- ) ;
106
-
102
+ )
107
103
}
108
104
109
105
CCollapse . propTypes = {
@@ -125,7 +121,7 @@ CCollapse.defaultProps = {
125
121
appear : false ,
126
122
enter : true ,
127
123
exit : true ,
128
- timeout : TransitionTimeouts . Collapse ,
124
+ timeout : 350 ,
129
125
} ;
130
126
131
- export default CCollapse ;
127
+ export default CCollapse
0 commit comments