Skip to content

Instantly share code, notes, and snippets.

@tclain
Created May 16, 2019 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tclain/baf0236392130fb5d5d9503eeb7515e0 to your computer and use it in GitHub Desktop.
Save tclain/baf0236392130fb5d5d9503eeb7515e0 to your computer and use it in GitHub Desktop.
// 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