Skip to content

Instantly share code, notes, and snippets.

@Jimmydalecleveland
Created August 22, 2019 00:12
Show Gist options
  • Save Jimmydalecleveland/46c8d4a129d5ea1e7dca7f41a2060072 to your computer and use it in GitHub Desktop.
Save Jimmydalecleveland/46c8d4a129d5ea1e7dca7f41a2060072 to your computer and use it in GitHub Desktop.
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