Created
May 23, 2017 04:07
-
-
Save kennydee/c1764dcde58adfd8341d48629313c6b4 to your computer and use it in GitHub Desktop.
Styled component without styled components for React Native
This file contains hidden or 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 React, { PropTypes } from 'react'; | |
import * as theme from '../theme'; | |
const styled = (Component, styler) => props => { | |
const propsWithTheme = { ...props, theme }; | |
const style = typeof styler === 'function' ? styler(propsWithTheme) : styler; | |
// React doesn't support "forwarding" ref for now | |
if (propsWithTheme.innerRef) { | |
propsWithTheme.ref = propsWithTheme.innerRef; | |
} | |
const component = <Component {...propsWithTheme} style={[style, propsWithTheme.style]} />; | |
component.propTypes = { | |
style: PropTypes.object, | |
}; | |
component.defaultProps = { | |
style: {}, | |
}; | |
return component; | |
}; | |
export default styled; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment