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