benvp / ex_cva Goto Github PK
View Code? Open in Web Editor NEWClass Variance Authority for Elixir
License: MIT License
Class Variance Authority for Elixir
License: MIT License
I've been following the docs and been unable to get a compound variant to work. It seems that there may be a level missing or, more likely, I'm complete misunderstanding them.
Any examples you can point to would be great.
Here's what we're doing. We've defined an intent
variant on button/1
with several values, e.g. primary
, secondary
, etc. We've defined a color
variant. Our app has two main areas and we differentiate them, in part, based on color.
So, I want a primary red button, I can do <.button intent="primary" color="red" ...
My understanding of a compound variant would allow us to specify primary_red
in some manner to include classes from both intent="primary" and color="red".
How do we indicate in the instance of the function component that we want a compound variant?
Right now, you can only do something like: variant :color, [blue: "text-blue-500"]
and not variant :color, @text_colors
because the macro is not expanding the module attribute. Would you be willing to support a similar syntax? This seems very helpful for cases where you want to share the variant definitions between similar components.
Imagine the given scenario: You have an icon button component with two sizes, for each size you want not only to change the button classes but also the icon classes (so it resizes appropriately with the button):
variant :size, [sm: "text-sm px-2 py-1", lg: "text-lg px-4 py-2"]
slot :inner_block, required: true
def icon_button(assigns) do
~H"""
<button class={@cva_class}>
<.icon name="award" class="h-2 w-2 mr-2" />
<%= render_slot(@inner_block) %>
</button>
"""
end
It seems to me that this would be a good job for compound_variant
if we had a way to split the classes instead of merging with @cva_class
. Would you be interested in supporting something like this?
compound_variant :icon_class, "h-2 w-2 mr-2", size: :sm
compound_variant :icon_class, "h-4 w-4 mr-4", size: :lg
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.