3 ms·
Note that while CSS modules doesn't provide an out-of-the-box solution for themeing you can use css variables and then either just swap out the variables (if yo
by pluma 10y ago
Note that while CSS modules doesn't provide an out-of-the-box solution for themeing you can use css variables and then either just swap out the variables (if you only target browsers that support the custom properties spec) or run the CSS through postCSS.
The important difference however is that CSS-in-JS can swap out themes on the fly whereas this would be a static solution that doesn't scale e.g. if you need per-user customization.
- mxstbr 10y ago> if you only target browsers that support the custom properties spec That "sidenote" is exactly why vanilla CSS has a "Kinda" for theming. Taking a look at caniuse[0], only 66.39% of browsers have support for custom properties – not exactly production ready. That being said, once custom properties are well supported they're an amazing solution for theming! Take a look at this talk Glen (the co-creator of CSS modules and now styled-components) gave at JSConf BP for some hints towards this future: https://www.youtube.com/watch?v=XR6eM_5pAb0 https://www.youtube.com/watch?v=XR6eM_5pAb0 [0]: http://caniuse.com/#feat=css-variables http://caniuse.com/#feat=css-variables
- pluma 10y agoIMO PostCSS is a workable solution until that number gets closer to 100%. It just requires the aforementioned post-processing step per theme to "render" the stylesheet with the correct variables: https://github.com/postcss/postcss-custom-properties https://github.com/postcss/postcss-custom-properties