shoelace-rails 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -2
- data/app/helpers/shoelace/components/error_wrappable.rb +21 -0
- data/app/helpers/shoelace/components/sl_checkbox.rb +40 -0
- data/app/helpers/shoelace/components/sl_collection_radio_buttons.rb +47 -0
- data/app/helpers/shoelace/components/sl_color_picker.rb +30 -0
- data/app/helpers/shoelace/components/sl_input.rb +33 -0
- data/app/helpers/shoelace/components/sl_radio_button.rb +20 -0
- data/app/helpers/shoelace/components/sl_range.rb +22 -0
- data/app/helpers/shoelace/components/sl_select.rb +77 -0
- data/app/helpers/shoelace/components/sl_switch.rb +23 -0
- data/app/helpers/shoelace/components/sl_textarea.rb +20 -0
- data/app/helpers/shoelace/form_builder.rb +8 -0
- data/app/helpers/shoelace/sl_form_builder.rb +111 -0
- data/app/helpers/shoelace/sl_form_helper.rb +139 -0
- data/lib/shoelace/rails/version.rb +1 -1
- data/lib/shoelace/railtie.rb +2 -4
- data/test/helpers/form_builder/sl_checkbox_test.rb +45 -0
- data/test/helpers/form_builder/sl_color_picker_test.rb +26 -0
- data/test/helpers/form_builder/sl_input_test.rb +126 -0
- data/test/helpers/form_builder/sl_radio_group_test.rb +63 -0
- data/test/helpers/form_builder/sl_range_test.rb +34 -0
- data/test/helpers/form_builder/sl_select_test.rb +320 -0
- data/test/helpers/form_builder/sl_switch_test.rb +26 -0
- data/test/helpers/form_builder/sl_textarea_test.rb +72 -0
- data/test/helpers/form_builder_test.rb +16 -0
- data/test/helpers/form_helper_test.rb +3 -442
- data/test/helpers/translation_test.rb +12 -4
- data/test/test_helper.rb +22 -0
- metadata +25 -4
- data/app/helpers/shoelace/form_helper.rb +0 -408
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require_relative '../../../app/helpers/shoelace/sl_form_helper'
|
5
|
+
|
6
|
+
class FormBuilderSlTextareaTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
8
|
+
|
9
|
+
test "#text_area" do
|
10
|
+
sl_form_for(User.new, url: "/") do |form|
|
11
|
+
assert_dom_equal <<~HTML, form.text_area(:name)
|
12
|
+
<sl-textarea label="Name" resize="auto" name="user[name]" id="user_name"></sl-textarea>
|
13
|
+
HTML
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test "#text_area with an invalid value" do
|
18
|
+
yuki = User.new.tap(&:validate)
|
19
|
+
|
20
|
+
sl_form_for(yuki, url: "/") do |form|
|
21
|
+
assert_dom_equal <<~HTML, form.text_area(:name)
|
22
|
+
<sl-textarea label="Name" resize="auto" name="user[name]" id="user_name" data-invalid="" invalid=""></sl-textarea>
|
23
|
+
HTML
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test "#text_area with a value" do
|
28
|
+
sl_form_for(User.new(name: "Yuki Nishijima"), url: "/") do |form|
|
29
|
+
assert_dom_equal <<~HTML, form.text_area(:name)
|
30
|
+
<sl-textarea label="Name" resize="auto" value="Yuki Nishijima" name="user[name]" id="user_name"></sl-textarea>
|
31
|
+
HTML
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test "#text_area with an one-off value" do
|
36
|
+
sl_form_for(User.new(name: "Yuki Nishijima"), url: "/") do |form|
|
37
|
+
assert_dom_equal <<~HTML, form.text_area(:name, value: "Yuki")
|
38
|
+
<sl-textarea label="Name" resize="auto" value="Yuki" name="user[name]" id="user_name"></sl-textarea>
|
39
|
+
HTML
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
test "#text_area without a label" do
|
44
|
+
sl_form_for(User.new, url: "/") do |form|
|
45
|
+
assert_dom_equal <<~HTML, form.text_area(:name, label: nil)
|
46
|
+
<sl-textarea resize="auto" name="user[name]" id="user_name"></sl-textarea>
|
47
|
+
HTML
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
test "#text_area with a size" do
|
52
|
+
sl_form_for(User.new, url: "/") do |form|
|
53
|
+
assert_dom_equal <<~HTML, form.text_area(:name, size: "small")
|
54
|
+
<sl-textarea label="Name" resize="auto" size="small" name="user[name]" id="user_name"></sl-textarea>
|
55
|
+
HTML
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test "#text_area with a block" do
|
60
|
+
sl_form_for(User.new, url: "/") do |form|
|
61
|
+
expected = <<~HTML
|
62
|
+
<sl-textarea label="Name" resize="auto" name="user[name]" id="user_name">
|
63
|
+
<div slot="help-text">Name can not be blank.</div>
|
64
|
+
</sl-textarea>
|
65
|
+
HTML
|
66
|
+
|
67
|
+
assert_dom_equal(expected, form.text_area(:name) {
|
68
|
+
content_tag(:div, "Name can not be blank.", slot: "help-text")
|
69
|
+
})
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require_relative '../../app/helpers/shoelace/sl_form_builder'
|
5
|
+
|
6
|
+
class FormBuilderTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
8
|
+
|
9
|
+
test "#submit" do
|
10
|
+
sl_form_for(User.new, url: "/") do |form|
|
11
|
+
assert_dom_equal <<~HTML, form.submit("Save")
|
12
|
+
<sl-button type="submit" variant="primary" data-disable-with="Save">Save</sl-button>
|
13
|
+
HTML
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
require_relative '../../app/helpers/shoelace/
|
4
|
+
require_relative '../../app/helpers/shoelace/sl_form_builder'
|
5
5
|
|
6
|
-
class
|
7
|
-
include Shoelace::
|
8
|
-
|
9
|
-
AUTOCOMPLETE_ATTRIBUTE = ActionView::VERSION::STRING >= '6.1.0' ? 'autocomplete="off"' : ''
|
6
|
+
class SlFormHelperTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
10
8
|
|
11
9
|
test "#sl_text_field_tag with name and value" do
|
12
10
|
assert_dom_equal <<~HTML, sl_text_field_tag('name', 'Your name')
|
@@ -65,441 +63,4 @@ class FormHelperTest < ActionView::TestCase
|
|
65
63
|
</sl-form>
|
66
64
|
HTML
|
67
65
|
end
|
68
|
-
|
69
|
-
test "#text_field" do
|
70
|
-
sl_form_for(User.new, url: "/") do |form|
|
71
|
-
assert_dom_equal <<~HTML, form.text_field(:name)
|
72
|
-
<sl-input label="Name" type="text" name="user[name]" id="user_name"></sl-input>
|
73
|
-
HTML
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
test "#text_field with a default value" do
|
78
|
-
sl_form_for(User.new(name: "Yuki"), url: "/") do |form|
|
79
|
-
assert_dom_equal <<~HTML, form.text_field(:name)
|
80
|
-
<sl-input label="Name" type="text" name="user[name]" id="user_name" value="Yuki"></sl-input>
|
81
|
-
HTML
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
test "#email_field" do
|
86
|
-
sl_form_for(User.new, url: "/") do |form|
|
87
|
-
assert_dom_equal <<~HTML, form.email_field(:name)
|
88
|
-
<sl-input label="Name" type="email" name="user[name]" id="user_name"></sl-input>
|
89
|
-
HTML
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
test "#number_field" do
|
94
|
-
sl_form_for(User.new, url: "/") do |form|
|
95
|
-
assert_dom_equal <<~HTML, form.number_field(:name)
|
96
|
-
<sl-input label="Name" type="number" name="user[name]" id="user_name"></sl-input>
|
97
|
-
HTML
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
test "#password_field" do
|
102
|
-
sl_form_for(User.new, url: "/") do |form|
|
103
|
-
assert_dom_equal <<~HTML, form.password_field(:name)
|
104
|
-
<sl-input label="Name" type="password" name="user[name]" id="user_name"></sl-input>
|
105
|
-
HTML
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
test "#search_field" do
|
110
|
-
sl_form_for(User.new, url: "/") do |form|
|
111
|
-
assert_dom_equal <<~HTML, form.search_field(:name)
|
112
|
-
<sl-input label="Name" type="search" name="user[name]" id="user_name"></sl-input>
|
113
|
-
HTML
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
test "#telephone_field" do
|
118
|
-
sl_form_for(User.new, url: "/") do |form|
|
119
|
-
assert_dom_equal <<~HTML, form.telephone_field(:name)
|
120
|
-
<sl-input label="Name" type="tel" name="user[name]" id="user_name"></sl-input>
|
121
|
-
HTML
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
test "#phone_field" do
|
126
|
-
sl_form_for(User.new, url: "/") do |form|
|
127
|
-
assert_dom_equal <<~HTML, form.phone_field(:name)
|
128
|
-
<sl-input label="Name" type="tel" name="user[name]" id="user_name"></sl-input>
|
129
|
-
HTML
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
test "#text_field with a block" do
|
134
|
-
sl_form_for(User.new(name: "Yuki"), url: "/") do |form|
|
135
|
-
assert_dom_equal <<~HTML, form.text_field(:name) { 'slot' }
|
136
|
-
<sl-input label="Name" type="text" name="user[name]" id="user_name" value="Yuki">slot</sl-input>
|
137
|
-
HTML
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
test "#url_field" do
|
142
|
-
sl_form_for(User.new, url: "/") do |form|
|
143
|
-
assert_dom_equal <<~HTML, form.url_field(:name)
|
144
|
-
<sl-input label="Name" type="url" name="user[name]" id="user_name"></sl-input>
|
145
|
-
HTML
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
test "#color_field" do
|
150
|
-
sl_form_for(User.new, url: "/") do |form|
|
151
|
-
assert_dom_equal <<~HTML, form.color_field(:name)
|
152
|
-
<sl-color-picker name="user[name]" id="user_name" label="Name"></sl-color-picker>
|
153
|
-
HTML
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
test "#range_field" do
|
158
|
-
sl_form_for(User.new, url: "/") do |form|
|
159
|
-
assert_dom_equal <<~HTML, form.range_field(:name)
|
160
|
-
<sl-range label="Name" name="user[name]" id="user_name"></sl-range>
|
161
|
-
HTML
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
test "#range_field without a label" do
|
166
|
-
sl_form_for(User.new, url: "/") do |form|
|
167
|
-
assert_dom_equal <<~HTML, form.range_field(:name, label: nil)
|
168
|
-
<sl-range name="user[name]" id="user_name"></sl-range>
|
169
|
-
HTML
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
test "#switch_field" do
|
174
|
-
sl_form_for(User.new, url: "/") do |form|
|
175
|
-
assert_dom_equal <<~HTML, form.switch_field(:name)
|
176
|
-
<sl-switch name="user[name]" id="user_name">Name</sl-switch>
|
177
|
-
HTML
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
test "#text_area" do
|
182
|
-
sl_form_for(User.new, url: "/") do |form|
|
183
|
-
assert_dom_equal <<~HTML, form.text_area(:name)
|
184
|
-
<sl-textarea label="Name" resize="auto" name="user[name]" id="user_name"></sl-textarea>
|
185
|
-
HTML
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
test "#text_area with a value" do
|
190
|
-
sl_form_for(User.new(name: "Yuki Nishijima"), url: "/") do |form|
|
191
|
-
assert_dom_equal <<~HTML, form.text_area(:name)
|
192
|
-
<sl-textarea label="Name" resize="auto" value="Yuki Nishijima" name="user[name]" id="user_name"></sl-textarea>
|
193
|
-
HTML
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
test "#text_area with an one-off value" do
|
198
|
-
sl_form_for(User.new(name: "Yuki Nishijima"), url: "/") do |form|
|
199
|
-
assert_dom_equal <<~HTML, form.text_area(:name, value: "Yuki")
|
200
|
-
<sl-textarea label="Name" resize="auto" value="Yuki" name="user[name]" id="user_name"></sl-textarea>
|
201
|
-
HTML
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
test "#text_area without a label" do
|
206
|
-
sl_form_for(User.new, url: "/") do |form|
|
207
|
-
assert_dom_equal <<~HTML, form.text_area(:name, label: nil)
|
208
|
-
<sl-textarea resize="auto" name="user[name]" id="user_name"></sl-textarea>
|
209
|
-
HTML
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
test "#text_area with a size" do
|
214
|
-
sl_form_for(User.new, url: "/") do |form|
|
215
|
-
assert_dom_equal <<~HTML, form.text_area(:name, size: "small")
|
216
|
-
<sl-textarea label="Name" resize="auto" size="small" name="user[name]" id="user_name"></sl-textarea>
|
217
|
-
HTML
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
test "#text_area with a block" do
|
222
|
-
sl_form_for(User.new, url: "/") do |form|
|
223
|
-
expected = <<~HTML
|
224
|
-
<sl-textarea label="Name" resize="auto" name="user[name]" id="user_name">
|
225
|
-
<div slot="help-text">Name can not be blank.</div>
|
226
|
-
</sl-textarea>
|
227
|
-
HTML
|
228
|
-
|
229
|
-
assert_dom_equal(expected, form.text_area(:name) {
|
230
|
-
content_tag(:div, "Name can not be blank.", slot: "help-text")
|
231
|
-
})
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
test "#check_box" do
|
236
|
-
sl_form_for(User.new, url: "/") do |form|
|
237
|
-
if ActionView::VERSION::STRING >= '6.1.0'
|
238
|
-
assert_dom_equal <<~HTML, form.check_box(:name)
|
239
|
-
<input name="user[name]" type="hidden" value="0" autocomplete="off" />
|
240
|
-
<sl-checkbox value="1" name="user[name]" id="user_name">Name</sl-checkbox>
|
241
|
-
HTML
|
242
|
-
else
|
243
|
-
assert_dom_equal <<~HTML, form.check_box(:name)
|
244
|
-
<input name="user[name]" type="hidden" value="0" />
|
245
|
-
<sl-checkbox value="1" name="user[name]" id="user_name">Name</sl-checkbox>
|
246
|
-
HTML
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
test "#check_box with a block" do
|
252
|
-
sl_form_for(User.new, url: "/") do |form|
|
253
|
-
if ActionView::VERSION::STRING >= '6.1.0'
|
254
|
-
assert_dom_equal <<~HTML, form.check_box(:name) { "Maintainer Name" }
|
255
|
-
<input name="user[name]" type="hidden" value="0" autocomplete="off" />
|
256
|
-
<sl-checkbox value="1" name="user[name]" id="user_name">Maintainer Name</sl-checkbox>
|
257
|
-
HTML
|
258
|
-
else
|
259
|
-
assert_dom_equal <<~HTML, form.check_box(:name) { "Maintainer Name" }
|
260
|
-
<input name="user[name]" type="hidden" value="0" />
|
261
|
-
<sl-checkbox value="1" name="user[name]" id="user_name">Maintainer Name</sl-checkbox>
|
262
|
-
HTML
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
test "#check_box without a hidden input" do
|
268
|
-
sl_form_for(User.new, url: "/") do |form|
|
269
|
-
assert_dom_equal <<~HTML, form.check_box(:name, include_hidden: false) { "Maintainer Name" }
|
270
|
-
<sl-checkbox value="1" name="user[name]" id="user_name">Maintainer Name</sl-checkbox>
|
271
|
-
HTML
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
test "#select" do
|
276
|
-
users = {
|
277
|
-
"Yuki Nishijima" => 1,
|
278
|
-
"Matz" => 2,
|
279
|
-
"Koichi Sasada" => 3
|
280
|
-
}
|
281
|
-
|
282
|
-
sl_form_for(User.new, url: "/") do |form|
|
283
|
-
assert_dom_equal <<~HTML, form.select(:name, users)
|
284
|
-
<sl-select label="Name" name="user[name]" id="user_name">
|
285
|
-
<sl-option value="1">Yuki Nishijima</sl-option>
|
286
|
-
<sl-option value="2">Matz</sl-option>
|
287
|
-
<sl-option value="3">Koichi Sasada</sl-option>
|
288
|
-
</sl-select>
|
289
|
-
HTML
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
test "#select with a custom value" do
|
294
|
-
users = {
|
295
|
-
"Yuki Nishijima" => 1,
|
296
|
-
"Matz" => 2,
|
297
|
-
"Koichi Sasada" => 3
|
298
|
-
}
|
299
|
-
|
300
|
-
sl_form_for(User.new, url: "/") do |form|
|
301
|
-
assert_dom_equal <<~HTML, form.select(:name, users, {}, { value: 3 })
|
302
|
-
<sl-select label="Name" value="3" name="user[name]" id="user_name">
|
303
|
-
<sl-option value="1">Yuki Nishijima</sl-option>
|
304
|
-
<sl-option value="2">Matz</sl-option>
|
305
|
-
<sl-option value="3">Koichi Sasada</sl-option>
|
306
|
-
</sl-select>
|
307
|
-
HTML
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
test "#select with custom selected and disabled values" do
|
312
|
-
users = {
|
313
|
-
"Yuki Nishijima" => 1,
|
314
|
-
"Matz" => 2,
|
315
|
-
"Koichi Sasada" => 3
|
316
|
-
}
|
317
|
-
|
318
|
-
sl_form_for(User.new, url: "/") do |form|
|
319
|
-
assert_dom_equal <<~HTML, form.select(:name, users, selected: 3, disabled: 1)
|
320
|
-
<sl-select label="Name" name="user[name]" id="user_name">
|
321
|
-
<sl-option value="1" disabled="disabled">Yuki Nishijima</sl-option>
|
322
|
-
<sl-option value="2">Matz</sl-option>
|
323
|
-
<sl-option value="3" checked="checked">Koichi Sasada</sl-option>
|
324
|
-
</sl-select>
|
325
|
-
HTML
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
test "#select with multiple" do
|
330
|
-
users = {
|
331
|
-
"Yuki Nishijima" => 1,
|
332
|
-
"Matz" => 2,
|
333
|
-
"Koichi Sasada" => 3
|
334
|
-
}
|
335
|
-
|
336
|
-
sl_form_for(User.new, url: "/") do |form|
|
337
|
-
assert_dom_equal <<~HTML, form.select(:name, users, {}, { multiple: true })
|
338
|
-
<sl-select label="Name" name="user[name][]" id="user_name" multiple="multiple">
|
339
|
-
<sl-option value="1">Yuki Nishijima</sl-option>
|
340
|
-
<sl-option value="2">Matz</sl-option>
|
341
|
-
<sl-option value="3">Koichi Sasada</sl-option>
|
342
|
-
</sl-select>
|
343
|
-
HTML
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
test "#select with grouped options" do
|
348
|
-
users = {
|
349
|
-
"Main maintainers" => [
|
350
|
-
["Matz", 2],
|
351
|
-
["Koichi Sasada", 3]
|
352
|
-
],
|
353
|
-
"Default gem maintainers" => [
|
354
|
-
["Yuki Nishijima", 1],
|
355
|
-
]
|
356
|
-
}
|
357
|
-
|
358
|
-
sl_form_for(User.new, url: "/") do |form|
|
359
|
-
assert_dom_equal <<~HTML, form.select(:name, users)
|
360
|
-
<sl-select label="Name" name="user[name]" id="user_name">
|
361
|
-
<small>Main maintainers</small>
|
362
|
-
<sl-option value="2">Matz</sl-option>
|
363
|
-
<sl-option value="3">Koichi Sasada</sl-option>
|
364
|
-
<sl-divider></sl-divider>
|
365
|
-
<small>Default gem maintainers</small>
|
366
|
-
<sl-option value="1">Yuki Nishijima</sl-option>
|
367
|
-
</sl-select>
|
368
|
-
HTML
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
test "#select with grouped options with a default value" do
|
373
|
-
users = {
|
374
|
-
"Main maintainers" => [
|
375
|
-
["Matz", 2],
|
376
|
-
["Koichi Sasada", 3]
|
377
|
-
],
|
378
|
-
"Default gem maintainers" => [
|
379
|
-
["Yuki Nishijima", 1],
|
380
|
-
]
|
381
|
-
}
|
382
|
-
|
383
|
-
sl_form_for(User.new(name: 2), url: "/") do |form|
|
384
|
-
assert_dom_equal <<~HTML, form.select(:name, users)
|
385
|
-
<sl-select label="Name" name="user[name]" id="user_name" value="2">
|
386
|
-
<small>Main maintainers</small>
|
387
|
-
<sl-option value="2" checked="checked">Matz</sl-option>
|
388
|
-
<sl-option value="3">Koichi Sasada</sl-option>
|
389
|
-
<sl-divider></sl-divider>
|
390
|
-
<small>Default gem maintainers</small>
|
391
|
-
<sl-option value="1">Yuki Nishijima</sl-option>
|
392
|
-
</sl-select>
|
393
|
-
HTML
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
test "#collection_select" do
|
398
|
-
users = {
|
399
|
-
1 => "Yuki Nishijima",
|
400
|
-
2 => "Matz",
|
401
|
-
3 => "Koichi Sasada",
|
402
|
-
}
|
403
|
-
|
404
|
-
sl_form_for(User.new, url: "/") do |form|
|
405
|
-
assert_dom_equal <<~HTML, form.collection_select(:name, users, :first, :last)
|
406
|
-
<sl-select label="Name" name="user[name]" id="user_name">
|
407
|
-
<sl-option value="1">Yuki Nishijima</sl-option>
|
408
|
-
<sl-option value="2">Matz</sl-option>
|
409
|
-
<sl-option value="3">Koichi Sasada</sl-option>
|
410
|
-
</sl-select>
|
411
|
-
HTML
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
test "#collection_select with a default value" do
|
416
|
-
users = {
|
417
|
-
1 => "Yuki Nishijima",
|
418
|
-
2 => "Matz",
|
419
|
-
3 => "Koichi Sasada",
|
420
|
-
}
|
421
|
-
|
422
|
-
sl_form_for(User.new(name: "2"), url: "/") do |form|
|
423
|
-
assert_dom_equal <<~HTML, form.collection_select(:name, users, :first, :last)
|
424
|
-
<sl-select label="Name" name="user[name]" id="user_name" value="2">
|
425
|
-
<sl-option value="1">Yuki Nishijima</sl-option>
|
426
|
-
<sl-option value="2" checked="checked">Matz</sl-option>
|
427
|
-
<sl-option value="3">Koichi Sasada</sl-option>
|
428
|
-
</sl-select>
|
429
|
-
HTML
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
test "#grouped_collection_select" do
|
434
|
-
users = [
|
435
|
-
OpenStruct.new(
|
436
|
-
group_name: "Main maintainers",
|
437
|
-
members: [
|
438
|
-
OpenStruct.new(id: 1, name: "Matz"),
|
439
|
-
OpenStruct.new(id: 2, name: "Koichi Sasada"),
|
440
|
-
]
|
441
|
-
),
|
442
|
-
OpenStruct.new(
|
443
|
-
group_name: "Default gem maintainers",
|
444
|
-
members: [OpenStruct.new(id: 3, name: "Yuki Nishijima")]
|
445
|
-
),
|
446
|
-
]
|
447
|
-
|
448
|
-
sl_form_for(User.new(name: "2"), url: "/") do |form|
|
449
|
-
assert_dom_equal <<~HTML, form.grouped_collection_select(:name, users, :members, :group_name, :id, :name)
|
450
|
-
<sl-select label="Name" name="user[name]" id="user_name" value="2">
|
451
|
-
<small>Main maintainers</small>
|
452
|
-
<sl-option value="1">Matz</sl-option>
|
453
|
-
<sl-option value="2" checked="checked">Koichi Sasada</sl-option>
|
454
|
-
<sl-divider></sl-divider>
|
455
|
-
<small>Default gem maintainers</small>
|
456
|
-
<sl-option value="3">Yuki Nishijima</sl-option>
|
457
|
-
</sl-select>
|
458
|
-
HTML
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
test "#collection_radio_buttons" do
|
463
|
-
users = {
|
464
|
-
1 => "Yuki Nishijima",
|
465
|
-
2 => "Matz",
|
466
|
-
3 => "Koichi Sasada",
|
467
|
-
}
|
468
|
-
|
469
|
-
sl_form_for(User.new, url: "/") do |form|
|
470
|
-
assert_dom_equal <<~HTML, form.collection_radio_buttons(:name, users, :first, :last)
|
471
|
-
<sl-radio-group label="Name" name="user[name]" id="user_name">
|
472
|
-
<sl-radio value="1" id="user_name_1">Yuki Nishijima</sl-radio>
|
473
|
-
<sl-radio value="2" id="user_name_2">Matz</sl-radio>
|
474
|
-
<sl-radio value="3" id="user_name_3">Koichi Sasada</sl-radio>
|
475
|
-
</sl-radio-group>
|
476
|
-
HTML
|
477
|
-
end
|
478
|
-
end
|
479
|
-
|
480
|
-
test "#collection_radio_buttons with a default value" do
|
481
|
-
users = {
|
482
|
-
1 => "Yuki Nishijima",
|
483
|
-
2 => "Matz",
|
484
|
-
3 => "Koichi Sasada",
|
485
|
-
}
|
486
|
-
|
487
|
-
sl_form_for(User.new(name: 1), url: "/") do |form|
|
488
|
-
assert_dom_equal <<~HTML, form.collection_radio_buttons(:name, users, :first, :last)
|
489
|
-
<sl-radio-group label="Name" name="user[name]" value="1" id="user_name">
|
490
|
-
<sl-radio value="1" id="user_name_1">Yuki Nishijima</sl-radio>
|
491
|
-
<sl-radio value="2" id="user_name_2">Matz</sl-radio>
|
492
|
-
<sl-radio value="3" id="user_name_3">Koichi Sasada</sl-radio>
|
493
|
-
</sl-radio-group>
|
494
|
-
HTML
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
test "#submit" do
|
499
|
-
sl_form_for(User.new, url: "/") do |form|
|
500
|
-
assert_dom_equal <<~HTML, form.submit("Save")
|
501
|
-
<sl-button type="submit" variant="primary" data-disable-with="Save">Save</sl-button>
|
502
|
-
HTML
|
503
|
-
end
|
504
|
-
end
|
505
66
|
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
require_relative '../../app/helpers/shoelace/
|
4
|
+
require_relative '../../app/helpers/shoelace/sl_form_builder'
|
5
5
|
|
6
6
|
class TranslationTest < ActionView::TestCase
|
7
7
|
include ActionView::Helpers::TranslationHelper
|
8
|
-
include Shoelace::
|
9
|
-
|
10
|
-
AUTOCOMPLETE_ATTRIBUTE = ActionView::VERSION::STRING >= '6.1.0' ? 'autocomplete="off"' : ''
|
8
|
+
include Shoelace::SlFormHelper
|
11
9
|
|
12
10
|
setup do
|
13
11
|
I18n.backend.store_translations :en,
|
@@ -42,6 +40,16 @@ class TranslationTest < ActionView::TestCase
|
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
43
|
+
test "Form helpers should fall back to the humanize method when there is no matching translation" do
|
44
|
+
I18n.backend.reload!
|
45
|
+
|
46
|
+
sl_form_for(OpenStruct.new, as: :user, url: "/") do |form|
|
47
|
+
assert_dom_equal <<~HTML, form.text_field(:name_eq)
|
48
|
+
<sl-input label="Name eq" type="text" name="user[name_eq]" id="user_name_eq"></sl-input>
|
49
|
+
HTML
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
45
53
|
test "#color_field should respect label translations" do
|
46
54
|
sl_form_for(User.new, url: "/") do |form|
|
47
55
|
assert_dom_equal <<~HTML, form.color_field(:name)
|
data/test/test_helper.rb
CHANGED
@@ -9,10 +9,32 @@ require "action_view"
|
|
9
9
|
require "action_view/testing/resolvers"
|
10
10
|
require "active_model"
|
11
11
|
|
12
|
+
require_relative '../app/helpers/shoelace/sl_form_builder'
|
13
|
+
|
12
14
|
ActionView::TestCase.include(Rails::Dom::Testing::Assertions)
|
15
|
+
Shoelace::SlFormBuilder.field_error_proc = nil
|
13
16
|
|
14
17
|
class User
|
15
18
|
include ActiveModel::Model
|
16
19
|
|
17
20
|
attr_accessor :name
|
21
|
+
|
22
|
+
validates :name, presence: true
|
23
|
+
end
|
24
|
+
|
25
|
+
class ActionView::TestCase
|
26
|
+
AUTOCOMPLETE_ATTRIBUTE = ActionView::VERSION::STRING >= '6.1.0' ? 'autocomplete="off"' : ''
|
27
|
+
|
28
|
+
def with_default_input_slot_method(input_slot_method = :render_default_slot)
|
29
|
+
Shoelace::SlFormBuilder.default_input_slot_method = input_slot_method
|
30
|
+
yield
|
31
|
+
ensure
|
32
|
+
Shoelace::SlFormBuilder.default_input_slot_method = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def render_default_slot(resource, _attribute)
|
38
|
+
content_tag(:div, "Help text for #{_attribute} #{resource.name}", slot: "help-text")
|
39
|
+
end
|
18
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoelace-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Nishijima
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -97,7 +97,19 @@ files:
|
|
97
97
|
- LICENSE.txt
|
98
98
|
- README.md
|
99
99
|
- Rakefile
|
100
|
-
- app/helpers/shoelace/
|
100
|
+
- app/helpers/shoelace/components/error_wrappable.rb
|
101
|
+
- app/helpers/shoelace/components/sl_checkbox.rb
|
102
|
+
- app/helpers/shoelace/components/sl_collection_radio_buttons.rb
|
103
|
+
- app/helpers/shoelace/components/sl_color_picker.rb
|
104
|
+
- app/helpers/shoelace/components/sl_input.rb
|
105
|
+
- app/helpers/shoelace/components/sl_radio_button.rb
|
106
|
+
- app/helpers/shoelace/components/sl_range.rb
|
107
|
+
- app/helpers/shoelace/components/sl_select.rb
|
108
|
+
- app/helpers/shoelace/components/sl_switch.rb
|
109
|
+
- app/helpers/shoelace/components/sl_textarea.rb
|
110
|
+
- app/helpers/shoelace/form_builder.rb
|
111
|
+
- app/helpers/shoelace/sl_form_builder.rb
|
112
|
+
- app/helpers/shoelace/sl_form_helper.rb
|
101
113
|
- app/helpers/shoelace/tag_helper.rb
|
102
114
|
- bin/console
|
103
115
|
- bin/setup
|
@@ -116,6 +128,15 @@ files:
|
|
116
128
|
- lib/shoelace/testing.rb
|
117
129
|
- lib/tasks/shoelace.rake
|
118
130
|
- shoelace-rails.gemspec
|
131
|
+
- test/helpers/form_builder/sl_checkbox_test.rb
|
132
|
+
- test/helpers/form_builder/sl_color_picker_test.rb
|
133
|
+
- test/helpers/form_builder/sl_input_test.rb
|
134
|
+
- test/helpers/form_builder/sl_radio_group_test.rb
|
135
|
+
- test/helpers/form_builder/sl_range_test.rb
|
136
|
+
- test/helpers/form_builder/sl_select_test.rb
|
137
|
+
- test/helpers/form_builder/sl_switch_test.rb
|
138
|
+
- test/helpers/form_builder/sl_textarea_test.rb
|
139
|
+
- test/helpers/form_builder_test.rb
|
119
140
|
- test/helpers/form_helper_test.rb
|
120
141
|
- test/helpers/tag_helper_test.rb
|
121
142
|
- test/helpers/translation_test.rb
|
@@ -142,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
163
|
- !ruby/object:Gem::Version
|
143
164
|
version: '0'
|
144
165
|
requirements: []
|
145
|
-
rubygems_version: 3.5.
|
166
|
+
rubygems_version: 3.5.11
|
146
167
|
signing_key:
|
147
168
|
specification_version: 4
|
148
169
|
summary: Rails view helpers Shoelace.style, the design system.
|