Created
May 16, 2019 14:48
-
-
Save tclain/baf0236392130fb5d5d9503eeb7515e0 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
// define a object for you theme | |
export const theme = { | |
'colors.hello': true | |
} | |
// dynamically infer the possible theme key | |
export type ThemeKeys = keyof typeof theme | |
// restrict interpolation to be only theme keys | |
function themedStyled(strings: TemplateStringsArray, ...args: ThemeKeys[]){ | |
// pseudo-code, we can interpolate the values in the tagged-templates css function | |
return css(strings, ...args.map(themeKey => theme[themeKey])) | |
} | |
// usage | |
// type Ctrl + enter in your favorite IDE | |
themedStyled` | |
background-color: ${}; | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment