Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow passing false for variants with only true/:yes options #8

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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