Releases: stephannv/phlex-variants
Releases · stephannv/phlex-variants
v0.2.0
What's Changed
- perf: Improve performance of build_style method by @stephannv in #5
- feat: Improve undefined method msg for style builder by @stephannv in #6
- feat: Improve variant not found error message by @stephannv in #7
- feat: Allow passing false for variants with only true/:yes options by @stephannv in #8
- docs: Mention generated constants by @stephannv in #9
- feat: Allow only true/false for boolean variants by @stephannv in #10
New Contributors
- @stephannv made their first contribution in #5
Full Changelog: v0.1.0...v0.2.0
First release
class Button < Phlex::HTML
include Phlex::Variants
style do
base "btn"
variants do
color do
default "btn-default"
primary "btn-primary"
danger "btn-danger"
end
size do
xs "btn-xs"
md "btn-md"
lg "btn-lg"
end
outline do
yes "btn-outline"
end
end
defaults color: :default, size: :md
end
attr_reader :color, :size, :outline
def initialize(color: nil, size: nil, outline: nil)
@color = color
@size = size
@outline = outline
end
def view_template(&)
a(class: build_style(color:, size:, outline:), &)
end
end
Button.new.call { "Hello" }
# => "<a class="btn btn-default btn-md">Hello<a>"
Button.new(color: :primary, size: :lg, outline: true).call { "Hello" }
# => "<a class="btn btn-primary btn-lg btn-outline">Hello<a>"
Button.build_style(color: :danger, size: :xs)
# => "btn btn-danger btn-xs"