crown_marketplace_utils 0.1.0.beta.6 → 0.1.0.beta.7
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/Gemfile.lock +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +91 -89
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +24 -22
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/breadcrumbs.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/button.rb +109 -107
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/details.rb +33 -31
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/error_message.rb +49 -47
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/character_count.rb +144 -142
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/checkboxes.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb +126 -124
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +75 -73
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb +137 -135
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/radios.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb +111 -109
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +86 -84
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +181 -179
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/fieldset.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/form_group.rb +37 -35
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/header.rb +142 -140
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/hint.rb +25 -23
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +69 -67
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/notification_banner.rb +121 -119
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +290 -288
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/step_by_step_navigation.rb +187 -185
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/tag.rb +29 -27
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +39 -37
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper.rb +31 -29
- data/lib/crown_marketplace_utils/version.rb +1 -1
- metadata +1 -1
@@ -2,201 +2,203 @@
|
|
2
2
|
|
3
3
|
require_relative '../field'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
concat(
|
45
|
-
if govuk_checkboxes_options[:form]
|
46
|
-
govuk_checkbox_field_form(govuk_checkboxes_options[:form], attribute, items, **govuk_field_options)
|
47
|
-
else
|
48
|
-
govuk_checkbox_field_tag(attribute, items, **govuk_field_options)
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
module Field
|
9
|
+
# = GOV.UK Checkboxes
|
10
|
+
#
|
11
|
+
# This helper is used for generating the checkboxes component from the
|
12
|
+
# {https://design-system.service.gov.uk/components/checkboxes GDS - Components - Checkboxes}
|
13
|
+
#
|
14
|
+
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
15
|
+
|
16
|
+
module Checkboxes
|
17
|
+
include Field
|
18
|
+
|
19
|
+
# Generates the HTML for the GOV.UK Checkboxes component
|
20
|
+
#
|
21
|
+
# @param attribute [String, Symbol] the attribute of the raido buttons
|
22
|
+
# @param items [Array] array of checkbox items, see {_govuk_checkboxes_fields}
|
23
|
+
# @param govuk_checkboxes_options [Hash] options that will be used for the parts of the fieldset, form group, hint and checkbox buttons
|
24
|
+
#
|
25
|
+
# @option govuk_checkboxes_options [String] :error_message (nil) the error message to be displayed
|
26
|
+
# @option govuk_checkboxes_options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
27
|
+
# @option govuk_checkboxes_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
28
|
+
# the checkbox tags and find the error message
|
29
|
+
# @option govuk_checkboxes_options [Hash] :form_group see {govuk_fields}
|
30
|
+
# @option govuk_checkboxes_options [Hash] :fieldset see {govuk_fields}
|
31
|
+
# @option govuk_checkboxes_options [Hash] :hint see {govuk_field}
|
32
|
+
# @option govuk_checkboxes_options [Hash] :checkboxes ({}) the options that will be used when rendering the checkbox buttons.
|
33
|
+
# See {_govuk_checkboxes_fields} for more details.
|
34
|
+
#
|
35
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Checkboxes
|
36
|
+
# which can then be rendered on the page
|
37
|
+
|
38
|
+
def govuk_checkboxes(attribute, items, **govuk_checkboxes_options)
|
39
|
+
govuk_fields(:checkboxes, attribute, **govuk_checkboxes_options) do |govuk_field_options|
|
40
|
+
if govuk_checkboxes_options[:model] || govuk_checkboxes_options[:form]
|
41
|
+
values = (govuk_checkboxes_options[:model] || govuk_checkboxes_options[:form].object).send(attribute) || []
|
42
|
+
items.each { |item| item[:checked] = values.include?(item[:value]) }
|
49
43
|
end
|
50
|
-
)
|
51
|
-
end
|
52
|
-
end
|
53
44
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
# @option (see _govuk_checkboxes_fields)
|
63
|
-
#
|
64
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the checkbox buttons which is used in {govuk_checkboxes}
|
65
|
-
|
66
|
-
def govuk_checkbox_field_tag(attribute, items, **govuk_checkboxes_options)
|
67
|
-
_govuk_checkboxes_fields(items, **govuk_checkboxes_options) do |checkbox_item|
|
68
|
-
govuk_checkbox_item_tag(attribute, checkbox_item)
|
45
|
+
concat(
|
46
|
+
if govuk_checkboxes_options[:form]
|
47
|
+
govuk_checkbox_field_form(govuk_checkboxes_options[:form], attribute, items, **govuk_field_options)
|
48
|
+
else
|
49
|
+
govuk_checkbox_field_tag(attribute, items, **govuk_field_options)
|
50
|
+
end
|
51
|
+
)
|
52
|
+
end
|
69
53
|
end
|
70
|
-
end
|
71
54
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
55
|
+
private
|
56
|
+
|
57
|
+
# Generates the checkboxes HTML for {govuk_checkboxes}
|
58
|
+
#
|
59
|
+
# @param attribute [String, Symbol] the attribute of the raido buttons
|
60
|
+
# @param items [Array] array of checkbox items, see {_govuk_checkboxes_fields}
|
61
|
+
# @param govuk_checkboxes_options [Hash] options that will be used in customising the HTML
|
62
|
+
#
|
63
|
+
# @option (see _govuk_checkboxes_fields)
|
64
|
+
#
|
65
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the checkbox buttons which is used in {govuk_checkboxes}
|
66
|
+
|
67
|
+
def govuk_checkbox_field_tag(attribute, items, **govuk_checkboxes_options)
|
68
|
+
_govuk_checkboxes_fields(items, **govuk_checkboxes_options) do |checkbox_item|
|
69
|
+
govuk_checkbox_item_tag(attribute, checkbox_item)
|
70
|
+
end
|
84
71
|
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Wrapper method used by {govuk_checkbox_field_tag} and {govuk_checkbox_field_form} to generate the checkboxes HTML
|
88
|
-
#
|
89
|
-
# @param items [Array] array of checkbox items.
|
90
|
-
# Each item is a hash which can be:
|
91
|
-
# - +:divider+ text to separate checkbox items
|
92
|
-
# - checkbox item, see {_govuk_checkbox_item}
|
93
|
-
# @param govuk_checkboxes_options [Hash] options that will be used in customising the HTML
|
94
|
-
#
|
95
|
-
# @option govuk_checkboxes_options [String] :classes additional CSS classes for the checkboxes HTML
|
96
|
-
# @option govuk_checkboxes_options [Hash] :attributes ({ module: 'govuk-checkboxes' }) any additional attributes that will added as part of the HTML
|
97
|
-
#
|
98
|
-
# @yield the checkbox item HTML generated by {govuk_checkbox_field_tag} or {govuk_checkbox_field_form}
|
99
|
-
#
|
100
|
-
# @yieldparam checkbox_item [Hash] the current checkbox item to be rendered
|
101
|
-
#
|
102
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the checkbox buttons which is used in {govuk_checkbox_field_tag} or {govuk_checkbox_field_form}
|
103
72
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
73
|
+
# Generates the checkboxes HTML for {govuk_checkboxes} when there is a ActionView::Helpers::FormBuilder
|
74
|
+
#
|
75
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the checkbox buttons
|
76
|
+
# @param (see govuk_checkbox_field_tag)
|
77
|
+
#
|
78
|
+
# @option (see _govuk_checkboxes_fields)
|
79
|
+
#
|
80
|
+
# @return (see govuk_checkbox_field_tag)
|
81
|
+
|
82
|
+
def govuk_checkbox_field_form(form, attribute, items, **govuk_checkboxes_options)
|
83
|
+
_govuk_checkboxes_fields(items, **govuk_checkboxes_options) do |checkbox_item|
|
84
|
+
govuk_checkbox_item_form(form, attribute, checkbox_item)
|
85
|
+
end
|
86
|
+
end
|
108
87
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
88
|
+
# Wrapper method used by {govuk_checkbox_field_tag} and {govuk_checkbox_field_form} to generate the checkboxes HTML
|
89
|
+
#
|
90
|
+
# @param items [Array] array of checkbox items.
|
91
|
+
# Each item is a hash which can be:
|
92
|
+
# - +:divider+ text to separate checkbox items
|
93
|
+
# - checkbox item, see {_govuk_checkbox_item}
|
94
|
+
# @param govuk_checkboxes_options [Hash] options that will be used in customising the HTML
|
95
|
+
#
|
96
|
+
# @option govuk_checkboxes_options [String] :classes additional CSS classes for the checkboxes HTML
|
97
|
+
# @option govuk_checkboxes_options [Hash] :attributes ({ module: 'govuk-checkboxes' }) any additional attributes that will added as part of the HTML
|
98
|
+
#
|
99
|
+
# @yield the checkbox item HTML generated by {govuk_checkbox_field_tag} or {govuk_checkbox_field_form}
|
100
|
+
#
|
101
|
+
# @yieldparam checkbox_item [Hash] the current checkbox item to be rendered
|
102
|
+
#
|
103
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the checkbox buttons which is used in {govuk_checkbox_field_tag} or {govuk_checkbox_field_form}
|
104
|
+
|
105
|
+
def _govuk_checkboxes_fields(items, **govuk_checkboxes_options)
|
106
|
+
govuk_checkboxes_options[:attributes] ||= {}
|
107
|
+
govuk_checkboxes_options[:attributes][:class] = "govuk-checkboxes #{govuk_checkboxes_options[:classes]}".rstrip
|
108
|
+
(govuk_checkboxes_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-checkboxes' })
|
109
|
+
|
110
|
+
tag.div(**govuk_checkboxes_options[:attributes]) do
|
111
|
+
capture do
|
112
|
+
items.each do |checkbox_item|
|
113
|
+
concat(
|
114
|
+
if checkbox_item[:divider]
|
115
|
+
tag.div(checkbox_item[:divider], class: 'govuk-checkboxes__divider')
|
116
|
+
else
|
117
|
+
tag.div(class: 'govuk-checkboxes__item') do
|
118
|
+
yield(checkbox_item)
|
119
|
+
end
|
118
120
|
end
|
119
|
-
|
120
|
-
|
121
|
+
)
|
122
|
+
end
|
121
123
|
end
|
122
124
|
end
|
123
125
|
end
|
124
|
-
end
|
125
126
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
127
|
+
# Generates the HTML for a checkbox button for {govuk_checkbox_field_form}
|
128
|
+
#
|
129
|
+
# @param (see _govuk_checkbox_item)
|
130
|
+
#
|
131
|
+
# @option (see _govuk_checkbox_item)
|
132
|
+
#
|
133
|
+
# @return (see _govuk_checkbox_item)
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
def govuk_checkbox_item_tag(attribute, checkbox_item)
|
136
|
+
_govuk_checkbox_item(attribute, checkbox_item) do
|
137
|
+
checkbox_item[:attributes][:id] ||= "#{sanitize_to_id(attribute)}_#{sanitize_to_id(checkbox_item[:value])}"
|
137
138
|
|
138
|
-
|
139
|
-
|
139
|
+
concat(check_box_tag("#{attribute}[]", checkbox_item[:value], checkbox_item[:checked], class: 'govuk-checkboxes__input', **checkbox_item[:attributes]))
|
140
|
+
concat(govuk_label(checkbox_item[:attributes][:id], checkbox_item[:label][:text], **checkbox_item[:label]))
|
141
|
+
end
|
140
142
|
end
|
141
|
-
end
|
142
|
-
|
143
|
-
# Generates the HTML for a checkbox button for {govuk_checkbox_field_tag}
|
144
|
-
#
|
145
|
-
# @param (see _govuk_checkbox_item)
|
146
|
-
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the checkbox buttons
|
147
|
-
#
|
148
|
-
# @option (see _govuk_checkbox_item)
|
149
|
-
#
|
150
|
-
# @return (see _govuk_checkbox_item)
|
151
143
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
144
|
+
# Generates the HTML for a checkbox button for {govuk_checkbox_field_tag}
|
145
|
+
#
|
146
|
+
# @param (see _govuk_checkbox_item)
|
147
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the checkbox buttons
|
148
|
+
#
|
149
|
+
# @option (see _govuk_checkbox_item)
|
150
|
+
#
|
151
|
+
# @return (see _govuk_checkbox_item)
|
152
|
+
|
153
|
+
def govuk_checkbox_item_form(form, attribute, checkbox_item)
|
154
|
+
_govuk_checkbox_item(attribute, checkbox_item) do
|
155
|
+
(checkbox_item[:label][:attributes] ||= {})[:value] = checkbox_item[:value]
|
156
|
+
checkbox_item[:label][:attributes][:for] = checkbox_item[:attributes][:id] if checkbox_item[:attributes][:id]
|
157
|
+
|
158
|
+
concat(form.check_box(attribute, checkbox_item[:attributes].merge({ class: 'govuk-checkboxes__input', multiple: true, include_hidden: false }), checkbox_item[:value]))
|
159
|
+
concat(govuk_label(attribute, checkbox_item[:label][:text], form: form, **checkbox_item[:label]))
|
160
|
+
end
|
159
161
|
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# rubocop:disable Metrics/AbcSize
|
163
162
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
163
|
+
# rubocop:disable Metrics/AbcSize
|
164
|
+
|
165
|
+
# Wrapper method used by {govuk_checkbox_item_tag} and {govuk_checkbox_item_form} to generate the checkboxes HTML
|
166
|
+
# including the label and hint, if there is one.
|
167
|
+
#
|
168
|
+
# @param attribute [String, Symbol] the attribute of the raido buttons
|
169
|
+
# @param checkbox_item [Hash] the options for the checkbox item
|
170
|
+
#
|
171
|
+
# @option checkbox_item [String] :classes additional CSS classes for the checkbox button HTML
|
172
|
+
# @option checkbox_item [Hash] :label the parameters that will be used to create the label for the checkbox button, see {govuk_label}
|
173
|
+
# @option checkbox_item [Hash] :hint (nil) the parameters that will be used to create the hint for the checkbox button, see {govuk_hint}.
|
174
|
+
# If no hint is given then no hint will be rendered
|
175
|
+
# @option checkbox_item [Hash] :conditional (nil) content that will appear when the checkbox input is checked.
|
176
|
+
# It can have the following options:
|
177
|
+
# - +[:content]+ the content that will be shown
|
178
|
+
# - +[:attributes][:id]+ the id of the conditional section
|
179
|
+
# If no conditional is given then no conditional content will be rendered
|
180
|
+
# @option checkbox_item [Hash] :attributes ({}) any additional attributes that will be added as part of the checkbox button HTML
|
181
|
+
#
|
182
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the checkbox buttons, label and hint
|
183
|
+
# which is used in {govuk_checkbox_item_tag} and {govuk_checkbox_item_form}
|
184
|
+
|
185
|
+
def _govuk_checkbox_item(attribute, checkbox_item)
|
186
|
+
checkbox_item[:attributes] ||= {}
|
187
|
+
checkbox_item[:label] ||= {}
|
188
|
+
checkbox_item[:label][:classes] = "govuk-checkboxes__label #{checkbox_item[:label][:classes]}".rstrip
|
189
|
+
|
190
|
+
set_item_options_for_hint('checkboxes', attribute, checkbox_item)
|
191
|
+
set_conditional_item_options('checkboxes', attribute, checkbox_item)
|
183
192
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
set_item_options_for_hint('checkboxes', attribute, checkbox_item)
|
190
|
-
set_conditional_item_options('checkboxes', attribute, checkbox_item)
|
191
|
-
|
192
|
-
capture do
|
193
|
-
yield
|
194
|
-
concat(govuk_hint(checkbox_item[:hint][:text], **checkbox_item[:hint])) if checkbox_item[:hint]
|
195
|
-
concat(tag.div(checkbox_item[:conditional][:content], class: checkbox_item[:conditional][:attributes][:class], id: checkbox_item[:conditional][:attributes][:id])) if checkbox_item[:conditional]
|
193
|
+
capture do
|
194
|
+
yield
|
195
|
+
concat(govuk_hint(checkbox_item[:hint][:text], **checkbox_item[:hint])) if checkbox_item[:hint]
|
196
|
+
concat(tag.div(checkbox_item[:conditional][:content], class: checkbox_item[:conditional][:attributes][:class], id: checkbox_item[:conditional][:attributes][:id])) if checkbox_item[:conditional]
|
197
|
+
end
|
196
198
|
end
|
197
|
-
end
|
198
199
|
|
199
|
-
|
200
|
+
# rubocop:enable Metrics/AbcSize
|
201
|
+
end
|
200
202
|
end
|
201
203
|
end
|
202
204
|
end
|