Skip to content

Commit

Permalink
Move elementType into utils
Browse files Browse the repository at this point in the history
  • Loading branch information
colebemis committed Jul 19, 2019
1 parent a9c0de1 commit 82f62a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/Link.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import PropTypes from 'prop-types'
import {isValidElementType} from 'react-is'
import styled from 'styled-components'
import {system} from 'styled-system'
import {COMMON, TYPOGRAPHY} from './constants'
import theme from './theme'
import elementType from './utils/elementType'

const buttonStyles = {
display: 'inline-block',
Expand Down Expand Up @@ -40,13 +40,7 @@ Link.defaultProps = {
}

Link.propTypes = {
as: (props, propName, componentName) => {
if (props[propName] && !isValidElementType(props[propName])) {
return new Error(
`Invalid prop '${propName}' supplied to '${componentName}': the prop is not a valid React component`
)
}
},
as: elementType,
href: PropTypes.string,
theme: PropTypes.object,
underline: PropTypes.bool,
Expand Down
14 changes: 14 additions & 0 deletions src/utils/elementType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {isValidElementType} from 'react-is'

// This function is a temporary workaround until we can get
// the official PropTypes.elementType working (https://git.io/fjMLX).
// PropTypes.elementType is currently `undefined` in the browser.
function elementType(props, propName, componentName) {
if (props[propName] && !isValidElementType(props[propName])) {
return new Error(
`Invalid prop '${propName}' supplied to '${componentName}': the prop is not a valid React component`
)
}
}

export default elementType

0 comments on commit 82f62a2

Please sign in to comment.