Skip to content

Allow controlling if/how compound variants are merged with @csa_class #6

@thiagomajesk

Description

@thiagomajesk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions