-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from javierav/feature/block-slots
Add support for slots and advanced configuration via code block
- Loading branch information
Showing
6 changed files
with
243 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require "test_helper" | ||
|
||
class BlockTest < Minitest::Test | ||
def setup | ||
@cv = ClassVariants.build do | ||
base "text-white py-1 px-3 rounded-full" | ||
|
||
variant color: :primary, class: "bg-blue-500" | ||
variant color: :secondary, class: "bg-purple-500" | ||
variant color: :success, class: "bg-green-500" | ||
|
||
variant size: :sm, class: "py-1 px-3 text-xs" | ||
variant size: :md, class: "py-1.5 px-4 text-sm" | ||
variant size: :lg, class: "py-2 px-6 text-md" | ||
|
||
variant disabled: true, class: "opacity-50 bg-gray-500" | ||
variant visible: false, class: "hidden" | ||
|
||
variant color: :success, disabled: true, class: "bg-green-100 text-green-700" | ||
|
||
defaults size: :sm | ||
end | ||
end | ||
|
||
def test_render_with_defaults | ||
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs", @cv.render | ||
end | ||
|
||
def test_render_with_size | ||
assert_equal "text-white py-1 px-3 rounded-full py-1.5 px-4 text-sm", @cv.render(size: :md) | ||
end | ||
|
||
def test_render_with_size_and_color | ||
assert_equal( | ||
"text-white py-1 px-3 rounded-full bg-green-500 py-1 px-3 text-xs", | ||
@cv.render(size: :sm, color: :success) | ||
) | ||
end | ||
|
||
def test_boolean_variants | ||
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs", @cv.render(visible: true) | ||
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs hidden", @cv.render(visible: false) | ||
end | ||
|
||
def test_compound_variants | ||
assert_equal( | ||
"text-white py-1 px-3 rounded-full bg-green-500 py-1 px-3 text-xs opacity-50 bg-gray-500 bg-green-100 text-green-700", | ||
@cv.render(color: :success, disabled: true) | ||
) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require "test_helper" | ||
|
||
class HashTest < Minitest::Test | ||
def setup | ||
@cv = ClassVariants.build( | ||
base: "text-white py-1 px-3 rounded-full", | ||
variants: { | ||
color: { | ||
primary: "bg-blue-500", | ||
secondary: "bg-purple-500", | ||
success: "bg-green-500" | ||
}, | ||
size: { | ||
sm: "py-1 px-3 text-xs", | ||
md: "py-1.5 px-4 text-sm", | ||
lg: "py-2 px-6 text-md" | ||
}, | ||
disabled: "opacity-50 bg-gray-500", | ||
"!visible": "hidden" | ||
}, | ||
compound_variants: [ | ||
{color: :success, disabled: true, class: "bg-green-100 text-green-700"} | ||
], | ||
defaults: { | ||
size: :sm | ||
} | ||
) | ||
end | ||
|
||
def test_render_with_defaults | ||
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs", @cv.render | ||
end | ||
|
||
def test_render_with_size | ||
assert_equal "text-white py-1 px-3 rounded-full py-1.5 px-4 text-sm", @cv.render(size: :md) | ||
end | ||
|
||
def test_render_with_size_and_color | ||
assert_equal( | ||
"text-white py-1 px-3 rounded-full bg-green-500 py-1 px-3 text-xs", | ||
@cv.render(size: :sm, color: :success) | ||
) | ||
end | ||
|
||
def test_boolean_variants | ||
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs", @cv.render(visible: true) | ||
assert_equal "text-white py-1 px-3 rounded-full py-1 px-3 text-xs hidden", @cv.render(visible: false) | ||
end | ||
|
||
def test_compound_variants | ||
assert_equal( | ||
"text-white py-1 px-3 rounded-full bg-green-500 py-1 px-3 text-xs opacity-50 bg-gray-500 bg-green-100 text-green-700", | ||
@cv.render(color: :success, disabled: true) | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require "test_helper" | ||
|
||
class SlotTest < Minitest::Test | ||
def setup | ||
@cv = ClassVariants.build do | ||
base do | ||
slot :root, class: "rounded py-3 px-5 mb-4" | ||
slot :title, class: "font-bold mb-1" | ||
end | ||
|
||
variant variant: :outlined do | ||
slot :root, class: "border" | ||
end | ||
|
||
variant variant: :outlined, severity: :error do | ||
slot :root, class: "border-red-700 dark:border-red-500" | ||
slot :title, class: "text-red-700 dark:text-red-500" | ||
slot :message, class: "text-red-600 dark:text-red-500" | ||
end | ||
|
||
variant variant: :outlined, severity: :success do | ||
slot :root, class: "border-green-700 dark:border-green-500" | ||
slot :title, class: "text-green-700 dark:text-green-500" | ||
slot :message, class: "text-green-600 dark:text-green-500" | ||
end | ||
|
||
variant variant: :filled, severity: :error do | ||
slot :root, class: "bg-red-100 dark:bg-red-800" | ||
slot :title, class: "text-red-900 dark:text-red-50" | ||
slot :message, class: "text-red-700 dark:text-red-200" | ||
end | ||
|
||
variant variant: :filled, severity: :success do | ||
slot :root, class: "bg-green-100 dark:bg-green-800" | ||
slot :title, class: "text-green-900 dark:text-green-50" | ||
slot :message, class: "text-green-700 dark:text-green-200" | ||
end | ||
|
||
defaults variant: :filled, severity: :success | ||
end | ||
end | ||
|
||
def test_render_default_slot | ||
assert_equal "", @cv.render | ||
end | ||
|
||
def test_render_nonexistent_slot | ||
assert_equal "", @cv.render(:nonexistent) | ||
end | ||
|
||
def test_render_slot_with_defaults | ||
assert_equal "rounded py-3 px-5 mb-4 bg-green-100 dark:bg-green-800", @cv.render(:root) | ||
end | ||
|
||
def test_render_slot_with_variant | ||
assert_equal "rounded py-3 px-5 mb-4 border border-green-700 dark:border-green-500", @cv.render(:root, variant: :outlined) | ||
end | ||
|
||
def test_render_slot_without_base | ||
assert_equal "text-green-700 dark:text-green-200", @cv.render(:message) | ||
end | ||
|
||
def test_render_slot_with_unused_variant | ||
assert_equal( | ||
"rounded py-3 px-5 mb-4 border border-green-700 dark:border-green-500", | ||
@cv.render(:root, variant: :outlined, type: :button) | ||
) | ||
end | ||
end |