govuk_design_system_formbuilder 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/govuk_design_system_formbuilder/builder.rb +46 -29
- data/lib/govuk_design_system_formbuilder/containers/character_count.rb +2 -2
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +13 -12
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +9 -8
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +12 -62
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +18 -10
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +10 -9
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +17 -13
- data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/caption.rb +6 -4
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +12 -11
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +2 -2
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +11 -11
- data/lib/govuk_design_system_formbuilder/elements/date.rb +19 -18
- data/lib/govuk_design_system_formbuilder/elements/error_message.rb +3 -3
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +15 -15
- data/lib/govuk_design_system_formbuilder/elements/file.rb +11 -10
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +4 -4
- data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/label.rb +11 -11
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +79 -0
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +14 -13
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +2 -2
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +2 -2
- data/lib/govuk_design_system_formbuilder/elements/select.rb +18 -17
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +9 -4
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +7 -6
- data/lib/govuk_design_system_formbuilder/traits/input.rb +8 -7
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 702ad71c46989cfeb455ced19e6c9c426685947bac6c6057f902bf1deb44eb97
|
4
|
+
data.tar.gz: 263eda546cf3f17b3611613e77c0f24f9c52995015752c4cc534f914b0c689be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 063007b8ff7a1ab6c2bb1c470b36895047217d8149b84fb1a9b8aac12b0a3d5e7910828bd0e44bc2aafafa972f4c5f032bea0bc55cd7ae60fe99c32a716a9156
|
7
|
+
data.tar.gz: 20cd7ac352b111277d57843b810eebb6cb73ef50c719501115b8a6f91264abd4b34646431c6ae9794df88378c0ee4f0bc835c7a5c633b3b251003581b0353664
|
@@ -17,6 +17,7 @@ module GOVUKDesignSystemFormBuilder
|
|
17
17
|
# @option caption text [String] the caption text
|
18
18
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
19
19
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
20
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
20
21
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
21
22
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
22
23
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -40,8 +41,8 @@ module GOVUKDesignSystemFormBuilder
|
|
40
41
|
# = f.govuk_text_field :callsign,
|
41
42
|
# label: -> { tag.h3('Call-sign') }
|
42
43
|
#
|
43
|
-
def govuk_text_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
44
|
-
Elements::Inputs::Text.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
44
|
+
def govuk_text_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
45
|
+
Elements::Inputs::Text.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
45
46
|
end
|
46
47
|
|
47
48
|
# Generates a input of type +tel+
|
@@ -59,6 +60,7 @@ module GOVUKDesignSystemFormBuilder
|
|
59
60
|
# @option caption text [String] the caption text
|
60
61
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
61
62
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
63
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
62
64
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
63
65
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
64
66
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -83,8 +85,8 @@ module GOVUKDesignSystemFormBuilder
|
|
83
85
|
# = f.govuk_phone_field :work_number,
|
84
86
|
# label: -> { tag.h3('Work number') }
|
85
87
|
#
|
86
|
-
def govuk_phone_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
87
|
-
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
88
|
+
def govuk_phone_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
89
|
+
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
88
90
|
end
|
89
91
|
|
90
92
|
# Generates a input of type +email+
|
@@ -102,6 +104,7 @@ module GOVUKDesignSystemFormBuilder
|
|
102
104
|
# @option caption text [String] the caption text
|
103
105
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
104
106
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
107
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
105
108
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
106
109
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
107
110
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -124,8 +127,8 @@ module GOVUKDesignSystemFormBuilder
|
|
124
127
|
# = f.govuk_email_field :personal_email,
|
125
128
|
# label: -> { tag.h3('Personal email address') }
|
126
129
|
#
|
127
|
-
def govuk_email_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
128
|
-
Elements::Inputs::Email.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
130
|
+
def govuk_email_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
131
|
+
Elements::Inputs::Email.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
129
132
|
end
|
130
133
|
|
131
134
|
# Generates a input of type +password+
|
@@ -143,6 +146,7 @@ module GOVUKDesignSystemFormBuilder
|
|
143
146
|
# @option caption text [String] the caption text
|
144
147
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
145
148
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
149
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
146
150
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
147
151
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
148
152
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -164,8 +168,8 @@ module GOVUKDesignSystemFormBuilder
|
|
164
168
|
# = f.govuk_password_field :passcode,
|
165
169
|
# label: -> { tag.h3('What is your secret pass code?') }
|
166
170
|
#
|
167
|
-
def govuk_password_field(attribute_name, hint_text: nil, label: {}, width: nil, caption: {}, **args, &block)
|
168
|
-
Elements::Inputs::Password.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
171
|
+
def govuk_password_field(attribute_name, hint_text: nil, label: {}, width: nil, form_group_classes: nil, caption: {}, **args, &block)
|
172
|
+
Elements::Inputs::Password.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
169
173
|
end
|
170
174
|
|
171
175
|
# Generates a input of type +url+
|
@@ -183,6 +187,7 @@ module GOVUKDesignSystemFormBuilder
|
|
183
187
|
# @option caption text [String] the caption text
|
184
188
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
185
189
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
190
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
186
191
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
187
192
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
188
193
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -205,8 +210,8 @@ module GOVUKDesignSystemFormBuilder
|
|
205
210
|
# = f.govuk_url_field :work_website,
|
206
211
|
# label: -> { tag.h3("Enter your company's website") }
|
207
212
|
#
|
208
|
-
def govuk_url_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
209
|
-
Elements::Inputs::URL.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
213
|
+
def govuk_url_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
214
|
+
Elements::Inputs::URL.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
210
215
|
end
|
211
216
|
|
212
217
|
# Generates a input of type +number+
|
@@ -224,6 +229,7 @@ module GOVUKDesignSystemFormBuilder
|
|
224
229
|
# @option caption text [String] the caption text
|
225
230
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
226
231
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
232
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
227
233
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
228
234
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
229
235
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -249,8 +255,8 @@ module GOVUKDesignSystemFormBuilder
|
|
249
255
|
# = f.govuk_url_field :personal_best_over_100m,
|
250
256
|
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
|
251
257
|
#
|
252
|
-
def govuk_number_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
253
|
-
Elements::Inputs::Number.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
258
|
+
def govuk_number_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
259
|
+
Elements::Inputs::Number.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
254
260
|
end
|
255
261
|
|
256
262
|
# Generates a +textarea+ element with a label, optional hint. Also offers
|
@@ -272,6 +278,7 @@ module GOVUKDesignSystemFormBuilder
|
|
272
278
|
# @param threshold [Integer] only show the +max_words+ and +max_chars+ warnings once a threshold (percentage) is reached
|
273
279
|
# @param rows [Integer] sets the initial number of rows
|
274
280
|
# @option args [Hash] args additional arguments are applied as attributes to the +textarea+ element
|
281
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
275
282
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
276
283
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
277
284
|
# @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
|
@@ -297,8 +304,8 @@ module GOVUKDesignSystemFormBuilder
|
|
297
304
|
# = f.govuk_text_area :instructions,
|
298
305
|
# label: -> { tag.h3("How do you set it up?") }
|
299
306
|
#
|
300
|
-
def govuk_text_area(attribute_name, hint_text: nil, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, **args, &block)
|
301
|
-
Elements::TextArea.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, **args, &block).html
|
307
|
+
def govuk_text_area(attribute_name, hint_text: nil, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group_classes: nil, **args, &block)
|
308
|
+
Elements::TextArea.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, form_group_classes: form_group_classes, **args, &block).html
|
302
309
|
end
|
303
310
|
|
304
311
|
# Generates a +select+ element containing +option+ for each member in the provided collection
|
@@ -314,6 +321,7 @@ module GOVUKDesignSystemFormBuilder
|
|
314
321
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
315
322
|
# @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
|
316
323
|
# @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
|
324
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
317
325
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
318
326
|
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select Rails collection_select (called by govuk_collection_select)
|
319
327
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -335,7 +343,7 @@ module GOVUKDesignSystemFormBuilder
|
|
335
343
|
# = f.govuk_collection_select(:team, @teams, :id, :name) do
|
336
344
|
# label: -> { tag.h3("Which team did you represent?") }
|
337
345
|
#
|
338
|
-
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint_text: nil, label: {}, caption: {}, &block)
|
346
|
+
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint_text: nil, label: {}, caption: {}, form_group_classes: nil, &block)
|
339
347
|
Elements::Select.new(
|
340
348
|
self,
|
341
349
|
object_name,
|
@@ -348,6 +356,7 @@ module GOVUKDesignSystemFormBuilder
|
|
348
356
|
caption: caption,
|
349
357
|
options: options,
|
350
358
|
html_options: html_options,
|
359
|
+
form_group_classes: form_group_classes,
|
351
360
|
&block
|
352
361
|
).html
|
353
362
|
end
|
@@ -376,7 +385,7 @@ module GOVUKDesignSystemFormBuilder
|
|
376
385
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
377
386
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
378
387
|
# @param bold_labels [Boolean] controls whether the radio button labels are bold
|
379
|
-
# @param classes [String] Classes to add to the radio button container.
|
388
|
+
# @param classes [Array,String] Classes to add to the radio button container.
|
380
389
|
# @option legend text [String] the fieldset legend's text content
|
381
390
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
382
391
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
@@ -418,7 +427,7 @@ module GOVUKDesignSystemFormBuilder
|
|
418
427
|
# :name,
|
419
428
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
420
429
|
#
|
421
|
-
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, &block)
|
430
|
+
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, form_group_classes: nil, &block)
|
422
431
|
Elements::Radios::Collection.new(
|
423
432
|
self,
|
424
433
|
object_name,
|
@@ -434,6 +443,7 @@ module GOVUKDesignSystemFormBuilder
|
|
434
443
|
small: small,
|
435
444
|
bold_labels: bold_labels,
|
436
445
|
classes: classes,
|
446
|
+
form_group_classes: form_group_classes,
|
437
447
|
&block
|
438
448
|
).html
|
439
449
|
end
|
@@ -457,8 +467,9 @@ module GOVUKDesignSystemFormBuilder
|
|
457
467
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
458
468
|
# @option caption text [String] the caption text
|
459
469
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
470
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
460
471
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
461
|
-
# @param classes [String] Classes to add to the radio button container.
|
472
|
+
# @param classes [Array,String] Classes to add to the radio button container.
|
462
473
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
463
474
|
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
464
475
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -480,8 +491,8 @@ module GOVUKDesignSystemFormBuilder
|
|
480
491
|
# = f.govuk_radio_button :burger_id, :regular, label: { text: 'Hamburger' }, link_errors: true
|
481
492
|
# = f.govuk_radio_button :burger_id, :cheese, label: { text: 'Cheeseburger' }
|
482
493
|
#
|
483
|
-
def govuk_radio_buttons_fieldset(attribute_name, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, classes: nil, &block)
|
484
|
-
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, inline: inline, small: small, classes: classes, &block).html
|
494
|
+
def govuk_radio_buttons_fieldset(attribute_name, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, classes: nil, form_group_classes: nil, &block)
|
495
|
+
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, inline: inline, small: small, classes: classes, form_group_classes: form_group_classes, &block).html
|
485
496
|
end
|
486
497
|
|
487
498
|
# Generates a radio button
|
@@ -532,7 +543,7 @@ module GOVUKDesignSystemFormBuilder
|
|
532
543
|
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
533
544
|
# @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
|
534
545
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
535
|
-
# @param classes [String] Classes to add to the checkbox container.
|
546
|
+
# @param classes [Array,String] Classes to add to the checkbox container.
|
536
547
|
# @param legend [Hash,Proc] options for configuring the legend
|
537
548
|
# @option legend text [String] the fieldset legend's text content
|
538
549
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
@@ -541,6 +552,7 @@ module GOVUKDesignSystemFormBuilder
|
|
541
552
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
542
553
|
# @option caption text [String] the caption text
|
543
554
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
555
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
544
556
|
# @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
|
545
557
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
546
558
|
#
|
@@ -577,7 +589,7 @@ module GOVUKDesignSystemFormBuilder
|
|
577
589
|
# :name,
|
578
590
|
# legend: -> { tag.h3('What kind of sandwich do you want?') }
|
579
591
|
#
|
580
|
-
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, small: false, classes: nil, &block)
|
592
|
+
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, small: false, classes: nil, form_group_classes: nil, &block)
|
581
593
|
Elements::CheckBoxes::Collection.new(
|
582
594
|
self,
|
583
595
|
object_name,
|
@@ -591,6 +603,7 @@ module GOVUKDesignSystemFormBuilder
|
|
591
603
|
caption: caption,
|
592
604
|
small: small,
|
593
605
|
classes: classes,
|
606
|
+
form_group_classes: form_group_classes,
|
594
607
|
&block
|
595
608
|
).html
|
596
609
|
end
|
@@ -611,7 +624,8 @@ module GOVUKDesignSystemFormBuilder
|
|
611
624
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
612
625
|
# @option caption text [String] the caption text
|
613
626
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
614
|
-
# @param classes [String] Classes to add to the checkbox container.
|
627
|
+
# @param classes [Array,String] Classes to add to the checkbox container.
|
628
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
615
629
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
616
630
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
617
631
|
#
|
@@ -625,7 +639,7 @@ module GOVUKDesignSystemFormBuilder
|
|
625
639
|
# = f.govuk_check_box :desired_filling, :lemonade, label: { text: 'Lemonade' }, link_errors: true
|
626
640
|
# = f.govuk_check_box :desired_filling, :fizzy_orange, label: { text: 'Fizzy orange' }
|
627
641
|
#
|
628
|
-
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint_text: {}, small: false, classes: nil, &block)
|
642
|
+
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint_text: {}, small: false, classes: nil, form_group_classes: nil, &block)
|
629
643
|
Containers::CheckBoxesFieldset.new(
|
630
644
|
self,
|
631
645
|
object_name,
|
@@ -635,6 +649,7 @@ module GOVUKDesignSystemFormBuilder
|
|
635
649
|
caption: caption,
|
636
650
|
small: small,
|
637
651
|
classes: classes,
|
652
|
+
form_group_classes: form_group_classes,
|
638
653
|
&block
|
639
654
|
).html
|
640
655
|
end
|
@@ -680,7 +695,7 @@ module GOVUKDesignSystemFormBuilder
|
|
680
695
|
# @param text [String] the button text
|
681
696
|
# @param warning [Boolean] makes the button red ({https://design-system.service.gov.uk/components/button/#warning-buttons warning}) when true
|
682
697
|
# @param secondary [Boolean] makes the button grey ({https://design-system.service.gov.uk/components/button/#secondary-buttons secondary}) when true
|
683
|
-
# @param classes [String] Classes to add to the submit button
|
698
|
+
# @param classes [Array,String] Classes to add to the submit button
|
684
699
|
# @param prevent_double_click [Boolean] adds JavaScript to safeguard the
|
685
700
|
# form from being submitted more than once
|
686
701
|
# @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
|
@@ -721,6 +736,7 @@ module GOVUKDesignSystemFormBuilder
|
|
721
736
|
# @option caption text [String] the caption text
|
722
737
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
723
738
|
# @param omit_day [Boolean] do not render a day input, only capture month and year
|
739
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
724
740
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
725
741
|
# @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
|
726
742
|
# will be added to the inputs
|
@@ -740,8 +756,8 @@ module GOVUKDesignSystemFormBuilder
|
|
740
756
|
# @example A date input with legend supplied as a proc
|
741
757
|
# = f.govuk_date_field :finishes_on,
|
742
758
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
743
|
-
def govuk_date_field(attribute_name, hint_text: nil, legend: {}, caption: {}, date_of_birth: false, omit_day: false, &block)
|
744
|
-
Elements::Date.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, &block).html
|
759
|
+
def govuk_date_field(attribute_name, hint_text: nil, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group_classes: nil, &block)
|
760
|
+
Elements::Date.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, form_group_classes: form_group_classes, &block).html
|
745
761
|
end
|
746
762
|
|
747
763
|
# Generates a summary of errors in the form, each linking to the corresponding
|
@@ -799,6 +815,7 @@ module GOVUKDesignSystemFormBuilder
|
|
799
815
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
800
816
|
# @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
|
801
817
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
818
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
802
819
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
803
820
|
#
|
804
821
|
# @example A photo upload field with file type specifier and injected content
|
@@ -817,8 +834,8 @@ module GOVUKDesignSystemFormBuilder
|
|
817
834
|
# @note Remember to set +multipart: true+ when creating a form with file
|
818
835
|
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
|
819
836
|
# the Rails documentation} for more information
|
820
|
-
def govuk_file_field(attribute_name, label: {}, caption: {}, hint_text: nil, **args, &block)
|
821
|
-
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint_text: hint_text, **args, &block).html
|
837
|
+
def govuk_file_field(attribute_name, label: {}, caption: {}, hint_text: nil, form_group_classes: nil, **args, &block)
|
838
|
+
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint_text: hint_text, form_group_classes: form_group_classes, **args, &block).html
|
822
839
|
end
|
823
840
|
end
|
824
841
|
end
|
@@ -14,12 +14,12 @@ module GOVUKDesignSystemFormBuilder
|
|
14
14
|
def html
|
15
15
|
return yield unless limit?
|
16
16
|
|
17
|
-
content_tag('div', **
|
17
|
+
content_tag('div', **options) { yield }
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def
|
22
|
+
def options
|
23
23
|
{
|
24
24
|
class: %(#{brand}-character-count),
|
25
25
|
data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Containers
|
3
3
|
class CheckBoxes < Base
|
4
|
-
using PrefixableArray
|
5
|
-
|
6
4
|
def initialize(builder, small:, classes: nil)
|
7
5
|
@builder = builder
|
8
6
|
@small = small
|
@@ -10,25 +8,28 @@ module GOVUKDesignSystemFormBuilder
|
|
10
8
|
end
|
11
9
|
|
12
10
|
def html
|
13
|
-
content_tag('div', **
|
14
|
-
yield
|
15
|
-
end
|
11
|
+
content_tag('div', **options) { yield }
|
16
12
|
end
|
17
13
|
|
18
14
|
private
|
19
15
|
|
20
|
-
def
|
16
|
+
def options
|
21
17
|
{
|
22
|
-
class:
|
18
|
+
class: classes,
|
23
19
|
data: { module: %(#{brand}-checkboxes) }
|
24
20
|
}
|
25
21
|
end
|
26
22
|
|
27
|
-
def
|
28
|
-
%
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
def classes
|
24
|
+
[%(#{brand}-checkboxes), small_class, custom_classes].flatten.compact
|
25
|
+
end
|
26
|
+
|
27
|
+
def small_class
|
28
|
+
%(#{brand}-checkboxes--small) if @small
|
29
|
+
end
|
30
|
+
|
31
|
+
def custom_classes
|
32
|
+
Array.wrap(@classes)
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -4,19 +4,20 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
include Traits::Error
|
5
5
|
include Traits::Hint
|
6
6
|
|
7
|
-
def initialize(builder, object_name, attribute_name, hint_text:, legend:, caption:, small:, classes:, &block)
|
7
|
+
def initialize(builder, object_name, attribute_name, hint_text:, legend:, caption:, small:, classes:, form_group_classes:, &block)
|
8
8
|
super(builder, object_name, attribute_name, &block)
|
9
9
|
|
10
|
-
@legend
|
11
|
-
@caption
|
12
|
-
@hint_text
|
13
|
-
@small
|
14
|
-
@classes
|
15
|
-
@
|
10
|
+
@legend = legend
|
11
|
+
@caption = caption
|
12
|
+
@hint_text = hint_text
|
13
|
+
@small = small
|
14
|
+
@classes = classes
|
15
|
+
@form_group_classes = form_group_classes
|
16
|
+
@block_content = capture { block.call }
|
16
17
|
end
|
17
18
|
|
18
19
|
def html
|
19
|
-
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
20
|
+
Containers::FormGroup.new(@builder, @object_name, @attribute_name, classes: @form_group_classes).html do
|
20
21
|
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
21
22
|
safe_join([hint_element, error_element, checkboxes])
|
22
23
|
end
|
@@ -1,90 +1,40 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Containers
|
3
3
|
class Fieldset < Base
|
4
|
-
using PrefixableArray
|
5
|
-
|
6
|
-
include Traits::Caption
|
7
|
-
include Traits::Localisation
|
8
|
-
|
9
|
-
LEGEND_SIZES = %w(xl l m s).freeze
|
10
|
-
|
11
4
|
def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, caption: {}, described_by: nil, &block)
|
12
5
|
super(builder, object_name, attribute_name, &block)
|
13
6
|
|
7
|
+
@legend = legend
|
8
|
+
@caption = caption
|
14
9
|
@described_by = described_by(described_by)
|
15
10
|
@attribute_name = attribute_name
|
16
|
-
|
17
|
-
case legend
|
18
|
-
when Proc
|
19
|
-
@legend_raw = legend.call
|
20
|
-
when Hash
|
21
|
-
@legend_options = legend_defaults.merge(legend)
|
22
|
-
@caption = caption
|
23
|
-
else
|
24
|
-
fail(ArgumentError, %(legend must be a Proc or Hash))
|
25
|
-
end
|
26
11
|
end
|
27
12
|
|
28
13
|
def html
|
29
|
-
content_tag('fieldset', **
|
30
|
-
safe_join([
|
14
|
+
content_tag('fieldset', **options) do
|
15
|
+
safe_join([legend_element, (@block_content || yield)])
|
31
16
|
end
|
32
17
|
end
|
33
18
|
|
34
19
|
private
|
35
20
|
|
36
|
-
def
|
21
|
+
def options
|
37
22
|
{
|
38
|
-
class:
|
23
|
+
class: classes,
|
39
24
|
aria: { describedby: @described_by }
|
40
25
|
}
|
41
26
|
end
|
42
27
|
|
43
|
-
def
|
44
|
-
%
|
45
|
-
end
|
46
|
-
|
47
|
-
def legend
|
48
|
-
@legend_raw || legend_content
|
49
|
-
end
|
50
|
-
|
51
|
-
def legend_content
|
52
|
-
if legend_text.present?
|
53
|
-
content_tag('legend', class: legend_classes) do
|
54
|
-
content_tag(@legend_options.dig(:tag), class: legend_heading_classes) do
|
55
|
-
safe_join([caption_element, legend_text])
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def legend_text
|
62
|
-
@legend_options.dig(:text) || localised_text(:legend)
|
63
|
-
end
|
64
|
-
|
65
|
-
def legend_size
|
66
|
-
@legend_options.dig(:size).tap do |size|
|
67
|
-
fail "invalid size '#{size}', must be #{LEGEND_SIZES.join(', ')}" unless size.in?(LEGEND_SIZES)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def legend_classes
|
72
|
-
[%(fieldset__legend), %(fieldset__legend--#{legend_size})].prefix(brand).tap do |classes|
|
73
|
-
classes.push(%(#{brand}-visually-hidden)) if @legend_options.dig(:hidden)
|
74
|
-
end
|
28
|
+
def classes
|
29
|
+
%(#{brand}-fieldset)
|
75
30
|
end
|
76
31
|
|
77
|
-
def
|
78
|
-
|
32
|
+
def legend_element
|
33
|
+
@legend_element ||= Elements::Legend.new(@builder, @object_name, @attribute_name, **legend_options)
|
79
34
|
end
|
80
35
|
|
81
|
-
def
|
82
|
-
{
|
83
|
-
hidden: false,
|
84
|
-
text: nil,
|
85
|
-
tag: config.default_legend_tag,
|
86
|
-
size: config.default_legend_size
|
87
|
-
}
|
36
|
+
def legend_options
|
37
|
+
{ legend: @legend, caption: @caption }
|
88
38
|
end
|
89
39
|
end
|
90
40
|
end
|