Skip to content

Instantly share code, notes, and snippets.

@Jimmydalecleveland
Last active August 22, 2019 00:18
Show Gist options
  • Save Jimmydalecleveland/a5ed951d5e84cbfc6b3e21ea7fb310e9 to your computer and use it in GitHub Desktop.
Save Jimmydalecleveland/a5ed951d5e84cbfc6b3e21ea7fb310e9 to your computer and use it in GitHub Desktop.
function styled(css, ...variables) {
// . . .
const computedCss = css
.map(
(chunk, index) =>
// now fires a callback at 'variables[index]'
`${chunk}${variables[index] ? variables[index](props) : ''}`
)
.join('')
return computedCss
}
const Button = styled`
/* now passes a callback that accepts a 'props' object */
background: ${({ primary, theme }) =>
primary ? theme.colors.primary : theme.colors.secondary};
/* ... */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment