govuk_design_system_formbuilder 2.2.0 → 2.5.1b1

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -0
  3. data/README.md +2 -2
  4. data/lib/govuk_design_system_formbuilder.rb +8 -1
  5. data/lib/govuk_design_system_formbuilder/base.rb +16 -1
  6. data/lib/govuk_design_system_formbuilder/builder.rb +60 -15
  7. data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +2 -2
  8. data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +12 -9
  9. data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +2 -2
  10. data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +1 -1
  11. data/lib/govuk_design_system_formbuilder/elements/caption.rb +3 -3
  12. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +2 -2
  13. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +2 -2
  14. data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +5 -3
  15. data/lib/govuk_design_system_formbuilder/elements/collection_select.rb +52 -0
  16. data/lib/govuk_design_system_formbuilder/elements/date.rb +37 -15
  17. data/lib/govuk_design_system_formbuilder/elements/error_message.rb +1 -1
  18. data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +11 -4
  19. data/lib/govuk_design_system_formbuilder/elements/file.rb +3 -2
  20. data/lib/govuk_design_system_formbuilder/elements/hint.rb +1 -1
  21. data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +1 -0
  22. data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +1 -0
  23. data/lib/govuk_design_system_formbuilder/elements/inputs/password.rb +1 -0
  24. data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +1 -0
  25. data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +1 -0
  26. data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +1 -0
  27. data/lib/govuk_design_system_formbuilder/elements/label.rb +3 -3
  28. data/lib/govuk_design_system_formbuilder/elements/legend.rb +3 -5
  29. data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +3 -3
  30. data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +2 -2
  31. data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +9 -7
  32. data/lib/govuk_design_system_formbuilder/elements/select.rb +22 -32
  33. data/lib/govuk_design_system_formbuilder/elements/submit.rb +17 -14
  34. data/lib/govuk_design_system_formbuilder/elements/text_area.rb +5 -4
  35. data/lib/govuk_design_system_formbuilder/traits/caption.rb +1 -1
  36. data/lib/govuk_design_system_formbuilder/traits/error.rb +2 -2
  37. data/lib/govuk_design_system_formbuilder/traits/fieldset_item.rb +2 -2
  38. data/lib/govuk_design_system_formbuilder/traits/hint.rb +2 -2
  39. data/lib/govuk_design_system_formbuilder/traits/html_attributes.rb +51 -0
  40. data/lib/govuk_design_system_formbuilder/traits/input.rb +5 -5
  41. data/lib/govuk_design_system_formbuilder/traits/label.rb +1 -1
  42. data/lib/govuk_design_system_formbuilder/traits/select.rb +15 -0
  43. data/lib/govuk_design_system_formbuilder/traits/supplemental.rb +2 -2
  44. data/lib/govuk_design_system_formbuilder/version.rb +1 -1
  45. metadata +48 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4be57c3d159d67c07fc56632dd6c212bb834c5272d6eb1697f17e269fabf185a
4
- data.tar.gz: 8a9e652ad341513e78883fc5c68c3e704cb59cd3228bb7e5574c12f53735af72
3
+ metadata.gz: f503a3ef6180ed825ae959e1ae649d0b8e2d3b806e8705e9ec40802b29fef2cb
4
+ data.tar.gz: 0ca7e8d4b36a8f19799bb3a85fd533ebaa820f3baf1591ef421f4d7010d20c42
5
5
  SHA512:
6
- metadata.gz: 0b99bc098db98b484a0544cd69430bc9c34c00f4f93782d0879b222339b16d0c08c44bf95760a6b617f87b467f1a1381b9bbf35619333ba5f713dc2aa96415f1
7
- data.tar.gz: 64532cd5b33f6e1e78f5ba1a21a48ce2713018b7d8b00bbd32a7018436ebec11a2561024113930ddeb6d7059f359074ed0cfee0fe23219eba20d634c6c12784e
6
+ metadata.gz: 60a7c79b00eb5e5536509a3c77f688efde68a51764c05a7507bca26c289336d3238d4d5554d2b973fc186ec5f0c8e20f670e912aacac91fafa20e184d3c7eb84
7
+ data.tar.gz: a4a8c1d7ccee0ffc54a8de95450fc0603053f6efb2770963e81fe32c192ee464e402138fae41c5ab72a19c6afbbd8848c2817959008ee1ca1dceb90e4b922566
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (C) 2019 Crown Copyright (Government Digital Service)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -8,8 +8,8 @@
8
8
  [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=DFE-Digital/govuk_design_system_formbuilder)](https://dependabot.com)
9
9
  [![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk_design_system_formbuilder)](https://github.com/DFE-Digital/govuk_design_system_formbuilder/blob/master/LICENSE)
10
10
  [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.11.0-brightgreen)](https://design-system.service.gov.uk)
11
- [![Rails](https://img.shields.io/badge/Ruby-2.6.6%20%E2%95%B1%202.7.2%20%E2%95%B1%203.0.0-E16D6D)](https://www.ruby-lang.org/en/downloads/)
12
- [![Ruby](https://img.shields.io/badge/Rails-6.0.3%20%E2%95%B1%206.1.0-E16D6D)](https://weblog.rubyonrails.org/releases/)
11
+ [![Rails](https://img.shields.io/badge/Ruby-2.6.7%20%E2%95%B1%202.7.3%20%E2%95%B1%203.0.1-E16D6D)](https://www.ruby-lang.org/en/downloads/)
12
+ [![Ruby](https://img.shields.io/badge/Rails-6.0.3.6%20%E2%95%B1%206.1.3.1-E16D6D)](https://weblog.rubyonrails.org/releases/)
13
13
 
14
14
  This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
15
15
 
@@ -1,3 +1,4 @@
1
+ require 'deep_merge/rails_compat'
1
2
  require 'active_support/configurable'
2
3
 
3
4
  [%w(traits *.rb), %w(*.rb), %w(elements ** *.rb), %w(containers ** *.rb)]
@@ -48,6 +49,9 @@ module GOVUKDesignSystemFormBuilder
48
49
  # * +:localisation_schema_legend+, +:localisation_schema_hint+ and
49
50
  # +:localisation_schema_label+ each override the schema root for their
50
51
  # particular context, allowing them to be independently customised.
52
+ #
53
+ # * +:enable_logger+ controls whether or not the library will emit log
54
+ # messages via Rails.logger.warn, defaults to +true+
51
55
  # ===
52
56
  DEFAULTS = {
53
57
  brand: 'govuk',
@@ -66,7 +70,10 @@ module GOVUKDesignSystemFormBuilder
66
70
  localisation_schema_label: nil,
67
71
  localisation_schema_hint: nil,
68
72
  localisation_schema_legend: nil,
69
- localisation_schema_caption: nil
73
+ localisation_schema_caption: nil,
74
+
75
+ enable_logger: true,
76
+ enable_log_on_invalid_date: false
70
77
  }.freeze
71
78
 
72
79
  DEFAULTS.each_key { |k| config_accessor(k) { DEFAULTS[k] } }
@@ -25,6 +25,15 @@ module GOVUKDesignSystemFormBuilder
25
25
 
26
26
  private
27
27
 
28
+ # returns the attributes bound to the object that are
29
+ # required to build all contained elements
30
+ #
31
+ # @return [GOVUKDesignSystemFormBuilder::FormBuilder, Symbol, Symbol] an array containing the
32
+ # builder, object name and attribute name
33
+ def bound
34
+ [@builder, @object_name, @attribute_name]
35
+ end
36
+
28
37
  def brand(override = nil)
29
38
  override || config.brand
30
39
  end
@@ -57,7 +66,7 @@ module GOVUKDesignSystemFormBuilder
57
66
  end
58
67
 
59
68
  def described_by(*ids)
60
- ids.flatten.compact.join(' ').presence
69
+ ids.flatten.compact
61
70
  end
62
71
 
63
72
  # Builds the values used for HTML id attributes throughout the builder
@@ -87,5 +96,11 @@ module GOVUKDesignSystemFormBuilder
87
96
  .parameterize
88
97
  .tr(replace, delimiter)
89
98
  end
99
+
100
+ def warn(message)
101
+ return unless config.enable_logger
102
+
103
+ Rails.logger.warn(message)
104
+ end
90
105
  end
91
106
  end
@@ -341,6 +341,7 @@ module GOVUKDesignSystemFormBuilder
341
341
  # @param form_group [Hash] configures the form group
342
342
  # @option form_group classes [Array,String] sets the form group's classes
343
343
  # @option form_group kwargs [Hash] additional attributes added to the form group
344
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +textarea+ element
344
345
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
345
346
  # @return [ActiveSupport::SafeBuffer] HTML output
346
347
  # @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
@@ -380,13 +381,13 @@ module GOVUKDesignSystemFormBuilder
380
381
  # supplied the hint will be wrapped in a +div+ instead of a +span+
381
382
  # @option hint text [String] the hint text
382
383
  # @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
384
+ # @param label [Hash,Proc] configures or sets the associated label content
383
385
  # @option label text [String] the label text
384
386
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
385
387
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
386
388
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
387
389
  # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
388
390
  # @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
389
- # @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
390
391
  # @param form_group [Hash] configures the form group
391
392
  # @option form_group classes [Array,String] sets the form group's classes
392
393
  # @option form_group kwargs [Hash] additional attributes added to the form group
@@ -411,8 +412,8 @@ module GOVUKDesignSystemFormBuilder
411
412
  # = f.govuk_collection_select(:team, @teams, :id, :name) do
412
413
  # label: -> { tag.h3("Which team did you represent?") }
413
414
  #
414
- def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint: {}, label: {}, caption: {}, form_group: {}, &block)
415
- Elements::Select.new(
415
+ def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block)
416
+ Elements::CollectionSelect.new(
416
417
  self,
417
418
  object_name,
418
419
  attribute_name,
@@ -423,12 +424,48 @@ module GOVUKDesignSystemFormBuilder
423
424
  label: label,
424
425
  caption: caption,
425
426
  options: options,
426
- html_options: html_options,
427
427
  form_group: form_group,
428
+ **kwargs,
428
429
  &block
429
430
  ).html
430
431
  end
431
432
 
433
+ # Generates a +select+ element containing an +option+ for every choice provided
434
+ #
435
+ # @param attribute_name [Symbol] The name of the attribute
436
+ # @param choices [Array,Hash] The +option+ values, usually provided via
437
+ # the +options_for_select+ or +grouped_options_for_select+ helpers.
438
+ # @param options [Hash] Options hash passed through to Rails' +select+ helper
439
+ # @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
440
+ # supplied the hint will be wrapped in a +div+ instead of a +span+
441
+ # @option hint text [String] the hint text
442
+ # @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
443
+ # @param label [Hash,Proc] configures or sets the associated label content
444
+ # @option label text [String] the label text
445
+ # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
446
+ # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
447
+ # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
448
+ # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
449
+ # @param form_group [Hash] configures the form group
450
+ # @option form_group classes [Array,String] sets the form group's classes
451
+ # @option form_group kwargs [Hash] additional attributes added to the form group
452
+ # @param block [Block] build the contents of the select element manually for exact control
453
+ # @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select Rails select (called by govuk_collection_select)
454
+ # @return [ActiveSupport::SafeBuffer] HTML output
455
+ #
456
+ # @example A select box with custom data attributes
457
+ #
458
+ # @colours = [
459
+ # ["PapayaWhip", "pw", { data: { hex: "#ffefd5" } }],
460
+ # ["Chocolate", "choc", { data: { hex: "#d2691e" } }],
461
+ # ]
462
+ #
463
+ # = f.govuk_select :hat_colour, options_for_select(@colours)
464
+ #
465
+ def govuk_select(attribute_name, choices = nil, options: {}, label: {}, hint: {}, form_group: {}, caption: {}, **kwargs, &block)
466
+ Elements::Select.new(self, object_name, attribute_name, choices, options: options, label: label, hint: hint, form_group: form_group, caption: caption, **kwargs, &block).html
467
+ end
468
+
432
469
  # Generates a radio button for each item in the supplied collection
433
470
  #
434
471
  # @note Unlike the Rails +#collection_radio_buttons+ helper, this version can also insert
@@ -597,6 +634,7 @@ module GOVUKDesignSystemFormBuilder
597
634
  # container and only revealed when the radio button is picked
598
635
  # @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
599
636
  # from the error summary. <b>Should only be set to +true+ for the first radio button in a fieldset</b>
637
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
600
638
  # @return [ActiveSupport::SafeBuffer] HTML output
601
639
  #
602
640
  # @example A single radio button for our new favourite colour
@@ -604,8 +642,8 @@ module GOVUKDesignSystemFormBuilder
604
642
  # = f.govuk_radio_buttons_fieldset :favourite_colour do
605
643
  # = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
606
644
  #
607
- def govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, &block)
608
- Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint: hint, label: label, link_errors: link_errors, &block).html
645
+ def govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, **kwargs, &block)
646
+ Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint: hint, label: label, link_errors: link_errors, **kwargs, &block).html
609
647
  end
610
648
 
611
649
  # Inserts a text divider into a list of radio buttons
@@ -775,6 +813,7 @@ module GOVUKDesignSystemFormBuilder
775
813
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
776
814
  # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
777
815
  # @param multiple [Boolean] controls whether the check box is part of a collection or represents a single attribute
816
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
778
817
  # @param block [Block] any HTML passed in will form the contents of the fieldset
779
818
  # @return [ActiveSupport::SafeBuffer] HTML output
780
819
  #
@@ -786,7 +825,7 @@ module GOVUKDesignSystemFormBuilder
786
825
  # label: { text: 'Do you agree with our terms and conditions?' },
787
826
  # hint: { text: 'You will not be able to proceed unless you do' }
788
827
  #
789
- def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, &block)
828
+ def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, **kwargs, &block)
790
829
  Elements::CheckBoxes::FieldsetCheckBox.new(
791
830
  self,
792
831
  object_name,
@@ -797,6 +836,7 @@ module GOVUKDesignSystemFormBuilder
797
836
  label: label,
798
837
  link_errors: link_errors,
799
838
  multiple: multiple,
839
+ **kwargs,
800
840
  &block
801
841
  ).html
802
842
  end
@@ -813,6 +853,7 @@ module GOVUKDesignSystemFormBuilder
813
853
  # client-side validation provided by the browser. This is to provide a more consistent and accessible user
814
854
  # experience
815
855
  # @param disabled [Boolean] makes the button disabled when true
856
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
816
857
  # @param block [Block] When content is passed in via a block the submit element and the block content will
817
858
  # be wrapped in a +<div class="govuk-button-group">+ which will space the buttons and links within
818
859
  # evenly.
@@ -829,8 +870,8 @@ module GOVUKDesignSystemFormBuilder
829
870
  # = f.govuk_submit "Proceed", prevent_double_click: true do
830
871
  # = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
831
872
  #
832
- def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, classes: nil, prevent_double_click: true, validate: config.default_submit_validate, disabled: false, &block)
833
- Elements::Submit.new(self, text, warning: warning, secondary: secondary, classes: classes, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, &block).html
873
+ def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, classes: nil, prevent_double_click: true, validate: config.default_submit_validate, disabled: false, **kwargs, &block)
874
+ Elements::Submit.new(self, text, warning: warning, secondary: secondary, classes: classes, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, **kwargs, &block).html
834
875
  end
835
876
 
836
877
  # Generates three inputs for the +day+, +month+ and +year+ components of a date
@@ -838,6 +879,7 @@ module GOVUKDesignSystemFormBuilder
838
879
  # @note When using this input be aware that Rails's multiparam time and date handling falls foul
839
880
  # of {https://bugs.ruby-lang.org/issues/5988 this} bug, so incorrect dates like +2019-09-31+ will
840
881
  # be 'rounded' up to +2019-10-01+.
882
+ # @note When using this input values will be retrieved from the attribute if it is a Date object or a multiparam date hash
841
883
  # @param attribute_name [Symbol] The name of the attribute
842
884
  # @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
843
885
  # supplied the hint will be wrapped in a +div+ instead of a +span+
@@ -858,6 +900,7 @@ module GOVUKDesignSystemFormBuilder
858
900
  # @param form_group [Hash] configures the form group
859
901
  # @option form_group classes [Array,String] sets the form group's classes
860
902
  # @option form_group kwargs [Hash] additional attributes added to the form group
903
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
861
904
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
862
905
  # @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
863
906
  # will be added to the inputs
@@ -877,8 +920,8 @@ module GOVUKDesignSystemFormBuilder
877
920
  # @example A date input with legend supplied as a proc
878
921
  # = f.govuk_date_field :finishes_on,
879
922
  # legend: -> { tag.h3('Which category do you belong to?') }
880
- def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, wildcards: false, &block)
881
- Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, form_group: form_group, wildcards: wildcards, &block).html
923
+ def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, wildcards: false, **kwargs, &block)
924
+ Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, form_group: form_group, wildcards: wildcards, **kwargs, &block).html
882
925
  end
883
926
 
884
927
  # Generates a summary of errors in the form, each linking to the corresponding
@@ -887,6 +930,7 @@ module GOVUKDesignSystemFormBuilder
887
930
  # @param title [String] the error summary heading
888
931
  # @param link_base_errors_to [Symbol,String] set the field that errors on +:base+ are linked
889
932
  # to, as there won't be a field representing the object base.
933
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the error summary +div+ element
890
934
  #
891
935
  # @note Only the first error in the +#errors+ array for each attribute will
892
936
  # be included.
@@ -895,8 +939,8 @@ module GOVUKDesignSystemFormBuilder
895
939
  # = f.govuk_error_summary 'Uh-oh, spaghettios'
896
940
  #
897
941
  # @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
898
- def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil)
899
- Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to).html
942
+ def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil, **kwargs)
943
+ Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, **kwargs).html
900
944
  end
901
945
 
902
946
  # Generates a fieldset containing the contents of the block
@@ -912,6 +956,7 @@ module GOVUKDesignSystemFormBuilder
912
956
  # @option caption text [String] the caption text
913
957
  # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
914
958
  # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
959
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
915
960
  #
916
961
  # @example A fieldset containing address fields
917
962
  # = f.govuk_fieldset legend: { text: 'Address' } do
@@ -927,8 +972,8 @@ module GOVUKDesignSystemFormBuilder
927
972
  # @see https://design-system.service.gov.uk/components/fieldset/ GOV.UK fieldset
928
973
  # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
929
974
  # @return [ActiveSupport::SafeBuffer] HTML output
930
- def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, &block)
931
- Containers::Fieldset.new(self, legend: legend, caption: caption, described_by: described_by, &block).html
975
+ def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, **kwargs, &block)
976
+ Containers::Fieldset.new(self, legend: legend, caption: caption, described_by: described_by, **kwargs, &block).html
932
977
  end
933
978
 
934
979
  # Generates an input of type +file+
@@ -18,8 +18,8 @@ module GOVUKDesignSystemFormBuilder
18
18
  end
19
19
 
20
20
  def html
21
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
22
- Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
21
+ Containers::FormGroup.new(*bound, **@form_group).html do
22
+ Containers::Fieldset.new(*bound, **fieldset_options).html do
23
23
  safe_join([hint_element, error_element, hidden_field, checkboxes])
24
24
  end
25
25
  end
@@ -1,17 +1,20 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Containers
3
3
  class Fieldset < Base
4
- def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, caption: {}, described_by: nil, &block)
4
+ include Traits::HTMLAttributes
5
+
6
+ def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, caption: {}, described_by: nil, **kwargs, &block)
5
7
  super(builder, object_name, attribute_name, &block)
6
8
 
7
- @legend = legend
8
- @caption = caption
9
- @described_by = described_by(described_by)
10
- @attribute_name = attribute_name
9
+ @legend = legend
10
+ @caption = caption
11
+ @described_by = described_by(described_by)
12
+ @attribute_name = attribute_name
13
+ @html_attributes = kwargs
11
14
  end
12
15
 
13
16
  def html
14
- tag.fieldset(**options) do
17
+ tag.fieldset(**attributes(@html_attributes)) do
15
18
  safe_join([legend_element, (@block_content || yield)])
16
19
  end
17
20
  end
@@ -21,19 +24,19 @@ module GOVUKDesignSystemFormBuilder
21
24
  def options
22
25
  {
23
26
  class: classes,
24
- aria: { describedby: @described_by }
27
+ aria: { describedby: [@described_by] }
25
28
  }
26
29
  end
27
30
 
28
31
  def classes
29
- %(#{brand}-fieldset)
32
+ [%(#{brand}-fieldset)]
30
33
  end
31
34
 
32
35
  def legend_element
33
36
  @legend_element ||= if @legend.nil?
34
37
  Elements::Null.new
35
38
  else
36
- Elements::Legend.new(@builder, @object_name, @attribute_name, **legend_options)
39
+ Elements::Legend.new(*bound, **legend_options)
37
40
  end
38
41
  end
39
42
 
@@ -18,8 +18,8 @@ module GOVUKDesignSystemFormBuilder
18
18
  end
19
19
 
20
20
  def html
21
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
22
- Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
21
+ Containers::FormGroup.new(*bound, **@form_group).html do
22
+ Containers::Fieldset.new(*bound, **fieldset_options).html do
23
23
  safe_join([hint_element, error_element, radios])
24
24
  end
25
25
  end
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
8
8
  end
9
9
 
10
10
  def html
11
- return nil if @content.blank?
11
+ return if @content.blank?
12
12
 
13
13
  tag.div(id: supplemental_id) { @content }
14
14
  end
@@ -3,7 +3,7 @@ module GOVUKDesignSystemFormBuilder
3
3
  class Caption < Base
4
4
  include Traits::Localisation
5
5
 
6
- def initialize(builder, object_name, attribute_name, text: nil, size: nil, **kwargs)
6
+ def initialize(builder, object_name, attribute_name, text: nil, size: config.default_caption_size, **kwargs)
7
7
  super(builder, object_name, attribute_name)
8
8
 
9
9
  @text = text(text)
@@ -12,7 +12,7 @@ module GOVUKDesignSystemFormBuilder
12
12
  end
13
13
 
14
14
  def html
15
- return nil unless active?
15
+ return unless active?
16
16
 
17
17
  tag.span(@text, class: @size_class, **@html_attributes)
18
18
  end
@@ -28,7 +28,7 @@ module GOVUKDesignSystemFormBuilder
28
28
  end
29
29
 
30
30
  def size_class(size)
31
- case size || config.default_caption_size
31
+ case size
32
32
  when 'xl' then %(#{brand}-caption-xl)
33
33
  when 'l' then %(#{brand}-caption-l)
34
34
  when 'm' then %(#{brand}-caption-m)
@@ -23,8 +23,8 @@ module GOVUKDesignSystemFormBuilder
23
23
  end
24
24
 
25
25
  def html
26
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
27
- Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
26
+ Containers::FormGroup.new(*bound, **@form_group).html do
27
+ Containers::Fieldset.new(*bound, **fieldset_options).html do
28
28
  safe_join([supplemental_content, hint_element, error_element, check_boxes])
29
29
  end
30
30
  end
@@ -36,11 +36,11 @@ module GOVUKDesignSystemFormBuilder
36
36
  end
37
37
 
38
38
  def label_element
39
- @label_element ||= Label.new(@builder, @object_name, @attribute_name, @checkbox, value: @value, link_errors: @link_errors)
39
+ @label_element ||= Label.new(*bound, @checkbox, value: @value, link_errors: @link_errors)
40
40
  end
41
41
 
42
42
  def hint_element
43
- @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
43
+ @hint_element ||= Elements::Hint.new(*bound, **hint_options, **hint_content)
44
44
  end
45
45
 
46
46
  def hint_options