Created
August 22, 2019 00:12
-
-
Save Jimmydalecleveland/46c8d4a129d5ea1e7dca7f41a2060072 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
const theme = { | |
spacing: { | |
min: '2px', | |
max: '24px', | |
}, | |
colors: { | |
primary: 'coral', | |
secondary: 'peachpuff', | |
}, | |
} | |
function styled(css, ...variables) { | |
const computedCss = css | |
.map((chunk, index) => `${chunk}${variables[index] || ''}`) | |
.join('') | |
return computedCss | |
} | |
const Button = styled` | |
background: ${theme.colors.secondary}; | |
margin-bottom: ${theme.spacing.min}; | |
span { | |
padding: 0.25em 1em; | |
color: ${theme.colors.primary}; | |
} | |
` | |
/* Output: | |
background: peachpuff; | |
margin-bottom: 2px; | |
span { | |
padding: 0.25em 1em; | |
color: coral; | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment