Skip to content

Commit a237ec1

Browse files
committed
Allow passing additional classes when render
1 parent f3ef3d2 commit a237ec1

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unreleased
22
- Add support for slots ([#15](https://github.com/avo-hq/class_variants/pull/15))
3+
- Allow passing additional classes when render ([#17](https://github.com/avo-hq/class_variants/pull/17))
34

45
## 0.0.8 (2024-10-24)
56
- Deprecate usage of positional arguments ([#12](https://github.com/avo-hq/class_variants/pull/12))

lib/class_variants/instance.rb

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def initialize(**options, &block)
1111
end
1212

1313
def render(slot = :default, **overrides)
14+
classes = overrides.delete(:class)
15+
1416
# Start with our default classes
1517
result = [@base[slot]]
1618

@@ -25,6 +27,9 @@ def render(slot = :default, **overrides)
2527
end
2628
end
2729

30+
# add the passed in classes to the result
31+
result << classes
32+
2833
# Compact out any nil values we may have dug up
2934
result.compact!
3035

test/block_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ def test_compound_variants
4848
@cv.render(color: :success, disabled: true)
4949
)
5050
end
51+
52+
def test_additional_classes
53+
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs text-black", @cv.render(class: "text-black")
54+
end
5155
end

test/hash_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@ def test_compound_variants
5353
@cv.render(color: :success, disabled: true)
5454
)
5555
end
56+
57+
def test_additional_classes
58+
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs text-black", @cv.render(class: "text-black")
59+
end
5660
end

0 commit comments

Comments
 (0)