govuk_design_system_formbuilder 2.1.7 → 2.3.0

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -0
  3. data/README.md +3 -3
  4. data/lib/govuk_design_system_formbuilder.rb +10 -0
  5. data/lib/govuk_design_system_formbuilder/base.rb +9 -0
  6. data/lib/govuk_design_system_formbuilder/builder.rb +28 -19
  7. data/lib/govuk_design_system_formbuilder/containers/button_group.rb +15 -0
  8. data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +2 -2
  9. data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +11 -8
  10. data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +2 -2
  11. data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +1 -1
  12. data/lib/govuk_design_system_formbuilder/elements/caption.rb +3 -3
  13. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +15 -14
  14. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +2 -2
  15. data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +4 -2
  16. data/lib/govuk_design_system_formbuilder/elements/date.rb +13 -12
  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 +3 -3
  31. data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +8 -6
  32. data/lib/govuk_design_system_formbuilder/elements/select.rb +22 -19
  33. data/lib/govuk_design_system_formbuilder/elements/submit.rb +21 -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 +9 -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/supplemental.rb +2 -2
  43. data/lib/govuk_design_system_formbuilder/version.rb +1 -1
  44. metadata +35 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3150318cc7e6d0cd73188a05884f0b321b7facd3523d4d4458cc70efee5f396
4
- data.tar.gz: feabd9a11432921e52ef3fc9c948e154106b18105d61ff512c391951f4e21cbd
3
+ metadata.gz: 2f56b92f232ffd2b98c38637c49b2e4255f3be12cab3825f795a735cbfae0107
4
+ data.tar.gz: 0f4dfd572130559b3140a838310ce471a4adee41f46fed32ca5046cfa29ed9d0
5
5
  SHA512:
6
- metadata.gz: 18b17fbcd9cd16c57c5a42fc580595773a9a06835c768e7330245f006268e2b3999a520cbe39279e59bd84086eeea165018df4689e287212354352b21641a9c0
7
- data.tar.gz: 36fb4d615b1fb988f5a248a310ea8be52310125330df52c0a843e96f95ecbf209f30de2c0ad7489d64581140920fd8c0f2a29430cc534d8f5d9700ae8a1211a4
6
+ metadata.gz: 67861fee01f6a14cac7bbf9db87d1633dcf13e569aaa2179f5e16d21f8aed5e7b7d553a5bd96e601ab5b4181e6c27c905fa5fd6d7e80c811a2cff28d42b1f83f
7
+ data.tar.gz: a889d6d02fd1978e73aa2328debc5b6268993eca88755b3cf31889dfe4c973d28e09dfb9d13bbe462347aeea74a1f46dfb8ba8f4f7c20ad3da5c2c8d1d6aa114
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
@@ -7,9 +7,9 @@
7
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/fde73b5dc9476197281b/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/test_coverage)
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
- [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.10.2-brightgreen)](https://design-system.service.gov.uk)
11
- [![Rails](https://img.shields.io/badge/Ruby-2.5.8%20%E2%95%B1%202.6.6%20%E2%95%B1%202.7.2-E16D6D)](https://weblog.rubyonrails.org/releases/)
12
- [![Ruby](https://img.shields.io/badge/Rails-5.2.4%20%E2%95%B1%206.0.3%20%E2%95%B1%206.1.0-E16D6D)](https://www.ruby-lang.org/en/downloads/)
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/)
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)]
@@ -34,6 +35,12 @@ module GOVUKDesignSystemFormBuilder
34
35
  # blocks. As per the GOV.UK Design System spec, it defaults to
35
36
  # 'There is a problem'.
36
37
  #
38
+ # * +:default_collection_check_boxes_include_hidden+ controls whether or not
39
+ # a hidden field is added when rendering a collection of check boxes
40
+ #
41
+ # * +:default_collection_radio_buttons_include_hidden+ controls whether or not
42
+ # a hidden field is added when rendering a collection of radio buttons
43
+ #
37
44
  # * +:localisation_schema_fallback+ sets the prefix elements for the array
38
45
  # used to build the localisation string. The final two elements are always
39
46
  # are the object name and attribute name. The _special_ value +__context__+,
@@ -52,6 +59,9 @@ module GOVUKDesignSystemFormBuilder
52
59
  default_submit_button_text: 'Continue',
53
60
  default_radio_divider_text: 'or',
54
61
  default_error_summary_title: 'There is a problem',
62
+ default_collection_check_boxes_include_hidden: true,
63
+ default_collection_radio_buttons_include_hidden: true,
64
+ default_submit_validate: false,
55
65
 
56
66
  localisation_schema_fallback: %i(helpers __context__),
57
67
  localisation_schema_label: nil,
@@ -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
@@ -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
@@ -386,7 +387,6 @@ module GOVUKDesignSystemFormBuilder
386
387
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
387
388
  # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
388
389
  # @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
390
  # @param form_group [Hash] configures the form group
391
391
  # @option form_group classes [Array,String] sets the form group's classes
392
392
  # @option form_group kwargs [Hash] additional attributes added to the form group
@@ -411,7 +411,7 @@ module GOVUKDesignSystemFormBuilder
411
411
  # = f.govuk_collection_select(:team, @teams, :id, :name) do
412
412
  # label: -> { tag.h3("Which team did you represent?") }
413
413
  #
414
- def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint: {}, label: {}, caption: {}, form_group: {}, &block)
414
+ def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block)
415
415
  Elements::Select.new(
416
416
  self,
417
417
  object_name,
@@ -423,8 +423,8 @@ module GOVUKDesignSystemFormBuilder
423
423
  label: label,
424
424
  caption: caption,
425
425
  options: options,
426
- html_options: html_options,
427
426
  form_group: form_group,
427
+ **kwargs,
428
428
  &block
429
429
  ).html
430
430
  end
@@ -501,7 +501,7 @@ module GOVUKDesignSystemFormBuilder
501
501
  # :name,
502
502
  # legend: -> { tag.h3('Which category do you belong to?') }
503
503
  #
504
- def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, include_hidden: false, form_group: {}, &block)
504
+ def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, include_hidden: config.default_collection_radio_buttons_include_hidden, form_group: {}, &block)
505
505
  Elements::Radios::Collection.new(
506
506
  self,
507
507
  object_name,
@@ -597,6 +597,7 @@ module GOVUKDesignSystemFormBuilder
597
597
  # container and only revealed when the radio button is picked
598
598
  # @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
599
599
  # from the error summary. <b>Should only be set to +true+ for the first radio button in a fieldset</b>
600
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
600
601
  # @return [ActiveSupport::SafeBuffer] HTML output
601
602
  #
602
603
  # @example A single radio button for our new favourite colour
@@ -604,8 +605,8 @@ module GOVUKDesignSystemFormBuilder
604
605
  # = f.govuk_radio_buttons_fieldset :favourite_colour do
605
606
  # = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
606
607
  #
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
608
+ def govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, **kwargs, &block)
609
+ Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint: hint, label: label, link_errors: link_errors, **kwargs, &block).html
609
610
  end
610
611
 
611
612
  # Inserts a text divider into a list of radio buttons
@@ -646,6 +647,7 @@ module GOVUKDesignSystemFormBuilder
646
647
  # @param form_group [Hash] configures the form group
647
648
  # @option form_group classes [Array,String] sets the form group's classes
648
649
  # @option form_group kwargs [Hash] additional attributes added to the form group
650
+ # @param include_hidden [Boolean] controls whether a hidden field is inserted to allow for empty submissions
649
651
  # @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
650
652
  # @return [ActiveSupport::SafeBuffer] HTML output
651
653
  #
@@ -682,7 +684,7 @@ module GOVUKDesignSystemFormBuilder
682
684
  # :name,
683
685
  # legend: -> { tag.h3('What kind of sandwich do you want?') }
684
686
  #
685
- def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, small: false, classes: nil, form_group: {}, &block)
687
+ def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, small: false, classes: nil, form_group: {}, include_hidden: config.default_collection_check_boxes_include_hidden, &block)
686
688
  Elements::CheckBoxes::Collection.new(
687
689
  self,
688
690
  object_name,
@@ -697,6 +699,7 @@ module GOVUKDesignSystemFormBuilder
697
699
  small: small,
698
700
  classes: classes,
699
701
  form_group: form_group,
702
+ include_hidden: include_hidden,
700
703
  &block
701
704
  ).html
702
705
  end
@@ -773,6 +776,7 @@ module GOVUKDesignSystemFormBuilder
773
776
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
774
777
  # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
775
778
  # @param multiple [Boolean] controls whether the check box is part of a collection or represents a single attribute
779
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
776
780
  # @param block [Block] any HTML passed in will form the contents of the fieldset
777
781
  # @return [ActiveSupport::SafeBuffer] HTML output
778
782
  #
@@ -784,7 +788,7 @@ module GOVUKDesignSystemFormBuilder
784
788
  # label: { text: 'Do you agree with our terms and conditions?' },
785
789
  # hint: { text: 'You will not be able to proceed unless you do' }
786
790
  #
787
- def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, &block)
791
+ def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, **kwargs, &block)
788
792
  Elements::CheckBoxes::FieldsetCheckBox.new(
789
793
  self,
790
794
  object_name,
@@ -795,6 +799,7 @@ module GOVUKDesignSystemFormBuilder
795
799
  label: label,
796
800
  link_errors: link_errors,
797
801
  multiple: multiple,
802
+ **kwargs,
798
803
  &block
799
804
  ).html
800
805
  end
@@ -811,9 +816,10 @@ module GOVUKDesignSystemFormBuilder
811
816
  # client-side validation provided by the browser. This is to provide a more consistent and accessible user
812
817
  # experience
813
818
  # @param disabled [Boolean] makes the button disabled when true
814
- # @param block [Block] Any supplied HTML will be inserted immediately after
815
- # the submit button. It is intended for other buttons directly related to
816
- # the form's operation, such as 'Cancel' or 'Safe draft'
819
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
820
+ # @param block [Block] When content is passed in via a block the submit element and the block content will
821
+ # be wrapped in a +<div class="govuk-button-group">+ which will space the buttons and links within
822
+ # evenly.
817
823
  # @raise [ArgumentError] raised if both +warning+ and +secondary+ are true
818
824
  # @return [ActiveSupport::SafeBuffer] HTML output
819
825
  # @note Only the first additional button or link (passed in via a block) will be given the
@@ -827,8 +833,8 @@ module GOVUKDesignSystemFormBuilder
827
833
  # = f.govuk_submit "Proceed", prevent_double_click: true do
828
834
  # = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
829
835
  #
830
- def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, classes: nil, prevent_double_click: true, validate: false, disabled: false, &block)
831
- Elements::Submit.new(self, text, warning: warning, secondary: secondary, classes: classes, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, &block).html
836
+ 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)
837
+ Elements::Submit.new(self, text, warning: warning, secondary: secondary, classes: classes, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, **kwargs, &block).html
832
838
  end
833
839
 
834
840
  # Generates three inputs for the +day+, +month+ and +year+ components of a date
@@ -856,6 +862,7 @@ module GOVUKDesignSystemFormBuilder
856
862
  # @param form_group [Hash] configures the form group
857
863
  # @option form_group classes [Array,String] sets the form group's classes
858
864
  # @option form_group kwargs [Hash] additional attributes added to the form group
865
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
859
866
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
860
867
  # @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
861
868
  # will be added to the inputs
@@ -875,8 +882,8 @@ module GOVUKDesignSystemFormBuilder
875
882
  # @example A date input with legend supplied as a proc
876
883
  # = f.govuk_date_field :finishes_on,
877
884
  # legend: -> { tag.h3('Which category do you belong to?') }
878
- def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, wildcards: false, &block)
879
- 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
885
+ def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, wildcards: false, **kwargs, &block)
886
+ 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
880
887
  end
881
888
 
882
889
  # Generates a summary of errors in the form, each linking to the corresponding
@@ -885,6 +892,7 @@ module GOVUKDesignSystemFormBuilder
885
892
  # @param title [String] the error summary heading
886
893
  # @param link_base_errors_to [Symbol,String] set the field that errors on +:base+ are linked
887
894
  # to, as there won't be a field representing the object base.
895
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the error summary +div+ element
888
896
  #
889
897
  # @note Only the first error in the +#errors+ array for each attribute will
890
898
  # be included.
@@ -893,8 +901,8 @@ module GOVUKDesignSystemFormBuilder
893
901
  # = f.govuk_error_summary 'Uh-oh, spaghettios'
894
902
  #
895
903
  # @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
896
- def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil)
897
- Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to).html
904
+ def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil, **kwargs)
905
+ Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, **kwargs).html
898
906
  end
899
907
 
900
908
  # Generates a fieldset containing the contents of the block
@@ -910,6 +918,7 @@ module GOVUKDesignSystemFormBuilder
910
918
  # @option caption text [String] the caption text
911
919
  # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
912
920
  # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
921
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
913
922
  #
914
923
  # @example A fieldset containing address fields
915
924
  # = f.govuk_fieldset legend: { text: 'Address' } do
@@ -925,8 +934,8 @@ module GOVUKDesignSystemFormBuilder
925
934
  # @see https://design-system.service.gov.uk/components/fieldset/ GOV.UK fieldset
926
935
  # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
927
936
  # @return [ActiveSupport::SafeBuffer] HTML output
928
- def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, &block)
929
- Containers::Fieldset.new(self, legend: legend, caption: caption, described_by: described_by, &block).html
937
+ def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, **kwargs, &block)
938
+ Containers::Fieldset.new(self, legend: legend, caption: caption, described_by: described_by, **kwargs, &block).html
930
939
  end
931
940
 
932
941
  # Generates an input of type +file+
@@ -0,0 +1,15 @@
1
+ module GOVUKDesignSystemFormBuilder
2
+ module Containers
3
+ class ButtonGroup < Base
4
+ def initialize(builder, buttons)
5
+ super(builder, nil, nil)
6
+
7
+ @buttons = buttons
8
+ end
9
+
10
+ def html
11
+ tag.div(@buttons, class: %(#{brand}-button-group))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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
@@ -26,14 +29,14 @@ module GOVUKDesignSystemFormBuilder
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)
@@ -6,24 +6,25 @@ module GOVUKDesignSystemFormBuilder
6
6
  include Traits::Hint
7
7
  include Traits::Supplemental
8
8
 
9
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, legend:, caption:, small:, classes:, form_group:, hint_method: nil, &block)
9
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, legend:, caption:, small:, classes:, form_group:, include_hidden:, hint_method: nil, &block)
10
10
  super(builder, object_name, attribute_name, &block)
11
11
 
12
- @collection = collection
13
- @value_method = value_method
14
- @text_method = text_method
15
- @hint_method = hint_method
16
- @small = small
17
- @legend = legend
18
- @caption = caption
19
- @hint = hint
20
- @classes = classes
21
- @form_group = form_group
12
+ @collection = collection
13
+ @value_method = value_method
14
+ @text_method = text_method
15
+ @hint_method = hint_method
16
+ @small = small
17
+ @legend = legend
18
+ @caption = caption
19
+ @hint = hint
20
+ @classes = classes
21
+ @form_group = form_group
22
+ @include_hidden = include_hidden
22
23
  end
23
24
 
24
25
  def html
25
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
26
- 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
27
28
  safe_join([supplemental_content, hint_element, error_element, check_boxes])
28
29
  end
29
30
  end
@@ -56,7 +57,7 @@ module GOVUKDesignSystemFormBuilder
56
57
  def collection
57
58
  link_errors = has_errors?
58
59
 
59
- @builder.collection_check_boxes(@attribute_name, @collection, @value_method, @text_method) do |check_box|
60
+ @builder.collection_check_boxes(@attribute_name, @collection, @value_method, @text_method, include_hidden: @include_hidden) do |check_box|
60
61
  Elements::CheckBoxes::CollectionCheckBox.new(
61
62
  @builder,
62
63
  @object_name,