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
@@ -1,15 +1,22 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module CheckBoxes
4
- class FieldsetCheckBox < GOVUKDesignSystemFormBuilder::Base
5
- def initialize(builder, object_name, attribute_name, value, label:, hint_text:, link_errors:, multiple:, &block)
4
+ class FieldsetCheckBox < Base
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, unchecked_value, label:, hint:, link_errors:, multiple:, &block)
6
12
  super(builder, object_name, attribute_name)
7
13
 
8
- @value = value
9
- @label = label
10
- @hint_text = hint_text
11
- @multiple = multiple
12
- @link_errors = link_errors
14
+ @value = value
15
+ @unchecked_value = unchecked_value
16
+ @label = label
17
+ @hint = hint
18
+ @multiple = multiple
19
+ @link_errors = link_errors
13
20
 
14
21
  if block_given?
15
22
  @conditional_content = wrap_conditional(block)
@@ -18,53 +25,53 @@ module GOVUKDesignSystemFormBuilder
18
25
  end
19
26
 
20
27
  def html
21
- safe_join(
22
- [
23
- content_tag('div', class: 'govuk-checkboxes__item') do
24
- safe_join(
25
- [
26
- input,
27
- label_element.html,
28
- hint_element.html,
29
- ]
30
- )
31
- end,
32
- @conditional_content
33
- ]
34
- )
28
+ safe_join([item, @conditional_content])
35
29
  end
36
30
 
37
31
  private
38
32
 
39
- def input
40
- @builder.check_box(
41
- @attribute_name,
42
- {
43
- id: field_id(link_errors: @link_errors),
44
- class: check_box_classes,
45
- multiple: @multiple,
46
- aria: { describedby: hint_id },
47
- data: { 'aria-controls' => @conditional_id }
48
- },
49
- @value,
50
- false
51
- )
33
+ def item
34
+ tag.div(class: %(#{brand}-checkboxes__item)) do
35
+ safe_join([check_box, label_element, hint_element])
36
+ end
37
+ end
38
+
39
+ def check_box
40
+ @builder.check_box(@attribute_name, options, @value, @unchecked_value)
41
+ end
42
+
43
+ def options
44
+ {
45
+ id: field_id(link_errors: @link_errors),
46
+ class: classes,
47
+ multiple: @multiple,
48
+ aria: { describedby: hint_id },
49
+ data: { 'aria-controls' => @conditional_id }
50
+ }
51
+ end
52
+
53
+ def classes
54
+ %w(checkboxes__input).prefix(brand)
52
55
  end
53
56
 
54
57
  def label_element
55
- @label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, checkbox: true, value: @value, **@label, link_errors: @link_errors)
58
+ @label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
59
+ end
60
+
61
+ def label_options
62
+ { checkbox: true, value: @value, link_errors: @link_errors }
56
63
  end
57
64
 
58
65
  def hint_element
59
- @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, @hint_text, @value, checkbox: true)
66
+ @hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
60
67
  end
61
68
 
62
- def conditional_classes
63
- %w(govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden)
69
+ def hint_options
70
+ { checkbox: true }
64
71
  end
65
72
 
66
- def check_box_classes
67
- %w(govuk-checkboxes__input)
73
+ def conditional_classes
74
+ %w(checkboxes__conditional checkboxes__conditional--hidden).prefix(brand)
68
75
  end
69
76
  end
70
77
  end
@@ -1,7 +1,11 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module CheckBoxes
4
- class Label < GOVUKDesignSystemFormBuilder::Base
4
+ class Label < Base
5
+ using PrefixableArray
6
+
7
+ include Traits::Localisation
8
+
5
9
  def initialize(builder, object_name, attribute_name, checkbox, value:, link_errors: true)
6
10
  super(builder, object_name, attribute_name)
7
11
 
@@ -11,13 +15,15 @@ module GOVUKDesignSystemFormBuilder
11
15
  end
12
16
 
13
17
  def html
14
- @checkbox.label(for: field_id(link_errors: @link_errors), class: label_classes)
18
+ @checkbox.label(for: field_id(link_errors: @link_errors), class: label_classes) do
19
+ [localised_text(:label), @checkbox.text, @value].compact.first
20
+ end
15
21
  end
16
22
 
17
23
  private
18
24
 
19
25
  def label_classes
20
- %w(govuk-label govuk-checkboxes__label)
26
+ %w(label checkboxes__label).prefix(brand)
21
27
  end
22
28
  end
23
29
  end
@@ -1,36 +1,45 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
- class Date < GOVUKDesignSystemFormBuilder::Base
3
+ class Date < Base
4
+ using PrefixableArray
5
+
6
+ include Traits::Error
7
+ include Traits::Hint
8
+ include Traits::Supplemental
9
+
4
10
  SEGMENTS = { day: '3i', month: '2i', year: '1i' }.freeze
5
11
 
6
- def initialize(builder, object_name, attribute_name, legend:, hint_text:, date_of_birth: false, omit_day:, &block)
12
+ def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, date_of_birth: false, omit_day:, form_group:, &block)
7
13
  super(builder, object_name, attribute_name, &block)
8
14
 
9
15
  @legend = legend
10
- @hint_text = hint_text
16
+ @caption = caption
17
+ @hint = hint
11
18
  @date_of_birth = date_of_birth
12
19
  @omit_day = omit_day
20
+ @form_group = form_group
13
21
  end
14
22
 
15
23
  def html
16
- Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
17
- Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
18
- safe_join(
19
- [
20
- hint_element.html,
21
- error_element.html,
22
- supplemental_content.html,
23
- content_tag('div', class: 'govuk-date-input') do
24
- safe_join([day, month, year])
25
- end
26
- ]
27
- )
24
+ Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
25
+ Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
26
+ safe_join([supplemental_content, hint_element, error_element, date])
28
27
  end
29
28
  end
30
29
  end
31
30
 
32
31
  private
33
32
 
33
+ def fieldset_options
34
+ { legend: @legend, caption: @caption, described_by: [error_id, hint_id, supplemental_id] }
35
+ end
36
+
37
+ def date
38
+ tag.div(class: %(#{brand}-date-input)) do
39
+ safe_join([day, month, year])
40
+ end
41
+ end
42
+
34
43
  def omit_day?
35
44
  @omit_day
36
45
  end
@@ -38,61 +47,59 @@ module GOVUKDesignSystemFormBuilder
38
47
  def day
39
48
  return nil if omit_day?
40
49
 
41
- date_input_item(:day, link_errors: true)
50
+ date_part(:day, width: 2, link_errors: true)
42
51
  end
43
52
 
44
53
  def month
45
- date_input_item(:month, link_errors: omit_day?)
54
+ date_part(:month, width: 2, link_errors: omit_day?)
46
55
  end
47
56
 
48
57
  def year
49
- date_input_item(:year, width: 4)
58
+ date_part(:year, width: 4)
50
59
  end
51
60
 
52
- def date_input_item(segment, width: 2, link_errors: false)
61
+ def date_part(segment, width:, link_errors: false)
53
62
  value = @builder.object.try(@attribute_name).try(segment)
54
63
 
55
- content_tag('div', class: %w(govuk-date-input__item)) do
56
- content_tag('div', class: %w(govuk-form-group)) do
57
- safe_join(
58
- [
59
- tag.label(
60
- segment.capitalize,
61
- class: date_input_label_classes,
62
- for: date_attribute_id(segment, link_errors)
63
- ),
64
-
65
- tag.input(
66
- id: date_attribute_id(segment, link_errors),
67
- class: date_input_classes(width),
68
- name: date_attribute_name(segment),
69
- type: 'text',
70
- pattern: '[0-9]*',
71
- inputmode: 'numeric',
72
- value: value,
73
- autocomplete: date_of_birth_autocomplete_value(segment)
74
- )
75
- ]
76
- )
64
+ tag.div(class: %(#{brand}-date-input__item)) do
65
+ tag.div(class: %(#{brand}-form-group)) do
66
+ safe_join([label(segment, link_errors), input(segment, link_errors, width, value)])
77
67
  end
78
68
  end
79
69
  end
80
70
 
81
- def date_input_classes(width)
82
- %w(govuk-input govuk-date-input__input).tap do |classes|
83
- classes.push("govuk-input--width-#{width}")
84
- classes.push("govuk-input--error") if has_errors?
85
- end
71
+ def label(segment, link_errors)
72
+ tag.label(
73
+ segment.capitalize,
74
+ class: label_classes,
75
+ for: id(segment, link_errors)
76
+ )
77
+ end
78
+
79
+ def input(segment, link_errors, width, value)
80
+ tag.input(
81
+ id: id(segment, link_errors),
82
+ class: classes(width),
83
+ name: name(segment),
84
+ type: 'text',
85
+ pattern: '[0-9]*',
86
+ inputmode: 'numeric',
87
+ value: value,
88
+ autocomplete: date_of_birth_autocomplete_value(segment)
89
+ )
86
90
  end
87
91
 
88
- def date_input_label_classes
89
- %w(govuk-label govuk-date-input__label)
92
+ def classes(width)
93
+ %w(input date-input__input).prefix(brand).tap do |classes|
94
+ classes.push(%(#{brand}-input--width-#{width}))
95
+ classes.push(%(#{brand}-input--error)) if has_errors?
96
+ end
90
97
  end
91
98
 
92
99
  # if the field has errors we want the govuk_error_summary to
93
100
  # be able to link to the day field. Otherwise, generate IDs
94
101
  # in the normal fashion
95
- def date_attribute_id(segment, link_errors)
102
+ def id(segment, link_errors)
96
103
  if has_errors? && link_errors
97
104
  field_id(link_errors: link_errors)
98
105
  else
@@ -100,12 +107,13 @@ module GOVUKDesignSystemFormBuilder
100
107
  end
101
108
  end
102
109
 
103
- def date_attribute_name(segment)
104
- "%<object_name>s[%<attribute_name>s(%<segment>s)]" % {
110
+ def name(segment)
111
+ format(
112
+ "%<object_name>s[%<input_name>s(%<segment>s)]",
105
113
  object_name: @object_name,
106
- attribute_name: @attribute_name,
114
+ input_name: @attribute_name,
107
115
  segment: SEGMENTS.fetch(segment)
108
- }
116
+ )
109
117
  end
110
118
 
111
119
  def date_of_birth_autocomplete_value(segment)
@@ -113,6 +121,10 @@ module GOVUKDesignSystemFormBuilder
113
121
 
114
122
  { day: 'bday-day', month: 'bday-month', year: 'bday-year' }.fetch(segment)
115
123
  end
124
+
125
+ def label_classes
126
+ %w(label date-input__label).prefix(brand)
127
+ end
116
128
  end
117
129
  end
118
130
  end
@@ -1,6 +1,10 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
- class ErrorMessage < GOVUKDesignSystemFormBuilder::Base
3
+ class ErrorMessage < Base
4
+ using PrefixableArray
5
+
6
+ include Traits::Error
7
+
4
8
  def initialize(builder, object_name, attribute_name)
5
9
  super(builder, object_name, attribute_name)
6
10
  end
@@ -8,16 +12,17 @@ module GOVUKDesignSystemFormBuilder
8
12
  def html
9
13
  return nil unless has_errors?
10
14
 
11
- content_tag('span', class: 'govuk-error-message', id: error_id) do
12
- safe_join(
13
- [
14
- tag.span('Error: ', class: 'govuk-visually-hidden'),
15
- message
16
- ]
17
- )
15
+ tag.span(class: %(#{brand}-error-message), id: error_id) do
16
+ safe_join([hidden_prefix, message])
18
17
  end
19
18
  end
20
19
 
20
+ private
21
+
22
+ def hidden_prefix
23
+ tag.span('Error: ', class: %(#{brand}-visually-hidden))
24
+ end
25
+
21
26
  def message
22
27
  @builder.object.errors.messages[@attribute_name]&.first
23
28
  end
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
- class ErrorSummary < GOVUKDesignSystemFormBuilder::Base
3
+ class ErrorSummary < Base
4
+ include Traits::Error
5
+
4
6
  def initialize(builder, object_name, title)
5
7
  @builder = builder
6
8
  @object_name = object_name
@@ -10,47 +12,44 @@ module GOVUKDesignSystemFormBuilder
10
12
  def html
11
13
  return nil unless object_has_errors?
12
14
 
13
- content_tag('div', class: summary_class, **error_summary_attributes) do
14
- safe_join(
15
- [
16
- tag.h2(@title, id: error_summary_title_id, class: summary_class('title')),
17
- content_tag('div', class: summary_class('body')) do
18
- content_tag('ul', class: ['govuk-list', summary_class('list')]) do
19
- safe_join(
20
- @builder.object.errors.messages.map do |attribute, messages|
21
- error_list_item(attribute, messages.first)
22
- end
23
- )
24
- end
25
- end
26
- ]
27
- )
15
+ tag.div(class: summary_class, **summary_options) do
16
+ safe_join([title, summary])
28
17
  end
29
18
  end
30
19
 
31
20
  private
32
21
 
33
- def error_list_item(attribute, message)
34
- content_tag('li') do
35
- link_to(
36
- message,
37
- same_page_link(field_id(attribute)),
38
- data: {
39
- turbolinks: false
40
- }
41
- )
22
+ def title
23
+ tag.h2(@title, id: summary_title_id, class: summary_class('title'))
24
+ end
25
+
26
+ def summary
27
+ tag.div(class: summary_class('body')) do
28
+ tag.ul(class: [%(#{brand}-list), summary_class('list')]) do
29
+ safe_join(list)
30
+ end
31
+ end
32
+ end
33
+
34
+ def list
35
+ @builder.object.errors.messages.map do |attribute, messages|
36
+ list_item(attribute, messages.first)
42
37
  end
43
38
  end
44
39
 
40
+ def list_item(attribute, message)
41
+ tag.li(link_to(message, same_page_link(field_id(attribute)), data: { turbolinks: false }))
42
+ end
43
+
45
44
  def same_page_link(target)
46
45
  '#'.concat(target)
47
46
  end
48
47
 
49
48
  def summary_class(part = nil)
50
49
  if part
51
- 'govuk-error-summary'.concat('__', part)
50
+ %(#{brand}-error-summary).concat('__', part)
52
51
  else
53
- 'govuk-error-summary'
52
+ %(#{brand}-error-summary)
54
53
  end
55
54
  end
56
55
 
@@ -58,7 +57,7 @@ module GOVUKDesignSystemFormBuilder
58
57
  build_id('field-error', attribute_name: attribute)
59
58
  end
60
59
 
61
- def error_summary_title_id
60
+ def summary_title_id
62
61
  'error-summary-title'
63
62
  end
64
63
 
@@ -66,15 +65,15 @@ module GOVUKDesignSystemFormBuilder
66
65
  @builder.object.errors.any?
67
66
  end
68
67
 
69
- def error_summary_attributes
68
+ def summary_options
70
69
  {
71
70
  tabindex: -1,
72
71
  role: 'alert',
73
72
  data: {
74
- module: 'govuk-error-summary'
73
+ module: %(#{brand}-error-summary)
75
74
  },
76
75
  aria: {
77
- labelledby: error_summary_title_id
76
+ labelledby: summary_title_id
78
77
  }
79
78
  }
80
79
  end
@@ -1,39 +1,46 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
- class File < GOVUKDesignSystemFormBuilder::Base
4
- def initialize(builder, object_name, attribute_name, hint_text:, label:, **extra_args, &block)
3
+ class File < Base
4
+ using PrefixableArray
5
+
6
+ include Traits::Error
7
+ include Traits::Hint
8
+ include Traits::Label
9
+ include Traits::Supplemental
10
+
11
+ def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
5
12
  super(builder, object_name, attribute_name, &block)
6
13
 
7
- @label = label
8
- @hint_text = hint_text
9
- @extra_args = extra_args
14
+ @label = label
15
+ @caption = caption
16
+ @hint = hint
17
+ @html_attributes = kwargs
18
+ @form_group = form_group
10
19
  end
11
20
 
12
21
  def html
13
- Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
14
- safe_join(
15
- [
16
- label_element.html,
17
- hint_element.html,
18
- error_element.html,
19
- supplemental_content.html,
20
- @builder.file_field(
21
- @attribute_name,
22
- id: field_id(link_errors: true),
23
- class: file_classes,
24
- aria: { describedby: described_by(hint_id, error_id, supplemental_id) },
25
- **@extra_args
26
- )
27
- ]
28
- )
22
+ Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
23
+ safe_join([label_element, supplemental_content, hint_element, error_element, file])
29
24
  end
30
25
  end
31
26
 
32
27
  private
33
28
 
34
- def file_classes
35
- %w(govuk-file-upload).tap do |c|
36
- c.push('govuk-file-upload--error') if has_errors?
29
+ def file
30
+ @builder.file_field(@attribute_name, **options, **@html_attributes)
31
+ end
32
+
33
+ def options
34
+ {
35
+ id: field_id(link_errors: true),
36
+ class: classes,
37
+ aria: { describedby: described_by(hint_id, error_id, supplemental_id) }
38
+ }
39
+ end
40
+
41
+ def classes
42
+ %w(file-upload).prefix(brand).tap do |c|
43
+ c.push(%(#{brand}-file-upload--error)) if has_errors?
37
44
  end
38
45
  end
39
46
  end
@@ -1,33 +1,69 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
- class Hint < GOVUKDesignSystemFormBuilder::Base
4
- def initialize(builder, object_name, attribute_name, text, value = nil, radio: false, checkbox: false)
3
+ class Hint < Base
4
+ using PrefixableArray
5
+
6
+ include Traits::Localisation
7
+
8
+ def initialize(builder, object_name, attribute_name, value: nil, text: nil, content: nil, radio: false, checkbox: false, **kwargs)
5
9
  super(builder, object_name, attribute_name)
6
10
 
7
- @value = value
8
- @hint_text = text
9
- @radio_class = radio_class(radio)
10
- @checkbox_class = checkbox_class(checkbox)
11
+ @value = value
12
+ @radio = radio
13
+ @checkbox = checkbox
14
+ @html_attributes = kwargs
15
+
16
+ if content
17
+ @raw = capture { content.call }
18
+ else
19
+ @text = retrieve_text(text)
20
+ end
21
+ end
22
+
23
+ def active?
24
+ [@text, @raw].any?(&:present?)
11
25
  end
12
26
 
13
27
  def html
14
- return nil if @hint_text.blank?
28
+ return nil unless active?
29
+
30
+ content_tag(hint_tag, **hint_options, **@html_attributes) { hint_body }
31
+ end
32
+
33
+ def hint_id
34
+ return nil unless active?
15
35
 
16
- tag.span(@hint_text, class: hint_classes, id: hint_id)
36
+ build_id('hint')
17
37
  end
18
38
 
19
39
  private
20
40
 
21
- def hint_classes
22
- %w(govuk-hint).push(@radio_class, @checkbox_class).compact
41
+ def hint_options
42
+ { class: classes, id: hint_id }
43
+ end
44
+
45
+ def hint_tag
46
+ @raw.presence ? 'div' : 'span'
47
+ end
48
+
49
+ def hint_body
50
+ @raw || @text
51
+ end
52
+
53
+ def retrieve_text(supplied)
54
+ supplied.presence || localised_text(:hint)
55
+ end
56
+
57
+ def classes
58
+ %w(hint).prefix(brand).push(radio_class, checkbox_class).compact
23
59
  end
24
60
 
25
- def radio_class(radio)
26
- radio ? 'govuk-radios__hint' : nil
61
+ def radio_class
62
+ @radio ? %(#{brand}-radios__hint) : nil
27
63
  end
28
64
 
29
- def checkbox_class(checkbox)
30
- checkbox ? 'govuk-checkboxes__hint' : nil
65
+ def checkbox_class
66
+ @checkbox ? %(#{brand}-checkboxes__hint) : nil
31
67
  end
32
68
  end
33
69
  end
@@ -2,6 +2,14 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class Email < Base
5
+ include Traits::Input
6
+ include Traits::Error
7
+ include Traits::Hint
8
+ include Traits::Label
9
+ include Traits::Supplemental
10
+
11
+ private
12
+
5
13
  def builder_method
6
14
  :email_field
7
15
  end
@@ -2,6 +2,12 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class Number < 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
  :number_field
7
13
  end
@@ -0,0 +1,17 @@
1
+ module GOVUKDesignSystemFormBuilder
2
+ module Elements
3
+ module Inputs
4
+ class Password < Base
5
+ include Traits::Input
6
+ include Traits::Error
7
+ include Traits::Hint
8
+ include Traits::Label
9
+ include Traits::Supplemental
10
+
11
+ def builder_method
12
+ :password_field
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end