diff --git a/package.json b/package.json index a7bd699..799aa04 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/rollup.config.js b/rollup.config.js index 3d92a55..fd269e8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -26,7 +26,11 @@ const config = { replace({ 'process.env.NODE_ENV': JSON.stringify(env), }), - commonjs(), + commonjs({ + namedExports: { + 'react-is': ['isValidElementType', 'isElement'], + }, + }), ], } diff --git a/src/propTypes.js b/src/propTypes.js index 0f8534e..da1f842 100644 --- a/src/propTypes.js +++ b/src/propTypes.js @@ -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 diff --git a/src/utils.js b/src/utils.js index 00b9b61..40d5d3f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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) ? : typeof Comp === 'function' ? Comp(props) : fallback -} + if (ReactIs.isElement(Comp) || typeof Comp === 'string') { + return Comp + } else if (ReactIs.isValidElementType(Comp)) { + return + } -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 }