class_variants icon indicating copy to clipboard operation
class_variants copied to clipboard

[Proposal] Create a `cv` helper method

Open adrianthedev opened this issue 6 months ago • 1 comments

How about creating a cv helpers which would default to class_variants.

adrianthedev avatar May 15 '25 08:05 adrianthedev

@adrianthedev I've been thinking about this and I think the cv rails view helper makes sense as a shorthand to the new functionality proposed in #36 , so we can do the following:

# config/initializers/class_variants.rb
ClassVariants.define :button do
  variant color: :red, class: "bg-red-500"
  variant color: :green, class: "bg-green-500"
end
# app/views/pages/home.html.erb
<%= button_tag "Reset", class: cv(:button, color: :red) %>

Internally it could be implemented as follows:

def cv(name, ...)
  ClassVariants.for(name).render(...)
end

javierav avatar Aug 20 '25 11:08 javierav