Skip to content

Commit

Permalink
Allow passing additional classes when render
Browse files Browse the repository at this point in the history
  • Loading branch information
javierav committed Oct 17, 2024
1 parent fe9ddbd commit 727eb74
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Unreleased
- Allow passing additional classes when render ([#17](https://github.com/avo-hq/class_variants/pull/17))

## 0.0.7 (2023-12-07)
- Add support for compound variants ([#8](https://github.com/avo-hq/class_variants/pull/8))
Expand Down
5 changes: 5 additions & 0 deletions lib/class_variants/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def initialize(classes = "", variants: {}, compoundVariants: [], defaults: {})
# rubocop:enable Naming/VariableName

def render(**overrides)
classes = overrides.delete(:class)

# Start with our default classes
result = [@classes]

Expand All @@ -29,6 +31,9 @@ def render(**overrides)
end
end

# add the passed in classes to the result
result << classes

# Compact out any nil values we may have dug up
result.compact!

Expand Down
4 changes: 4 additions & 0 deletions test/class_variants_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ def test_compound_variants
@cv.render(ring: true, color: :green)
)
end

def test_additional_classes
assert_equal "rounded border text-md text-black", @cv.render(class: "text-black")
end
end

0 comments on commit 727eb74

Please sign in to comment.