Skip to content

Instantly share code, notes, and snippets.

@maciejmatu
Last active October 21, 2017 21:28
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 maciejmatu/43b89d9f69d50d59e209e1a631c1bf48 to your computer and use it in GitHub Desktop.
Save maciejmatu/43b89d9f69d50d59e209e1a631c1bf48 to your computer and use it in GitHub Desktop.
// 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