Skip to content

Instantly share code, notes, and snippets.

@smashercosmo
Created June 4, 2018 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smashercosmo/d915a7be167641a86a7eef6b82075c20 to your computer and use it in GitHub Desktop.
Save smashercosmo/d915a7be167641a86a7eef6b82075c20 to your computer and use it in GitHub Desktop.
shouldForwardProp example
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