class_variants
class_variants copied to clipboard
[Proposal] Create a `cv` helper method
How about creating a cv helpers which would default to class_variants.
@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