crown_marketplace_utils 0.1.0.beta.4 → 0.1.0.beta.5
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/.rubocop.yml +1 -1
- data/Gemfile.lock +5 -5
- data/README.md +1 -3
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +116 -0
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +34 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/breadcrumbs.rb +2 -2
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/button.rb +11 -19
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/details.rb +1 -1
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/error_message.rb +1 -1
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/character_count.rb +25 -50
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/checkboxes.rb +52 -68
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/date_input.rb +46 -127
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +94 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/input.rb +34 -72
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/radios.rb +52 -68
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/select.rb +28 -64
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +105 -0
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +215 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/fieldset.rb +1 -1
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/form_group.rb +10 -21
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/header.rb +1 -1
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/hint.rb +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +88 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/notification_banner.rb +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +338 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/step_by_step_navigation.rb +1 -1
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/tag.rb +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +52 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper.rb → helpers/gov_uk_helper.rb} +7 -1
- data/lib/crown_marketplace_utils/version.rb +1 -1
- data/lib/crown_marketplace_utils.rb +1 -1
- metadata +28 -25
- data/lib/crown_marketplace_utils/gov_uk_helper/field/file_upload.rb +0 -125
- data/lib/crown_marketplace_utils/gov_uk_helper/field/textarea.rb +0 -140
- data/lib/crown_marketplace_utils/gov_uk_helper/field.rb +0 -305
- data/lib/crown_marketplace_utils/gov_uk_helper/label.rb +0 -97
- data/lib/crown_marketplace_utils/gov_uk_helper/pagination.rb +0 -214
@@ -0,0 +1,338 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
module CrownMarketplaceUtils::Helpers
|
6
|
+
module GovUkHelper
|
7
|
+
# rubocop:disable Metrics/ModuleLength
|
8
|
+
|
9
|
+
# = GOV.UK Pagination
|
10
|
+
#
|
11
|
+
# This helper is used for generating the pagination component from the
|
12
|
+
# {https://design-system.service.gov.uk/components/pagination GDS - Components - Pagination}
|
13
|
+
|
14
|
+
module Pagination
|
15
|
+
include ActionView::Context
|
16
|
+
include ActionView::Helpers::TagHelper
|
17
|
+
include ActionView::Helpers::TextHelper
|
18
|
+
include ActionView::Helpers::UrlHelper
|
19
|
+
|
20
|
+
# Generates the HTML for the GOV.UK Pagination component
|
21
|
+
#
|
22
|
+
# @param (see _govuk_pagination)
|
23
|
+
#
|
24
|
+
# @option (see _govuk_pagination)
|
25
|
+
#
|
26
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Pagination
|
27
|
+
# which can then be rendered on the page
|
28
|
+
|
29
|
+
def govuk_pagination(**govuk_pagination_options)
|
30
|
+
_govuk_pagination(**govuk_pagination_options) do |block_is_level|
|
31
|
+
capture do
|
32
|
+
concat(govuk_pagination_previous(block_is_level, form: govuk_pagination_options[:form], **govuk_pagination_options[:previous])) if govuk_pagination_options[:previous]
|
33
|
+
concat(govuk_pagination_items(govuk_pagination_options[:items], form: govuk_pagination_options[:form])) if govuk_pagination_options[:items]
|
34
|
+
concat(govuk_pagination_next(block_is_level, form: govuk_pagination_options[:form], **govuk_pagination_options[:next])) if govuk_pagination_options[:next]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Wrapper method used by {govuk_pagination}
|
42
|
+
#
|
43
|
+
# @param govuk_pagination_options [Hash] options that will be used in customising the HTML
|
44
|
+
#
|
45
|
+
# @option govuk_pagination_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create pagination buttons
|
46
|
+
# @option govuk_pagination_options [String] :classes additional CSS classes for the pagination HTML
|
47
|
+
# @option govuk_pagination_options [Array] :items an array of items for the pagination (see: {govuk_pagination_items})
|
48
|
+
# @option govuk_pagination_options [Hash] :previous the previous link (see: {govuk_pagination_previous})
|
49
|
+
# @option govuk_pagination_options [Hash] :next the next link (see: {govuk_pagination_next})
|
50
|
+
# @option govuk_pagination_options [Hash] :attributes ({role: 'navigation', aria: { label: 'results' }})
|
51
|
+
# any additional attributes that will added as part of the HTML
|
52
|
+
#
|
53
|
+
# @yield the pagination HTML generated by {govuk_pagination}
|
54
|
+
#
|
55
|
+
# @yieldparam block_is_level [Boolean] flag to indicate if there are no items
|
56
|
+
#
|
57
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the Pagination
|
58
|
+
# which is used in {govuk_pagination}
|
59
|
+
|
60
|
+
def _govuk_pagination(**govuk_pagination_options)
|
61
|
+
govuk_pagination_options[:attributes] ||= {}
|
62
|
+
govuk_pagination_options[:attributes][:class] = "govuk-pagination #{govuk_pagination_options[:classes]}".rstrip
|
63
|
+
|
64
|
+
block_is_level = govuk_pagination_options[:items].blank? && (govuk_pagination_options[:next].present? || govuk_pagination_options[:previous].present?)
|
65
|
+
|
66
|
+
govuk_pagination_options[:attributes][:class] << ' govuk-pagination--block' if block_is_level
|
67
|
+
|
68
|
+
govuk_pagination_options[:attributes].merge!({ role: 'navigation' })
|
69
|
+
(govuk_pagination_options[:attributes][:aria] ||= {})[:label] ||= 'results'
|
70
|
+
|
71
|
+
tag.nav(**govuk_pagination_options[:attributes]) do
|
72
|
+
yield(block_is_level)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Generates the previous link for {govuk_pagination}
|
77
|
+
#
|
78
|
+
# @param (see govuk_pagination_previous_content)
|
79
|
+
#
|
80
|
+
# @option (see govuk_pagination_previous_content)
|
81
|
+
#
|
82
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the previous link which is used in {govuk_pagination}
|
83
|
+
|
84
|
+
def govuk_pagination_previous(block_is_level, **govuk_pagination_previous_options)
|
85
|
+
govuk_pagination_previous_options[:attributes] ||= {}
|
86
|
+
govuk_pagination_previous_options[:attributes][:class] = "govuk-link govuk-pagination__link #{'pagination--button_as_link' if govuk_pagination_previous_options[:form]}".rstrip
|
87
|
+
govuk_pagination_previous_options[:attributes][:rel] = 'prev'
|
88
|
+
|
89
|
+
pagination_previous_content = govuk_pagination_previous_content(block_is_level, govuk_pagination_previous_options)
|
90
|
+
|
91
|
+
tag.div(class: 'govuk-pagination__prev') do
|
92
|
+
if govuk_pagination_previous_options[:form]
|
93
|
+
govuk_pagination_previous_options[:form].button(pagination_previous_content, **govuk_pagination_previous_options[:attributes])
|
94
|
+
else
|
95
|
+
link_to(pagination_previous_content, govuk_pagination_previous_options[:href], **govuk_pagination_previous_options[:attributes])
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Used by {govuk_pagination_previous}
|
101
|
+
# to generate the previous link content
|
102
|
+
#
|
103
|
+
# @param block_is_level [Boolean] when there are no items, this will be true and will add extra classes
|
104
|
+
# to the link to make the next and previous pagination links level
|
105
|
+
# @param govuk_pagination_previous_options [Hash] options that will be used in customising the HTML
|
106
|
+
#
|
107
|
+
# @option govuk_pagination_previous_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create previous button
|
108
|
+
# @option govuk_pagination_previous_options [String] :href the URL for the link
|
109
|
+
# @option govuk_pagination_previous_options [String] :text ('Previous') the text for the link
|
110
|
+
# @option govuk_pagination_previous_options [String] :lable_text additional text for the link when the pagination block is level
|
111
|
+
# @option govuk_pagination_previous_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
112
|
+
#
|
113
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the previous link/button
|
114
|
+
|
115
|
+
def govuk_pagination_previous_content(block_is_level, govuk_pagination_previous_options)
|
116
|
+
capture do
|
117
|
+
concat(govuk_pagination_icon(:prev))
|
118
|
+
concat(tag.span(govuk_pagination_previous_options[:text] || 'Previous', class: pagination_next_and_previous_classes(block_is_level, govuk_pagination_previous_options)))
|
119
|
+
concat(govuk_pagination_icon_label_text(block_is_level, govuk_pagination_previous_options[:lable_text]))
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Generates the next link for {govuk_pagination}
|
124
|
+
#
|
125
|
+
# @param (see govuk_pagination_next_content)
|
126
|
+
#
|
127
|
+
# @option (see govuk_pagination_next_content)
|
128
|
+
#
|
129
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the next link which is used in {govuk_pagination}
|
130
|
+
|
131
|
+
def govuk_pagination_next(block_is_level, **govuk_pagination_next_options)
|
132
|
+
govuk_pagination_next_options[:attributes] ||= {}
|
133
|
+
govuk_pagination_next_options[:attributes][:class] = "govuk-link govuk-pagination__link #{'pagination--button_as_link' if govuk_pagination_next_options[:form]}".rstrip
|
134
|
+
govuk_pagination_next_options[:attributes][:rel] = 'next'
|
135
|
+
|
136
|
+
pagination_next_content = govuk_pagination_next_content(block_is_level, govuk_pagination_next_options)
|
137
|
+
|
138
|
+
tag.div(class: 'govuk-pagination__next') do
|
139
|
+
if govuk_pagination_next_options[:form]
|
140
|
+
govuk_pagination_next_options[:form].button(pagination_next_content, **govuk_pagination_next_options[:attributes])
|
141
|
+
else
|
142
|
+
link_to(pagination_next_content, govuk_pagination_next_options[:href], **govuk_pagination_next_options[:attributes])
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Used by {govuk_pagination_next} to generate the next link content
|
148
|
+
#
|
149
|
+
# @param block_is_level [Boolean] when there are no items, this will be true and will add extra classe
|
150
|
+
# to the link to make the next and previous pagination links level
|
151
|
+
# @param govuk_pagination_next_options [Hash] options that will be used in customising the HTML
|
152
|
+
#
|
153
|
+
# @option govuk_pagination_next_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create next button
|
154
|
+
# @option govuk_pagination_next_options [String] :href the URL for the link
|
155
|
+
# @option govuk_pagination_next_options [String] :text ('Next') the text for the link
|
156
|
+
# @option govuk_pagination_next_options [String] :lable_text additional text for the link when the pagination block is level
|
157
|
+
# @option govuk_pagination_next_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
158
|
+
#
|
159
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the next link/button
|
160
|
+
|
161
|
+
def govuk_pagination_next_content(block_is_level, **govuk_pagination_next_options)
|
162
|
+
capture do
|
163
|
+
concat(govuk_pagination_icon(:next)) if block_is_level
|
164
|
+
concat(tag.span(govuk_pagination_next_options[:text] || 'Next', class: pagination_next_and_previous_classes(block_is_level, govuk_pagination_next_options)))
|
165
|
+
concat(govuk_pagination_icon_label_text(block_is_level, govuk_pagination_next_options[:lable_text]))
|
166
|
+
concat(govuk_pagination_icon(:next)) unless block_is_level
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Returns the classes for the previous and next link/button label
|
171
|
+
#
|
172
|
+
# @param (see govuk_pagination_next_content)
|
173
|
+
|
174
|
+
def pagination_next_and_previous_classes(block_is_level, govuk_pagination_options)
|
175
|
+
"govuk-pagination__link-title #{'govuk-pagination__link-title--decorated' if block_is_level && !govuk_pagination_options[:lable_text]}".rstrip
|
176
|
+
end
|
177
|
+
|
178
|
+
# Generates the item links for {govuk_pagination}
|
179
|
+
#
|
180
|
+
# @param (see _govuk_pagination_items)
|
181
|
+
# @param form [ActionView::Helpers::FormBuilder] optional form builder used to create the item buttons
|
182
|
+
#
|
183
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the lits of items which is used in {govuk_pagination}
|
184
|
+
|
185
|
+
def govuk_pagination_items(govuk_pagination_items, form:)
|
186
|
+
if form
|
187
|
+
_govuk_pagination_items(govuk_pagination_items) do |govuk_pagination_item|
|
188
|
+
govuk_pagination_item_number_form(form, govuk_pagination_item)
|
189
|
+
end
|
190
|
+
else
|
191
|
+
_govuk_pagination_items(govuk_pagination_items) do |govuk_pagination_item|
|
192
|
+
govuk_pagination_item_number_tag(govuk_pagination_item)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
# Wrapper method used by {govuk_pagination_items}
|
198
|
+
# to generate the pagination items HTML
|
199
|
+
#
|
200
|
+
# @param govuk_pagination_items [Array(Hash)] an array of item hashes for the pagination.
|
201
|
+
# There are two types of item:
|
202
|
+
# - {govuk_pagination_item_ellipsis ellipsis item}
|
203
|
+
# - {govuk_pagination_item_number_tag number item}
|
204
|
+
#
|
205
|
+
# @yield the pagination number item HTML generated by {govuk_pagination_items}
|
206
|
+
#
|
207
|
+
# @yieldparam govuk_pagination_item [Hash] the current pagination item in the loop
|
208
|
+
#
|
209
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the lits of items which is
|
210
|
+
# used in {govuk_pagination_items}
|
211
|
+
|
212
|
+
def _govuk_pagination_items(govuk_pagination_items)
|
213
|
+
tag.ul(class: 'govuk-pagination__list') do
|
214
|
+
capture do
|
215
|
+
govuk_pagination_items.each do |govuk_pagination_item|
|
216
|
+
case govuk_pagination_item[:type]
|
217
|
+
when :ellipsis
|
218
|
+
concat(govuk_pagination_item_ellipsis)
|
219
|
+
when :number
|
220
|
+
concat(yield(govuk_pagination_item))
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# Generates the icon for:
|
228
|
+
# - {govuk_pagination_previous}
|
229
|
+
# - {govuk_pagination_next}
|
230
|
+
#
|
231
|
+
# @param type [Symbol] the type of the pagination icon (+:prev+ or +:next+)
|
232
|
+
#
|
233
|
+
# @return [ActiveSupport::SafeBuffer]
|
234
|
+
|
235
|
+
def govuk_pagination_icon(type)
|
236
|
+
tag.svg(class: "govuk-pagination__icon govuk-pagination__icon--#{type}", xmlns: 'http://www.w3.org/2000/svg', height: '13', width: '15', aria: { hidden: 'true' }, focusable: 'false', viewBox: '0 0 15 13') do
|
237
|
+
tag.path(d: PAGINATION_ICON_PATHS[type])
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# Generates the label text for:
|
242
|
+
# - {govuk_pagination_previous}
|
243
|
+
# - {govuk_pagination_next}
|
244
|
+
#
|
245
|
+
# @param block_is_level [Boolean] when there are no items, this will be true
|
246
|
+
# @param label_text [String] the additional text for the link
|
247
|
+
#
|
248
|
+
# @return [ActiveSupport::SafeBuffer]
|
249
|
+
|
250
|
+
def govuk_pagination_icon_label_text(block_is_level, label_text)
|
251
|
+
return unless block_is_level && label_text
|
252
|
+
|
253
|
+
capture do
|
254
|
+
concat(tag.span(':', class: 'govuk-visually-hidden'))
|
255
|
+
concat(tag.span(label_text, class: 'govuk-pagination__link-label'))
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# Generates the ellipsis HTML for {govuk_pagination_items}
|
260
|
+
#
|
261
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an ellipsis item which is used in {govuk_pagination_items}
|
262
|
+
|
263
|
+
def govuk_pagination_item_ellipsis
|
264
|
+
tag.li('⋯', class: 'govuk-pagination__item govuk-pagination__item--ellipses')
|
265
|
+
end
|
266
|
+
|
267
|
+
# Generates the number item HTML for {govuk_pagination_items}
|
268
|
+
#
|
269
|
+
# @param (see _govuk_pagination_item_number)
|
270
|
+
#
|
271
|
+
# @option (see _govuk_pagination_item_number)
|
272
|
+
#
|
273
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an number item which is used in {govuk_pagination_items}
|
274
|
+
|
275
|
+
def govuk_pagination_item_number_tag(govuk_pagination_item)
|
276
|
+
_govuk_pagination_item_number(govuk_pagination_item) do
|
277
|
+
link_to(govuk_pagination_item[:number], govuk_pagination_item[:href], **govuk_pagination_item[:attributes])
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
# Generates the number item HTML for {govuk_pagination_items} when there is a ActionView::Helpers::FormBuilder
|
282
|
+
#
|
283
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the item button
|
284
|
+
# @param (see _govuk_pagination_item_number)
|
285
|
+
#
|
286
|
+
# @option (see _govuk_pagination_item_number)
|
287
|
+
#
|
288
|
+
# @return (see govuk_pagination_item_number_tag)
|
289
|
+
|
290
|
+
def govuk_pagination_item_number_form(form, govuk_pagination_item)
|
291
|
+
govuk_pagination_item[:classes] = 'pagination-number--button_as_link'
|
292
|
+
|
293
|
+
_govuk_pagination_item_number(govuk_pagination_item) do
|
294
|
+
form.button(govuk_pagination_item[:number], **govuk_pagination_item[:attributes])
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
# Wrapper method used by {govuk_pagination_item_number_tag} and {govuk_pagination_item_number_form}
|
299
|
+
# to generate the pagination number item HTML
|
300
|
+
#
|
301
|
+
# @param govuk_pagination_item [Hash] options that will be used in customising the HTML
|
302
|
+
#
|
303
|
+
# @option govuk_pagination_item [String] :href the URL for the link
|
304
|
+
# @option govuk_pagination_item [String] :number the number for the link
|
305
|
+
# @option govuk_pagination_item [String] :current is this item the current page
|
306
|
+
# @option govuk_pagination_item [Hash] :attributes ({aria: { label: 'Page <NUMBER>' } })
|
307
|
+
# any additional attributes that will added as part of the HTML
|
308
|
+
#
|
309
|
+
# @yield the pagination number item link (when {govuk_pagination_item_number_tag}) or button (when {govuk_pagination_item_number_form})
|
310
|
+
#
|
311
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an number item which is used
|
312
|
+
# in {govuk_pagination_item_number_tag} or {govuk_pagination_item_number_form}
|
313
|
+
|
314
|
+
def _govuk_pagination_item_number(govuk_pagination_item, &block)
|
315
|
+
(govuk_pagination_item[:attributes] ||= {})[:aria] ||= {}
|
316
|
+
govuk_pagination_item[:attributes][:class] = "govuk-link govuk-pagination__link #{govuk_pagination_item[:classes]}".rstrip
|
317
|
+
govuk_pagination_item[:attributes][:aria][:label] ||= "Page #{govuk_pagination_item[:number]}"
|
318
|
+
|
319
|
+
govuk_pagination_list_classes = +'govuk-pagination__item'
|
320
|
+
|
321
|
+
if govuk_pagination_item[:current]
|
322
|
+
govuk_pagination_list_classes << ' govuk-pagination__item--current'
|
323
|
+
govuk_pagination_item[:attributes][:aria][:current] = 'page'
|
324
|
+
end
|
325
|
+
|
326
|
+
tag.li(class: govuk_pagination_list_classes, &block)
|
327
|
+
end
|
328
|
+
|
329
|
+
# The paths for the pagination next and previous icons
|
330
|
+
|
331
|
+
PAGINATION_ICON_PATHS = {
|
332
|
+
prev: 'm6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z',
|
333
|
+
next: 'm8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z'
|
334
|
+
}.freeze
|
335
|
+
end
|
336
|
+
# rubocop:enable Metrics/ModuleLength
|
337
|
+
end
|
338
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
module CrownMarketplaceUtils::Helpers
|
6
|
+
module GovUkHelper
|
7
|
+
# = GOV.UK Warning text
|
8
|
+
#
|
9
|
+
# This helper is used for generating the warning text component from the
|
10
|
+
# {https://design-system.service.gov.uk/components/warning-text GDS - Components - Warning text}
|
11
|
+
|
12
|
+
module WarningText
|
13
|
+
include ActionView::Context
|
14
|
+
include ActionView::Helpers::TagHelper
|
15
|
+
include ActionView::Helpers::TextHelper
|
16
|
+
|
17
|
+
# Generates the HTML for the GOV.UK Warning text component
|
18
|
+
#
|
19
|
+
# @param text [String] (nil) the text for the warning
|
20
|
+
# @param govuk_warning_text_options [Hash] options that will be used in customising the HTML
|
21
|
+
#
|
22
|
+
# @option govuk_warning_text_options [String] :classes additional CSS classes for the tag HTML
|
23
|
+
# @option govuk_warning_text_options [String] :icon_fallback_text the fallback text for the icon (default: +'Warning'+)
|
24
|
+
# @option govuk_warning_text_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
25
|
+
#
|
26
|
+
# @yield HTML that will be used in the warning text. Ignored if text is passed.
|
27
|
+
#
|
28
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Warning text
|
29
|
+
# which can then be rendered on the page
|
30
|
+
|
31
|
+
def govuk_warning_text(text = nil, **govuk_warning_text_options)
|
32
|
+
govuk_warning_text_options[:class] = "govuk-warning-text #{govuk_warning_text_options[:classes]}".rstrip
|
33
|
+
|
34
|
+
tag.div(class: govuk_warning_text_options[:class], **(govuk_warning_text_options[:attributes] || {})) do
|
35
|
+
capture do
|
36
|
+
concat(tag.span('!', class: 'govuk-warning-text__icon'))
|
37
|
+
concat(tag.strong(class: 'govuk-warning-text__text') do
|
38
|
+
capture do
|
39
|
+
concat(tag.span(govuk_warning_text_options[:icon_fallback_text] || 'Warning', class: 'govuk-warning-text__assistive'))
|
40
|
+
if text
|
41
|
+
concat(text)
|
42
|
+
else
|
43
|
+
yield
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'gov_uk_helper/accordion'
|
4
|
+
require_relative 'gov_uk_helper/back_link'
|
3
5
|
require_relative 'gov_uk_helper/breadcrumbs'
|
4
6
|
require_relative 'gov_uk_helper/button'
|
5
7
|
require_relative 'gov_uk_helper/details'
|
@@ -22,12 +24,15 @@ require_relative 'gov_uk_helper/notification_banner'
|
|
22
24
|
require_relative 'gov_uk_helper/pagination'
|
23
25
|
require_relative 'gov_uk_helper/step_by_step_navigation'
|
24
26
|
require_relative 'gov_uk_helper/tag'
|
27
|
+
require_relative 'gov_uk_helper/warning_text'
|
25
28
|
|
26
|
-
module CrownMarketplaceUtils
|
29
|
+
module CrownMarketplaceUtils::Helpers
|
27
30
|
# This module loads in all the GOV.UK Helper methods.
|
28
31
|
# These are a collection of view helpers to help render GOV.UK components
|
29
32
|
|
30
33
|
module GovUkHelper
|
34
|
+
include Accordion
|
35
|
+
include BackLink
|
31
36
|
include Breadcrumbs
|
32
37
|
include Button
|
33
38
|
include Details
|
@@ -50,5 +55,6 @@ module CrownMarketplaceUtils
|
|
50
55
|
include Pagination
|
51
56
|
include StepByStepNavigation
|
52
57
|
include Tag
|
58
|
+
include WarningText
|
53
59
|
end
|
54
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crown_marketplace_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.beta.
|
4
|
+
version: 0.1.0.beta.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tim-s-ccs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -168,29 +168,32 @@ files:
|
|
168
168
|
- Rakefile
|
169
169
|
- crown_marketplace_utils.gemspec
|
170
170
|
- lib/crown_marketplace_utils.rb
|
171
|
-
- lib/crown_marketplace_utils/gov_uk_helper.rb
|
172
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
173
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
174
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
175
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
176
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
177
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
178
|
-
- lib/crown_marketplace_utils/gov_uk_helper/field
|
179
|
-
- lib/crown_marketplace_utils/gov_uk_helper/field/
|
180
|
-
- lib/crown_marketplace_utils/gov_uk_helper/field/
|
181
|
-
- lib/crown_marketplace_utils/gov_uk_helper/field/
|
182
|
-
- lib/crown_marketplace_utils/gov_uk_helper/field/
|
183
|
-
- lib/crown_marketplace_utils/gov_uk_helper/field/
|
184
|
-
- lib/crown_marketplace_utils/gov_uk_helper/field/
|
185
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
186
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
187
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
188
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
189
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
190
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
191
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
192
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
193
|
-
- lib/crown_marketplace_utils/gov_uk_helper/
|
171
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper.rb
|
172
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb
|
173
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb
|
174
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/breadcrumbs.rb
|
175
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/button.rb
|
176
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/details.rb
|
177
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/error_message.rb
|
178
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb
|
179
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/field/character_count.rb
|
180
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/field/checkboxes.rb
|
181
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb
|
182
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb
|
183
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb
|
184
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/field/radios.rb
|
185
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb
|
186
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb
|
187
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/fieldset.rb
|
188
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/form_group.rb
|
189
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/header.rb
|
190
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/hint.rb
|
191
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb
|
192
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/notification_banner.rb
|
193
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb
|
194
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/step_by_step_navigation.rb
|
195
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/tag.rb
|
196
|
+
- lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb
|
194
197
|
- lib/crown_marketplace_utils/version.rb
|
195
198
|
- sig/crown_marketplace_utils.rbs
|
196
199
|
homepage: https://github.com/tim-s-ccs/crown_marketplace_utils
|
@@ -1,125 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../field'
|
4
|
-
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module GovUkHelper
|
7
|
-
module Field
|
8
|
-
# = GOV.UK File Upload
|
9
|
-
#
|
10
|
-
# This helper is used for generating the file upload component from the
|
11
|
-
# {https://design-system.service.gov.uk/components/file-upload GDS - Components - File Upload}
|
12
|
-
#
|
13
|
-
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
14
|
-
|
15
|
-
module FileUpload
|
16
|
-
include Field
|
17
|
-
|
18
|
-
# Generates the HTML for the GOV.UK file upload component
|
19
|
-
#
|
20
|
-
# @param attribute [String, Symbol] the attribute of the file upload
|
21
|
-
# @param error_message [String] the error message to be displayed
|
22
|
-
# @param govuk_file_upload_options [Hash] options that will be used for the parts of the form group, label, hint and file upload
|
23
|
-
#
|
24
|
-
# @option govuk_file_upload_options [Hash] :form_group see {govuk_field}
|
25
|
-
# @option govuk_file_upload_options [Hash] :label see {govuk_field}
|
26
|
-
# @option govuk_file_upload_options [Hash] :hint see {govuk_field}
|
27
|
-
# @option govuk_file_upload_options [Hash] :file_upload ({}) the options that will be used when rendering the file upload.
|
28
|
-
# See {govuk_file_upload_field} for more details.
|
29
|
-
#
|
30
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK File Upload
|
31
|
-
# which can then be rendered on the page
|
32
|
-
|
33
|
-
def govuk_file_upload(attribute, error_message = nil, **govuk_file_upload_options)
|
34
|
-
govuk_field(:file_upload, attribute, error_message, **govuk_file_upload_options) do |govuk_field_options|
|
35
|
-
concat(govuk_file_upload_field(attribute, error_message, **govuk_field_options))
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Generates the HTML for the GOV.UK file upload component using an ActiveModel.
|
40
|
-
# Unlike {govuk_file_upload}, the method will be able to automatically determine if the error message needs to be shown.
|
41
|
-
#
|
42
|
-
# @param model [ActiveModel] model that will be used to find an error message for the file upload
|
43
|
-
# @param attribute [String, Symbol] the attribute of the file upload
|
44
|
-
# @param govuk_file_upload_options [Hash] options that will be used for the parts of the form group, label, hint and file upload
|
45
|
-
#
|
46
|
-
# @option (see govuk_file_upload)
|
47
|
-
#
|
48
|
-
# @return (see govuk_file_upload)
|
49
|
-
|
50
|
-
def govuk_file_upload_with_model(model, attribute, **govuk_file_upload_options)
|
51
|
-
govuk_field_with_model(:file_upload, model, attribute, **govuk_file_upload_options) do |govuk_field_options, error_message|
|
52
|
-
concat(govuk_file_upload_field(attribute, error_message, **govuk_field_options))
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Generates the HTML for the GOV.UK file upload component using an ActionView::Helpers::FormBuilder.
|
57
|
-
# Unlike {govuk_file_upload}, the method will be able to automatically determine if the error message needs to be shown.
|
58
|
-
#
|
59
|
-
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the file upload input
|
60
|
-
# @param attribute [String, Symbol] the attribute of the file upload
|
61
|
-
# @param govuk_file_upload_options [Hash] options that will be used for the parts of the form group, label, hint and file upload
|
62
|
-
#
|
63
|
-
# @option (see govuk_file_upload)
|
64
|
-
#
|
65
|
-
# @return (see govuk_file_upload)
|
66
|
-
|
67
|
-
def govuk_file_upload_with_form(form, attribute, **govuk_file_upload_options)
|
68
|
-
govuk_field_with_form(:file_upload, form, attribute, **govuk_file_upload_options) do |govuk_field_options, error_message|
|
69
|
-
concat(govuk_file_upload_field_with_form(form, attribute, error_message, **govuk_field_options))
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
# Generates the file upload HTML for {govuk_file_upload} and {govuk_file_upload_with_model}
|
76
|
-
#
|
77
|
-
# @param attribute [String, Symbol] the attribute of the file upload
|
78
|
-
# @param error_message [String] the error message to be displayed
|
79
|
-
# @param govuk_file_upload_options [Hash] options that will be used in customising the HTML
|
80
|
-
#
|
81
|
-
# @option (see set_file_upload_options)
|
82
|
-
#
|
83
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the file upload field which is used in {govuk_file_upload} and {govuk_file_upload_with_model}
|
84
|
-
|
85
|
-
def govuk_file_upload_field(attribute, error_message, **govuk_file_upload_options)
|
86
|
-
set_file_upload_options(error_message, govuk_file_upload_options)
|
87
|
-
|
88
|
-
file_field_tag(attribute, class: govuk_file_upload_options[:classes], **govuk_file_upload_options[:attributes])
|
89
|
-
end
|
90
|
-
|
91
|
-
# Generates the file upload HTML for {govuk_file_upload_with_form}
|
92
|
-
#
|
93
|
-
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the file upload input
|
94
|
-
# @param attribute [String, Symbol] the attribute of the file upload
|
95
|
-
# @param error_message [String] used to indicate if there is an error which will add an extra classes
|
96
|
-
# @param govuk_file_upload_options [Hash] options that will be used in customising the HTML
|
97
|
-
#
|
98
|
-
# @option (see set_file_upload_options)
|
99
|
-
#
|
100
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the file upload field which is used in {govuk_file_upload_with_form}
|
101
|
-
|
102
|
-
def govuk_file_upload_field_with_form(form, attribute, error_message, **govuk_file_upload_options)
|
103
|
-
set_file_upload_options(error_message, govuk_file_upload_options)
|
104
|
-
|
105
|
-
form.file_field(attribute, class: govuk_file_upload_options[:classes], **govuk_file_upload_options[:attributes])
|
106
|
-
end
|
107
|
-
|
108
|
-
# Initialises the attributes for the file upload input
|
109
|
-
#
|
110
|
-
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
111
|
-
# @param govuk_file_upload_options [Hash] options that will be used in customising the HTML
|
112
|
-
#
|
113
|
-
# @option govuk_file_upload_options [String] :classes additional CSS classes for the file iupload HTML
|
114
|
-
# @option govuk_file_upload_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
115
|
-
|
116
|
-
def set_file_upload_options(error_message, govuk_file_upload_options)
|
117
|
-
govuk_file_upload_options[:classes] = "govuk-file-upload #{govuk_file_upload_options[:classes]}".rstrip
|
118
|
-
govuk_file_upload_options[:classes] << ' govuk-file-upload--error' if error_message
|
119
|
-
|
120
|
-
govuk_file_upload_options[:attributes] ||= {}
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|