Skip to content

Commit

Permalink
feat: Allow passing false for variants with only true/:yes options
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv committed Sep 29, 2024
1 parent c4a9100 commit 106162e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/phlex/variants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def build_variants_style(variants)
value = options[option]

next value if value

# doesn't raise error when passing false for variant with only true/:yes option
next if option == false && options.has_key?(true)
end

raise_variant_not_found_error(options, variant, option)
Expand Down
14 changes: 14 additions & 0 deletions spec/phlex/variants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ def view_template
expect(example.build_style(loading: :yes, full: :no)).to eq "btn-loading btn-fit"
end

it "doesn't raise error when passing false for a variant with only true/:yes options" do
example = phlex_class do
style do
variants do
outline do
yes "btn-outline"
end
end
end
end

expect(example.build_style(outline: false)).to eq ""
end

it "ignores nil variants" do
example = phlex_class do
style do
Expand Down

0 comments on commit 106162e

Please sign in to comment.