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'
127
138const 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'
1813} ;
1914
20- const getTransitionClass = status => {
21- return transitionStatusToClassHash [ status ] || 'collapse' ;
15+ const getTransitionClass = status => {
16+ return transitionStatusToClassHash [ status ] || 'collapse'
2217}
2318
24- const getHeight = node => {
19+ const getHeight = node => {
2520 return node . scrollHeight ;
2621}
2722
2823//component - CoreUI / CCollapse
2924
30- const CCollapse = props => {
25+ const CCollapse = props => {
3126
3227 const {
3328 children,
@@ -36,7 +31,7 @@ const CCollapse = props=>{
3631 innerRef,
3732 show,
3833 navbar,
39- ...otherProps
34+ ...rest
4035 } = props ;
4136
4237 const [ height , setHeight ] = useState ( null ) ;
@@ -68,9 +63,11 @@ const CCollapse = props=>{
6863 }
6964
7065 //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 )
7471
7572 return (
7673 < Transition
@@ -83,13 +80,13 @@ const CCollapse = props=>{
8380 onExited = { onExited }
8481 >
8582 { ( status ) => {
86- let collapseClass = getTransitionClass ( status ) ;
83+ let collapseClass = getTransitionClass ( status )
8784 const classes = classNames (
8885 className ,
8986 collapseClass ,
9087 navbar && 'navbar-collapse'
9188 ) ;
92- const style = height === null ? null : { height } ;
89+ const style = height === null ? null : { height }
9390 return (
9491 < div
9592 { ...childProps }
@@ -99,11 +96,10 @@ const CCollapse = props=>{
9996 >
10097 { children }
10198 </ div >
102- ) ;
99+ )
103100 } }
104101 </ Transition >
105- ) ;
106-
102+ )
107103}
108104
109105CCollapse . propTypes = {
@@ -125,7 +121,7 @@ CCollapse.defaultProps = {
125121 appear : false ,
126122 enter : true ,
127123 exit : true ,
128- timeout : TransitionTimeouts . Collapse ,
124+ timeout : 350 ,
129125} ;
130126
131- export default CCollapse ;
127+ export default CCollapse
0 commit comments