3 ms·
Having X class strictly linked to X widget or component breaks down when your widget has multiple subcomponents which may or not be reusable, like having Y widg
by ookblah 3y ago
Having X class strictly linked to X widget or component breaks down when your widget has multiple subcomponents which may or not be reusable, like having Y widget and Y widget with some slightly changed parameters. Suddenly your "clean" system isn't so clean and you end up either adding inline styles, extract these components into their own classes and naming them which just moves the complexity elsewhere, or creating your own frankenstein utility classes.
There' s reason why there was a rise in something like tailwind, because they ended up creating what IMO we end up doing anyway. For me, it's 100x easier to maintain to open a component up that is months old and grok every everything about it without having to reference some other CSS file or structure. If I want to tweak some aspect I can do so easily right there, I don't have to jump back and forth, and it's better than inline because I benefit from things like hover styles and responsive classes which I can't do inline. You can always extract truly reusable pieces into their own class.
Is it more verbose? Yes. Can it be abused? Yes. But I wouldn't go back to the "old" way and it isn't for lack of knowing how.
- toastal 3y agoCriticizing utility-first libraries doesn’t imply that a) the only alternative is some component-based naming scheme nor b) that you can’t use pieces of both & definitely isn’t suggesting c) use inline style. I’ve used a mix of different system where appropriate for years now & it’s been a pretty good way to go. And you can still give the component a name even if you do mostly or all utility classes for your team & other users.
- ookblah 3y agoi'm just going by the example that you gave which is of a component based naming scheme. just to be clear, perhaps we're talking about the same thing (mix of style) just from a different angle and more emphasis on one or the other. i still use a "global" stylesheet as a base but the majority of our work within components is utility classes, so i'm also not suggesting that everything be utility only.
- toastal 3y agoRoger. I’m mainly saying jamming everything into a utility that is one prop per class is a mess. Mixing where appropriate is good.