govuk_design_system_formbuilder 2.0.0b1 → 2.0.0b2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/govuk_design_system_formbuilder/builder.rb +94 -63
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +3 -3
- data/lib/govuk_design_system_formbuilder/elements/caption.rb +10 -5
- data/lib/govuk_design_system_formbuilder/elements/file.rb +6 -6
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +4 -4
- data/lib/govuk_design_system_formbuilder/elements/label.rb +12 -10
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +17 -9
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +1 -1
- data/lib/govuk_design_system_formbuilder/traits/caption.rb +1 -9
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd1f1c56336a4852ae5915c148e7c47abeef5590f87fc083437a4f4a680addba
|
4
|
+
data.tar.gz: 929a16808249de59a675c3215837e1522d2982a46497fea6b207e90f9c9d8aa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad2ad55fb5f7752862fde79ec8ffcfba5ef9cb1ea20e30b266c7152a7d78eef6fa9f40682f69a7db395b9f8104645735eb71c1efbc538506d3015fb888542932
|
7
|
+
data.tar.gz: 2c1d49579c09742a5dc2f8be8ddf7bcee4edb6d2d9d39e610705dfd10efc4bf0df18ad00026cd932d10b790aca1ee93a964079329ee9be0067c4c4f84c84a83a
|
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
|
|
8
8
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
9
9
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
10
10
|
# @option hint text [String] the hint text
|
11
|
-
# @option hint
|
11
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
12
12
|
#
|
13
13
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
14
14
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
@@ -17,13 +17,15 @@ module GOVUKDesignSystemFormBuilder
|
|
17
17
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
18
18
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
19
19
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
20
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
20
21
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
21
22
|
# @option caption text [String] the caption text
|
22
23
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
23
|
-
# @option
|
24
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
25
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
24
26
|
# @param form_group [Hash] configures the form group
|
25
27
|
# @option form_group classes [Array,String] sets the form group's classes
|
26
|
-
# @option form_group
|
28
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
27
29
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
28
30
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
29
31
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -47,8 +49,8 @@ module GOVUKDesignSystemFormBuilder
|
|
47
49
|
# = f.govuk_text_field :callsign,
|
48
50
|
# label: -> { tag.h3('Call-sign') }
|
49
51
|
#
|
50
|
-
def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
51
|
-
Elements::Inputs::Text.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
52
|
+
def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
53
|
+
Elements::Inputs::Text.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
52
54
|
end
|
53
55
|
|
54
56
|
# Generates a input of type +tel+
|
@@ -57,7 +59,7 @@ module GOVUKDesignSystemFormBuilder
|
|
57
59
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
58
60
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
59
61
|
# @option hint text [String] the hint text
|
60
|
-
# @option hint
|
62
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
61
63
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
62
64
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
63
65
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -65,13 +67,15 @@ module GOVUKDesignSystemFormBuilder
|
|
65
67
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
66
68
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
67
69
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
70
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
68
71
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
69
72
|
# @option caption text [String] the caption text
|
70
73
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
71
|
-
# @option
|
74
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
75
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
72
76
|
# @param form_group [Hash] configures the form group
|
73
77
|
# @option form_group classes [Array,String] sets the form group's classes
|
74
|
-
# @option form_group
|
78
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
75
79
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
76
80
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
77
81
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -96,8 +100,8 @@ module GOVUKDesignSystemFormBuilder
|
|
96
100
|
# = f.govuk_phone_field :work_number,
|
97
101
|
# label: -> { tag.h3('Work number') }
|
98
102
|
#
|
99
|
-
def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
100
|
-
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
103
|
+
def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
104
|
+
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
101
105
|
end
|
102
106
|
|
103
107
|
# Generates a input of type +email+
|
@@ -106,7 +110,7 @@ module GOVUKDesignSystemFormBuilder
|
|
106
110
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
107
111
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
108
112
|
# @option hint text [String] the hint text
|
109
|
-
# @option hint
|
113
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
110
114
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
111
115
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
112
116
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -114,13 +118,15 @@ module GOVUKDesignSystemFormBuilder
|
|
114
118
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
115
119
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
116
120
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
121
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
117
122
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
118
123
|
# @option caption text [String] the caption text
|
119
124
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
120
|
-
# @option
|
125
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
126
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
121
127
|
# @param form_group [Hash] configures the form group
|
122
128
|
# @option form_group classes [Array,String] sets the form group's classes
|
123
|
-
# @option form_group
|
129
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
124
130
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
125
131
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
126
132
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -143,8 +149,8 @@ module GOVUKDesignSystemFormBuilder
|
|
143
149
|
# = f.govuk_email_field :personal_email,
|
144
150
|
# label: -> { tag.h3('Personal email address') }
|
145
151
|
#
|
146
|
-
def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
147
|
-
Elements::Inputs::Email.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
152
|
+
def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
153
|
+
Elements::Inputs::Email.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
148
154
|
end
|
149
155
|
|
150
156
|
# Generates a input of type +password+
|
@@ -153,7 +159,7 @@ module GOVUKDesignSystemFormBuilder
|
|
153
159
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
154
160
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
155
161
|
# @option hint text [String] the hint text
|
156
|
-
# @option hint
|
162
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
157
163
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
158
164
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
159
165
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -161,13 +167,15 @@ module GOVUKDesignSystemFormBuilder
|
|
161
167
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
162
168
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
163
169
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
170
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
164
171
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
165
172
|
# @option caption text [String] the caption text
|
166
173
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
167
|
-
# @option
|
174
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
175
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
168
176
|
# @param form_group [Hash] configures the form group
|
169
177
|
# @option form_group classes [Array,String] sets the form group's classes
|
170
|
-
# @option form_group
|
178
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
171
179
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
172
180
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
173
181
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -189,8 +197,8 @@ module GOVUKDesignSystemFormBuilder
|
|
189
197
|
# = f.govuk_password_field :passcode,
|
190
198
|
# label: -> { tag.h3('What is your secret pass code?') }
|
191
199
|
#
|
192
|
-
def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, form_group: {}, caption: {}, **
|
193
|
-
Elements::Inputs::Password.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
200
|
+
def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, form_group: {}, caption: {}, **kwargs, &block)
|
201
|
+
Elements::Inputs::Password.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
194
202
|
end
|
195
203
|
|
196
204
|
# Generates a input of type +url+
|
@@ -199,7 +207,7 @@ module GOVUKDesignSystemFormBuilder
|
|
199
207
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
200
208
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
201
209
|
# @option hint text [String] the hint text
|
202
|
-
# @option hint
|
210
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
203
211
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
204
212
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
205
213
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -207,13 +215,15 @@ module GOVUKDesignSystemFormBuilder
|
|
207
215
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
208
216
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
209
217
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
218
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
210
219
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
211
220
|
# @option caption text [String] the caption text
|
212
221
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
213
|
-
# @option
|
222
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
223
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
214
224
|
# @param form_group [Hash] configures the form group
|
215
225
|
# @option form_group classes [Array,String] sets the form group's classes
|
216
|
-
# @option form_group
|
226
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
217
227
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
218
228
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
219
229
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -236,8 +246,8 @@ module GOVUKDesignSystemFormBuilder
|
|
236
246
|
# = f.govuk_url_field :work_website,
|
237
247
|
# label: -> { tag.h3("Enter your company's website") }
|
238
248
|
#
|
239
|
-
def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
240
|
-
Elements::Inputs::URL.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
249
|
+
def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
250
|
+
Elements::Inputs::URL.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
241
251
|
end
|
242
252
|
|
243
253
|
# Generates a input of type +number+
|
@@ -246,7 +256,7 @@ module GOVUKDesignSystemFormBuilder
|
|
246
256
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
247
257
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
248
258
|
# @option hint text [String] the hint text
|
249
|
-
# @option hint
|
259
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
250
260
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
251
261
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
252
262
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -254,13 +264,15 @@ module GOVUKDesignSystemFormBuilder
|
|
254
264
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
255
265
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
256
266
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
267
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
257
268
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
258
269
|
# @option caption text [String] the caption text
|
259
270
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
260
|
-
# @option
|
271
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
272
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
261
273
|
# @param form_group [Hash] configures the form group
|
262
274
|
# @option form_group classes [Array,String] sets the form group's classes
|
263
|
-
# @option form_group
|
275
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
264
276
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
265
277
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
266
278
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -286,8 +298,8 @@ module GOVUKDesignSystemFormBuilder
|
|
286
298
|
# = f.govuk_url_field :personal_best_over_100m,
|
287
299
|
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
|
288
300
|
#
|
289
|
-
def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
290
|
-
Elements::Inputs::Number.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
301
|
+
def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
302
|
+
Elements::Inputs::Number.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
291
303
|
end
|
292
304
|
|
293
305
|
# Generates a +textarea+ element with a label, optional hint. Also offers
|
@@ -298,23 +310,25 @@ module GOVUKDesignSystemFormBuilder
|
|
298
310
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
299
311
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
300
312
|
# @option hint text [String] the hint text
|
301
|
-
# @option hint
|
313
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
302
314
|
# @param label [Hash,Proc] configures or sets the associated label content
|
303
315
|
# @option label text [String] the label text
|
304
316
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
305
317
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
306
318
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
319
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
307
320
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
308
321
|
# @option caption text [String] the caption text
|
309
322
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
323
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
310
324
|
# @param max_words [Integer] adds the GOV.UK max word count
|
311
325
|
# @param max_chars [Integer] adds the GOV.UK max characters count
|
312
326
|
# @param threshold [Integer] only show the +max_words+ and +max_chars+ warnings once a threshold (percentage) is reached
|
313
327
|
# @param rows [Integer] sets the initial number of rows
|
314
|
-
# @option
|
328
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +textarea+ element
|
315
329
|
# @param form_group [Hash] configures the form group
|
316
330
|
# @option form_group classes [Array,String] sets the form group's classes
|
317
|
-
# @option form_group
|
331
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
318
332
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
319
333
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
320
334
|
# @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
|
@@ -340,8 +354,8 @@ module GOVUKDesignSystemFormBuilder
|
|
340
354
|
# = f.govuk_text_area :instructions,
|
341
355
|
# label: -> { tag.h3("How do you set it up?") }
|
342
356
|
#
|
343
|
-
def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **
|
344
|
-
Elements::TextArea.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, form_group: form_group, **
|
357
|
+
def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **kwargs, &block)
|
358
|
+
Elements::TextArea.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, form_group: form_group, **kwargs, &block).html
|
345
359
|
end
|
346
360
|
|
347
361
|
# Generates a +select+ element containing +option+ for each member in the provided collection
|
@@ -353,16 +367,17 @@ module GOVUKDesignSystemFormBuilder
|
|
353
367
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
354
368
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
355
369
|
# @option hint text [String] the hint text
|
356
|
-
# @option hint
|
370
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
357
371
|
# @option label text [String] the label text
|
358
372
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
359
373
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
360
374
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
375
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
361
376
|
# @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
|
362
377
|
# @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
|
363
378
|
# @param form_group [Hash] configures the form group
|
364
379
|
# @option form_group classes [Array,String] sets the form group's classes
|
365
|
-
# @option form_group
|
380
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
366
381
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
367
382
|
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select Rails collection_select (called by govuk_collection_select)
|
368
383
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -424,8 +439,8 @@ module GOVUKDesignSystemFormBuilder
|
|
424
439
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
425
440
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
426
441
|
# @option hint text [String] the hint text
|
427
|
-
# @option hint
|
428
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
442
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
443
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
429
444
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
430
445
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
431
446
|
# @param bold_labels [Boolean] controls whether the radio button labels are bold
|
@@ -434,9 +449,11 @@ module GOVUKDesignSystemFormBuilder
|
|
434
449
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
435
450
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
436
451
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
452
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
437
453
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
438
454
|
# @option caption text [String] the caption text
|
439
455
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
456
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
440
457
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
441
458
|
#
|
442
459
|
# @example A collection of radio buttons for favourite colours, labels capitalised via a proc
|
@@ -503,20 +520,22 @@ module GOVUKDesignSystemFormBuilder
|
|
503
520
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
504
521
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
505
522
|
# @option hint text [String] the hint text
|
506
|
-
# @option hint
|
507
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
523
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
524
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
508
525
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
509
526
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
510
527
|
# @option legend text [String] the fieldset legend's text content
|
511
528
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
512
529
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
513
530
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
531
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
514
532
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
515
533
|
# @option caption text [String] the caption text
|
516
534
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
535
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
517
536
|
# @param form_group [Hash] configures the form group
|
518
537
|
# @option form_group classes [Array,String] sets the form group's classes
|
519
|
-
# @option form_group
|
538
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
520
539
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
521
540
|
# @param classes [Array,String] Classes to add to the radio button container.
|
522
541
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
@@ -551,11 +570,13 @@ module GOVUKDesignSystemFormBuilder
|
|
551
570
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
552
571
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
553
572
|
# @option hint text [String] the hint text
|
554
|
-
# @option hint
|
555
|
-
# @
|
556
|
-
# @option
|
557
|
-
# @option
|
558
|
-
# @option
|
573
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
574
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
575
|
+
# @option label text [String] the label text
|
576
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
577
|
+
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
578
|
+
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
579
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
559
580
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
560
581
|
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
561
582
|
# @param block [Block] Any supplied HTML will be wrapped in a conditional
|
@@ -596,10 +617,10 @@ module GOVUKDesignSystemFormBuilder
|
|
596
617
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
597
618
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
598
619
|
# @option hint text [String] the hint text
|
599
|
-
# @option hint
|
620
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
600
621
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
601
622
|
# @param classes [Array,String] Classes to add to the checkbox container.
|
602
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
623
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
603
624
|
# @option legend text [String] the fieldset legend's text content
|
604
625
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
605
626
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
@@ -607,9 +628,10 @@ module GOVUKDesignSystemFormBuilder
|
|
607
628
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
608
629
|
# @option caption text [String] the caption text
|
609
630
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
631
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
610
632
|
# @param form_group [Hash] configures the form group
|
611
633
|
# @option form_group classes [Array,String] sets the form group's classes
|
612
|
-
# @option form_group
|
634
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
613
635
|
# @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
|
614
636
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
615
637
|
#
|
@@ -674,20 +696,22 @@ module GOVUKDesignSystemFormBuilder
|
|
674
696
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
675
697
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
676
698
|
# @option hint text [String] the hint text
|
677
|
-
# @option hint
|
699
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
678
700
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
679
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
701
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
680
702
|
# @option legend text [String] the fieldset legend's text content
|
681
703
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
682
704
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
683
705
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
706
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
684
707
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
685
708
|
# @option caption text [String] the caption text
|
686
709
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
710
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
687
711
|
# @param classes [Array,String] Classes to add to the checkbox container.
|
688
712
|
# @param form_group [Hash] configures the form group
|
689
713
|
# @option form_group classes [Array,String] sets the form group's classes
|
690
|
-
# @option form_group
|
714
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
691
715
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
692
716
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
693
717
|
#
|
@@ -723,12 +747,13 @@ module GOVUKDesignSystemFormBuilder
|
|
723
747
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
724
748
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
725
749
|
# @option hint text [String] the hint text
|
726
|
-
# @option hint
|
750
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
727
751
|
# @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
|
728
752
|
# @option label text [String] the label text
|
729
753
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
730
754
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
731
755
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
756
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
732
757
|
# @param multiple [Boolean] controls whether the check box is part of a collection or represents a single attribute
|
733
758
|
# @param block [Block] any HTML passed in will form the contents of the fieldset
|
734
759
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -794,19 +819,21 @@ module GOVUKDesignSystemFormBuilder
|
|
794
819
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
795
820
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
796
821
|
# @option hint text [String] the hint text
|
797
|
-
# @option hint
|
798
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
822
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
823
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
799
824
|
# @option legend text [String] the fieldset legend's text content
|
800
825
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
801
826
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
802
827
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
828
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
803
829
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
804
830
|
# @option caption text [String] the caption text
|
805
831
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
832
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
806
833
|
# @param omit_day [Boolean] do not render a day input, only capture month and year
|
807
834
|
# @param form_group [Hash] configures the form group
|
808
835
|
# @option form_group classes [Array,String] sets the form group's classes
|
809
|
-
# @option form_group
|
836
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
810
837
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
811
838
|
# @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
|
812
839
|
# will be added to the inputs
|
@@ -845,15 +872,17 @@ module GOVUKDesignSystemFormBuilder
|
|
845
872
|
|
846
873
|
# Generates a fieldset containing the contents of the block
|
847
874
|
#
|
848
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
875
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
849
876
|
# @param described_by [Array<String>] the ids of the elements that describe this fieldset, usually hints and errors
|
850
877
|
# @option legend text [String] the fieldset legend's text content
|
851
878
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
852
879
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
853
880
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
881
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
854
882
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
855
883
|
# @option caption text [String] the caption text
|
856
884
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
885
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
857
886
|
#
|
858
887
|
# @example A fieldset containing address fields
|
859
888
|
# = f.govuk_fieldset legend: { text: 'Address' }
|
@@ -880,17 +909,19 @@ module GOVUKDesignSystemFormBuilder
|
|
880
909
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
881
910
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
882
911
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
912
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
883
913
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
884
914
|
# @option caption text [String] the caption text
|
885
915
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
916
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
886
917
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
887
918
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
888
919
|
# @option hint text [String] the hint text
|
889
|
-
# @option hint
|
890
|
-
# @option
|
920
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
921
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
891
922
|
# @param form_group [Hash] configures the form group
|
892
923
|
# @option form_group classes [Array,String] sets the form group's classes
|
893
|
-
# @option form_group
|
924
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
894
925
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
895
926
|
#
|
896
927
|
# @example A photo upload field with file type specifier and injected content
|
@@ -909,8 +940,8 @@ module GOVUKDesignSystemFormBuilder
|
|
909
940
|
# @note Remember to set +multipart: true+ when creating a form with file
|
910
941
|
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
|
911
942
|
# the Rails documentation} for more information
|
912
|
-
def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **
|
913
|
-
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **
|
943
|
+
def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block)
|
944
|
+
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **kwargs, &block).html
|
914
945
|
end
|
915
946
|
end
|
916
947
|
end
|
@@ -4,12 +4,12 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
def initialize(builder, object_name, attribute_name, classes: nil, **kwargs)
|
5
5
|
super(builder, object_name, attribute_name)
|
6
6
|
|
7
|
-
@classes
|
8
|
-
@
|
7
|
+
@classes = classes
|
8
|
+
@html_attributes = kwargs
|
9
9
|
end
|
10
10
|
|
11
11
|
def html
|
12
|
-
tag.div(class: classes, **@
|
12
|
+
tag.div(class: classes, **@html_attributes) { yield }
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -3,21 +3,26 @@ module GOVUKDesignSystemFormBuilder
|
|
3
3
|
class Caption < Base
|
4
4
|
include Traits::Localisation
|
5
5
|
|
6
|
-
def initialize(builder, object_name, attribute_name, text
|
6
|
+
def initialize(builder, object_name, attribute_name, text: nil, size: nil, **kwargs)
|
7
7
|
super(builder, object_name, attribute_name)
|
8
8
|
|
9
|
-
@text
|
10
|
-
@size_class
|
9
|
+
@text = text(text)
|
10
|
+
@size_class = size_class(size)
|
11
|
+
@html_attributes = kwargs
|
11
12
|
end
|
12
13
|
|
13
14
|
def html
|
14
|
-
return nil
|
15
|
+
return nil unless active?
|
15
16
|
|
16
|
-
tag.span(@text, class: @size_class)
|
17
|
+
tag.span(@text, class: @size_class, **@html_attributes)
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
20
21
|
|
22
|
+
def active?
|
23
|
+
@text.present?
|
24
|
+
end
|
25
|
+
|
21
26
|
def text(override)
|
22
27
|
override || localised_text(:caption)
|
23
28
|
end
|
@@ -11,11 +11,11 @@ module GOVUKDesignSystemFormBuilder
|
|
11
11
|
def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
|
12
12
|
super(builder, object_name, attribute_name, &block)
|
13
13
|
|
14
|
-
@label
|
15
|
-
@caption
|
16
|
-
@hint
|
17
|
-
@
|
18
|
-
@form_group
|
14
|
+
@label = label
|
15
|
+
@caption = caption
|
16
|
+
@hint = hint
|
17
|
+
@html_attributes = kwargs
|
18
|
+
@form_group = form_group
|
19
19
|
end
|
20
20
|
|
21
21
|
def html
|
@@ -27,7 +27,7 @@ module GOVUKDesignSystemFormBuilder
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def file
|
30
|
-
@builder.file_field(@attribute_name, **options, **@
|
30
|
+
@builder.file_field(@attribute_name, **options, **@html_attributes)
|
31
31
|
end
|
32
32
|
|
33
33
|
def options
|
@@ -13,7 +13,7 @@ module GOVUKDesignSystemFormBuilder
|
|
13
13
|
@html_attributes = kwargs
|
14
14
|
|
15
15
|
if content
|
16
|
-
@
|
16
|
+
@raw = capture { content.call }
|
17
17
|
else
|
18
18
|
@text = retrieve_text(text)
|
19
19
|
@value = value
|
@@ -21,7 +21,7 @@ module GOVUKDesignSystemFormBuilder
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def active?
|
24
|
-
[@text, @
|
24
|
+
[@text, @raw].any?(&:present?)
|
25
25
|
end
|
26
26
|
|
27
27
|
def html
|
@@ -43,11 +43,11 @@ module GOVUKDesignSystemFormBuilder
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def hint_tag
|
46
|
-
@
|
46
|
+
@raw.presence ? 'div' : 'span'
|
47
47
|
end
|
48
48
|
|
49
49
|
def hint_body
|
50
|
-
@
|
50
|
+
@raw || @text
|
51
51
|
end
|
52
52
|
|
53
53
|
def retrieve_text(supplied)
|
@@ -6,22 +6,24 @@ module GOVUKDesignSystemFormBuilder
|
|
6
6
|
include Traits::Caption
|
7
7
|
include Traits::Localisation
|
8
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)
|
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)
|
10
10
|
super(builder, object_name, attribute_name)
|
11
11
|
|
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
|
+
|
12
19
|
# content is passed in directly via a proc and overrides
|
13
20
|
# the other display options
|
14
21
|
if content
|
15
22
|
@content = capture { content.call }
|
16
23
|
else
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@radio = radio
|
21
|
-
@checkbox = checkbox
|
22
|
-
@tag = tag
|
23
|
-
@link_errors = link_errors
|
24
|
-
@caption = caption
|
24
|
+
@text = retrieve_text(text, hidden)
|
25
|
+
@size_class = size_class(size)
|
26
|
+
@caption = caption
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -42,7 +44,7 @@ module GOVUKDesignSystemFormBuilder
|
|
42
44
|
private
|
43
45
|
|
44
46
|
def label
|
45
|
-
@builder.label(@attribute_name, **options) do
|
47
|
+
@builder.label(@attribute_name, **options, **@html_attributes) do
|
46
48
|
@content || safe_join([caption, @text])
|
47
49
|
end
|
48
50
|
end
|
@@ -4,15 +4,19 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
include Traits::Caption
|
5
5
|
include Traits::Localisation
|
6
6
|
|
7
|
-
def initialize(builder, object_name, attribute_name, legend:, caption
|
7
|
+
def initialize(builder, object_name, attribute_name, legend:, caption:, **kwargs)
|
8
8
|
super(builder, object_name, attribute_name)
|
9
9
|
|
10
|
+
@html_attributes = kwargs
|
11
|
+
|
10
12
|
case legend
|
13
|
+
when NilClass
|
14
|
+
@active = false
|
11
15
|
when Proc
|
12
16
|
@raw = capture { legend.call }
|
13
17
|
when Hash
|
14
18
|
defaults.merge(legend).tap do |l|
|
15
|
-
@text =
|
19
|
+
@text = retrieve_text(l.dig(:text))
|
16
20
|
@hidden = l.dig(:hidden)
|
17
21
|
@tag = l.dig(:tag)
|
18
22
|
@size = l.dig(:size)
|
@@ -29,18 +33,22 @@ module GOVUKDesignSystemFormBuilder
|
|
29
33
|
|
30
34
|
private
|
31
35
|
|
36
|
+
def active?
|
37
|
+
[@text, @raw].any?(&:present?)
|
38
|
+
end
|
39
|
+
|
32
40
|
def content
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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])
|
38
46
|
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
|
-
def
|
43
|
-
supplied_text
|
50
|
+
def retrieve_text(supplied_text)
|
51
|
+
[supplied_text, localised_text(:legend), @attribute_name&.capitalize].compact.first
|
44
52
|
end
|
45
53
|
|
46
54
|
def classes
|
@@ -39,7 +39,7 @@ module GOVUKDesignSystemFormBuilder
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def label_element
|
42
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options
|
42
|
+
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
|
43
43
|
end
|
44
44
|
|
45
45
|
def label_options
|
@@ -8,15 +8,7 @@ module GOVUKDesignSystemFormBuilder
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def caption_options
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def caption_text
|
15
|
-
@caption&.dig(:text)
|
16
|
-
end
|
17
|
-
|
18
|
-
def caption_size
|
19
|
-
@caption&.dig(:size)
|
11
|
+
@caption
|
20
12
|
end
|
21
13
|
end
|
22
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_design_system_formbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.0b2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Yates
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -303,7 +303,7 @@ metadata:
|
|
303
303
|
documentation_uri: https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder
|
304
304
|
homepage_uri: https://govuk-form-builder.netlify.app
|
305
305
|
source_code_uri: https://github.com/DFE-Digital/govuk_design_system_formbuilder
|
306
|
-
post_install_message:
|
306
|
+
post_install_message:
|
307
307
|
rdoc_options: []
|
308
308
|
require_paths:
|
309
309
|
- lib
|
@@ -319,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
319
319
|
version: 1.3.1
|
320
320
|
requirements: []
|
321
321
|
rubygems_version: 3.1.2
|
322
|
-
signing_key:
|
322
|
+
signing_key:
|
323
323
|
specification_version: 4
|
324
324
|
summary: GOV.UK-compliant Rails form builder
|
325
325
|
test_files: []
|