So, the first example, the technical solution to reuse components in slightly different use cases that I've seen and I personally hate, but we'll get to it, is the class name injection. So when you have... Oh, this is a React example. So, when we have a component that disposes a class name prop that you can inject in the underlying children.
A lot of people do it. Don't get me wrong, it's my take that it's bad. It works fairly well for a lot of people. So, this thing allows you to inject a class name, apply the class name to whatever children make sense to this icon button, and you apply your CSS however you want.
There are a few problems I see with this because you have a dedicated, normally a dedicated CSS file, and then you don't know how that interacts with the base of that component. You have custom CSS that gets added to an extension that lives far away from the original base button, and if the base button changes, what happens to this? Like, how does that interact? Maybe this is used only in one place in your website, and you change the base that is used everywhere else, and you break something and you didn't even know about it. Unless you have visual regression. But who does that? I mean, a few people do. But really, in the day to day, do you use it? How many of you do visual regression approval to go live with changes in the UI? Okay, two. That's what I thought. It's expensive. Like, don't get me wrong. It's the right thing to do. It's very expensive to set up and maintain and create a proper build process around that. Like, it's... It's not easy.
On top of that, like, if you have that level of flexibility, you could create things that are not following the patterns that your designer wants. Or maybe your designer made a mistake and they created exceptions that shouldn't be there. Like, there are patterns for a reason. But why is this having different colors for over and active? Is that meaningful semantically? I don't know. It sounds like... It looks like a smudge to me in the code.
So again, it works really well, because it's the most flexible way to extend anything. But the four styles could be written in expected ways and we are creating a lot of variants that are pretty much to the whim of the moment for whoever designed them.
So, another technology is the ad hoc modifiers. I'm sure we use that.
Comments