Skip to content

Commit 727eb74

Browse files
committed
Allow passing additional classes when render
1 parent fe9ddbd commit 727eb74

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Unreleased
2+
- Allow passing additional classes when render ([#17](https://github.com/avo-hq/class_variants/pull/17))
23

34
## 0.0.7 (2023-12-07)
45
- Add support for compound variants ([#8](https://github.com/avo-hq/class_variants/pull/8))

lib/class_variants/instance.rb

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def initialize(classes = "", variants: {}, compoundVariants: [], defaults: {})
1212
# rubocop:enable Naming/VariableName
1313

1414
def render(**overrides)
15+
classes = overrides.delete(:class)
16+
1517
# Start with our default classes
1618
result = [@classes]
1719

@@ -29,6 +31,9 @@ def render(**overrides)
2931
end
3032
end
3133

34+
# add the passed in classes to the result
35+
result << classes
36+
3237
# Compact out any nil values we may have dug up
3338
result.compact!
3439

test/class_variants_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ def test_compound_variants
5454
@cv.render(ring: true, color: :green)
5555
)
5656
end
57+
58+
def test_additional_classes
59+
assert_equal "rounded border text-md text-black", @cv.render(class: "text-black")
60+
end
5761
end

0 commit comments

Comments
 (0)