govuk_design_system_formbuilder 1.1.10 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/govuk_design_system_formbuilder.rb +7 -1
  4. data/lib/govuk_design_system_formbuilder/base.rb +12 -0
  5. data/lib/govuk_design_system_formbuilder/builder.rb +311 -74
  6. data/lib/govuk_design_system_formbuilder/containers/character_count.rb +2 -2
  7. data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +5 -3
  8. data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +3 -2
  9. data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +37 -16
  10. data/lib/govuk_design_system_formbuilder/containers/form_group.rb +4 -2
  11. data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +3 -2
  12. data/lib/govuk_design_system_formbuilder/containers/radios.rb +7 -5
  13. data/lib/govuk_design_system_formbuilder/elements/caption.rb +34 -0
  14. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +3 -2
  15. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +5 -3
  16. data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +7 -4
  17. data/lib/govuk_design_system_formbuilder/elements/check_boxes/label.rb +8 -2
  18. data/lib/govuk_design_system_formbuilder/elements/date.rb +15 -11
  19. data/lib/govuk_design_system_formbuilder/elements/error_message.rb +4 -2
  20. data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +4 -4
  21. data/lib/govuk_design_system_formbuilder/elements/file.rb +6 -3
  22. data/lib/govuk_design_system_formbuilder/elements/hint.rb +5 -3
  23. data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +2 -0
  24. data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +2 -0
  25. data/lib/govuk_design_system_formbuilder/elements/inputs/password.rb +2 -0
  26. data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +2 -0
  27. data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +2 -0
  28. data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +2 -0
  29. data/lib/govuk_design_system_formbuilder/elements/label.rb +30 -20
  30. data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +3 -2
  31. data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +4 -2
  32. data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +7 -4
  33. data/lib/govuk_design_system_formbuilder/elements/select.rb +6 -3
  34. data/lib/govuk_design_system_formbuilder/elements/submit.rb +10 -7
  35. data/lib/govuk_design_system_formbuilder/elements/text_area.rb +12 -5
  36. data/lib/govuk_design_system_formbuilder/traits/caption.rb +24 -0
  37. data/lib/govuk_design_system_formbuilder/traits/input.rb +16 -16
  38. data/lib/govuk_design_system_formbuilder/traits/label.rb +12 -1
  39. data/lib/govuk_design_system_formbuilder/traits/localisation.rb +18 -10
  40. data/lib/govuk_design_system_formbuilder/version.rb +1 -1
  41. metadata +16 -43
  42. data/lib/govuk_design_system_formbuilder/elements/check_boxes/hint.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d20300d83e65da38b6ae0b3a20a6e4e1bbdd9d04a9911ecf29829417abe5ba6f
4
- data.tar.gz: a62f856b0804bc22eacfabcf7c31166651cee64d2dee82d8454b92a693a4b553
3
+ metadata.gz: db9e3152ce56de44fbcb67ed0110cf9613ed0180597baf36cbc93316c41c72c5
4
+ data.tar.gz: 5df5f7b19116b6846cbe305e14006993b86194db2677017c29344f7132ad6f54
5
5
  SHA512:
6
- metadata.gz: 586414dba6e14f1f4d8f16638b6634c1aedbadf600e4fbaf2ea67fd7bcae93cca3046a247187d08df5a609ceec318526f0effa4183fe8f903288f76926535e0a
7
- data.tar.gz: 323c190132caefde2e449f6b8f9088fdd13a58a520c166a17c43b35d53bc13c613c770b4fea82efc470ad5c90fdcf0e976226bc61811430ff1e301f5d8e1a66c
6
+ metadata.gz: bfc94cbbf30b95c91c136dd00db6d666d631d94edcecb0e673eb9e03d0771b739b00a58708c967cf720a4dc1bc10af929faea8aee8b6f44ab2916434a0c0bc7f
7
+ data.tar.gz: 721f67fb7fa2eb2883fd6d47c89b4aa86b4dcdae371501fb151d9d050132be1a59a739197216c1726566fb1f28bbba9a64fbc41dd8eec4b946abaddddb06bc3f
data/README.md CHANGED
@@ -7,10 +7,10 @@
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.6.0-brightgreen)](https://design-system.service.gov.uk)
10
+ [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.7.0-brightgreen)](https://design-system.service.gov.uk)
11
11
 
12
12
  This gem provides a easy-to-use form builder that generates forms that are
13
- fully-compliant with version 3.6.0 of the [GOV.UK Design System](https://design-system.service.gov.uk/),
13
+ fully-compliant with version 3.7.0 of the [GOV.UK Design System](https://design-system.service.gov.uk/),
14
14
  minimising the amount of markup you need to write.
15
15
 
16
16
  In addition to the basic markup, the more-advanced functionality of the Design
@@ -11,6 +11,9 @@ module GOVUKDesignSystemFormBuilder
11
11
 
12
12
  # Default form builder configuration
13
13
  #
14
+ # * +:brand+ sets the value used to prefix all classes, used to allow the
15
+ # builder to be branded for alternative (similar) design systems.
16
+ #
14
17
  # * +:default_legend_size+ controls the default size of legend text.
15
18
  # Can be either +xl+, +l+, +m+ or +s+.
16
19
  #
@@ -38,6 +41,8 @@ module GOVUKDesignSystemFormBuilder
38
41
  # particular context, allowing them to be independently customised.
39
42
  # ===
40
43
  DEFAULTS = {
44
+ brand: 'govuk',
45
+
41
46
  default_legend_size: 'm',
42
47
  default_legend_tag: 'h1',
43
48
  default_submit_button_text: 'Continue',
@@ -47,7 +52,8 @@ module GOVUKDesignSystemFormBuilder
47
52
  localisation_schema_fallback: %i(helpers __context__),
48
53
  localisation_schema_label: nil,
49
54
  localisation_schema_hint: nil,
50
- localisation_schema_legend: nil
55
+ localisation_schema_legend: nil,
56
+ localisation_schema_caption: nil
51
57
  }.freeze
52
58
 
53
59
  DEFAULTS.each_key { |k| config_accessor(k) { DEFAULTS[k] } }
@@ -1,4 +1,12 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
+ module PrefixableArray
3
+ refine Array do
4
+ def prefix(text, delimiter: '-')
5
+ map { |item| text + delimiter + item }
6
+ end
7
+ end
8
+ end
9
+
2
10
  class Base
3
11
  delegate :capture, :content_tag, :safe_join, :tag, :raw, :link_to, to: :@builder
4
12
  delegate :config, to: GOVUKDesignSystemFormBuilder
@@ -12,6 +20,10 @@ module GOVUKDesignSystemFormBuilder
12
20
 
13
21
  private
14
22
 
23
+ def brand(override = nil)
24
+ override || config.brand
25
+ end
26
+
15
27
  # returns the id value used for the input
16
28
  #
17
29
  # @note field_id is overridden so that the error summary can link to the
@@ -8,15 +8,19 @@ module GOVUKDesignSystemFormBuilder
8
8
  # @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
9
9
  # @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
10
10
  # or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
11
- # @param [Hash] label configures the associated label
11
+ # @param label [Hash,Proc] configures or sets the associated label content
12
12
  # @option label text [String] the label text
13
13
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
14
14
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
15
15
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
16
- # @option args [Hash] args additional arguments are applied as attributes to +input+ element
16
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
17
+ # @option caption text [String] the caption text
18
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
19
+ # @option args [Hash] args additional arguments are applied as attributes to the +input+ element
17
20
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
18
21
  # @return [ActiveSupport::SafeBuffer] HTML output
19
22
  # @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
23
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
20
24
  #
21
25
  # @example A required full name field with a placeholder
22
26
  # = f.govuk_text_field :name,
@@ -24,8 +28,20 @@ module GOVUKDesignSystemFormBuilder
24
28
  # hint_text: 'It says it on your birth certificate',
25
29
  # required: true,
26
30
  # placeholder: 'Ralph Wiggum'
27
- def govuk_text_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
28
- Elements::Inputs::Text.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
31
+ #
32
+ # @example A text field with injected content
33
+ # = f.govuk_text_field :pseudonym,
34
+ # label: { text: 'Pseudonym' } do
35
+ #
36
+ # p.govuk-inset-text
37
+ # | Ensure your stage name is unique
38
+ #
39
+ # @example A text field with the label supplied as a proc
40
+ # = f.govuk_text_field :callsign,
41
+ # label: -> { tag.h3('Call-sign') }
42
+ #
43
+ def govuk_text_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
44
+ Elements::Inputs::Text.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
29
45
  end
30
46
 
31
47
  # Generates a input of type +tel+
@@ -34,16 +50,20 @@ module GOVUKDesignSystemFormBuilder
34
50
  # @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
35
51
  # @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
36
52
  # or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
37
- # @param [Hash] label configures the associated label
53
+ # @param label [Hash,Proc] configures or sets the associated label content
38
54
  # @option label text [String] the label text
39
55
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
40
56
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
41
57
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
42
- # @option args [Hash] args additional arguments are applied as attributes to +input+ element
58
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
59
+ # @option caption text [String] the caption text
60
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
61
+ # @option args [Hash] args additional arguments are applied as attributes to the +input+ element
43
62
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
44
63
  # @return [ActiveSupport::SafeBuffer] HTML output
45
64
  # @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
46
65
  # @see https://design-system.service.gov.uk/patterns/telephone-numbers/ GOV.UK Telephone number patterns
66
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
47
67
  #
48
68
  # @example A required phone number field with a placeholder
49
69
  # = f.govuk_phone_field :phone_number,
@@ -51,8 +71,20 @@ module GOVUKDesignSystemFormBuilder
51
71
  # hint_text: 'Include the dialling code',
52
72
  # required: true,
53
73
  # placeholder: '0123 456 789'
54
- def govuk_phone_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
55
- Elements::Inputs::Phone.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
74
+ #
75
+ # @example A phone field with injected content
76
+ # = f.govuk_phone_field :fax_number,
77
+ # label: { text: 'Fax number' } do
78
+ #
79
+ # p.govuk-inset-text
80
+ # | Yes, fax machines are still a thing
81
+ #
82
+ # @example A phone field with the label supplied as a proc
83
+ # = f.govuk_phone_field :work_number,
84
+ # label: -> { tag.h3('Work number') }
85
+ #
86
+ def govuk_phone_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
87
+ Elements::Inputs::Phone.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
56
88
  end
57
89
 
58
90
  # Generates a input of type +email+
@@ -61,23 +93,39 @@ module GOVUKDesignSystemFormBuilder
61
93
  # @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
62
94
  # @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
63
95
  # or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
64
- # @param [Hash] label configures the associated label
96
+ # @param label [Hash,Proc] configures or sets the associated label content
65
97
  # @option label text [String] the label text
66
98
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
67
99
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
68
100
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
69
- # @option args [Hash] args additional arguments are applied as attributes to +input+ element
101
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
102
+ # @option caption text [String] the caption text
103
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
104
+ # @option args [Hash] args additional arguments are applied as attributes to the +input+ element
70
105
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
71
106
  # @return [ActiveSupport::SafeBuffer] HTML output
72
107
  # @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
73
108
  # @see https://design-system.service.gov.uk/patterns/email-addresses/ GOV.UK Email address patterns
109
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
74
110
  #
75
111
  # @example An email address field with a placeholder
76
112
  # = f.govuk_email_field :email_address,
77
113
  # label: { text: 'Enter your email address' },
78
114
  # placeholder: 'ralph.wiggum@springfield.edu'
79
- def govuk_email_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
80
- Elements::Inputs::Email.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
115
+ #
116
+ # @example An email field with injected content
117
+ # = f.govuk_phone_field :work_email,
118
+ # label: { text: 'Work email address' } do
119
+ #
120
+ # p.govuk-inset-text
121
+ # | Use your work address
122
+ #
123
+ # @example A email field with the label supplied as a proc
124
+ # = f.govuk_email_field :personal_email,
125
+ # label: -> { tag.h3('Personal email address') }
126
+ #
127
+ def govuk_email_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
128
+ Elements::Inputs::Email.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
81
129
  end
82
130
 
83
131
  # Generates a input of type +password+
@@ -86,22 +134,38 @@ module GOVUKDesignSystemFormBuilder
86
134
  # @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
87
135
  # @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
88
136
  # or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
89
- # @param [Hash] label configures the associated label
137
+ # @param label [Hash,Proc] configures or sets the associated label content
90
138
  # @option label text [String] the label text
91
139
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
92
140
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
93
141
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
94
- # @option args [Hash] args additional arguments are applied as attributes to +input+ element
142
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
143
+ # @option caption text [String] the caption text
144
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
145
+ # @option args [Hash] args additional arguments are applied as attributes to the +input+ element
95
146
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
96
147
  # @return [ActiveSupport::SafeBuffer] HTML output
97
148
  # @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
98
149
  # @see https://design-system.service.gov.uk/patterns/passwords/ GOV.UK Password patterns
150
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
99
151
  #
100
152
  # @example A password field
101
153
  # = f.govuk_password_field :password,
102
154
  # label: { text: 'Enter your password' }
103
- def govuk_password_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
104
- Elements::Inputs::Password.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
155
+ #
156
+ # @example A password field with injected content
157
+ # = f.govuk_password_field :password,
158
+ # label: { text: 'Password' } do
159
+ #
160
+ # p.govuk-inset-text
161
+ # | Ensure your password is at least 16 characters long
162
+ #
163
+ # @example A password field with the label supplied as a proc
164
+ # = f.govuk_password_field :passcode,
165
+ # label: -> { tag.h3('What is your secret pass code?') }
166
+ #
167
+ def govuk_password_field(attribute_name, hint_text: nil, label: {}, width: nil, caption: {}, **args, &block)
168
+ Elements::Inputs::Password.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
105
169
  end
106
170
 
107
171
  # Generates a input of type +url+
@@ -110,23 +174,39 @@ module GOVUKDesignSystemFormBuilder
110
174
  # @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
111
175
  # @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
112
176
  # or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
113
- # @param [Hash] label configures the associated label
177
+ # @param label [Hash,Proc] configures or sets the associated label content
114
178
  # @option label text [String] the label text
115
179
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
116
180
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
117
181
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
118
- # @option args [Hash] args additional arguments are applied as attributes to +input+ element
182
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
183
+ # @option caption text [String] the caption text
184
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
185
+ # @option args [Hash] args additional arguments are applied as attributes to the +input+ element
119
186
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
120
187
  # @return [ActiveSupport::SafeBuffer] HTML output
121
188
  # @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
189
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
122
190
  #
123
191
  # @example A url field with autocomplete
124
192
  # = f.govuk_url_field :favourite_website,
125
193
  # label: { text: 'Enter your favourite website' },
126
194
  # placeholder: 'https://www.gov.uk',
127
195
  # autocomplete: 'url'
128
- def govuk_url_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
129
- Elements::Inputs::URL.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
196
+ #
197
+ # @example A url field with injected content
198
+ # = f.govuk_url_field :personal_website,
199
+ # label: { text: 'Enter your website' } do
200
+ #
201
+ # p.govuk-inset-text
202
+ # | This will be visible on your profile
203
+ #
204
+ # @example A url field with the label supplied as a proc
205
+ # = f.govuk_url_field :work_website,
206
+ # label: -> { tag.h3("Enter your company's website") }
207
+ #
208
+ def govuk_url_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
209
+ Elements::Inputs::URL.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
130
210
  end
131
211
 
132
212
  # Generates a input of type +number+
@@ -135,15 +215,19 @@ module GOVUKDesignSystemFormBuilder
135
215
  # @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
136
216
  # @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
137
217
  # or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
138
- # @param [Hash] label configures the associated label
218
+ # @param label [Hash,Proc] configures or sets the associated label content
139
219
  # @option label text [String] the label text
140
220
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
141
221
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
142
222
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
223
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
224
+ # @option caption text [String] the caption text
225
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
143
226
  # @option args [Hash] args additional arguments are applied as attributes to the +input+ element
144
227
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
145
228
  # @return [ActiveSupport::SafeBuffer] HTML output
146
229
  # @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
230
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
147
231
  #
148
232
  # @example A number field with placeholder, min, max and step
149
233
  # = f.govuk_number_field :iq,
@@ -152,8 +236,21 @@ module GOVUKDesignSystemFormBuilder
152
236
  # min: 80,
153
237
  # max: 150,
154
238
  # step: 5
155
- def govuk_number_field(attribute_name, hint_text: nil, label: {}, width: nil, **args, &block)
156
- Elements::Inputs::Number.new(self, object_name, attribute_name, hint_text: hint_text, label: label, width: width, **args, &block).html
239
+ #
240
+ # @example A number field with injected content
241
+ # = f.govuk_number_field :height_in_cm,
242
+ # label: { text: 'Height in centimetres' } do
243
+ #
244
+ # p.govuk-inset-text
245
+ # | If you haven't measured your height in the last 6 months
246
+ # do it now
247
+ #
248
+ # @example A number field with the label supplied as a proc
249
+ # = f.govuk_url_field :personal_best_over_100m,
250
+ # label: -> { tag.h3("How many seconds does it take you to run 100m?") }
251
+ #
252
+ def govuk_number_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
253
+ Elements::Inputs::Number.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
157
254
  end
158
255
 
159
256
  # Generates a +textarea+ element with a label, optional hint. Also offers
@@ -162,11 +259,14 @@ module GOVUKDesignSystemFormBuilder
162
259
  #
163
260
  # @param attribute_name [Symbol] The name of the attribute
164
261
  # @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
165
- # @param [Hash] label configures the associated label
262
+ # @param label [Hash,Proc] configures or sets the associated label content
166
263
  # @option label text [String] the label text
167
264
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
168
265
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
169
266
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
267
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
268
+ # @option caption text [String] the caption text
269
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
170
270
  # @param max_words [Integer] adds the GOV.UK max word count
171
271
  # @param max_chars [Integer] adds the GOV.UK max characters count
172
272
  # @param threshold [Integer] only show the +max_words+ and +max_chars+ warnings once a threshold (percentage) is reached
@@ -174,17 +274,31 @@ module GOVUKDesignSystemFormBuilder
174
274
  # @option args [Hash] args additional arguments are applied as attributes to the +textarea+ element
175
275
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
176
276
  # @return [ActiveSupport::SafeBuffer] HTML output
277
+ # @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
177
278
  # @see https://design-system.service.gov.uk/components/character-count GOV.UK character count component
279
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
178
280
  # @note Setting +max_chars+ or +max_words+ will add a caption beneath the +textarea+ with a live count of words
179
281
  # or characters
180
282
  #
181
283
  # @example A text area with a custom number of rows and a word limit
182
- # = f.govuk_number_field :cv,
284
+ # = f.govuk_text_area :cv,
183
285
  # label: { text: 'Tell us about your work history' },
184
286
  # rows: 8,
185
287
  # max_words: 300
186
- def govuk_text_area(attribute_name, hint_text: nil, label: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, **args, &block)
187
- Elements::TextArea.new(self, object_name, attribute_name, hint_text: hint_text, label: label, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, **args, &block).html
288
+ #
289
+ # @example A text area with injected content
290
+ # = f.govuk_text_area :description,
291
+ # label: { text: 'Where did the incident take place?' } do
292
+ #
293
+ # p.govuk-inset-text
294
+ # | If you don't know exactly leave this section blank
295
+ #
296
+ # @example A text area with the label supplied as a proc
297
+ # = f.govuk_text_area :instructions,
298
+ # label: -> { tag.h3("How do you set it up?") }
299
+ #
300
+ def govuk_text_area(attribute_name, hint_text: nil, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, **args, &block)
301
+ Elements::TextArea.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, **args, &block).html
188
302
  end
189
303
 
190
304
  # Generates a +select+ element containing +option+ for each member in the provided collection
@@ -200,7 +314,25 @@ module GOVUKDesignSystemFormBuilder
200
314
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
201
315
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
202
316
  # @return [ActiveSupport::SafeBuffer] HTML output
203
- def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint_text: nil, label: {}, &block)
317
+ #
318
+ # @example A select box with hint
319
+ # = f.govuk_collection_select :grade,
320
+ # @grades,
321
+ # :id,
322
+ # :name,
323
+ # hint_text: "If you took the test more than once enter your highest grade"
324
+ #
325
+ # @example A select box with injected content
326
+ # = f.govuk_collection_select(:favourite_colour, @colours, :id, :name) do
327
+ #
328
+ # p.govuk-inset-text
329
+ # | Select the closest match
330
+ #
331
+ # @example A select box with the label supplied as a proc
332
+ # = f.govuk_collection_select(:team, @teams, :id, :name) do
333
+ # label: -> { tag.h3("Which team did you represent?") }
334
+ #
335
+ def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint_text: nil, label: {}, caption: {}, &block)
204
336
  Elements::Select.new(
205
337
  self,
206
338
  object_name,
@@ -210,6 +342,7 @@ module GOVUKDesignSystemFormBuilder
210
342
  text_method: text_method,
211
343
  hint_text: hint_text,
212
344
  label: label,
345
+ caption: caption,
213
346
  options: options,
214
347
  html_options: html_options,
215
348
  &block
@@ -229,19 +362,25 @@ module GOVUKDesignSystemFormBuilder
229
362
  # @param collection [Enumerable<Object>] Options to be added to the +select+ element
230
363
  # @param value_method [Symbol, Proc] The method called against each member of the collection to provide the value.
231
364
  # When a +Proc+ is provided it must take a single argument that is a single member of the collection
232
- # @param text_method [Symbol, Proc] The method called against each member of the collection to provide the label text.
233
- # When a +Proc+ is provided it must take a single argument that is a single member of the collection
234
- # @param hint_method [Symbol, Proc] The method called against each member of the collection to provide the hint text.
235
- # When a +Proc+ is provided it must take a single argument that is a single member of the collection
365
+ # @param text_method [Symbol, Proc, nil] The method called against each member of the collection to provide the label text.
366
+ # When a +Proc+ is provided it must take a single argument that is a single member of the collection.
367
+ # When a +nil+ value is provided the label text will be retrieved from the locale.
368
+ # @param hint_method [Symbol, Proc, nil] The method called against each member of the collection to provide the hint text.
369
+ # When a +Proc+ is provided it must take a single argument that is a single member of the collection.
370
+ # When a +nil+ value is provided the hint text will be retrieved from the locale. This is the default and param can be omitted.
236
371
  # @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
237
- # @param legend [Hash] options for configuring the legend
372
+ # @param legend [Hash,Proc] options for configuring the legend
238
373
  # @param inline [Boolean] controls whether the radio buttons are displayed inline or not
239
374
  # @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
240
375
  # @param bold_labels [Boolean] controls whether the radio button labels are bold
241
376
  # @param classes [String] Classes to add to the radio button container.
242
377
  # @option legend text [String] the fieldset legend's text content
243
378
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
244
- # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+, defaults to +h1+
379
+ # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
380
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
381
+ # @param caption [Hash] configures or sets the caption content which is inserted above the legend
382
+ # @option caption text [String] the caption text
383
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
245
384
  # @return [ActiveSupport::SafeBuffer] HTML output
246
385
  #
247
386
  # @example A collection of radio buttons for favourite colours, labels capitalised via a proc
@@ -259,7 +398,24 @@ module GOVUKDesignSystemFormBuilder
259
398
  # legend: { text: 'Pick your favourite colour', size: 'm' },
260
399
  # hint_text: 'If you cannot find the exact match choose something close',
261
400
  # inline: false
262
- def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, inline: false, small: false, bold_labels: false, classes: nil, &block)
401
+ #
402
+ # @example A collection of radio buttons for grades with injected content
403
+ # = f.govuk_collection_radio_buttons :grade,
404
+ # @grades,
405
+ # :id,
406
+ # :name do
407
+ #
408
+ # p.govuk-inset-text
409
+ # | If you took the test more than once enter your highest grade
410
+ #
411
+ # @example A collection of radio buttons with the legend supplied as a proc
412
+ # = f.govuk_collection_radio_buttons :category,
413
+ # @categories,
414
+ # :id,
415
+ # :name,
416
+ # legend: -> { tag.h3('Which category do you belong to?') }
417
+ #
418
+ def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, &block)
263
419
  Elements::Radios::Collection.new(
264
420
  self,
265
421
  object_name,
@@ -270,6 +426,7 @@ module GOVUKDesignSystemFormBuilder
270
426
  hint_method: hint_method,
271
427
  hint_text: hint_text,
272
428
  legend: legend,
429
+ caption: caption,
273
430
  inline: inline,
274
431
  small: small,
275
432
  bold_labels: bold_labels,
@@ -282,29 +439,46 @@ module GOVUKDesignSystemFormBuilder
282
439
  #
283
440
  # @note The intention is to use {#govuk_radio_button} and {#govuk_radio_divider} within the passed-in block
284
441
  #
442
+ # @note To ensure the {#govuk_error_summary} link functions correctly ensure the first {#govuk_radio_button}
443
+ # is set to +link_errors: true+
444
+ #
285
445
  # @param attribute_name [Symbol] The name of the attribute
286
446
  # @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
287
- # @param legend [Hash] options for configuring the legend
447
+ # @param legend [Hash,Proc] options for configuring the legend
288
448
  # @param inline [Boolean] controls whether the radio buttons are displayed inline or not
289
449
  # @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
290
450
  # @option legend text [String] the fieldset legend's text content
291
451
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
292
452
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
453
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
454
+ # @param caption [Hash] configures or sets the caption content which is inserted above the legend
455
+ # @option caption text [String] the caption text
456
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
293
457
  # @param block [Block] a block of HTML that will be used to populate the fieldset
294
458
  # @param classes [String] Classes to add to the radio button container.
295
459
  # @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
460
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
296
461
  # @return [ActiveSupport::SafeBuffer] HTML output
297
462
  #
298
- # @example A collection of radio buttons for favourite colours with a divider
463
+ # @example A radio button fieldset for favourite colours with a divider
299
464
  #
300
- # = f.govuk_collection_radio_buttons :favourite_colour, inline: false do
301
- # = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
465
+ # = f.govuk_radio_buttons_fieldset :favourite_colour, inline: false do
466
+ # = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }, link_errors: true
302
467
  # = f.govuk_radio_button :favourite_colour, :green, label: { text: 'Green' }
303
468
  # = f.govuk_radio_divider
304
469
  # = f.govuk_radio_button :favourite_colour, :yellow, label: { text: 'Yellow' }
305
470
  #
306
- def govuk_radio_buttons_fieldset(attribute_name, hint_text: nil, legend: {}, inline: false, small: false, classes: nil, &block)
307
- Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, inline: inline, small: small, classes: classes, &block).html
471
+ # @example A radio button fieldset with the legend supplied as a proc
472
+ # = f.govuk_radio_buttons_fieldset :burger_id do
473
+ # @burgers,
474
+ # :id,
475
+ # :name,
476
+ # legend: -> { tag.h3('Which hamburger do you want with your meal?') } do
477
+ # = f.govuk_radio_button :burger_id, :regular, label: { text: 'Hamburger' }, link_errors: true
478
+ # = f.govuk_radio_button :burger_id, :cheese, label: { text: 'Cheeseburger' }
479
+ #
480
+ def govuk_radio_buttons_fieldset(attribute_name, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, classes: nil, &block)
481
+ Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, inline: inline, small: small, classes: classes, &block).html
308
482
  end
309
483
 
310
484
  # Generates a radio button
@@ -315,17 +489,19 @@ module GOVUKDesignSystemFormBuilder
315
489
  # @option legend text [String] the fieldset legend's text content
316
490
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
317
491
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
492
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
318
493
  # @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
494
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
319
495
  # @param block [Block] Any supplied HTML will be wrapped in a conditional
320
496
  # container and only revealed when the radio button is picked
321
- # @param link_errors [Boolean] controls whether this radio button should be linked to
497
+ # @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
322
498
  # from the error summary. <b>Should only be set to +true+ for the first radio button in a fieldset</b>
323
499
  # @return [ActiveSupport::SafeBuffer] HTML output
324
500
  #
325
- # @example A collection of radio buttons for favourite colours with a divider
501
+ # @example A single radio button for our new favourite colour
326
502
  #
327
- # = f.govuk_collection_radio_buttons :favourite_colour, inline: false do
328
- # = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' } do
503
+ # = f.govuk_radio_buttons_fieldset :favourite_colour do
504
+ # = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
329
505
  #
330
506
  def govuk_radio_button(attribute_name, value, hint_text: nil, label: {}, link_errors: false, &block)
331
507
  Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint_text: hint_text, label: label, link_errors: link_errors, &block).html
@@ -354,10 +530,14 @@ module GOVUKDesignSystemFormBuilder
354
530
  # @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
355
531
  # @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
356
532
  # @param classes [String] Classes to add to the checkbox container.
357
- # @param legend [Hash] options for configuring the legend
533
+ # @param legend [Hash,Proc] options for configuring the legend
358
534
  # @option legend text [String] the fieldset legend's text content
359
535
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
360
536
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
537
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
538
+ # @param caption [Hash] configures or sets the caption content which is inserted above the legend
539
+ # @option caption text [String] the caption text
540
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
361
541
  # @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
362
542
  # @return [ActiveSupport::SafeBuffer] HTML output
363
543
  #
@@ -377,7 +557,24 @@ module GOVUKDesignSystemFormBuilder
377
557
  # hint_text: "If it isn't listed here, tough luck",
378
558
  # inline: false,
379
559
  # classes: 'app-overflow-scroll',
380
- def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, small: false, classes: nil, &block)
560
+ #
561
+ # @example A collection of check boxes for types of bread
562
+ # = f.govuk_collection_check_boxes :bread,
563
+ # @variety,
564
+ # :id,
565
+ # :name do
566
+ #
567
+ # p.govuk-inset-text
568
+ # | Only Hearty Italian is available with the meal deal menu
569
+ #
570
+ # @example A collection of check boxes with the legend supplied as a proc
571
+ # = f.govuk_collection_check_boxes :sandwich_type,
572
+ # @breads,
573
+ # :id,
574
+ # :name,
575
+ # legend: -> { tag.h3('What kind of sandwich do you want?') }
576
+ #
577
+ def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, small: false, classes: nil, &block)
381
578
  Elements::CheckBoxes::Collection.new(
382
579
  self,
383
580
  object_name,
@@ -388,6 +585,7 @@ module GOVUKDesignSystemFormBuilder
388
585
  hint_method: hint_method,
389
586
  hint_text: hint_text,
390
587
  legend: legend,
588
+ caption: caption,
391
589
  small: small,
392
590
  classes: classes,
393
591
  &block
@@ -396,42 +594,54 @@ module GOVUKDesignSystemFormBuilder
396
594
 
397
595
  # Generate a fieldset intended to conatain one or more {#govuk_check_box}
398
596
  #
597
+ # @note To ensure the {#govuk_error_summary} link functions correctly ensure the first {#govuk_check_box}
598
+ # is set to +link_errors: true+
599
+ #
399
600
  # @param attribute_name [Symbol] The name of the attribute
400
601
  # @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
401
602
  # @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
402
- # @param legend [Hash] options for configuring the legend
603
+ # @param legend [Hash,Proc] options for configuring the legend
403
604
  # @option legend text [String] the fieldset legend's text content
404
605
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
405
606
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
607
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
608
+ # @param caption [Hash] configures or sets the caption content which is inserted above the legend
609
+ # @option caption text [String] the caption text
610
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
406
611
  # @param classes [String] Classes to add to the checkbox container.
407
612
  # @param block [Block] a block of HTML that will be used to populate the fieldset
408
613
  # @return [ActiveSupport::SafeBuffer] HTML output
409
614
  #
410
615
  # @example A collection of check boxes for sandwich fillings
411
- #
412
- # = f.govuk_check_boxes_fieldset :desired_filling,
616
+ # = f.govuk_check_boxes_fieldset :desired_filling, legend: { text: 'Which filling do you want?' },
413
617
  # = f.govuk_check_box :desired_filling, :cheese, label: { text: 'Cheese' }, link_errors: true
414
618
  # = f.govuk_check_box :desired_filling, :tomato, label: { text: 'Tomato' }
415
619
  #
416
- def govuk_check_boxes_fieldset(attribute_name, legend: {}, hint_text: {}, small: false, classes: nil, &block)
620
+ # @example A collection of check boxes for drinks choices with legend as a proc
621
+ # = f.govuk_check_boxes_fieldset :drink_id, legend: -> { tag.h3('Choose drinks to accompany your meal') },
622
+ # = f.govuk_check_box :desired_filling, :lemonade, label: { text: 'Lemonade' }, link_errors: true
623
+ # = f.govuk_check_box :desired_filling, :fizzy_orange, label: { text: 'Fizzy orange' }
624
+ #
625
+ def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint_text: {}, small: false, classes: nil, &block)
417
626
  Containers::CheckBoxesFieldset.new(
418
627
  self,
419
628
  object_name,
420
629
  attribute_name,
421
630
  hint_text: hint_text,
422
631
  legend: legend,
632
+ caption: caption,
423
633
  small: small,
424
634
  classes: classes,
425
635
  &block
426
636
  ).html
427
637
  end
428
638
 
429
- # Generates a single fieldset, intended for use within a {#govuk_check_boxes_fieldset}
639
+ # Generates a single check box, intended for use within a {#govuk_check_boxes_fieldset}
430
640
  #
431
641
  # @param attribute_name [Symbol] The name of the attribute
432
642
  # @param value [Boolean,String,Symbol,Integer] The value of the checkbox when it is checked
433
643
  # @param hint_text [String] the contents of the hint
434
- # @param link_errors [Boolean] controls whether this radio button should be linked to
644
+ # @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
435
645
  # @option label text [String] the label text
436
646
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
437
647
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
@@ -469,6 +679,7 @@ module GOVUKDesignSystemFormBuilder
469
679
  # @param secondary [Boolean] makes the button grey ({https://design-system.service.gov.uk/components/button/#secondary-buttons secondary}) when true
470
680
  # @todo The GOV.UK design system also supports {https://design-system.service.gov.uk/components/button/#disabled-buttons disabled buttons}, they
471
681
  # should probably be supported too
682
+ # @param classes [String] Classes to add to the submit button
472
683
  # @param prevent_double_click [Boolean] adds JavaScript to safeguard the
473
684
  # form from being submitted more than once
474
685
  # @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
@@ -488,8 +699,8 @@ module GOVUKDesignSystemFormBuilder
488
699
  # = f.govuk_submit "Proceed", prevent_double_click: true do
489
700
  # = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
490
701
  #
491
- def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, prevent_double_click: true, validate: false, &block)
492
- Elements::Submit.new(self, text, warning: warning, secondary: secondary, prevent_double_click: prevent_double_click, validate: validate, &block).html
702
+ def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, classes: nil, prevent_double_click: true, validate: false, &block)
703
+ Elements::Submit.new(self, text, warning: warning, secondary: secondary, classes: classes, prevent_double_click: prevent_double_click, validate: validate, &block).html
493
704
  end
494
705
 
495
706
  # Generates three inputs for the +day+, +month+ and +year+ components of a date
@@ -499,10 +710,14 @@ module GOVUKDesignSystemFormBuilder
499
710
  # be 'rounded' up to +2019-10-01+.
500
711
  # @param attribute_name [Symbol] The name of the attribute
501
712
  # @param hint_text [String] the contents of the hint
502
- # @param legend [Hash] options for configuring the legend
713
+ # @param legend [Hash,Proc] options for configuring the legend
503
714
  # @option legend text [String] the fieldset legend's text content
504
715
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
505
716
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
717
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
718
+ # @param caption [Hash] configures or sets the caption content which is inserted above the legend
719
+ # @option caption text [String] the caption text
720
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
506
721
  # @param omit_day [Boolean] do not render a day input, only capture month and year
507
722
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
508
723
  # @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
@@ -510,13 +725,21 @@ module GOVUKDesignSystemFormBuilder
510
725
  # @return [ActiveSupport::SafeBuffer] HTML output
511
726
  #
512
727
  # @see https://github.com/alphagov/govuk-frontend/issues/1449 GOV.UK date input element attributes, using text instead of number
728
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
513
729
  #
514
- # @example A regular date input with a legend and hint
730
+ # @example A regular date input with a legend, hint and injected content
515
731
  # = f.govuk_date_field :starts_on,
516
732
  # legend: { 'When does your event start?' },
517
- # hint_text: 'Leave this field blank if you don't know exactly' }
518
- def govuk_date_field(attribute_name, hint_text: nil, legend: {}, date_of_birth: false, omit_day: false, &block)
519
- Elements::Date.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, date_of_birth: date_of_birth, omit_day: omit_day, &block).html
733
+ # hint_text: 'Leave this field blank if you don't know exactly' } do
734
+ #
735
+ # p.govuk-inset-text
736
+ # | If you don't fill this in you won't be eligable for a refund
737
+ #
738
+ # @example A date input with legend supplied as a proc
739
+ # = f.govuk_date_field :finishes_on,
740
+ # legend: -> { tag.h3('Which category do you belong to?') }
741
+ def govuk_date_field(attribute_name, hint_text: nil, legend: {}, caption: {}, date_of_birth: false, omit_day: false, &block)
742
+ Elements::Date.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, &block).html
520
743
  end
521
744
 
522
745
  # Generates a summary of errors in the form, each linking to the corresponding
@@ -524,12 +747,6 @@ module GOVUKDesignSystemFormBuilder
524
747
  #
525
748
  # @param title [String] the error summary heading
526
749
  #
527
- # @todo Currently the summary anchors link to the inline error messages themselves rather to
528
- # the accompanying input. More work is required to improve this and it needs to be
529
- # handled in a less-generic manner. For example, we can't link to a specific radio button
530
- # if one hasn't been chosen but we should link to a {#govuk_text_field} if one has been left
531
- # blank
532
- #
533
750
  # @example An error summary with a custom title
534
751
  # = f.govuk_error_summary 'Uh-oh, spaghettios'
535
752
  #
@@ -540,11 +757,15 @@ module GOVUKDesignSystemFormBuilder
540
757
 
541
758
  # Generates a fieldset containing the contents of the block
542
759
  #
543
- # @param legend [Hash] options for configuring the legend
760
+ # @param legend [Hash,Proc] options for configuring the legend
544
761
  # @param described_by [Array<String>] the ids of the elements that describe this fieldset, usually hints and errors
545
762
  # @option legend text [String] the fieldset legend's text content
546
763
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
547
764
  # @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
765
+ # @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
766
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
767
+ # @option caption text [String] the caption text
768
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
548
769
  #
549
770
  # @example A fieldset containing address fields
550
771
  # = f.govuk_fieldset legend: { text: 'Address' }
@@ -552,10 +773,16 @@ module GOVUKDesignSystemFormBuilder
552
773
  # = f.govuk_text_field :town
553
774
  # = f.govuk_text_field :city
554
775
  #
776
+ # @example A fieldset with the legend as a proc
777
+ # = f.govuk_fieldset legend: -> { tag.h3('Skills') }
778
+ # = f.govuk_text_area :physical
779
+ # = f.govuk_text_area :mental
780
+ #
555
781
  # @see https://design-system.service.gov.uk/components/fieldset/ GOV.UK fieldset
782
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
556
783
  # @return [ActiveSupport::SafeBuffer] HTML output
557
- def govuk_fieldset(legend: { text: 'Fieldset heading' }, described_by: nil, &block)
558
- Containers::Fieldset.new(self, legend: legend, described_by: described_by).html(&block)
784
+ def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, &block)
785
+ Containers::Fieldset.new(self, legend: legend, caption: caption, described_by: described_by, &block).html
559
786
  end
560
787
 
561
788
  # Generates an input of type +file+
@@ -565,21 +792,31 @@ module GOVUKDesignSystemFormBuilder
565
792
  # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
566
793
  # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
567
794
  # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
795
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
796
+ # @option caption text [String] the caption text
797
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
568
798
  # @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
569
- # @option args [Hash] args additional arguments are applied as attributes to +input+ element
799
+ # @option args [Hash] args additional arguments are applied as attributes to the +input+ element
570
800
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
571
801
  #
572
- # @example A photo upload field with file type specifier
573
- # = f.govuk_file_field :photo, label: { text: 'Upload your photo' }, accept: 'image/*'
802
+ # @example A photo upload field with file type specifier and injected content
803
+ # = f.govuk_file_field :photo, label: { text: 'Upload your photo' }, accept: 'image/*' do
804
+ #
805
+ # p.govuk-inset-text
806
+ # | Explicit images will result in account termination
807
+ #
808
+ # @example A CV upload field with label as a proc
809
+ # = f.govuk_file_field :cv, label: -> { tag.h3('Upload your CV') }
574
810
  #
575
811
  # @see https://design-system.service.gov.uk/components/file-upload/ GOV.UK file upload
812
+ # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
576
813
  # @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file MDN documentation for file upload
577
814
  #
578
815
  # @note Remember to set +multipart: true+ when creating a form with file
579
816
  # uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
580
817
  # the Rails documentation} for more information
581
- def govuk_file_field(attribute_name, label: {}, hint_text: nil, **args, &block)
582
- Elements::File.new(self, object_name, attribute_name, label: label, hint_text: hint_text, **args, &block).html
818
+ def govuk_file_field(attribute_name, label: {}, caption: {}, hint_text: nil, **args, &block)
819
+ Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint_text: hint_text, **args, &block).html
583
820
  end
584
821
  end
585
822
  end