Skip to content

Commit 2d1975a

Browse files
authored
Merge pull request #60 from zumkorn/add-style-variants-string-support
Add string support for style variants
2 parents 5fee5af + 86d7302 commit 2d1975a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/view_component_contrib/style_variants.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def cast_value(val)
163163
case val
164164
when true then :yes
165165
when false then :no
166+
when String then val.to_sym
166167
else
167168
val
168169
end

test/cases/style_variants_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ def test_render_defaults
6262
assert_css "div.flex.flex-col.primary-color.primary-bg.text-sm"
6363
end
6464

65+
def test_render_string_value
66+
component = Component.new(theme: "secondary", size: "md", disabled: true)
67+
68+
render_inline(component)
69+
70+
assert_css "div.secondary-color.secondary-bg.text-md.opacity-50"
71+
end
72+
6573
class SubComponent < Component
6674
erb_template <<~ERB
6775
<div class="<%= style(:component, theme: theme, size: size) %>">

0 commit comments

Comments
 (0)