v6: prefer components in normalizeComponent (#1609)

* prefer components in normalizeComponent

* move react-is to direct dep
This commit is contained in:
Henry Q. Dineen
2019-11-20 08:47:06 -07:00
committed by Tanner Linsley
parent fb134462ff
commit f2e62a13f2
4 changed files with 24 additions and 29 deletions
+3 -2
View File
@@ -44,10 +44,11 @@
"docs:build": "yarn build && cd docs && yarn && yarn build"
},
"dependencies": {
"classnames": "^2.2.5"
"classnames": "^2.2.5",
"react-is": "^16.8.1"
},
"peerDependencies": {
"prop-types": "^15.5.0",
"prop-types": "^15.7.0",
"react": "^16.x.x",
"react-dom": "^16.x.x"
},
+5 -1
View File
@@ -26,7 +26,11 @@ const config = {
replace({
'process.env.NODE_ENV': JSON.stringify(env),
}),
commonjs(),
commonjs({
namedExports: {
'react-is': ['isValidElementType', 'isElement'],
},
}),
],
}
+8 -8
View File
@@ -82,14 +82,14 @@ export default {
columns: PropTypes.arrayOf(
PropTypes.shape({
// Renderers
Cell: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.func]),
Header: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.func]),
Footer: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.func]),
Aggregated: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.func]),
Pivot: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.func]),
PivotValue: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.func]),
Expander: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.func]),
Filter: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
Cell: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.elementType]),
Header: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.elementType]),
Footer: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.elementType]),
Aggregated: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.elementType]),
Pivot: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.elementType]),
PivotValue: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.elementType]),
Expander: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.elementType]),
Filter: PropTypes.oneOfType([PropTypes.element, PropTypes.elementType]),
// All Columns
sortable: PropTypes.bool, // use table default
+8 -18
View File
@@ -1,5 +1,7 @@
import React from 'react'
import classnames from 'classnames'
import * as ReactIs from 'react-is'
//
export default {
get,
@@ -204,24 +206,12 @@ function isSortingDesc (d) {
}
function normalizeComponent (Comp, props, fallback = Comp) {
return isReactComponent(Comp) ? <Comp {...props} /> : typeof Comp === 'function' ? Comp(props) : fallback
}
if (ReactIs.isElement(Comp) || typeof Comp === 'string') {
return Comp
} else if (ReactIs.isValidElementType(Comp)) {
return <Comp {...props} />
}
function isClassComponent (component) {
return (
typeof component === 'function' &&
!!Object.getPrototypeOf(component).isReactComponent
)
}
function isFunctionComponent (component) {
return (
typeof component === 'function' &&
String(component).includes('.createElement')
)
}
function isReactComponent (component) {
return isClassComponent(component) || isFunctionComponent(component)
return fallback
}