by iooi · 7y ago · 0 comments
For example, I'll usually have a constants.scss file that I @import in other files, which for example will have a $max-modal-width: 600px;
I have run across use cases where I want to read that value from JS, but I could never figure out how to do that and resorted to duplicating the constant's value in my code. CSS-in-JS would make this trivial.
With SCSS/Less, it's actually painful to try and inject these values in to the build, and more prone to error. In your example, say deployment A has a $max-modal-width of 600px, B is 550px. Or colors are different, fonts, other styling.
var style = getComputedStyle(document.body);
console.log(style.getPropertyValue('--color-font-general'));
:root { --color-font-general: #336699; }
As a bonus point, you can also change the values of CSS Variables and layout will update automatically. Take a closer look at styles of YouTube.There is more coming in project Houdini. https://developers.google.com/web/updates/2016/05/houdini#th...