govuk_design_system_formbuilder 0.7.8 → 0.7.9
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 +25 -23
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +11 -2
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +1 -3
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +4 -2
- data/lib/govuk_design_system_formbuilder/elements/label.rb +7 -16
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +1 -1
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a58527f914ed7e0cef5f178663fd7969e4fd2cc0b6fa631f0c6e370aac3430e
|
|
4
|
+
data.tar.gz: 93c8461e3a90d144f477a1fa79b8082c8679d34aa0a2473f89ea693a01836c8a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ffdbdd1aae03e6514927a6daeecc215e70b3bfd653491860b4ce148359689ae00d90cb35aa529b53016a64c89d8e84fe0678335b47055dad7089b930304f6ac6
|
|
7
|
+
data.tar.gz: ce348d7c0a8cc1aee7dda9297b64a3389e6d7d136ba422f54e155d7e14786634b591de980744f68f04d1c20971026dffd94c16931aab24fbcb87e7fa96174987
|
|
@@ -8,8 +8,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
8
8
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
9
9
|
# @param [Hash] label configures the associated label
|
|
10
10
|
# @option label text [String] the label text
|
|
11
|
-
# @option label size [String] the size of the label font, can be +
|
|
12
|
-
# @option label weight [String] the weight of the label font, can be +bold+ or +regular+
|
|
11
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
13
12
|
# @option args [Hash] args additional arguments are applied as attributes to +input+ element
|
|
14
13
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
15
14
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
@@ -32,8 +31,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
32
31
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
33
32
|
# @param [Hash] label configures the associated label
|
|
34
33
|
# @option label text [String] the label text
|
|
35
|
-
# @option label size [String] the size of the label font, can be +
|
|
36
|
-
# @option label weight [String] the weight of the label font, can be +bold+ or +regular+
|
|
34
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
37
35
|
# @option args [Hash] args additional arguments are applied as attributes to +input+ element
|
|
38
36
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
39
37
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
@@ -57,8 +55,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
57
55
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
58
56
|
# @param [Hash] label configures the associated label
|
|
59
57
|
# @option label text [String] the label text
|
|
60
|
-
# @option label size [String] the size of the label font, can be +
|
|
61
|
-
# @option label weight [String] the weight of the label font, can be +bold+ or +regular+
|
|
58
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
62
59
|
# @option args [Hash] args additional arguments are applied as attributes to +input+ element
|
|
63
60
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
64
61
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
@@ -80,8 +77,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
80
77
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
81
78
|
# @param [Hash] label configures the associated label
|
|
82
79
|
# @option label text [String] the label text
|
|
83
|
-
# @option label size [String] the size of the label font, can be +
|
|
84
|
-
# @option label weight [String] the weight of the label font, can be +bold+ or +regular+
|
|
80
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
85
81
|
# @option args [Hash] args additional arguments are applied as attributes to +input+ element
|
|
86
82
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
87
83
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
@@ -103,8 +99,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
103
99
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
104
100
|
# @param [Hash] label configures the associated label
|
|
105
101
|
# @option label text [String] the label text
|
|
106
|
-
# @option label size [String] the size of the label font, can be +
|
|
107
|
-
# @option label weight [String] the weight of the label font, can be +bold+ or +regular+
|
|
102
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
108
103
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
|
109
104
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
110
105
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
@@ -128,8 +123,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
128
123
|
# @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
|
|
129
124
|
# @param [Hash] label configures the associated label
|
|
130
125
|
# @option label text [String] the label text
|
|
131
|
-
# @option label size [String] the size of the label font, can be +
|
|
132
|
-
# @option label weight [String] the weight of the label font, can be +bold+ or +regular+
|
|
126
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
133
127
|
# @param max_words [Integer] adds the GOV.UK max word count
|
|
134
128
|
# @param max_chars [Integer] adds the GOV.UK max characters count
|
|
135
129
|
# @param threshold [Integer] only show the +max_words+ and +max_chars+ warnings once a threshold (percentage) is reached
|
|
@@ -157,8 +151,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
157
151
|
# @param text_method [Symbol] The method called against each member of the collection to provide the text
|
|
158
152
|
# @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
|
|
159
153
|
# @option label text [String] the label text
|
|
160
|
-
# @option label size [String] the size of the label font, can be +
|
|
161
|
-
# @option label weight [String] the weight of the label font, can be +bold+ or +regular+
|
|
154
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
162
155
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
163
156
|
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: { class: 'govuk-select' }, hint_text: nil, label: {})
|
|
164
157
|
label_element = Elements::Label.new(self, object_name, attribute_name, label)
|
|
@@ -205,6 +198,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
205
198
|
# @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
|
|
206
199
|
# @param legend [Hash] options for configuring the hash
|
|
207
200
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
|
201
|
+
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
|
208
202
|
# @option legend text [String] the fieldset legend's text content
|
|
209
203
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
210
204
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+, defaults to +h1+
|
|
@@ -225,7 +219,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
225
219
|
# legend: { text: 'Pick your favourite colour', size: 'm' },
|
|
226
220
|
# hint_text: 'If you cannot find the exact match choose something close',
|
|
227
221
|
# inline: false
|
|
228
|
-
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: { text: nil, size: 'm' }, inline: false)
|
|
222
|
+
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: { text: nil, size: 'm' }, inline: false, small: false)
|
|
229
223
|
hint_element = Elements::Hint.new(self, object_name, attribute_name, hint_text)
|
|
230
224
|
error_element = Elements::ErrorMessage.new(self, object_name, attribute_name)
|
|
231
225
|
|
|
@@ -237,7 +231,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
237
231
|
error_element.html,
|
|
238
232
|
|
|
239
233
|
(yield if block_given?),
|
|
240
|
-
Containers::Radios.new(self, inline: inline).html do
|
|
234
|
+
Containers::Radios.new(self, inline: inline, small: small).html do
|
|
241
235
|
safe_join(
|
|
242
236
|
collection.map do |item|
|
|
243
237
|
Elements::Radios::CollectionRadio.new(self, object_name, attribute_name, item, value_method, text_method, hint_method).html
|
|
@@ -258,6 +252,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
258
252
|
# @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
|
|
259
253
|
# @param legend [Hash] options for configuring the hash
|
|
260
254
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
|
255
|
+
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
|
261
256
|
# @option legend text [String] the fieldset legend's text content
|
|
262
257
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
263
258
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
|
@@ -272,7 +267,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
272
267
|
# = f.govuk_radio_divider
|
|
273
268
|
# = f.govuk_radio_button :favourite_colour, :yellow, label: { text: 'Yellow' }
|
|
274
269
|
#
|
|
275
|
-
def govuk_radio_buttons_fieldset(attribute_name,
|
|
270
|
+
def govuk_radio_buttons_fieldset(attribute_name, hint_text: nil, legend: {}, inline: false, small: false)
|
|
276
271
|
hint_element = Elements::Hint.new(self, object_name, attribute_name, hint_text)
|
|
277
272
|
error_element = Elements::ErrorMessage.new(self, object_name, attribute_name)
|
|
278
273
|
|
|
@@ -281,7 +276,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
281
276
|
safe_join([
|
|
282
277
|
hint_element.html,
|
|
283
278
|
error_element.html,
|
|
284
|
-
Containers::Radios.new(self, inline: inline).html do
|
|
279
|
+
Containers::Radios.new(self, inline: inline, small: small).html do
|
|
285
280
|
yield
|
|
286
281
|
end
|
|
287
282
|
])
|
|
@@ -331,6 +326,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
331
326
|
# @param text_method [Symbol] The method called against each member of the collection to provide the text
|
|
332
327
|
# @param hint_method [Symbol] The method called against each member of the collection to provide the hint text
|
|
333
328
|
# @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
|
|
329
|
+
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
|
334
330
|
# @param legend [Hash] options for configuring the hash
|
|
335
331
|
# @option legend text [String] the fieldset legend's text content
|
|
336
332
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
@@ -353,7 +349,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
353
349
|
# legend: { text: 'What do you want in your sandwich?', size: 'm' },
|
|
354
350
|
# hint_text: "If it isn't listed here, tough luck",
|
|
355
351
|
# inline: false
|
|
356
|
-
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, &block)
|
|
352
|
+
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, small: false, &block)
|
|
357
353
|
hint_element = Elements::Hint.new(self, object_name, attribute_name, hint_text)
|
|
358
354
|
error_element = Elements::ErrorMessage.new(self, object_name, attribute_name)
|
|
359
355
|
|
|
@@ -364,8 +360,10 @@ module GOVUKDesignSystemFormBuilder
|
|
|
364
360
|
hint_element.html,
|
|
365
361
|
error_element.html,
|
|
366
362
|
(block.call if block_given?),
|
|
367
|
-
|
|
368
|
-
|
|
363
|
+
Containers::CheckBoxes.new(self, small: small).html do
|
|
364
|
+
collection_check_boxes(attribute_name, collection, value_method, text_method) do |check_box|
|
|
365
|
+
Elements::CheckBoxes::CollectionCheckBox.new(self, attribute_name, check_box, hint_method).html
|
|
366
|
+
end
|
|
369
367
|
end
|
|
370
368
|
]
|
|
371
369
|
)
|
|
@@ -382,6 +380,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
382
380
|
# should probably be supported too
|
|
383
381
|
# @param prevent_double_click [Boolean] adds JavaScript to safeguard the
|
|
384
382
|
# form from being submitted more than once
|
|
383
|
+
# @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
|
|
384
|
+
# client-side validation provided by the browser. This is to provide a more consistent and accessible user
|
|
385
|
+
# experience
|
|
385
386
|
# @param block [Block] Any supplied HTML will be inserted immediately after
|
|
386
387
|
# the submit button. It is intended for other buttons directly related to
|
|
387
388
|
# the form's operation, such as 'Cancel' or 'Safe draft'
|
|
@@ -448,6 +449,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
448
449
|
# Generates a fieldset containing the contents of the block
|
|
449
450
|
#
|
|
450
451
|
# @param legend [Hash] options for configuring the hash
|
|
452
|
+
# @param described_by [Array<String>] the ids of the elements that describe this fieldset, usually hints and errors
|
|
451
453
|
# @option legend text [String] the fieldset legend's text content
|
|
452
454
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
453
455
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
|
@@ -460,8 +462,8 @@ module GOVUKDesignSystemFormBuilder
|
|
|
460
462
|
#
|
|
461
463
|
# @see https://design-system.service.gov.uk/components/fieldset/ GOV.UK fieldset
|
|
462
464
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
463
|
-
def govuk_fieldset(legend: { text: 'Fieldset heading' }, &block)
|
|
464
|
-
Containers::Fieldset.new(self, legend: legend).html(&block)
|
|
465
|
+
def govuk_fieldset(legend: { text: 'Fieldset heading' }, described_by: nil, &block)
|
|
466
|
+
Containers::Fieldset.new(self, legend: legend, described_by: described_by).html(&block)
|
|
465
467
|
end
|
|
466
468
|
end
|
|
467
469
|
end
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Containers
|
|
3
3
|
class CheckBoxes < Base
|
|
4
|
-
def initialize(builder)
|
|
4
|
+
def initialize(builder, small:)
|
|
5
5
|
@builder = builder
|
|
6
|
+
@small = small
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
def html
|
|
9
|
-
@builder.content_tag('div', class:
|
|
10
|
+
@builder.content_tag('div', class: check_boxes_classes, data: { module: 'checkboxes' }) do
|
|
10
11
|
yield
|
|
11
12
|
end
|
|
12
13
|
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def check_boxes_classes
|
|
18
|
+
%w(govuk-checkboxes).tap do |c|
|
|
19
|
+
c.push('govuk-checkboxes--small') if @small
|
|
20
|
+
end
|
|
21
|
+
end
|
|
13
22
|
end
|
|
14
23
|
end
|
|
15
24
|
end
|
|
@@ -2,8 +2,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Containers
|
|
3
3
|
class Fieldset < GOVUKDesignSystemFormBuilder::Base
|
|
4
4
|
LEGEND_DEFAULTS = { text: nil, tag: 'h1', size: 'xl' }.freeze
|
|
5
|
-
|
|
6
|
-
# FIXME standardise sizes with labels
|
|
7
5
|
LEGEND_SIZES = %w(xl l m s).freeze
|
|
8
6
|
|
|
9
7
|
def initialize(builder, legend: {}, described_by: nil)
|
|
@@ -49,7 +47,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
49
47
|
def descriptors(described_by)
|
|
50
48
|
return nil unless described_by.present?
|
|
51
49
|
|
|
52
|
-
|
|
50
|
+
described_by.compact.join(' ').presence
|
|
53
51
|
end
|
|
54
52
|
end
|
|
55
53
|
end
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Containers
|
|
3
3
|
class Radios < GOVUKDesignSystemFormBuilder::Base
|
|
4
|
-
def initialize(builder, inline:)
|
|
4
|
+
def initialize(builder, inline:, small:)
|
|
5
5
|
@builder = builder
|
|
6
|
-
@inline
|
|
6
|
+
@inline = inline
|
|
7
|
+
@small = small
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
def html
|
|
@@ -17,6 +18,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
17
18
|
def radios_classes
|
|
18
19
|
%w(govuk-radios).tap do |c|
|
|
19
20
|
c.push('govuk-radios--inline') if @inline
|
|
21
|
+
c.push('govuk-radios--small') if @small
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
end
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
3
|
class Label < GOVUKDesignSystemFormBuilder::Base
|
|
4
|
-
def initialize(builder, object_name, attribute_name, text: nil, value: nil, size:
|
|
4
|
+
def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, radio: false, checkbox: false)
|
|
5
5
|
super(builder, object_name, attribute_name)
|
|
6
6
|
|
|
7
7
|
@text = label_text(text)
|
|
8
8
|
@value = value # used by attribute_descriptor
|
|
9
9
|
@size_class = label_size_class(size)
|
|
10
|
-
@weight_class = label_weight_class(weight)
|
|
11
10
|
@radio_class = radio_class(radio)
|
|
12
11
|
@checkbox_class = checkbox_class(checkbox)
|
|
13
12
|
end
|
|
@@ -39,21 +38,13 @@ module GOVUKDesignSystemFormBuilder
|
|
|
39
38
|
|
|
40
39
|
def label_size_class(size)
|
|
41
40
|
case size
|
|
42
|
-
when '
|
|
43
|
-
when '
|
|
44
|
-
when '
|
|
45
|
-
when '
|
|
41
|
+
when 'xl' then "govuk-label--xl"
|
|
42
|
+
when 'l' then "govuk-label--l"
|
|
43
|
+
when 'm' then "govuk-label--m"
|
|
44
|
+
when 's' then "govuk-label--s"
|
|
45
|
+
when nil then nil
|
|
46
46
|
else
|
|
47
|
-
fail
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def label_weight_class(weight)
|
|
52
|
-
case weight
|
|
53
|
-
when 'bold' then "govuk-!-font-weight-bold"
|
|
54
|
-
when 'regular' then nil
|
|
55
|
-
else
|
|
56
|
-
fail 'weight must be bold or regular'
|
|
47
|
+
fail "size must be either 'xl', 'l', 'm', 's' or nil"
|
|
57
48
|
end
|
|
58
49
|
end
|
|
59
50
|
end
|