GoogleChromeLabs / postcss-jit-props

A CSS custom property helper based on PostCSS. Supply a pool of variables and this plugin will add them to the stylesheet as they are used.
https://stackblitz.com/edit/jit-open-props?file=postcss.config.js
Apache License 2.0
211 stars 9 forks source link

Add option for "destination" so all the JIT props can be put into somewhere other than `:root` #1

Closed argyleink closed 2 years ago

argyleink commented 2 years ago

For many various use cases, folks wont be bundling or will want scoped vars. Need to find a way to support these SSR, non-bundled and scoped use cases.

lunelson commented 2 years ago

An example of some custom-property patterns I'm typically working with, which ideally I could supply to this plugin as a CSS file path, would be something like the following:

:root,
.scheme-lite {
  --rgb-neutral-1: 252, 253, 254;
  --rgb-neutral-2: 241, 244, 247;
  --rgb-neutral-3: 231, 235, 241;
}

.scheme-dark {
  --rgb-neutral-1: 14, 16, 18;
  --rgb-neutral-2: 28, 31, 35;
  --rgb-neutral-3: 40, 44, 50;
}

:root {
  --font-size-sans-xs: 12px;
  --font-size-sans-s: 14px;
  --font-size-sans-m: 16px;
  --is__xs: initial;
  --is__s: initial;
  --is__m: initial;
  --is__ml: initial;
  --is__l: initial;
  --is__xl: initial;
}

@media screen and (min-width: 24em) {
  :root {
    --is__xs: /*!*/ /*!*/ ;
  }
}

@media screen and (min-width: 36em) {
  :root {
    --is__s: /*!*/ /*!*/ ;
    --font-size-sans-xs: 13px;
    --font-size-sans-s: 15px;
    --font-size-sans-m: 17px;
  }
}

@media screen and (min-width: 48em) {
  :root {
    --is__m: /*!*/ /*!*/ ;
  }
}

@media screen and (min-width: 60em) {
  :root {
    --is__ml: /*!*/ /*!*/ ;
    --font-size-sans-xs: 14px;
    --font-size-sans-s: 16px;
    --font-size-sans-m: 18px;
  }
}

@media screen and (min-width: 72em) {
  :root {
    --is__l: /*!*/ /*!*/ ;
  }
}

@media screen and (min-width: 84em) {
  :root {
    --is__xl: /*!*/ /*!*/ ;
    --font-size-sans-xs: 16px;
    --font-size-sans-s: 18px;
    --font-size-sans-m: 20px;
  }
}