Skip to content

Commit f14cbba

Browse files
committed
split theme components from slot to components
1 parent 64b7a29 commit f14cbba

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class SetDarkMode < ThemeToggle
5+
def view_template(&)
6+
div(**attrs, &)
7+
end
8+
9+
def default_attrs
10+
{
11+
class: "hidden dark:inline-block",
12+
data: {controller: "ruby-ui--theme-toggle", action: "click->ruby-ui--theme-toggle#setLightTheme"}
13+
}
14+
end
15+
end
16+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class SetLightMode < ThemeToggle
5+
def view_template(&)
6+
div(**attrs, &)
7+
end
8+
9+
def default_attrs
10+
{
11+
class: "dark:hidden",
12+
data: {controller: "ruby-ui--theme-toggle", action: "click->ruby-ui--theme-toggle#setDarkTheme"}
13+
}
14+
end
15+
end
16+
end

lib/ruby_ui/theme_toggle/theme_toggle.rb

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,5 @@ class ThemeToggle < Base
55
def view_template(&)
66
div(**attrs, &)
77
end
8-
9-
def light_mode(**user_attrs, &)
10-
light_attrs = mix(default_light_attrs, user_attrs)
11-
div(**light_attrs, &)
12-
end
13-
14-
def dark_mode(**user_attrs, &)
15-
dark_attrs = mix(default_dark_attrs, user_attrs)
16-
div(**dark_attrs, &)
17-
end
18-
19-
private
20-
21-
def default_attrs
22-
{
23-
data: {controller: "ruby-ui--theme-toggle"}
24-
}
25-
end
26-
27-
def default_light_attrs
28-
{
29-
class: "dark:hidden",
30-
data: {action: "click->ruby-ui--theme-toggle#setDarkTheme"}
31-
}
32-
end
33-
34-
def default_dark_attrs
35-
{
36-
class: "hidden dark:inline-block",
37-
data: {action: "click->ruby-ui--theme-toggle#setLightTheme"}
38-
}
39-
end
408
end
419
end

test/ruby_ui/theme_toggle_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ class RubyUI::ThemeToggleTest < ComponentTest
66
def test_render_with_all_items
77
output = phlex do
88
RubyUI.ThemeToggle do |toggle|
9-
toggle.light_mode do
9+
RubyUI.SetLightMode do
1010
RubyUI.Button(variant: :primary) { "Light" }
1111
end
1212

13-
toggle.dark_mode do
13+
RubyUI.SetDarkMode do
1414
RubyUI.Button(variant: :primary) { "Dark" }
1515
end
1616
end

0 commit comments

Comments
 (0)