govuk_design_system_formbuilder 2.2.0 → 2.3.0b1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4be57c3d159d67c07fc56632dd6c212bb834c5272d6eb1697f17e269fabf185a
4
- data.tar.gz: 8a9e652ad341513e78883fc5c68c3e704cb59cd3228bb7e5574c12f53735af72
3
+ metadata.gz: 641fbc9fbd19bc333cd0872da36c9286c7f956cdfe41ef5b9b234dbe264bc03a
4
+ data.tar.gz: 30a0000fa3868e7f7f6bf67347a025cf8f85e5e02a77bff4026d343088c3fb3f
5
5
  SHA512:
6
- metadata.gz: 0b99bc098db98b484a0544cd69430bc9c34c00f4f93782d0879b222339b16d0c08c44bf95760a6b617f87b467f1a1381b9bbf35619333ba5f713dc2aa96415f1
7
- data.tar.gz: 64532cd5b33f6e1e78f5ba1a21a48ce2713018b7d8b00bbd32a7018436ebec11a2561024113930ddeb6d7059f359074ed0cfee0fe23219eba20d634c6c12784e
6
+ metadata.gz: 53d6df89df5401b05190709bbad01273d0a2491484792d82307a1ffd6a054ef9de69f8d7d5ab7ae028c677603628bf203439959e70c8e2776504172c41fc2939
7
+ data.tar.gz: 5fa7f1475a37d063bab13dc27e4238ca6a7429abbe805b51436a6d3a1310c98df7defe60ad51ff376968d4ae8de8f828611daf79fc75a4602a6dbfeef3ae47f7
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.
@@ -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)]
@@ -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
@@ -411,7 +412,7 @@ 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
+ def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block)
415
416
  Elements::Select.new(
416
417
  self,
417
418
  object_name,
@@ -423,8 +424,8 @@ 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
@@ -597,6 +598,7 @@ module GOVUKDesignSystemFormBuilder
597
598
  # container and only revealed when the radio button is picked
598
599
  # @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
599
600
  # from the error summary. <b>Should only be set to +true+ for the first radio button in a fieldset</b>
601
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
600
602
  # @return [ActiveSupport::SafeBuffer] HTML output
601
603
  #
602
604
  # @example A single radio button for our new favourite colour
@@ -604,8 +606,8 @@ module GOVUKDesignSystemFormBuilder
604
606
  # = f.govuk_radio_buttons_fieldset :favourite_colour do
605
607
  # = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
606
608
  #
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
609
+ def govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, **kwargs, &block)
610
+ Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint: hint, label: label, link_errors: link_errors, **kwargs, &block).html
609
611
  end
610
612
 
611
613
  # Inserts a text divider into a list of radio buttons
@@ -775,6 +777,7 @@ module GOVUKDesignSystemFormBuilder
775
777
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
776
778
  # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
777
779
  # @param multiple [Boolean] controls whether the check box is part of a collection or represents a single attribute
780
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
778
781
  # @param block [Block] any HTML passed in will form the contents of the fieldset
779
782
  # @return [ActiveSupport::SafeBuffer] HTML output
780
783
  #
@@ -786,7 +789,7 @@ module GOVUKDesignSystemFormBuilder
786
789
  # label: { text: 'Do you agree with our terms and conditions?' },
787
790
  # hint: { text: 'You will not be able to proceed unless you do' }
788
791
  #
789
- def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, &block)
792
+ def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, **kwargs, &block)
790
793
  Elements::CheckBoxes::FieldsetCheckBox.new(
791
794
  self,
792
795
  object_name,
@@ -797,6 +800,7 @@ module GOVUKDesignSystemFormBuilder
797
800
  label: label,
798
801
  link_errors: link_errors,
799
802
  multiple: multiple,
803
+ **kwargs,
800
804
  &block
801
805
  ).html
802
806
  end
@@ -813,6 +817,7 @@ module GOVUKDesignSystemFormBuilder
813
817
  # client-side validation provided by the browser. This is to provide a more consistent and accessible user
814
818
  # experience
815
819
  # @param disabled [Boolean] makes the button disabled when true
820
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
816
821
  # @param block [Block] When content is passed in via a block the submit element and the block content will
817
822
  # be wrapped in a +<div class="govuk-button-group">+ which will space the buttons and links within
818
823
  # evenly.
@@ -829,8 +834,8 @@ module GOVUKDesignSystemFormBuilder
829
834
  # = f.govuk_submit "Proceed", prevent_double_click: true do
830
835
  # = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
831
836
  #
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
837
+ 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)
838
+ 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
839
  end
835
840
 
836
841
  # Generates three inputs for the +day+, +month+ and +year+ components of a date
@@ -858,6 +863,7 @@ module GOVUKDesignSystemFormBuilder
858
863
  # @param form_group [Hash] configures the form group
859
864
  # @option form_group classes [Array,String] sets the form group's classes
860
865
  # @option form_group kwargs [Hash] additional attributes added to the form group
866
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
861
867
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
862
868
  # @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
869
  # will be added to the inputs
@@ -877,8 +883,8 @@ module GOVUKDesignSystemFormBuilder
877
883
  # @example A date input with legend supplied as a proc
878
884
  # = f.govuk_date_field :finishes_on,
879
885
  # 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
886
+ def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, wildcards: false, **kwargs, &block)
887
+ 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
888
  end
883
889
 
884
890
  # Generates a summary of errors in the form, each linking to the corresponding
@@ -887,6 +893,7 @@ module GOVUKDesignSystemFormBuilder
887
893
  # @param title [String] the error summary heading
888
894
  # @param link_base_errors_to [Symbol,String] set the field that errors on +:base+ are linked
889
895
  # to, as there won't be a field representing the object base.
896
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the error summary +div+ element
890
897
  #
891
898
  # @note Only the first error in the +#errors+ array for each attribute will
892
899
  # be included.
@@ -895,8 +902,8 @@ module GOVUKDesignSystemFormBuilder
895
902
  # = f.govuk_error_summary 'Uh-oh, spaghettios'
896
903
  #
897
904
  # @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
905
+ def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil, **kwargs)
906
+ Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, **kwargs).html
900
907
  end
901
908
 
902
909
  # Generates a fieldset containing the contents of the block
@@ -912,6 +919,7 @@ module GOVUKDesignSystemFormBuilder
912
919
  # @option caption text [String] the caption text
913
920
  # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
914
921
  # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
922
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
915
923
  #
916
924
  # @example A fieldset containing address fields
917
925
  # = f.govuk_fieldset legend: { text: 'Address' } do
@@ -927,8 +935,8 @@ module GOVUKDesignSystemFormBuilder
927
935
  # @see https://design-system.service.gov.uk/components/fieldset/ GOV.UK fieldset
928
936
  # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
929
937
  # @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
938
+ def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, **kwargs, &block)
939
+ Containers::Fieldset.new(self, legend: legend, caption: caption, described_by: described_by, **kwargs, &block).html
932
940
  end
933
941
 
934
942
  # Generates an input of type +file+
@@ -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,7 +29,7 @@ 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
@@ -8,8 +8,9 @@ module GOVUKDesignSystemFormBuilder
8
8
  include Traits::Hint
9
9
  include Traits::FieldsetItem
10
10
  include Traits::Conditional
11
+ include Traits::HTMLAttributes
11
12
 
12
- def initialize(builder, object_name, attribute_name, value, unchecked_value, label:, hint:, link_errors:, multiple:, &block)
13
+ def initialize(builder, object_name, attribute_name, value, unchecked_value, label:, hint:, link_errors:, multiple:, **kwargs, &block)
13
14
  super(builder, object_name, attribute_name)
14
15
 
15
16
  @value = value
@@ -18,6 +19,7 @@ module GOVUKDesignSystemFormBuilder
18
19
  @hint = hint
19
20
  @multiple = multiple
20
21
  @link_errors = link_errors
22
+ @html_attributes = kwargs
21
23
 
22
24
  if block_given?
23
25
  @conditional_content = wrap_conditional(block)
@@ -38,7 +40,7 @@ module GOVUKDesignSystemFormBuilder
38
40
  end
39
41
 
40
42
  def check_box
41
- @builder.check_box(@attribute_name, options, @value, @unchecked_value)
43
+ @builder.check_box(@attribute_name, attributes(@html_attributes), @value, @unchecked_value)
42
44
  end
43
45
 
44
46
  def options
@@ -9,20 +9,21 @@ module GOVUKDesignSystemFormBuilder
9
9
 
10
10
  SEGMENTS = { day: '3i', month: '2i', year: '1i' }.freeze
11
11
 
12
- def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, omit_day:, form_group:, wildcards:, date_of_birth: false, &block)
12
+ def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, omit_day:, form_group:, wildcards:, date_of_birth: false, **kwargs, &block)
13
13
  super(builder, object_name, attribute_name, &block)
14
14
 
15
- @legend = legend
16
- @caption = caption
17
- @hint = hint
18
- @date_of_birth = date_of_birth
19
- @omit_day = omit_day
20
- @form_group = form_group
21
- @wildcards = wildcards
15
+ @legend = legend
16
+ @caption = caption
17
+ @hint = hint
18
+ @date_of_birth = date_of_birth
19
+ @omit_day = omit_day
20
+ @form_group = form_group
21
+ @wildcards = wildcards
22
+ @html_attributes = kwargs
22
23
  end
23
24
 
24
25
  def html
25
- Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
26
+ Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group, **@html_attributes).html do
26
27
  Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
27
28
  safe_join([supplemental_content, hint_element, error_element, date])
28
29
  end
@@ -2,18 +2,20 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class ErrorSummary < Base
4
4
  include Traits::Error
5
+ include Traits::HTMLAttributes
5
6
 
6
- def initialize(builder, object_name, title, link_base_errors_to:)
7
+ def initialize(builder, object_name, title, link_base_errors_to:, **kwargs)
7
8
  super(builder, object_name, nil)
8
9
 
9
10
  @title = title
10
11
  @link_base_errors_to = link_base_errors_to
12
+ @html_attributes = kwargs
11
13
  end
12
14
 
13
15
  def html
14
16
  return nil unless object_has_errors?
15
17
 
16
- tag.div(class: summary_class, **summary_options) do
18
+ tag.div(**attributes(@html_attributes)) do
17
19
  safe_join([title, summary])
18
20
  end
19
21
  end
@@ -46,6 +48,10 @@ module GOVUKDesignSystemFormBuilder
46
48
  '#'.concat(target)
47
49
  end
48
50
 
51
+ def classes
52
+ Array.wrap(summary_class)
53
+ end
54
+
49
55
  def summary_class(part = nil)
50
56
  if part
51
57
  %(#{brand}-error-summary).concat('__', part)
@@ -70,8 +76,9 @@ module GOVUKDesignSystemFormBuilder
70
76
  @builder.object.errors.any?
71
77
  end
72
78
 
73
- def summary_options
79
+ def options
74
80
  {
81
+ class: classes,
75
82
  tabindex: -1,
76
83
  role: 'alert',
77
84
  data: {
@@ -7,6 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  include Traits::Hint
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
+ include Traits::HTMLAttributes
10
11
 
11
12
  def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
12
13
  super(builder, object_name, attribute_name, &block)
@@ -27,7 +28,7 @@ module GOVUKDesignSystemFormBuilder
27
28
  private
28
29
 
29
30
  def file
30
- @builder.file_field(@attribute_name, **options, **@html_attributes)
31
+ @builder.file_field(@attribute_name, attributes(@html_attributes))
31
32
  end
32
33
 
33
34
  def options
@@ -7,6 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  include Traits::Hint
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
+ include Traits::HTMLAttributes
10
11
 
11
12
  private
12
13
 
@@ -7,6 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  include Traits::Hint
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
+ include Traits::HTMLAttributes
10
11
 
11
12
  def builder_method
12
13
  :number_field
@@ -7,6 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  include Traits::Hint
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
+ include Traits::HTMLAttributes
10
11
 
11
12
  def builder_method
12
13
  :password_field
@@ -7,6 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  include Traits::Hint
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
+ include Traits::HTMLAttributes
10
11
 
11
12
  def builder_method
12
13
  :phone_field
@@ -7,6 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  include Traits::Hint
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
+ include Traits::HTMLAttributes
10
11
 
11
12
  def builder_method
12
13
  :text_field
@@ -7,6 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  include Traits::Hint
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
+ include Traits::HTMLAttributes
10
11
 
11
12
  def builder_method
12
13
  :url_field
@@ -8,14 +8,16 @@ module GOVUKDesignSystemFormBuilder
8
8
  include Traits::Hint
9
9
  include Traits::FieldsetItem
10
10
  include Traits::Conditional
11
+ include Traits::HTMLAttributes
11
12
 
12
- def initialize(builder, object_name, attribute_name, value, label:, hint:, link_errors:, &block)
13
+ def initialize(builder, object_name, attribute_name, value, label:, hint:, link_errors:, **kwargs, &block)
13
14
  super(builder, object_name, attribute_name)
14
15
 
15
- @value = value
16
- @label = label
17
- @hint = hint
18
- @link_errors = has_errors? && link_errors
16
+ @value = value
17
+ @label = label
18
+ @hint = hint
19
+ @link_errors = has_errors? && link_errors
20
+ @html_attributes = kwargs
19
21
 
20
22
  if block_given?
21
23
  @conditional_content = wrap_conditional(block)
@@ -40,7 +42,7 @@ module GOVUKDesignSystemFormBuilder
40
42
  end
41
43
 
42
44
  def input
43
- @builder.radio_button(@attribute_name, @value, **options)
45
+ @builder.radio_button(@attribute_name, @value, **attributes(@html_attributes))
44
46
  end
45
47
 
46
48
  def options
@@ -5,19 +5,26 @@ module GOVUKDesignSystemFormBuilder
5
5
  include Traits::Label
6
6
  include Traits::Hint
7
7
  include Traits::Supplemental
8
+ include Traits::HTMLAttributes
8
9
 
9
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, label:, caption:, form_group:, options: {}, html_options: {}, &block)
10
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, label:, caption:, form_group:, options: {}, **kwargs, &block)
10
11
  super(builder, object_name, attribute_name, &block)
11
12
 
12
- @collection = collection
13
- @value_method = value_method
14
- @text_method = text_method
15
- @options = options
16
- @html_options = html_options
17
- @label = label
18
- @caption = caption
19
- @hint = hint
20
- @form_group = form_group
13
+ @collection = collection
14
+ @value_method = value_method
15
+ @text_method = text_method
16
+ @options = options
17
+ @label = label
18
+ @caption = caption
19
+ @hint = hint
20
+ @form_group = form_group
21
+ @html_attributes = kwargs
22
+
23
+ # FIXME remove this soon, worth informing people who miss the release notes that the
24
+ # args have changed though.
25
+ if :html_options.in?(kwargs.keys)
26
+ Rails.logger.warn("GOVUKDesignSystemFormBuilder: html_options has been deprecated, use keyword arguments instead")
27
+ end
21
28
  end
22
29
 
23
30
  def html
@@ -29,28 +36,24 @@ module GOVUKDesignSystemFormBuilder
29
36
  private
30
37
 
31
38
  def select
32
- @builder.collection_select(@attribute_name, @collection, @value_method, @text_method, @options, **options)
39
+ @builder.collection_select(@attribute_name, @collection, @value_method, @text_method, @options, **attributes(@html_attributes))
33
40
  end
34
41
 
35
42
  def options
36
- @html_options.deep_merge(
43
+ {
37
44
  id: field_id(link_errors: true),
38
45
  class: classes,
39
46
  aria: { describedby: described_by(hint_id, error_id, supplemental_id) }
40
- )
47
+ }
41
48
  end
42
49
 
43
50
  def classes
44
- [%(#{brand}-select), error_class, custom_classes].flatten.compact
51
+ [%(#{brand}-select), error_class].flatten.compact
45
52
  end
46
53
 
47
54
  def error_class
48
55
  %(#{brand}-select--error) if has_errors?
49
56
  end
50
-
51
- def custom_classes
52
- @html_options[:class]
53
- end
54
57
  end
55
58
  end
56
59
  end
@@ -2,8 +2,9 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Submit < Base
4
4
  using PrefixableArray
5
+ include Traits::HTMLAttributes
5
6
 
6
- def initialize(builder, text, warning:, secondary:, classes:, prevent_double_click:, validate:, disabled:, &block)
7
+ def initialize(builder, text, warning:, secondary:, classes:, prevent_double_click:, validate:, disabled:, **kwargs, &block)
7
8
  super(builder, nil, nil)
8
9
 
9
10
  fail ArgumentError, 'buttons can be warning or secondary' if warning && secondary
@@ -15,6 +16,7 @@ module GOVUKDesignSystemFormBuilder
15
16
  @classes = classes
16
17
  @validate = validate
17
18
  @disabled = disabled
19
+ @html_attributes = kwargs
18
20
  @block_content = capture { block.call } if block_given?
19
21
  end
20
22
 
@@ -33,21 +35,14 @@ module GOVUKDesignSystemFormBuilder
33
35
  end
34
36
 
35
37
  def submit
36
- @builder.submit(@text, class: classes, **options)
37
- end
38
-
39
- def classes
40
- %w(button)
41
- .prefix(brand)
42
- .push(warning_class, secondary_class, disabled_class, custom_classes)
43
- .flatten
44
- .compact
38
+ @builder.submit(@text, **attributes(@html_attributes))
45
39
  end
46
40
 
47
41
  def options
48
42
  {
49
43
  formnovalidate: !@validate,
50
44
  disabled: @disabled,
45
+ class: classes,
51
46
  data: {
52
47
  module: %(#{brand}-button),
53
48
  'prevent-double-click': @prevent_double_click
@@ -55,6 +50,14 @@ module GOVUKDesignSystemFormBuilder
55
50
  }
56
51
  end
57
52
 
53
+ def classes
54
+ %w(button)
55
+ .prefix(brand)
56
+ .push(warning_class, secondary_class, disabled_class, custom_classes)
57
+ .flatten
58
+ .compact
59
+ end
60
+
58
61
  def warning_class
59
62
  %(#{brand}-button--warning) if @warning
60
63
  end
@@ -7,6 +7,7 @@ module GOVUKDesignSystemFormBuilder
7
7
  include Traits::Hint
8
8
  include Traits::Label
9
9
  include Traits::Supplemental
10
+ include Traits::HTMLAttributes
10
11
 
11
12
  def initialize(builder, object_name, attribute_name, hint:, label:, caption:, rows:, max_words:, max_chars:, threshold:, form_group:, **kwargs, &block)
12
13
  super(builder, object_name, attribute_name, &block)
@@ -37,7 +38,7 @@ module GOVUKDesignSystemFormBuilder
37
38
  end
38
39
 
39
40
  def text_area
40
- @builder.text_area(@attribute_name, **options, **@html_attributes)
41
+ @builder.text_area(@attribute_name, **attributes(@html_attributes))
41
42
  end
42
43
 
43
44
  def classes
@@ -0,0 +1,9 @@
1
+ module GOVUKDesignSystemFormBuilder
2
+ module Traits
3
+ module HTMLAttributes
4
+ def attributes(html_attributes = {})
5
+ options.deeper_merge(html_attributes)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -37,7 +37,7 @@ module GOVUKDesignSystemFormBuilder
37
37
  end
38
38
 
39
39
  def input
40
- @builder.send(builder_method, @attribute_name, **options, **@html_attributes)
40
+ @builder.send(builder_method, @attribute_name, **attributes(@html_attributes))
41
41
  end
42
42
 
43
43
  def affixed?
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '2.2.0'.freeze
2
+ VERSION = '2.3.0b1'.freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_design_system_formbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0b1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-09 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: deep_merge
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: actionview
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -262,6 +276,7 @@ executables: []
262
276
  extensions: []
263
277
  extra_rdoc_files: []
264
278
  files:
279
+ - LICENSE
265
280
  - README.md
266
281
  - lib/govuk_design_system_formbuilder.rb
267
282
  - lib/govuk_design_system_formbuilder/base.rb
@@ -306,6 +321,7 @@ files:
306
321
  - lib/govuk_design_system_formbuilder/traits/error.rb
307
322
  - lib/govuk_design_system_formbuilder/traits/fieldset_item.rb
308
323
  - lib/govuk_design_system_formbuilder/traits/hint.rb
324
+ - lib/govuk_design_system_formbuilder/traits/html_attributes.rb
309
325
  - lib/govuk_design_system_formbuilder/traits/input.rb
310
326
  - lib/govuk_design_system_formbuilder/traits/label.rb
311
327
  - lib/govuk_design_system_formbuilder/traits/localisation.rb
@@ -331,9 +347,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
331
347
  version: '0'
332
348
  required_rubygems_version: !ruby/object:Gem::Requirement
333
349
  requirements:
334
- - - ">="
350
+ - - ">"
335
351
  - !ruby/object:Gem::Version
336
- version: '0'
352
+ version: 1.3.1
337
353
  requirements: []
338
354
  rubygems_version: 3.1.4
339
355
  signing_key: