File tree Expand file tree Collapse file tree 7 files changed +47
-42
lines changed Expand file tree Collapse file tree 7 files changed +47
-42
lines changed Original file line number Diff line number Diff line change @@ -18,5 +18,11 @@ def initialize(**user_attrs)
18
18
def default_attrs
19
19
{ }
20
20
end
21
+
22
+ if Rails . env . development?
23
+ def before_template
24
+ comment { "Before #{ self . class . name } " }
25
+ end
26
+ end
21
27
end
22
28
end
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -5,37 +5,5 @@ class ThemeToggle < Base
5
5
def view_template ( &)
6
6
div ( **attrs , &)
7
7
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
40
8
end
41
9
end
Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ def view_template
26
26
end
27
27
28
28
def dark_mode_toggle
29
- RubyUI . ThemeToggle do | toggle |
30
- toggle . light_mode do
29
+ ThemeToggle do
30
+ SetLightMode do
31
31
Button ( variant : :ghost , icon : true ) do
32
32
svg (
33
33
xmlns : "http://www.w3.org/2000/svg" ,
@@ -42,8 +42,7 @@ def dark_mode_toggle
42
42
end
43
43
end
44
44
end
45
-
46
- toggle . dark_mode do
45
+ SetDarkMode do
47
46
Button ( variant : :ghost , icon : true ) do
48
47
svg (
49
48
xmlns : "http://www.w3.org/2000/svg" ,
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ def view_template
49
49
render Docs ::VisualCodeExample . new ( title : "Toggle component" , context : self ) do
50
50
<<~RUBY
51
51
ThemeToggle do |toggle|
52
- toggle.light_mode do
52
+ SetLightMode do
53
53
Button(variant: :outline, icon: true) do
54
54
svg(
55
55
xmlns: "http://www.w3.org/2000/svg",
@@ -65,7 +65,7 @@ def view_template
65
65
end
66
66
end
67
67
68
- toggle.dark_mode do
68
+ SetDarkMode do
69
69
Button(variant: :outline, icon: true) do
70
70
svg(
71
71
xmlns: "http://www.w3.org/2000/svg",
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ def view_template
12
12
render Docs ::VisualCodeExample . new ( title : "With icon" , context : self ) do
13
13
<<~RUBY
14
14
ThemeToggle do |toggle|
15
- toggle.light_mode do
15
+ SetLightMode do
16
16
Button(variant: :ghost, icon: true) do
17
17
svg(
18
18
xmlns: "http://www.w3.org/2000/svg",
@@ -28,7 +28,7 @@ def view_template
28
28
end
29
29
end
30
30
31
- toggle.dark_mode do
31
+ SetDarkMode do
32
32
Button(variant: :ghost, icon: true) do
33
33
svg(
34
34
xmlns: "http://www.w3.org/2000/svg",
@@ -52,11 +52,11 @@ def view_template
52
52
render Docs ::VisualCodeExample . new ( title : "With text" , context : self ) do
53
53
<<~RUBY
54
54
ThemeToggle do |toggle|
55
- toggle.light_mode do
55
+ SetLightMode do
56
56
Button(variant: :primary) { "Light" }
57
57
end
58
58
59
- toggle.dark_mode do
59
+ SetDarkMode do
60
60
Button(variant: :primary) { "Dark" }
61
61
end
62
62
end
You can’t perform that action at this time.
0 commit comments