Hey Pedro,
I’ve been working on a somewhat similar solution to what you are proposing here. I was planning on open sourcing it once it was a little bit more polished, but the intention from the beginning was to open source it. I’m open on giving access to interested parties now.
The basic architecture is composed of 3 parts: Components, Nomenclators & Hydrators.
Components
Components are a super set of phoenix components with two additional macros: variant
and classes
(well, also component
, I couldn’t override def
, as phoenix already does that).
These two macros are used to describe how the component can change depending on either code calls aka, size={:sm}
or what class name are to be used for an inner element. Which brings me to the next part
Nomenclators
Nomenclators responsability is to give class names to components and it’s sub elements.
This is the default nomenclator, that spits classes like btn btn-sm btn-outline btn-primary
. If you check out the code, class_name/3 can be either _component, _variant, _option
, used to variant class names or _component, :classes, _class_name
that gives names to classes
macros defined in the component.
You can see how just with this, you could just add tailwind inline classes and forget about the next part:
Hydrators
Hydrators responsability is to Hydrate with css the skeleton that nomenclators create. They are auto generated based on: the apps it should go look for components, the parent hydrator and a nomenclator.
This is a very early stage of the DefaultHydrator
that users will be able to use as a base.
Next is the auto generated version of a hydrator that has DefaultHydrator
as it’s parent.
A few things to note here:
- Notice how it brings all the style and var code as comments from the parent (and it’s parent parent), so that you don’t need to go back and forth trying to understand why styles are the way they are.
- variables can be then injected into ~CSS sigils
- If you modify a sub hydrator the engine is smart enough not to crush the changes. Hydrators are constantly being regenerated.
- ~CSS sigils sorts and properly indents properties with a custom formatter.
- A main focus of this is to have many many themes for my app, and reuse style code as much as possible.
Finally there are a few mix tasks to generate all the files.
Right now I’m working on two things:
- Not your classic component gallery. You’ll not only be able to see all components and it’s possible variations, but have complete access to all variables and css code, so you can edit them right there in your browser, and have those changes be reflected on your code and compiled to css live.
- Actually implement some damn components.
There are more things about this library, but that’s the gist. Oh, and it’s called BuenaVista
.
Let me know if you’d interested in collaborating 