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

Allow passing additional classes when render #17

Merged
merged 1 commit into from
Oct 24, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased
- Add support for slots ([#15](https://github.com/avo-hq/class_variants/pull/15))
- Allow passing additional classes when render ([#17](https://github.com/avo-hq/class_variants/pull/17))

## 0.0.8 (2024-10-24)
- Deprecate usage of positional arguments ([#12](https://github.com/avo-hq/class_variants/pull/12))
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 @@ -11,6 +11,8 @@ def initialize(**options, &block)
end

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

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

Expand All @@ -25,6 +27,9 @@ def render(slot = :default, **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/block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ def test_compound_variants
@cv.render(color: :success, disabled: true)
)
end

def test_additional_classes
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs text-black", @cv.render(class: "text-black")
end
end
4 changes: 4 additions & 0 deletions test/hash_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ def test_compound_variants
@cv.render(color: :success, disabled: true)
)
end

def test_additional_classes
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs text-black", @cv.render(class: "text-black")
end
end