Created
June 4, 2018 14:29
-
-
Save smashercosmo/d915a7be167641a86a7eef6b82075c20 to your computer and use it in GitHub Desktop.
shouldForwardProp example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import styled from 'react-emotion' | |
import { bool } from 'prop-types' | |
import isPropValid from '@emotion/is-prop-valid' | |
import { | |
fontSize, | |
color, | |
textAlign, | |
fontWeight, | |
hover, | |
propTypes, | |
} from 'styled-system' | |
const block = props => { | |
if (props.block) return { display: 'block' } | |
return null | |
} | |
export const TextProps = { | |
...propTypes.fontSize, | |
...propTypes.color, | |
...propTypes.textAlign, | |
...propTypes.fontWeight, | |
...propTypes.hover, | |
block: bool, | |
} | |
const Text = styled('span', { | |
shouldForwardProp: prop => | |
isPropValid(prop) && ['color', 'fontSize', 'block'].indexOf(prop) === -1, | |
})(color, fontSize, fontWeight, textAlign, hover, block) | |
Text.propTypes = TextProps | |
Text.displayName = 'Text' | |
export default Text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment