Last active
October 21, 2017 21:28
-
-
Save maciejmatu/43b89d9f69d50d59e209e1a631c1bf48 to your computer and use it in GitHub Desktop.
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
// component props mock | |
const properties = { | |
color: 'red', | |
large: true | |
}; | |
// curried function | |
const styled = (props) => (strings, ...args) => { | |
return strings.map((string, i) => { | |
const correspondingItem = args[i]; | |
switch(typeof correspondingItem) { | |
case 'function': | |
return string + correspondingItem(props); | |
case 'undefined': | |
return string; | |
default: | |
return string + correspondingItem; | |
} | |
}).join(''); | |
} | |
const styles = styled(properties)` | |
width: 10px; | |
height: 10px; | |
background-color: ${props => props.color}; | |
font-size: ${props => props.large ? 20 : 14}px; | |
color: white; | |
`; | |
console.log(styles); | |
/* | |
" | |
width: 10px; | |
height: 10px; | |
background-color: red; | |
font-size: 20px; | |
color: white; | |
" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment