Hi there
I’m the author of phx_component_helpers and I have a recurring complaint of users regarding the CSS extension feature. I’m struggling to find a solution to this issue.
The purpose of this feature is to build components with default CSS classes and extend its classes when using the component. For instance a component can have following default style: border border-gray-400 bg-red
If I use it and extend its style with
bg-blue
the resulting CSS will be border border-gray bg-blue
We actually replace all classes from default styling having the same prefix (everything before first hyphen). It’s kinda working for a lot of cases but if you want to extend border border-2 border-orange-500
with border-red-500
it will be a little too greedy and replace all border classes resulting in border-red-500
instead of border border-2 border-red-500
.
The code is right there: phx_component_helpers/css.ex at main · cblavier/phx_component_helpers · GitHub
Another case completely defeating my prefix base approach is when you use multiple Tailwind classes that deal with the same CSS properties but do not share any common prefix. For instance you may want to extend a component using block
(in CSS it’s display: block;
) with flex
(in CSS it’s display: flex;
)
It looks like I might need some specific Tailwind related code dealing with Tailwind semantics. Do you know where I could find some JSON (or so) metadata regarding the whole Tailwind CSS class hierarchy?
Any other idea?