x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<div class="flex flex-col gap-4"> small <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle lui-toggle--small relative"> <input name="" type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" > <span class="lui-slider" style=""> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[5px] top-px left-px fa-solid fa-spinner"></i> </span> </span> </label> </div> small readonly <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle lui-toggle--small relative"> <input name="" disabled='disabled' type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" > <span class="lui-slider" style="cursor: not-allowed;"> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[5px] top-px left-px fa-solid fa-spinner"></i> </span> </span> <div class="lui-toggle__readonly" ></div> </label> </div> small readonly checked <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle lui-toggle--small relative"> <input name="" disabled='disabled' type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" checked> <span class="lui-slider" style="cursor: not-allowed;"> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[5px] top-px left-px fa-solid fa-spinner"></i> </span> </span> <div class="lui-toggle__readonly" ></div> </label> </div> normal <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle relative"> <input name="" type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" > <span class="lui-slider" style=""> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> </label> </div> normal readonly <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle relative"> <input name="" disabled='disabled' type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" > <span class="lui-slider" style="cursor: not-allowed;"> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> <div class="lui-toggle__readonly" ></div> </label> </div> normal readonly checked <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle relative"> <input name="" disabled='disabled' type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" checked> <span class="lui-slider" style="cursor: not-allowed;"> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> <div class="lui-toggle__readonly" ></div> </label> </div> normal with label <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle relative"> <input name="" type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" > <span class="lui-slider" style=""> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> </label> <p class="text-black text-primary-xs-regular"> Label Exemplo </p> </div> normal readonly with label <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle relative"> <input name="" disabled='disabled' type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" > <span class="lui-slider" style="cursor: not-allowed;"> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> <div class="lui-toggle__readonly" ></div> </label> <p class="text-black text-primary-xs-regular"> Label Exemplo </p> </div> normal with label and checked <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle relative"> <input name="" type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" checked> <span class="lui-slider" style=""> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> </label> <p class="text-black text-primary-xs-regular"> Label Exemplo </p> </div> normal with label and checked and position left <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <p class="text-black text-primary-xs-regular"> Label Exemplo </p> <label class="lui-toggle relative"> <input name="" type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" checked> <span class="lui-slider" style=""> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> </label> </div> normal with label and checked and position right <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle relative"> <input name="" type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" checked> <span class="lui-slider" style=""> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> </label> <p class="text-black text-primary-xs-regular"> Label Exemplo </p> </div> normal with label and checked and position right and autoload <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle relative"> <input name="" type="checkbox" data-toggle-target="input" data-action="toggle#startLoading " data-method="patch" data-turbo_frame="" checked> <span class="lui-slider" style=""> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> </label> <p class="text-black text-primary-xs-regular"> Label Exemplo </p> </div> normal with label and unchecked and position right and autoload <div class="flex items-center gap-2 flex-row" data-controller="toggle"> <label class="lui-toggle relative"> <input name="" type="checkbox" data-toggle-target="input" data-action="toggle#startLoading " data-method="patch" data-turbo_frame="" > <span class="lui-slider" style=""> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> </label> <p class="text-black text-primary-xs-regular"> Label Exemplo </p> </div> <div class="flex items-center gap-2 flex-row foo" data-controller="toggle" data-target="some->target"> <label class="lui-toggle relative"> <input name="" type="checkbox" data-toggle-target="input" data-action=" " data-method="patch" data-turbo_frame="" > <span class="lui-slider" style=""> <span class="lui-toggle__spinner" data-toggle-target="spinner"> <i class="absolute origin-center animate-spin text-[9px] top-px left-px fa-solid fa-spinner"></i> </span> </span> </label> <p class="text-black text-primary-xs-regular"> Label Exemplo </p> </div></div>No Usage documentation to display.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<div class="flex flex-col gap-4"> small <%= render LooposUi::Toggle.new(size: :small) %> small readonly <%= render LooposUi::Toggle.new(size: :small, readonly: true) %> small readonly checked <%= render LooposUi::Toggle.new(size: :small, readonly: true, checked: true) %> normal <%= render LooposUi::Toggle.new(size: :normal) %> normal readonly <%= render LooposUi::Toggle.new(size: :normal, readonly: true) %> normal readonly checked <%= render LooposUi::Toggle.new(size: :normal, readonly: true, checked: true) %> normal with label <%= render LooposUi::Toggle.new(size: :normal, label: "Label Exemplo") %> normal readonly with label <%= render LooposUi::Toggle.new(size: :normal, readonly: true, label: "Label Exemplo") %> normal with label and checked <%= render LooposUi::Toggle.new(size: :normal, label: "Label Exemplo", checked: true) %> normal with label and checked and position left <%= render LooposUi::Toggle.new(size: :normal, position: :left, label: "Label Exemplo", checked: true) %> normal with label and checked and position right <%= render LooposUi::Toggle.new(size: :normal, position: :right, checked: true, label: "Label Exemplo") %> normal with label and checked and position right and autoload <%= render LooposUi::Toggle.new(size: :normal, position: :right, checked: true, label: "Label Exemplo", autoload: true) %> normal with label and unchecked and position right and autoload <%= render LooposUi::Toggle.new(size: :normal, position: :right, checked: false, label: "Label Exemplo", autoload: true) %> <%= render LooposUi::Toggle.new(label: "Label Exemplo", attrs: {data: { target: "some->target" }, class: "foo" }) %></div>No notes provided.
No params configured.
Description
A simple 'Toggle' component that submits an action when clicked.
Arguments
| Property | Default | Description |
|---|---|---|
color |
nil |
[DEPRECATED] ⚠️ the background color is now default |
data_action |
nil |
The action of the corresponding stimulus controller |
checked |
nil |
The attribute that determines if it's checked or not, must be "true" or "false" |
turbo_frame |
nil |
The turbo_frame that will be updated |
autoload |
false |
If true, the toggle will start loading when clicked |
label |
nil |
The label of the toggle |
position |
:right |
The position of the label, can be :left or :right |
size |
:normal |
The size of the toggle, can be :small or :normal |
attrs |
{} |
The tag options for the wrapper component. Useful to add data-targets or controllers. |
How-to
The toggle should be used with an already existing stimulus controller and data frame. It also requires the programmer to create a form first. An example will be listed below.
Example
<% if current_user.can_edit_catalog? %> <%= form_with(model: [:admin_v2, category], data: { turbo_frame: '_lui-main-layout', controller: "autosubmit", autosubmit_target: "form" }, multipart: true) do |form|%> <%= form.fields_for :catalog_node, category.catalog_node do |catalog_node_form| %> <%= catalog_node_form.hidden_field :active, value: !category.active %> <%= render LooposUi::Toggle.new( color: LooposUi::Colors.find("apps-800-primary"), data_action: "change->autosubmit#submit", checked: category_presenter.active ? "true" : "false", turbo_frame: "_lui-main-layout" )%> <% end %> <% end %><% end %>