The king of the haters here, he's got a point. He's not wrong. It can be super frustrating when you're trying to make a teeny tiny, two-pixel adjustment to one little component. And then you realize, oh, suddenly I have to make 10 other adjustments. It's frustrating. I get it. And that's just one of the reasons why we are building Joy UI, which is a brand new sister library to Material UI that implements our own in-house design system along with some bleeding edge innovations in developer experience.
And this is most evident, I think, in the way we've constructed Joy UI to handle CSS variables. So what even is a CSS variable? According to MDN, CSS variables are entities defined by CSS authors that contain specific values to be reused throughout a document. It's easy enough to understand in the context of branding colors, right? You've got a set of colors that are going to be reused throughout a design. And if you need to change one, it's so much simpler if you have one singular source of truth so you're not stuck finding and replacing hundreds of instances of the wrong hex code. Having that one source of truth is so powerful. And one of things that's really cool is you can actually name your variables, right? It helps a lot to maintain consistency across your design system and to help future proof your code, right? So instead of trying to figure out why this piece of text is sized at 1.75 rem, you can see that it has this dynamic value that's set to header to text, which gives you a lot more information about why that style has been applied.
And as you dive deeper down the rabbit hole, what you realize is that CSS variables have some really cool applications with our design systems that extend far beyond mere branding. So here's an example of what's going under the hood of the JoyUI component, the input component, that I shared a few slides back. It's weird, right? It's kind of hard to get used to at first. I mean, what is even going on here? We've got CSS variables that are referencing other variables, and they're doing mathematical calculations based on those variables. And it's all happening in CSS, right? As Josh Como points out, we're just not used to this concept, this mental model of defining CSS properties that have dynamic values. And things get even weirder when you start doing math with your variables and referencing variables inside of variables. Indeed, in the case of JoyUI, we're using CSS variables to create components that can automatically adapt their styles to match those of their parents and children, since they all reference that one singular source of truth for their magic numbers. So OK, that sounds cool, but what difference does it actually make, right? Let's consider a switch component and observe the differences in developer experience between Material UI and JoyUI. So here's some examples of switches.
These are all Material UI switches. Switch, obviously, simple on and off toggle, it's composed of a track and a thumb. So the user clicks the thumb to slide it across the track and make their selection. It's pretty simple on the surface, but it can get quite annoying when you need to make pixel perfect adjustments to the Material UI component. For instance, if we need to change the width of the track here, well, then that throws the thumb completely out of whack because it doesn't know the length of the track. And if I try to change the size of the thumb, well that messes up its path as well. And don't even get me started on border radii. If I need to adjust the rounded corners, it's not as though I can simply pass the same values to both pieces.
Comments