govuk_design_system_formbuilder 0.9.8 → 2.0.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -35
  3. data/lib/govuk_design_system_formbuilder/base.rb +21 -46
  4. data/lib/govuk_design_system_formbuilder/builder.rb +528 -111
  5. data/lib/govuk_design_system_formbuilder/containers/character_count.rb +8 -7
  6. data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +20 -8
  7. data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +39 -14
  8. data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +21 -25
  9. data/lib/govuk_design_system_formbuilder/containers/form_group.rb +20 -9
  10. data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +28 -14
  11. data/lib/govuk_design_system_formbuilder/containers/radios.rb +27 -10
  12. data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +8 -9
  13. data/lib/govuk_design_system_formbuilder/elements/caption.rb +41 -0
  14. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +34 -22
  15. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +28 -18
  16. data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +47 -40
  17. data/lib/govuk_design_system_formbuilder/elements/check_boxes/label.rb +9 -3
  18. data/lib/govuk_design_system_formbuilder/elements/date.rb +65 -53
  19. data/lib/govuk_design_system_formbuilder/elements/error_message.rb +13 -8
  20. data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +30 -31
  21. data/lib/govuk_design_system_formbuilder/elements/file.rb +31 -24
  22. data/lib/govuk_design_system_formbuilder/elements/hint.rb +50 -14
  23. data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +8 -0
  24. data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +6 -0
  25. data/lib/govuk_design_system_formbuilder/elements/inputs/password.rb +17 -0
  26. data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +6 -0
  27. data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +6 -0
  28. data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +6 -0
  29. data/lib/govuk_design_system_formbuilder/elements/label.rb +63 -34
  30. data/lib/govuk_design_system_formbuilder/elements/legend.rb +87 -0
  31. data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +51 -35
  32. data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +41 -19
  33. data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +37 -24
  34. data/lib/govuk_design_system_formbuilder/elements/select.rb +34 -32
  35. data/lib/govuk_design_system_formbuilder/elements/submit.rb +39 -29
  36. data/lib/govuk_design_system_formbuilder/elements/text_area.rb +76 -32
  37. data/lib/govuk_design_system_formbuilder/traits/caption.rb +15 -0
  38. data/lib/govuk_design_system_formbuilder/traits/collection_item.rb +16 -0
  39. data/lib/govuk_design_system_formbuilder/traits/conditional.rb +17 -0
  40. data/lib/govuk_design_system_formbuilder/traits/error.rb +17 -0
  41. data/lib/govuk_design_system_formbuilder/traits/hint.rb +30 -0
  42. data/lib/govuk_design_system_formbuilder/traits/input.rb +105 -0
  43. data/lib/govuk_design_system_formbuilder/traits/label.rb +22 -0
  44. data/lib/govuk_design_system_formbuilder/traits/localisation.rb +51 -0
  45. data/lib/govuk_design_system_formbuilder/traits/supplemental.rb +17 -0
  46. data/lib/govuk_design_system_formbuilder/version.rb +1 -1
  47. data/lib/govuk_design_system_formbuilder.rb +89 -44
  48. metadata +62 -52
  49. data/lib/govuk_design_system_formbuilder/elements/check_boxes/hint.rb +0 -30
  50. data/lib/govuk_design_system_formbuilder/elements/inputs/base.rb +0 -79
@@ -2,6 +2,12 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class Phone < Base
5
+ include Traits::Input
6
+ include Traits::Error
7
+ include Traits::Hint
8
+ include Traits::Label
9
+ include Traits::Supplemental
10
+
5
11
  def builder_method
6
12
  :phone_field
7
13
  end
@@ -2,6 +2,12 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class Text < Base
5
+ include Traits::Input
6
+ include Traits::Error
7
+ include Traits::Hint
8
+ include Traits::Label
9
+ include Traits::Supplemental
10
+
5
11
  def builder_method
6
12
  :text_field
7
13
  end
@@ -2,6 +2,12 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class URL < Base
5
+ include Traits::Input
6
+ include Traits::Error
7
+ include Traits::Hint
8
+ include Traits::Label
9
+ include Traits::Supplemental
10
+
5
11
  def builder_method
6
12
  :url_field
7
13
  end
@@ -1,66 +1,95 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
- class Label < GOVUKDesignSystemFormBuilder::Base
4
- def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true)
3
+ class Label < Base
4
+ using PrefixableArray
5
+
6
+ include Traits::Caption
7
+ include Traits::Localisation
8
+
9
+ def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true, content: nil, caption: nil, **kwargs)
5
10
  super(builder, object_name, attribute_name)
6
11
 
7
- @text = label_text(text, hidden)
8
- @value = value # used by field_id
9
- @size_class = label_size_class(size)
10
- @radio_class = radio_class(radio)
11
- @checkbox_class = checkbox_class(checkbox)
12
- @tag = tag
13
- @link_errors = link_errors
12
+ @value = value # used by field_id
13
+ @tag = tag
14
+ @radio = radio
15
+ @checkbox = checkbox
16
+ @link_errors = link_errors
17
+ @html_attributes = kwargs
18
+
19
+ # content is passed in directly via a proc and overrides
20
+ # the other display options
21
+ if content
22
+ @content = capture { content.call }
23
+ else
24
+ @text = retrieve_text(text, hidden)
25
+ @size_class = size_class(size)
26
+ @caption = caption
27
+ end
14
28
  end
15
29
 
16
30
  def html
17
- return nil if @text.blank?
31
+ return nil unless active?
18
32
 
19
33
  if @tag.present?
20
- content_tag(@tag, class: 'govuk-label-wrapper') { build_label }
34
+ content_tag(@tag, class: %(#{brand}-label-wrapper)) { label }
21
35
  else
22
- build_label
36
+ label
23
37
  end
24
38
  end
25
39
 
40
+ def active?
41
+ [@content, @text].any?(&:present?)
42
+ end
43
+
26
44
  private
27
45
 
28
- def build_label
29
- @builder.label(
30
- @attribute_name,
31
- value: @value,
32
- for: field_id(link_errors: @link_errors),
33
- class: %w(govuk-label).push(@size_class, @weight_class, @radio_class, @checkbox_class).compact
34
- ) do
35
- @text
46
+ def label
47
+ @builder.label(@attribute_name, **options, **@html_attributes) do
48
+ @content || safe_join([caption, @text])
36
49
  end
37
50
  end
38
51
 
39
- def label_text(option_text, hidden)
40
- text = [option_text, @value, @attribute_name.capitalize].compact.first
52
+ def retrieve_text(option_text, hidden)
53
+ text = [option_text, localised_text(:label), @attribute_name.capitalize].compact.first
41
54
 
42
55
  if hidden
43
- tag.span(text, class: %w(govuk-visually-hidden))
56
+ tag.span(text, class: %(#{brand}-visually-hidden))
44
57
  else
45
- raw(text)
58
+ text
46
59
  end
47
60
  end
48
61
 
49
- def radio_class(radio)
50
- radio ? 'govuk-radios__label' : nil
62
+ def options
63
+ {
64
+ value: @value,
65
+ for: field_id(link_errors: @link_errors),
66
+ class: %w(label).prefix(brand).push(@size_class, @weight_class, radio_class, checkbox_class).compact
67
+ }
68
+ end
69
+
70
+ def caption
71
+ caption_element.html unless [@radio, @checkbox].any?
51
72
  end
52
73
 
53
- def checkbox_class(checkbox)
54
- checkbox ? 'govuk-checkboxes__label' : nil
74
+ def radio_class
75
+ return nil unless @radio
76
+
77
+ %(#{brand}-radios__label)
78
+ end
79
+
80
+ def checkbox_class
81
+ return nil unless @checkbox
82
+
83
+ %(#{brand}-checkboxes__label)
55
84
  end
56
85
 
57
- def label_size_class(size)
86
+ def size_class(size)
58
87
  case size
59
- when 'xl' then "govuk-label--xl"
60
- when 'l' then "govuk-label--l"
61
- when 'm' then "govuk-label--m"
62
- when 's' then "govuk-label--s"
63
- when nil then nil
88
+ when 'xl' then %(#{brand}-label--xl)
89
+ when 'l' then %(#{brand}-label--l)
90
+ when 'm' then %(#{brand}-label--m)
91
+ when 's' then %(#{brand}-label--s)
92
+ when nil then nil
64
93
  else
65
94
  fail "invalid size '#{size}', must be xl, l, m, s or nil"
66
95
  end
@@ -0,0 +1,87 @@
1
+ module GOVUKDesignSystemFormBuilder
2
+ module Elements
3
+ class Legend < Base
4
+ include Traits::Caption
5
+ include Traits::Localisation
6
+
7
+ def initialize(builder, object_name, attribute_name, legend:, caption:, **kwargs)
8
+ super(builder, object_name, attribute_name)
9
+
10
+ @html_attributes = kwargs
11
+
12
+ case legend
13
+ when NilClass
14
+ @active = false
15
+ when Proc
16
+ @raw = capture { legend.call }
17
+ when Hash
18
+ defaults.merge(legend).tap do |l|
19
+ @text = retrieve_text(l.dig(:text))
20
+ @hidden = l.dig(:hidden)
21
+ @tag = l.dig(:tag)
22
+ @size = l.dig(:size)
23
+ @caption = caption
24
+ end
25
+ else
26
+ fail(ArgumentError, %(legend must be a Proc or Hash))
27
+ end
28
+ end
29
+
30
+ def html
31
+ @raw || content
32
+ end
33
+
34
+ private
35
+
36
+ def active?
37
+ [@text, @raw].any?(&:present?)
38
+ end
39
+
40
+ def content
41
+ return nil unless active?
42
+
43
+ tag.legend(class: classes, **@html_attributes) do
44
+ content_tag(@tag, class: heading_classes) do
45
+ safe_join([caption_element, @text])
46
+ end
47
+ end
48
+ end
49
+
50
+ def retrieve_text(supplied_text)
51
+ [supplied_text, localised_text(:legend), @attribute_name&.capitalize].compact.first
52
+ end
53
+
54
+ def classes
55
+ [%(#{brand}-fieldset__legend), size_class, visually_hidden_class].compact
56
+ end
57
+
58
+ def size_class
59
+ case @size
60
+ when 'xl' then %(#{brand}-fieldset__legend--xl)
61
+ when 'l' then %(#{brand}-fieldset__legend--l)
62
+ when 'm' then %(#{brand}-fieldset__legend--m)
63
+ when 's' then %(#{brand}-fieldset__legend--s)
64
+ else
65
+ fail "invalid size '#{@size}', must be xl, l, m or s"
66
+ end
67
+ end
68
+
69
+ def visually_hidden_class
70
+ %(#{brand}-visually-hidden) if @hidden
71
+ end
72
+
73
+ def heading_classes
74
+ %(#{brand}-fieldset__heading)
75
+ end
76
+
77
+ def defaults
78
+ {
79
+ hidden: false,
80
+ text: nil,
81
+ tag: config.default_legend_tag,
82
+ size: config.default_legend_size
83
+ }
84
+ end
85
+ end
86
+ end
87
+ end
@@ -1,55 +1,71 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Radios
4
- class Collection < GOVUKDesignSystemFormBuilder::Base
5
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint_text:, legend:, inline:, small:, bold_labels:, &block)
4
+ class Collection < Base
5
+ include Traits::Error
6
+ include Traits::Hint
7
+ include Traits::Supplemental
8
+
9
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint:, legend:, caption:, inline:, small:, bold_labels:, classes:, form_group:, &block)
6
10
  super(builder, object_name, attribute_name, &block)
7
11
 
8
- @collection = collection
9
- @value_method = value_method
10
- @text_method = text_method
11
- @hint_method = hint_method
12
- @inline = inline
13
- @small = small
14
- @legend = legend
15
- @hint_text = hint_text
16
- @bold_labels = hint_method.present? || bold_labels
12
+ @collection = collection
13
+ @value_method = value_method
14
+ @text_method = text_method
15
+ @hint_method = hint_method
16
+ @inline = inline
17
+ @small = small
18
+ @legend = legend
19
+ @caption = caption
20
+ @hint = hint
21
+ @classes = classes
22
+ @form_group = form_group
23
+ @bold_labels = hint_method.present? || bold_labels
17
24
  end
18
25
 
19
26
  def html
20
- Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
21
- Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
22
- safe_join(
23
- [
24
- hint_element.html,
25
- error_element.html,
26
- supplemental_content.html,
27
- Containers::Radios.new(@builder, inline: @inline, small: @small).html do
28
- safe_join(build_collection)
29
- end
30
- ]
31
- )
27
+ Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
28
+ Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
29
+ safe_join([supplemental_content, hint_element, error_element, radios])
32
30
  end
33
31
  end
34
32
  end
35
33
 
36
34
  private
37
35
 
38
- def build_collection
36
+ def fieldset_options
37
+ {
38
+ legend: @legend,
39
+ caption: @caption,
40
+ described_by: [error_id, hint_id, supplemental_id]
41
+ }
42
+ end
43
+
44
+ def radios
45
+ Containers::Radios.new(@builder, inline: @inline, small: @small, classes: @classes).html do
46
+ safe_join(collection)
47
+ end
48
+ end
49
+
50
+ def collection
39
51
  @collection.map.with_index do |item, i|
40
- Elements::Radios::CollectionRadioButton.new(
41
- @builder,
42
- @object_name,
43
- @attribute_name,
44
- item,
45
- value_method: @value_method,
46
- text_method: @text_method,
47
- hint_method: @hint_method,
48
- link_errors: has_errors? && i.zero?,
49
- bold_labels: @bold_labels
50
- ).html
52
+ Elements::Radios::CollectionRadioButton.new(@builder, @object_name, @attribute_name, item, **collection_options(i)).html
51
53
  end
52
54
  end
55
+
56
+ def collection_options(index)
57
+ {
58
+ value_method: @value_method,
59
+ text_method: @text_method,
60
+ hint_method: @hint_method,
61
+ link_errors: link_errors?(index),
62
+ bold_labels: @bold_labels
63
+ }
64
+ end
65
+
66
+ def link_errors?(index)
67
+ has_errors? && index.zero?
68
+ end
53
69
  end
54
70
  end
55
71
  end
@@ -2,46 +2,68 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Radios
4
4
  class CollectionRadioButton < Base
5
+ include Traits::Hint
6
+ include Traits::CollectionItem
7
+
5
8
  # @param link_errors [Boolean] used to control the id generated for radio buttons. The
6
9
  # error summary requires that the id of the first radio is linked-to from the corresponding
7
10
  # error message. As when the summary is built what happens later in the form is unknown, we
8
11
  # need to control this to ensure the link is generated correctly
9
12
  def initialize(builder, object_name, attribute_name, item, value_method:, text_method:, hint_method:, link_errors: false, bold_labels:)
10
13
  super(builder, object_name, attribute_name)
14
+
11
15
  @item = item
12
- @value = item.send(value_method)
13
- @text = item.send(text_method)
14
- @hint_text = item.send(hint_method) if hint_method.present?
16
+ @value = retrieve(item, value_method)
17
+ @label_text = retrieve(item, text_method)
18
+ @hint_text = retrieve(item, hint_method)
15
19
  @link_errors = link_errors
16
20
  @bold_labels = bold_labels
17
21
  end
18
22
 
19
23
  def html
20
- content_tag('div', class: 'govuk-radios__item') do
21
- safe_join(
22
- [
23
- @builder.radio_button(
24
- @attribute_name,
25
- @value,
26
- id: field_id(link_errors: @link_errors),
27
- aria: { describedby: hint_id },
28
- class: %w(govuk-radios__input)
29
- ),
30
- label_element.html,
31
- hint_element.html
32
- ]
33
- )
24
+ tag.div(class: %(#{brand}-radios__item)) do
25
+ safe_join([radio, label_element, hint_element])
34
26
  end
35
27
  end
36
28
 
37
29
  private
38
30
 
31
+ def radio
32
+ @builder.radio_button(@attribute_name, @value, **options)
33
+ end
34
+
35
+ def options
36
+ {
37
+ id: field_id(link_errors: @link_errors),
38
+ aria: { describedby: hint_id },
39
+ class: %(#{brand}-radios__input)
40
+ }
41
+ end
42
+
39
43
  def hint_element
40
- @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, @hint_text, @value, radio: true)
44
+ @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
45
+ end
46
+
47
+ def hint_content
48
+ { text: @hint_text }
49
+ end
50
+
51
+ def hint_options
52
+ { value: @value, radio: true }
41
53
  end
42
54
 
43
55
  def label_element
44
- @label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, text: @text, value: @value, radio: true, size: label_size, link_errors: @link_errors)
56
+ @label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_options)
57
+ end
58
+
59
+ def label_options
60
+ {
61
+ text: @label_text,
62
+ value: @value,
63
+ radio: true,
64
+ size: label_size,
65
+ link_errors: @link_errors
66
+ }
45
67
  end
46
68
 
47
69
  def label_size
@@ -2,12 +2,18 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Radios
4
4
  class FieldsetRadioButton < Base
5
- def initialize(builder, object_name, attribute_name, value, label:, hint_text:, link_errors:, &block)
5
+ using PrefixableArray
6
+
7
+ include Traits::Label
8
+ include Traits::Hint
9
+ include Traits::Conditional
10
+
11
+ def initialize(builder, object_name, attribute_name, value, label:, hint:, link_errors:, &block)
6
12
  super(builder, object_name, attribute_name)
7
13
 
8
14
  @value = value
9
15
  @label = label
10
- @hint_text = hint_text
16
+ @hint = hint
11
17
  @link_errors = has_errors? && link_errors
12
18
 
13
19
  if block_given?
@@ -17,45 +23,52 @@ module GOVUKDesignSystemFormBuilder
17
23
  end
18
24
 
19
25
  def html
20
- safe_join(
21
- [
22
- content_tag('div', class: 'govuk-radios__item') do
23
- safe_join(
24
- [
25
- input,
26
- label_element.html,
27
- hint_element.html,
28
- ]
29
- )
30
- end,
31
- @conditional_content
32
- ]
33
- )
26
+ safe_join([radio, @conditional_content])
34
27
  end
35
28
 
36
29
  private
37
30
 
31
+ def radio
32
+ tag.div(class: %(#{brand}-radios__item)) do
33
+ safe_join([input, label_element, hint_element])
34
+ end
35
+ end
36
+
37
+ def radio_options
38
+ { radio: true }
39
+ end
40
+
38
41
  def label_element
39
- @label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, radio: true, value: @value, **@label, link_errors: @link_errors)
42
+ @label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
43
+ end
44
+
45
+ def label_options
46
+ { value: @value, link_errors: @link_errors }.merge(radio_options)
40
47
  end
41
48
 
42
49
  def hint_element
43
- @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, @hint_text, radio: true)
50
+ @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
51
+ end
52
+
53
+ def hint_options
54
+ { value: @value }.merge(radio_options)
44
55
  end
45
56
 
46
57
  def input
47
- @builder.radio_button(
48
- @attribute_name,
49
- @value,
58
+ @builder.radio_button(@attribute_name, @value, **options)
59
+ end
60
+
61
+ def options
62
+ {
50
63
  id: field_id(link_errors: @link_errors),
51
64
  aria: { describedby: hint_id },
52
65
  data: { 'aria-controls' => @conditional_id },
53
- class: %w(govuk-radios__input)
54
- )
66
+ class: %w(radios__input).prefix(brand)
67
+ }
55
68
  end
56
69
 
57
70
  def conditional_classes
58
- %w(govuk-radios__conditional govuk-radios__conditional--hidden)
71
+ %w(radios__conditional radios__conditional--hidden).prefix(brand)
59
72
  end
60
73
  end
61
74
  end
@@ -1,53 +1,55 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
- class Select < GOVUKDesignSystemFormBuilder::Base
4
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, options: {}, html_options: {}, hint_text:, label:, &block)
3
+ class Select < Base
4
+ include Traits::Error
5
+ include Traits::Label
6
+ include Traits::Hint
7
+ include Traits::Supplemental
8
+
9
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, options: {}, html_options: {}, hint:, label:, caption:, form_group:, &block)
5
10
  super(builder, object_name, attribute_name, &block)
6
11
 
7
- @collection = collection
8
- @value_method = value_method
9
- @text_method = text_method
10
- @options = options
11
- @html_options = html_options
12
- @label = label
13
- @hint_text = hint_text
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
14
21
  end
15
22
 
16
23
  def html
17
- Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
18
- safe_join(
19
- [
20
- label_element.html,
21
- hint_element.html,
22
- error_element.html,
23
- supplemental_content.html,
24
- @builder.collection_select(
25
- @attribute_name,
26
- @collection,
27
- @value_method,
28
- @text_method,
29
- @options,
30
- build_html_options
31
- )
32
- ]
33
- )
24
+ Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
25
+ safe_join([label_element, supplemental_content, hint_element, error_element, select])
34
26
  end
35
27
  end
36
28
 
37
29
  private
38
30
 
39
- def build_html_options
31
+ def select
32
+ @builder.collection_select(@attribute_name, @collection, @value_method, @text_method, @options, **options)
33
+ end
34
+
35
+ def options
40
36
  @html_options.deep_merge(
41
37
  id: field_id(link_errors: true),
42
- class: select_classes,
38
+ class: classes,
43
39
  aria: { describedby: described_by(hint_id, error_id, supplemental_id) }
44
40
  )
45
41
  end
46
42
 
47
- def select_classes
48
- %w(govuk-select).tap do |classes|
49
- classes.push('govuk-select--error') if has_errors?
50
- end
43
+ def classes
44
+ [%(#{brand}-select), error_class, custom_classes].flatten.compact
45
+ end
46
+
47
+ def error_class
48
+ %(#{brand}-select--error) if has_errors?
49
+ end
50
+
51
+ def custom_classes
52
+ @html_options.dig(:class)
51
53
  end
52
54
  end
53
55
  end