Skip to content

Commit 97ea903

Browse files
committed
fix: remove possibility of inheriting advanced transition options
- clear files: add omitByProps function - change toast css import
1 parent f677f5a commit 97ea903

File tree

9 files changed

+49
-31
lines changed

9 files changed

+49
-31
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"dependencies": {
4141
"@popperjs/core": "~2.4.0",
4242
"@coreui/icons": "^1.0.1",
43-
"@coreui/icons-react": "^1.0.0-alpha.5",
44-
"@coreui/utils": "1.2.4",
43+
"@coreui/icons-react": "^1.0.0-beta.1",
44+
"@coreui/utils": "~1.3.1",
4545
"classnames": "~2.2.6",
4646
"core-js": "~3.6.5",
4747
"perfect-scrollbar": "~1.5.0",
@@ -62,7 +62,7 @@
6262
"eslint": "^7.0.0",
6363
"eslint-plugin-import": "^2.20.2",
6464
"eslint-plugin-react": "^7.20.0",
65-
"nwb": "^0.24.6",
65+
"nwb": "^0.25.2",
6666
"sinon": "^9.0.2"
6767
},
6868
"repository": {

src/alert/CAlert.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useState, useEffect, useRef } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44
import CFade from '../fade/CFade'
5+
import { omitByKeys } from '@coreui/utils/src'
6+
import { CFadeProps } from '../utils/helper.js'
57
import CButtonClose from '../button/CButtonClose'
68

79
//component - CoreUI / CAlert
@@ -53,13 +55,15 @@ const CAlert = props => {
5355
return () => clearTimeout(timeout.current)
5456
}, [isOpen])
5557

58+
const attrs = omitByKeys(attributes, CFadeProps)
59+
5660
return (
5761
<CFade
5862
{...alertTransition}
5963
className={classes}
6064
in={Boolean(isOpen)}
6165
role="alert"
62-
{...attributes}
66+
{...attrs}
6367
>
6468
{ children }
6569
{ closeButton && <CButtonClose onClick={() => setIsOpen(false)} />}
@@ -80,8 +84,6 @@ CAlert.propTypes = {
8084
};
8185

8286
CAlert.defaultProps = {
83-
tag: 'div',
84-
//
8587
show: true,
8688
fade: true
8789
};

src/collapse/CCollapse.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {useState} from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
4-
import { pickByKeys } from '@coreui/utils/src'
4+
import { omitByKeys } from '@coreui/utils/src'
55
import { TransitionPropTypeKeys } from '../utils/helper.js'
66
import { Transition } from 'react-transition-group'
77

@@ -63,15 +63,10 @@ const CCollapse = props => {
6363
}
6464

6565
//render
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)
66+
const childProps = omitByKeys(rest, TransitionPropTypeKeys)
7167

7268
return (
7369
<Transition
74-
{...transitionProps}
7570
in={show}
7671
onEntering={onEntering}
7772
onEntered={onEntered}

src/fade/CFade.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
4-
import { pickByKeys } from '@coreui/utils/src'
4+
import { pickByKeys, omitByKeys } from '@coreui/utils/src'
55
import { TransitionPropTypeKeys, tagPropType } from '../utils/helper.js'
66
import { Transition } from 'react-transition-group'
77

@@ -21,10 +21,7 @@ const CFade = props => {
2121

2222
//render
2323
const transitionProps = pickByKeys(rest, TransitionPropTypeKeys)
24-
const childPropKeys = Object.keys(rest).filter(key => {
25-
return !TransitionPropTypeKeys.includes(key)
26-
})
27-
const childProps = pickByKeys(rest, childPropKeys)
24+
const childProps = omitByKeys(rest, TransitionPropTypeKeys)
2825

2926
return (
3027
<Transition {...transitionProps}>

src/index.d.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22

33
type ChildElement = any
44

5-
interface CAlert extends CFade {
5+
interface CAlert {
66
children?: ChildElement;
77
className?: string;
88
innerRef?: object | Function | string;
@@ -247,7 +247,7 @@ interface Transition {
247247
onExited?: Function;
248248
}
249249

250-
interface CCollapse extends Transition {
250+
interface CCollapse {
251251
children?: ChildElement | Array<ChildElement>;
252252
className?: string;
253253
innerRef?: object | Function | string;
@@ -908,14 +908,25 @@ interface CSubheader {
908908
innerRef?: object | Function | string;
909909
}
910910

911+
interface CSwitch {
912+
className?: string
913+
innerRef?: object | Function | string
914+
size?: '' | 'lg' | 'sm'
915+
color?: string
916+
labelOn?: string
917+
labelOff?: string
918+
variant?: '' | '3d' | 'opposite' | 'outline'
919+
shape?: '' | 'pill' | 'square'
920+
}
921+
911922
interface CTabContent {
912923
children?: ChildElement;
913924
className?: string;
914925
innerRef?: object | Function | string;
915926
fade?: boolean;
916927
}
917928

918-
interface CTabPane extends CFade {
929+
interface CTabPane {
919930
children?: ChildElement;
920931
className?: string;
921932
innerRef?: func | string | object;
@@ -928,7 +939,7 @@ interface CTabs {
928939
onActiveTabChange?: Function;
929940
}
930941

931-
interface CToast extends CFade {
942+
interface CToast {
932943
className?: string;
933944
children?: ChildElement;
934945
innerRef?: func | string | object;
@@ -1137,6 +1148,7 @@ export declare const CSidebarNavItem: (props: CSidebarNavItem) => React.SFC<CSid
11371148
export declare const CSidebarNavTitle: (props: CSidebarNavTitle) => React.SFC<CSidebarNavTitle>;
11381149
export declare const CSpinner: (props: CSpinner) => React.SFC<CSpinner>;
11391150
export declare const CSubheader: (props: CSubheader) => React.SFC<CSubheader>;
1151+
export declare const CSwitch: (props: CSwitch) => React.SFC<CSwitch>;
11401152
export declare const CTabContent: (props: CTabContent) => React.SFC<CTabContent>;
11411153
export declare const CTabPane: (props: CTabPane) => React.SFC<CTabPane>;
11421154
export declare const CTabs: (props: CTabs) => React.SFC<CTabs>;

src/tabs/CTabPane.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useState, useContext, createRef, useEffect } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44
import CFade from '../fade/CFade'
5+
import { omitByKeys } from '@coreui/utils/src'
6+
import { CFadeProps } from '../utils/helper.js'
57

68
import { Context } from './CTabs.js'
79
import { Context as FadeContext } from './CTabContent.js'
@@ -38,12 +40,14 @@ const CTabPane = props => {
3840
className
3941
)
4042

43+
const attrs = omitByKeys(attributes, CFadeProps)
44+
4145
return (
4246
<CFade
4347
in={isActive}
4448
baseClass={fade ? 'fade' : ''}
4549
className={classes}
46-
{...attributes}
50+
{...attrs}
4751
innerRef={ref}
4852
/>
4953
)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
.fade {
1+
.toast-fade {
22
transition: opacity .5s;
33
}
4-
.slowfade {
4+
.toast-fade-slow {
55
transition: opacity 2s;
66
}

src/toast/CToast.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import React, { useState, useRef, useEffect } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44
import CFade from '../fade/CFade'
5-
import style from './CToast.module.css'
5+
import { omitByKeys } from '@coreui/utils/src'
6+
import { CFadeProps } from '../utils/helper.js'
7+
import './CToast.css'
68

79
export const Context = React.createContext({})
810

@@ -81,14 +83,13 @@ const CToast = props => {
8183
}
8284

8385
// render
84-
const classes = classNames(
85-
'toast', className
86-
)
86+
const classes = classNames('toast', className)
8787

8888
const fadeClasses = classNames(
89-
fade ? style[`${state === 'hiding' ? 'slowfade' : 'fade' }`] : 'show'
89+
fade && (state === 'hiding' ? 'toast-fade-slow' : 'toast-fade')
9090
)
9191

92+
const attrs = omitByKeys(attributes, CFadeProps)
9293
return (
9394
<Context.Provider value={{ close }}>
9495
{
@@ -97,12 +98,12 @@ const CToast = props => {
9798
role="alert"
9899
aria-live="assertive"
99100
aria-atomic="true"
100-
{...attributes}
101101
in={state === true}
102102
onMouseOver={onMouseOver}
103103
onMouseOut={onMouseOut}
104104
baseClass={fadeClasses}
105105
innerRef={innerRef}
106+
{...attrs}
106107
>
107108
{children}
108109
</CFade>

src/utils/helper.js

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export const TransitionPropTypeKeys = [
1919
'onExited'
2020
];
2121

22+
export const CFadeProps = [
23+
...TransitionPropTypeKeys,
24+
'baseClass',
25+
'baseClassActive',
26+
'tag'
27+
]
28+
2229
export const canUseDOM = !!(
2330
typeof window !== 'undefined' &&
2431
window.document &&

0 commit comments

Comments
 (0)