Skip to content

Instantly share code, notes, and snippets.

@rattrayalex
Created November 4, 2020 18:53
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 rattrayalex/e9a0dbc4ba2b24f0795b10661af1fa57 to your computer and use it in GitHub Desktop.
Save rattrayalex/e9a0dbc4ba2b24f0795b10661af1fa57 to your computer and use it in GitHub Desktop.
Loose sketch of css-in-js root variables
const rootCSSVars = {
colorPrimary: {name: '--color-primary', value: 'red'},
colorSecondary: {name: '--color-secondary', value: 'orange'},
}
writeCSSToDOM(`
:root {
${_.mapValues(rootCSSVars, (v) => `${v.name}: ${v.value};\n`)}
}
`)
export const vars = _.map(rootCSSVars, (v, k) => ([k,`var(${name})`]));
// so you can do this:
import {vars} from 'my-styles'
css({
color: vars.primaryColor,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment