govuk_design_system_formbuilder 1.1.11 → 1.2.0b1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/govuk_design_system_formbuilder/base.rb +12 -0
- data/lib/govuk_design_system_formbuilder/builder.rb +1 -1
- data/lib/govuk_design_system_formbuilder/containers/character_count.rb +2 -2
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +5 -3
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +10 -9
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +4 -2
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +7 -5
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +4 -2
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +5 -3
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/label.rb +3 -1
- data/lib/govuk_design_system_formbuilder/elements/date.rb +9 -7
- data/lib/govuk_design_system_formbuilder/elements/error_message.rb +4 -2
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +4 -4
- data/lib/govuk_design_system_formbuilder/elements/file.rb +4 -2
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +5 -3
- data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/password.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/label.rb +11 -9
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +4 -2
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +5 -3
- data/lib/govuk_design_system_formbuilder/elements/select.rb +4 -2
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +7 -6
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +10 -4
- data/lib/govuk_design_system_formbuilder/traits/input.rb +14 -14
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- data/lib/govuk_design_system_formbuilder.rb +5 -0
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b26402e9e41729882759af55f46d0ca77021301c3e47d1fdf71674a5b7e10635
|
4
|
+
data.tar.gz: 29f61cc4bb6086cf19c08f57648be973aab134ef8a0b1ebded5a175cb8f79564
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5c38d0cc478cddeb01c6624abb8b4bced314197bd6e1f788a36d94f8ca5c62d2c19a2da96a7e7a3c2555af994a07cf3b10d4ed83dd270135e3af86157c11f6f
|
7
|
+
data.tar.gz: 95ca19e5a70cfc2f163e3ffadbd59b9644dc9f471723f468b56ea3e2d8a15c10761f651fc522ccf220a20c7b607083d3a0d71048d2ba240d5562e2cb06b2fae1
|
@@ -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
|
@@ -660,7 +660,7 @@ module GOVUKDesignSystemFormBuilder
|
|
660
660
|
# @see https://design-system.service.gov.uk/components/fieldset/ GOV.UK fieldset
|
661
661
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
662
662
|
def govuk_fieldset(legend: { text: 'Fieldset heading' }, described_by: nil, &block)
|
663
|
-
Containers::Fieldset.new(self, legend: legend, described_by: described_by
|
663
|
+
Containers::Fieldset.new(self, legend: legend, described_by: described_by).html(&block)
|
664
664
|
end
|
665
665
|
|
666
666
|
# Generates an input of type +file+
|
@@ -16,8 +16,8 @@ module GOVUKDesignSystemFormBuilder
|
|
16
16
|
|
17
17
|
content_tag(
|
18
18
|
'div',
|
19
|
-
class:
|
20
|
-
data: { module:
|
19
|
+
class: %(#{brand}-character-count),
|
20
|
+
data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact
|
21
21
|
) do
|
22
22
|
yield
|
23
23
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Containers
|
3
3
|
class CheckBoxes < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
def initialize(builder, small:, classes: nil)
|
5
7
|
@builder = builder
|
6
8
|
@small = small
|
@@ -8,7 +10,7 @@ module GOVUKDesignSystemFormBuilder
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def html
|
11
|
-
content_tag('div', class: check_boxes_classes, data: { module:
|
13
|
+
content_tag('div', class: check_boxes_classes, data: { module: %(#{brand}-checkboxes) }) do
|
12
14
|
yield
|
13
15
|
end
|
14
16
|
end
|
@@ -16,8 +18,8 @@ module GOVUKDesignSystemFormBuilder
|
|
16
18
|
private
|
17
19
|
|
18
20
|
def check_boxes_classes
|
19
|
-
%w(
|
20
|
-
c.push(
|
21
|
+
%w(checkboxes).prefix(brand).tap do |c|
|
22
|
+
c.push(%(#{brand}-checkboxes--small)) if @small
|
21
23
|
c.push(@classes) if @classes
|
22
24
|
end
|
23
25
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Containers
|
3
3
|
class Fieldset < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
include Traits::Localisation
|
5
7
|
|
6
8
|
LEGEND_SIZES = %w(xl l m s).freeze
|
7
9
|
|
8
|
-
def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, described_by: nil
|
9
|
-
super(builder, object_name, attribute_name
|
10
|
+
def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, described_by: nil)
|
11
|
+
super(builder, object_name, attribute_name)
|
10
12
|
|
11
13
|
@legend = legend_defaults.merge(legend)
|
12
14
|
@described_by = described_by(described_by)
|
@@ -15,7 +17,7 @@ module GOVUKDesignSystemFormBuilder
|
|
15
17
|
|
16
18
|
def html
|
17
19
|
content_tag('fieldset', class: fieldset_classes, aria: { describedby: @described_by }) do
|
18
|
-
safe_join([build_legend,
|
20
|
+
safe_join([build_legend, yield])
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -43,21 +45,20 @@ module GOVUKDesignSystemFormBuilder
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def fieldset_classes
|
46
|
-
%w(
|
48
|
+
%w(fieldset).prefix(brand)
|
47
49
|
end
|
48
50
|
|
49
51
|
def legend_classes
|
50
52
|
size = @legend.dig(:size)
|
51
53
|
fail "invalid size '#{size}', must be #{LEGEND_SIZES.join(', ')}" unless size.in?(LEGEND_SIZES)
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
classes
|
55
|
+
[%(fieldset__legend), %(fieldset__legend--#{size})].prefix(brand).tap do |classes|
|
56
|
+
classes.push(%(#{brand}-visually-hidden)) if @legend.dig(:hidden)
|
57
|
+
end
|
57
58
|
end
|
58
59
|
|
59
60
|
def legend_heading_classes
|
60
|
-
%(
|
61
|
+
%w(fieldset__heading).prefix(brand)
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Containers
|
3
3
|
class FormGroup < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
def initialize(builder, object_name, attribute_name)
|
5
7
|
super(builder, object_name, attribute_name)
|
6
8
|
end
|
@@ -14,8 +16,8 @@ module GOVUKDesignSystemFormBuilder
|
|
14
16
|
private
|
15
17
|
|
16
18
|
def form_group_classes
|
17
|
-
%w(
|
18
|
-
classes.push(
|
19
|
+
%w(form-group).prefix(brand).tap do |classes|
|
20
|
+
classes.push(%(#{brand}-form-group--error)) if has_errors?
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Containers
|
3
3
|
class Radios < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
include Traits::Hint
|
5
7
|
|
6
8
|
def initialize(builder, inline:, small:, classes:)
|
@@ -11,7 +13,7 @@ module GOVUKDesignSystemFormBuilder
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def html
|
14
|
-
content_tag('div', class: radios_classes, data: { module:
|
16
|
+
content_tag('div', class: radios_classes, data: { module: %(#{brand}-radios) }) do
|
15
17
|
yield
|
16
18
|
end
|
17
19
|
end
|
@@ -19,10 +21,10 @@ module GOVUKDesignSystemFormBuilder
|
|
19
21
|
private
|
20
22
|
|
21
23
|
def radios_classes
|
22
|
-
%w(
|
23
|
-
c.push(
|
24
|
-
c.push(
|
25
|
-
c.push(@classes)
|
24
|
+
%w(radios).prefix(brand).tap do |c|
|
25
|
+
c.push(%(#{brand}-radios--inline)) if @inline
|
26
|
+
c.push(%(#{brand}-radios--small)) if @small
|
27
|
+
c.push(@classes) if @classes
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
3
3
|
module CheckBoxes
|
4
4
|
class CollectionCheckBox < Base
|
5
|
+
using PrefixableArray
|
6
|
+
|
5
7
|
include Traits::CollectionItem
|
6
8
|
include Traits::Hint
|
7
9
|
|
@@ -16,12 +18,12 @@ module GOVUKDesignSystemFormBuilder
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def html
|
19
|
-
content_tag('div', class:
|
21
|
+
content_tag('div', class: %(#{brand}-checkboxes__item)) do
|
20
22
|
safe_join(
|
21
23
|
[
|
22
24
|
@checkbox.check_box(
|
23
25
|
id: field_id(link_errors: @link_errors),
|
24
|
-
class:
|
26
|
+
class: %(#{brand}-checkboxes__input),
|
25
27
|
aria: { describedby: hint_id }
|
26
28
|
),
|
27
29
|
label_element.html,
|
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
3
3
|
module CheckBoxes
|
4
4
|
class FieldsetCheckBox < Base
|
5
|
+
using PrefixableArray
|
6
|
+
|
5
7
|
include Traits::Hint
|
6
8
|
include Traits::Conditional
|
7
9
|
|
@@ -23,7 +25,7 @@ module GOVUKDesignSystemFormBuilder
|
|
23
25
|
def html
|
24
26
|
safe_join(
|
25
27
|
[
|
26
|
-
content_tag('div', class:
|
28
|
+
content_tag('div', class: %(#{brand}-checkboxes__item)) do
|
27
29
|
safe_join(
|
28
30
|
[
|
29
31
|
input,
|
@@ -63,11 +65,11 @@ module GOVUKDesignSystemFormBuilder
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def conditional_classes
|
66
|
-
%w(
|
68
|
+
%w(checkboxes__conditional checkboxes__conditional--hidden).prefix(brand)
|
67
69
|
end
|
68
70
|
|
69
71
|
def check_box_classes
|
70
|
-
%w(
|
72
|
+
%w(checkboxes__input).prefix(brand)
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
3
3
|
module CheckBoxes
|
4
4
|
class Label < Base
|
5
|
+
using PrefixableArray
|
6
|
+
|
5
7
|
include Traits::Localisation
|
6
8
|
|
7
9
|
def initialize(builder, object_name, attribute_name, checkbox, value:, link_errors: true)
|
@@ -21,7 +23,7 @@ module GOVUKDesignSystemFormBuilder
|
|
21
23
|
private
|
22
24
|
|
23
25
|
def label_classes
|
24
|
-
%w(
|
26
|
+
%w(label checkboxes__label).prefix(brand)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Elements
|
3
3
|
class Date < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
include Traits::Error
|
5
7
|
include Traits::Hint
|
6
8
|
include Traits::Supplemental
|
@@ -24,7 +26,7 @@ module GOVUKDesignSystemFormBuilder
|
|
24
26
|
supplemental_content.html,
|
25
27
|
hint_element.html,
|
26
28
|
error_element.html,
|
27
|
-
content_tag('div', class:
|
29
|
+
content_tag('div', class: %(#{brand}-date-input)) do
|
28
30
|
safe_join([day, month, year])
|
29
31
|
end
|
30
32
|
]
|
@@ -56,8 +58,8 @@ module GOVUKDesignSystemFormBuilder
|
|
56
58
|
def date_input_item(segment, width: 2, link_errors: false)
|
57
59
|
value = @builder.object.try(@attribute_name).try(segment)
|
58
60
|
|
59
|
-
content_tag('div', class: %w(
|
60
|
-
content_tag('div', class: %w(
|
61
|
+
content_tag('div', class: %w(date-input__item).prefix(brand)) do
|
62
|
+
content_tag('div', class: %w(form-group).prefix(brand)) do
|
61
63
|
safe_join(
|
62
64
|
[
|
63
65
|
tag.label(
|
@@ -83,14 +85,14 @@ module GOVUKDesignSystemFormBuilder
|
|
83
85
|
end
|
84
86
|
|
85
87
|
def date_input_classes(width)
|
86
|
-
%w(
|
87
|
-
classes.push(
|
88
|
-
classes.push(
|
88
|
+
%w(input date-input__input).prefix(brand).tap do |classes|
|
89
|
+
classes.push(%(#{brand}-input--width-#{width}))
|
90
|
+
classes.push(%(#{brand}-input--error)) if has_errors?
|
89
91
|
end
|
90
92
|
end
|
91
93
|
|
92
94
|
def date_input_label_classes
|
93
|
-
%w(
|
95
|
+
%w(label date-input__label).prefix(brand)
|
94
96
|
end
|
95
97
|
|
96
98
|
# if the field has errors we want the govuk_error_summary to
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Elements
|
3
3
|
class ErrorMessage < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
include Traits::Error
|
5
7
|
|
6
8
|
def initialize(builder, object_name, attribute_name)
|
@@ -10,10 +12,10 @@ module GOVUKDesignSystemFormBuilder
|
|
10
12
|
def html
|
11
13
|
return nil unless has_errors?
|
12
14
|
|
13
|
-
content_tag('span', class:
|
15
|
+
content_tag('span', class: %(#{brand}-error-message), id: error_id) do
|
14
16
|
safe_join(
|
15
17
|
[
|
16
|
-
tag.span('Error: ', class:
|
18
|
+
tag.span('Error: ', class: %(#{brand}-visually-hidden)),
|
17
19
|
message
|
18
20
|
]
|
19
21
|
)
|
@@ -17,7 +17,7 @@ module GOVUKDesignSystemFormBuilder
|
|
17
17
|
[
|
18
18
|
tag.h2(@title, id: error_summary_title_id, class: summary_class('title')),
|
19
19
|
content_tag('div', class: summary_class('body')) do
|
20
|
-
content_tag('ul', class: [
|
20
|
+
content_tag('ul', class: [%(#{brand}-list), summary_class('list')]) do
|
21
21
|
safe_join(
|
22
22
|
@builder.object.errors.messages.map do |attribute, messages|
|
23
23
|
error_list_item(attribute, messages.first)
|
@@ -50,9 +50,9 @@ module GOVUKDesignSystemFormBuilder
|
|
50
50
|
|
51
51
|
def summary_class(part = nil)
|
52
52
|
if part
|
53
|
-
|
53
|
+
%(#{brand}-error-summary).concat('__', part)
|
54
54
|
else
|
55
|
-
|
55
|
+
%(#{brand}-error-summary)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -73,7 +73,7 @@ module GOVUKDesignSystemFormBuilder
|
|
73
73
|
tabindex: -1,
|
74
74
|
role: 'alert',
|
75
75
|
data: {
|
76
|
-
module:
|
76
|
+
module: %(#{brand}-error-summary)
|
77
77
|
},
|
78
78
|
aria: {
|
79
79
|
labelledby: error_summary_title_id
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Elements
|
3
3
|
class File < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
include Traits::Error
|
5
7
|
include Traits::Hint
|
6
8
|
include Traits::Label
|
@@ -37,8 +39,8 @@ module GOVUKDesignSystemFormBuilder
|
|
37
39
|
private
|
38
40
|
|
39
41
|
def file_classes
|
40
|
-
%w(
|
41
|
-
c.push(
|
42
|
+
%w(file-upload).prefix(brand).tap do |c|
|
43
|
+
c.push(%(#{brand}-file-upload--error)) if has_errors?
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Elements
|
3
3
|
class Hint < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
include Traits::Hint
|
5
7
|
include Traits::Localisation
|
6
8
|
|
@@ -29,15 +31,15 @@ module GOVUKDesignSystemFormBuilder
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def hint_classes
|
32
|
-
%w(
|
34
|
+
%w(hint).prefix(brand).push(@radio_class, @checkbox_class).compact
|
33
35
|
end
|
34
36
|
|
35
37
|
def radio_class(radio)
|
36
|
-
radio ?
|
38
|
+
radio ? %(#{brand}-radios__hint) : nil
|
37
39
|
end
|
38
40
|
|
39
41
|
def checkbox_class(checkbox)
|
40
|
-
checkbox ?
|
42
|
+
checkbox ? %(#{brand}-checkboxes__hint) : nil
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Elements
|
3
3
|
class Label < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
include Traits::Localisation
|
5
7
|
|
6
8
|
def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true)
|
@@ -19,7 +21,7 @@ module GOVUKDesignSystemFormBuilder
|
|
19
21
|
return nil if @text.blank?
|
20
22
|
|
21
23
|
if @tag.present?
|
22
|
-
content_tag(@tag, class:
|
24
|
+
content_tag(@tag, class: %(#{brand}-label-wrapper)) { build_label }
|
23
25
|
else
|
24
26
|
build_label
|
25
27
|
end
|
@@ -32,7 +34,7 @@ module GOVUKDesignSystemFormBuilder
|
|
32
34
|
@attribute_name,
|
33
35
|
value: @value,
|
34
36
|
for: field_id(link_errors: @link_errors),
|
35
|
-
class: %w(
|
37
|
+
class: %w(label).prefix(brand).push(@size_class, @weight_class, @radio_class, @checkbox_class).compact
|
36
38
|
) do
|
37
39
|
@text
|
38
40
|
end
|
@@ -42,26 +44,26 @@ module GOVUKDesignSystemFormBuilder
|
|
42
44
|
text = [option_text, localised_text(:label), @attribute_name.capitalize].compact.first.to_s
|
43
45
|
|
44
46
|
if hidden
|
45
|
-
tag.span(text, class: %w(
|
47
|
+
tag.span(text, class: %w(visually-hidden).prefix(brand))
|
46
48
|
else
|
47
49
|
text
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
53
|
def radio_class(radio)
|
52
|
-
radio ?
|
54
|
+
radio ? %(#{brand}-radios__label) : nil
|
53
55
|
end
|
54
56
|
|
55
57
|
def checkbox_class(checkbox)
|
56
|
-
checkbox ?
|
58
|
+
checkbox ? %(#{brand}-checkboxes__label) : nil
|
57
59
|
end
|
58
60
|
|
59
61
|
def label_size_class(size)
|
60
62
|
case size
|
61
|
-
when 'xl' then
|
62
|
-
when 'l' then
|
63
|
-
when 'm' then
|
64
|
-
when 's' then
|
63
|
+
when 'xl' then %(#{brand}-label--xl)
|
64
|
+
when 'l' then %(#{brand}-label--l)
|
65
|
+
when 'm' then %(#{brand}-label--m)
|
66
|
+
when 's' then %(#{brand}-label--s)
|
65
67
|
when nil then nil
|
66
68
|
else
|
67
69
|
fail "invalid size '#{size}', must be xl, l, m, s or nil"
|
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
3
3
|
module Radios
|
4
4
|
class CollectionRadioButton < Base
|
5
|
+
using PrefixableArray
|
6
|
+
|
5
7
|
include Traits::Hint
|
6
8
|
include Traits::CollectionItem
|
7
9
|
|
@@ -21,7 +23,7 @@ module GOVUKDesignSystemFormBuilder
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def html
|
24
|
-
content_tag('div', class:
|
26
|
+
content_tag('div', class: %(#{brand}-radios__item)) do
|
25
27
|
safe_join(
|
26
28
|
[
|
27
29
|
@builder.radio_button(
|
@@ -29,7 +31,7 @@ module GOVUKDesignSystemFormBuilder
|
|
29
31
|
@value,
|
30
32
|
id: field_id(link_errors: @link_errors),
|
31
33
|
aria: { describedby: hint_id },
|
32
|
-
class: %w(
|
34
|
+
class: %w(radios__input).prefix(brand)
|
33
35
|
),
|
34
36
|
label_element.html,
|
35
37
|
hint_element.html
|
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
3
3
|
module Radios
|
4
4
|
class FieldsetRadioButton < Base
|
5
|
+
using PrefixableArray
|
6
|
+
|
5
7
|
include Traits::Hint
|
6
8
|
include Traits::Conditional
|
7
9
|
|
@@ -22,7 +24,7 @@ module GOVUKDesignSystemFormBuilder
|
|
22
24
|
def html
|
23
25
|
safe_join(
|
24
26
|
[
|
25
|
-
content_tag('div', class:
|
27
|
+
content_tag('div', class: %(#{brand}-radios__item)) do
|
26
28
|
safe_join(
|
27
29
|
[
|
28
30
|
input,
|
@@ -53,12 +55,12 @@ module GOVUKDesignSystemFormBuilder
|
|
53
55
|
id: field_id(link_errors: @link_errors),
|
54
56
|
aria: { describedby: hint_id },
|
55
57
|
data: { 'aria-controls' => @conditional_id },
|
56
|
-
class: %w(
|
58
|
+
class: %w(radios__input).prefix(brand)
|
57
59
|
)
|
58
60
|
end
|
59
61
|
|
60
62
|
def conditional_classes
|
61
|
-
%w(
|
63
|
+
%w(radios__conditional radios__conditional--hidden).prefix(brand)
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Elements
|
3
3
|
class Select < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
include Traits::Error
|
5
7
|
include Traits::Label
|
6
8
|
include Traits::Hint
|
@@ -50,8 +52,8 @@ module GOVUKDesignSystemFormBuilder
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def select_classes
|
53
|
-
%w(
|
54
|
-
classes.push(
|
55
|
+
%w(select).prefix(brand).tap do |classes|
|
56
|
+
classes.push(%(#{brand}-select--error)) if has_errors?
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Elements
|
3
3
|
class Submit < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
def initialize(builder, text, warning:, secondary:, classes:, prevent_double_click:, validate:, &block)
|
5
7
|
fail ArgumentError, 'buttons can be warning or secondary' if warning && secondary
|
6
8
|
|
@@ -19,7 +21,7 @@ module GOVUKDesignSystemFormBuilder
|
|
19
21
|
[
|
20
22
|
@builder.submit(
|
21
23
|
@text,
|
22
|
-
class: %w(
|
24
|
+
class: %w(button).prefix(brand).push(
|
23
25
|
warning_class,
|
24
26
|
secondary_class,
|
25
27
|
@classes,
|
@@ -35,23 +37,22 @@ module GOVUKDesignSystemFormBuilder
|
|
35
37
|
private
|
36
38
|
|
37
39
|
def warning_class
|
38
|
-
|
40
|
+
%(#{brand}-button--warning) if @warning
|
39
41
|
end
|
40
42
|
|
41
43
|
def secondary_class
|
42
|
-
|
44
|
+
%(#{brand}-button--secondary) if @secondary
|
43
45
|
end
|
44
46
|
|
45
47
|
def padding_class(content_present)
|
46
|
-
|
48
|
+
%(#{brand}-!-margin-right-1) if content_present
|
47
49
|
end
|
48
50
|
|
49
51
|
def extra_args
|
50
52
|
{
|
51
53
|
formnovalidate: !@validate,
|
52
54
|
data: {
|
53
|
-
module:
|
54
|
-
'prevent-double-click' => @prevent_double_click
|
55
|
+
module: %(#{brand}-button), 'prevent-double-click' => @prevent_double_click
|
55
56
|
}.select { |_k, v| v.present? }
|
56
57
|
}
|
57
58
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Elements
|
3
3
|
class TextArea < Base
|
4
|
+
using PrefixableArray
|
5
|
+
|
4
6
|
include Traits::Error
|
5
7
|
include Traits::Hint
|
6
8
|
include Traits::Label
|
@@ -48,9 +50,9 @@ module GOVUKDesignSystemFormBuilder
|
|
48
50
|
private
|
49
51
|
|
50
52
|
def govuk_textarea_classes
|
51
|
-
%w(
|
52
|
-
classes.push(
|
53
|
-
classes.push(
|
53
|
+
%w(textarea).prefix(brand).tap do |classes|
|
54
|
+
classes.push(%(#{brand}-textarea--error)) if has_errors?
|
55
|
+
classes.push(%(#{brand}-js-character-count)) if limit?
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
@@ -69,11 +71,15 @@ module GOVUKDesignSystemFormBuilder
|
|
69
71
|
def limit_description
|
70
72
|
return nil unless limit?
|
71
73
|
|
72
|
-
content_tag('span', id: limit_id, class:
|
74
|
+
content_tag('span', id: limit_id, class: limit_description_classes, aria: { live: 'polite' }) do
|
73
75
|
"You can enter up to #{limit_quantity} #{limit_type}"
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
79
|
+
def limit_description_classes
|
80
|
+
%w(hint character-count__message).prefix(brand)
|
81
|
+
end
|
82
|
+
|
77
83
|
def limit_quantity
|
78
84
|
@max_words || @max_chars
|
79
85
|
end
|
@@ -40,11 +40,11 @@ module GOVUKDesignSystemFormBuilder
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def input_classes
|
43
|
-
%
|
43
|
+
[%(#{brand}-input)].push(width_classes, error_classes).compact
|
44
44
|
end
|
45
45
|
|
46
46
|
def error_classes
|
47
|
-
|
47
|
+
%(#{brand}-input--error) if has_errors?
|
48
48
|
end
|
49
49
|
|
50
50
|
def width_classes
|
@@ -53,20 +53,20 @@ module GOVUKDesignSystemFormBuilder
|
|
53
53
|
case @width
|
54
54
|
|
55
55
|
# fixed (character) widths
|
56
|
-
when 20 then
|
57
|
-
when 10 then
|
58
|
-
when 5 then
|
59
|
-
when 4 then
|
60
|
-
when 3 then
|
61
|
-
when 2 then
|
56
|
+
when 20 then %(#{brand}-input--width-20)
|
57
|
+
when 10 then %(#{brand}-input--width-10)
|
58
|
+
when 5 then %(#{brand}-input--width-5)
|
59
|
+
when 4 then %(#{brand}-input--width-4)
|
60
|
+
when 3 then %(#{brand}-input--width-3)
|
61
|
+
when 2 then %(#{brand}-input--width-2)
|
62
62
|
|
63
63
|
# fluid widths
|
64
|
-
when 'full' then
|
65
|
-
when 'three-quarters' then
|
66
|
-
when 'two-thirds' then
|
67
|
-
when 'one-half' then
|
68
|
-
when 'one-third' then
|
69
|
-
when 'one-quarter' then
|
64
|
+
when 'full' then %(#{brand}-!-width-full)
|
65
|
+
when 'three-quarters' then %(#{brand}-!-width-three-quarters)
|
66
|
+
when 'two-thirds' then %(#{brand}-!-width-two-thirds)
|
67
|
+
when 'one-half' then %(#{brand}-!-width-one-half)
|
68
|
+
when 'one-third' then %(#{brand}-!-width-one-third)
|
69
|
+
when 'one-quarter' then %(#{brand}-!-width-one-quarter)
|
70
70
|
|
71
71
|
else fail(ArgumentError, "invalid width '#{@width}'")
|
72
72
|
end
|
@@ -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',
|
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: 1.
|
4
|
+
version: 1.2.0b1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Yates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -142,6 +142,34 @@ dependencies:
|
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: 0.17.1
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: adsf
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 1.4.2
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 1.4.2
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: adsf-live
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 1.4.2
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - "~>"
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 1.4.2
|
145
173
|
- !ruby/object:Gem::Dependency
|
146
174
|
name: htmlbeautifier
|
147
175
|
requirement: !ruby/object:Gem::Requirement
|
@@ -311,9 +339,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
311
339
|
version: '0'
|
312
340
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
313
341
|
requirements:
|
314
|
-
- - "
|
342
|
+
- - ">"
|
315
343
|
- !ruby/object:Gem::Version
|
316
|
-
version:
|
344
|
+
version: 1.3.1
|
317
345
|
requirements: []
|
318
346
|
rubygems_version: 3.0.3
|
319
347
|
signing_key:
|