Some of you might already be using this style. And you can wrap this with a theme provider that takes care of the rest. So something that's interesting is if I add this additional color, I kind of don't really have a way of knowing is this first, is this the right color, is this color defined? Second, is this color going to be applied? I kind of have to write this, render into the browser, see if it works. It probably is just black, so I right click inspect element, and that's when I get to know if it's the right color.
So we add a little more JavaScript and we type script. And with type script now what you get is you can type your theme and then you start getting the red squiggly line, which tells you that this property, FGHover, is actually not even defined on theme, so that's not the right thing to use. And then you can fix it. The other thing, if you haven't noticed, is I kind of messed up somewhere in the slides where background color is just, on hover, it's just pointing to the button background and not the hover background, and with theme, because now you control your theme, you control your styles, you can actually type them smarter, and it can give you smarter errors. For example, border color, I'm using button.bg, which is not actually a valid style, which is not actually a valid color variable in our component system, so we can give you these errors, like, this is not the right one, maybe you meant button.borderColor. Same goes for hover style, it says, HellasPentaCast, a type, themeColorBackground is not assignable. You have to use hover background. And because you have TypeScript, you have a compiler behind this, you also get features like autocomplete, which help you pick the right hover backgrounds.
So customizations are still interesting. This is the default, or the recommended way of customizing components with style components, where you wrap the button component in a style and then you can add your additional styles there. So something like this is nice, but it's also kind of a lot of boilerplate, it's a lot more work. I'm not a big fan of this style because it kind of diverges from the button. You'd have page button and then other thing would use the page button and you kind of get further and further from the original source. So, with just a little more JavaScript, this is team UI's logo, but team UI, system UI, this class of libraries made this syntax popular which is the SX prop or the CSS prop. And with this prop what you do is instead of defining a new component you define your overrides at this component usage level. So it's kind of like an inline tag but it's not, it compiles it down. So what you end up getting is something like this where your button styles are the default styles and then you merge them with the SX overrides styles that are provided. And of course you type the SX so you get the same type completion even in the application with the overrides. So pretty, pretty nice API, pretty cool. So we've gone from less, like very little JavaScript to a lot of JavaScript. But we've kind of got a lot of features along the way, so there's things like nesting, variable steaming, but there's also linting, import dependencies. We have a very opinionated autocomplete that we can configure which would be harder to do without JavaScript. So is that the success? Like is that what we wanted? I guess so. But of course things come with tradeoffs. So it's been such a big success that there are about 4,000 presentational components on GitHub which have the SX prop just for style overrides. And which has caused success problems, like shampoo problems.
Comments