crown_marketplace_utils 0.1.0.beta.4 → 0.1.0.beta.6
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 +11 -11
- 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 +5 -5
- 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
@@ -1,214 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'action_view'
|
4
|
-
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module GovUkHelper
|
7
|
-
# = GOV.UK Pagination
|
8
|
-
#
|
9
|
-
# This helper is used for generating the pagination component from the
|
10
|
-
# {https://design-system.service.gov.uk/components/pagination GDS - Components - Pagination}
|
11
|
-
|
12
|
-
module Pagination
|
13
|
-
include ActionView::Context
|
14
|
-
include ActionView::Helpers::TagHelper
|
15
|
-
include ActionView::Helpers::TextHelper
|
16
|
-
include ActionView::Helpers::UrlHelper
|
17
|
-
|
18
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
19
|
-
|
20
|
-
# Generates the HTML for the GOV.UK Pagination component
|
21
|
-
#
|
22
|
-
# @param govuk_pagination_options [Hash] options that will be used in customising the HTML
|
23
|
-
#
|
24
|
-
# @option govuk_pagination_options [String] :classes additional CSS classes for the pagination HTML
|
25
|
-
# @option govuk_pagination_options [Array] :items an array of items for the pagination (see: {govuk_pagination_items})
|
26
|
-
# @option govuk_pagination_options [Hash] :previous the previous link (see: {govuk_pagination_previous})
|
27
|
-
# @option govuk_pagination_options [Hash] :next the next link (see: {govuk_pagination_next})
|
28
|
-
# @option govuk_pagination_options [Hash] :attributes ({role: 'navigation', aria: { label: 'results' }})
|
29
|
-
# any additional attributes that will added as part of the HTML
|
30
|
-
#
|
31
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Pagination
|
32
|
-
# which can then be rendered on the page
|
33
|
-
|
34
|
-
def govuk_pagination(**govuk_pagination_options)
|
35
|
-
govuk_pagination_classes = ['govuk-pagination']
|
36
|
-
govuk_pagination_classes << govuk_pagination_options[:classes]
|
37
|
-
|
38
|
-
block_is_level = govuk_pagination_options[:items].blank? && (govuk_pagination_options[:next].present? || govuk_pagination_options[:previous].present?)
|
39
|
-
|
40
|
-
govuk_pagination_classes << 'govuk-pagination--block' if block_is_level
|
41
|
-
|
42
|
-
(govuk_pagination_options[:attributes] ||= {}).merge({ role: 'navigation' })
|
43
|
-
(govuk_pagination_options[:attributes][:aria] ||= {})[:label] ||= 'results'
|
44
|
-
|
45
|
-
tag.nav(class: govuk_pagination_classes, **govuk_pagination_options[:attributes]) do
|
46
|
-
capture do
|
47
|
-
concat(govuk_pagination_previous(block_is_level, **govuk_pagination_options[:previous])) if govuk_pagination_options[:previous]
|
48
|
-
concat(govuk_pagination_items(govuk_pagination_options[:items])) if govuk_pagination_options[:items]
|
49
|
-
concat(govuk_pagination_next(block_is_level, **govuk_pagination_options[:next])) if govuk_pagination_options[:next]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
# Generates the previous link for {govuk_pagination}
|
59
|
-
#
|
60
|
-
# @param block_is_level [Boolean] when there are no items, this will be true and will add extra classe
|
61
|
-
# to the link to make the next and previous pagination links level
|
62
|
-
# @param govuk_pagination_previous_options [Hash] options that will be used in customising the HTML
|
63
|
-
#
|
64
|
-
# @option govuk_pagination_previous_options [String] :href the URL for the link
|
65
|
-
# @option govuk_pagination_previous_options [String] :text ('Previous') the text for the link
|
66
|
-
# @option govuk_pagination_previous_options [String] :lable_text additional text for the link when the pagination block is level
|
67
|
-
# @option govuk_pagination_previous_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
68
|
-
#
|
69
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the previous link which is used in {govuk_pagination}
|
70
|
-
|
71
|
-
def govuk_pagination_previous(block_is_level, **govuk_pagination_previous_options)
|
72
|
-
govuk_pagination_previous_classes = ['govuk-pagination__link-title']
|
73
|
-
govuk_pagination_previous_classes << 'govuk-pagination__link-title--decorated' if block_is_level && !govuk_pagination_previous_options[:lable_text]
|
74
|
-
|
75
|
-
tag.div(class: 'govuk-pagination__prev') do
|
76
|
-
link_to(govuk_pagination_previous_options[:href], class: 'govuk-link govuk-pagination__link', rel: 'prev', **(govuk_pagination_previous_options[:attributes] || {})) do
|
77
|
-
capture do
|
78
|
-
concat(govuk_pagination_icon(:prev))
|
79
|
-
concat(tag.span(govuk_pagination_previous_options[:text] || 'Previous', class: govuk_pagination_previous_classes))
|
80
|
-
concat(govuk_pagination_icon_label_text(block_is_level, govuk_pagination_previous_options[:lable_text]))
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# Generates the next link for {govuk_pagination}
|
87
|
-
#
|
88
|
-
# @param block_is_level [Boolean] when there are no items, this will be true and will add extra classe
|
89
|
-
# to the link to make the next and previous pagination links level
|
90
|
-
# @param govuk_pagination_next_options [Hash] options that will be used in customising the HTML
|
91
|
-
#
|
92
|
-
# @option govuk_pagination_next_options [String] :href the URL for the link
|
93
|
-
# @option govuk_pagination_next_options [String] :text ('Next') the text for the link
|
94
|
-
# @option govuk_pagination_next_options [String] :lable_text additional text for the link when the pagination block is level
|
95
|
-
# @option govuk_pagination_next_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
96
|
-
#
|
97
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the next link which is used in {govuk_pagination}
|
98
|
-
|
99
|
-
def govuk_pagination_next(block_is_level, **govuk_pagination_next_options)
|
100
|
-
govuk_pagination_next_classes = ['govuk-pagination__link-title']
|
101
|
-
govuk_pagination_next_classes << 'govuk-pagination__link-title--decorated' if block_is_level && !govuk_pagination_next_options[:lable_text]
|
102
|
-
|
103
|
-
tag.div(class: 'govuk-pagination__next') do
|
104
|
-
link_to(govuk_pagination_next_options[:href], class: 'govuk-link govuk-pagination__link', rel: 'next', **(govuk_pagination_next_options[:attributes] || {})) do
|
105
|
-
capture do
|
106
|
-
concat(govuk_pagination_icon(:next)) if block_is_level
|
107
|
-
concat(tag.span(govuk_pagination_next_options[:text] || 'Next', class: govuk_pagination_next_classes))
|
108
|
-
concat(govuk_pagination_icon_label_text(block_is_level, govuk_pagination_next_options[:lable_text]))
|
109
|
-
concat(govuk_pagination_icon(:next)) unless block_is_level
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Generates the item links for {govuk_pagination}
|
116
|
-
#
|
117
|
-
# @param govuk_pagination_items [Array(Hash)] an array of item hashes for the pagination.
|
118
|
-
# There are two types of item:
|
119
|
-
# - {govuk_pagination_item_ellipsis ellipsis item}
|
120
|
-
# - {govuk_pagination_item_number number item}
|
121
|
-
#
|
122
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the lits of items which is used in {govuk_pagination}
|
123
|
-
|
124
|
-
def govuk_pagination_items(govuk_pagination_items)
|
125
|
-
tag.ul(class: 'govuk-pagination__list') do
|
126
|
-
capture do
|
127
|
-
govuk_pagination_items.each do |govuk_pagination_item|
|
128
|
-
case govuk_pagination_item[:type]
|
129
|
-
when :ellipsis
|
130
|
-
concat(govuk_pagination_item_ellipsis)
|
131
|
-
when :number
|
132
|
-
concat(govuk_pagination_item_number(govuk_pagination_item))
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
# Generates the icon for:
|
140
|
-
# - {govuk_pagination_previous}
|
141
|
-
# - {govuk_pagination_next}
|
142
|
-
#
|
143
|
-
# @param type [Symbol] the type of the pagination icon (+:prev+ or +:next+)
|
144
|
-
#
|
145
|
-
# @return [ActiveSupport::SafeBuffer]
|
146
|
-
|
147
|
-
def govuk_pagination_icon(type)
|
148
|
-
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
|
149
|
-
tag.path(d: PAGINATION_ICON_PATHS[type])
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# Generates the label text for:
|
154
|
-
# - {govuk_pagination_previous}
|
155
|
-
# - {govuk_pagination_next}
|
156
|
-
#
|
157
|
-
# @param block_is_level [Boolean] when there are no items, this will be true
|
158
|
-
# @param label_text [String] the additional text for the link
|
159
|
-
#
|
160
|
-
# @return [ActiveSupport::SafeBuffer]
|
161
|
-
|
162
|
-
def govuk_pagination_icon_label_text(block_is_level, label_text)
|
163
|
-
return unless block_is_level && label_text
|
164
|
-
|
165
|
-
capture do
|
166
|
-
concat(tag.span(':', class: 'govuk-visually-hidden'))
|
167
|
-
concat(tag.span(label_text, class: 'govuk-pagination__link-label'))
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# Generates the ellipsis HTML for {govuk_pagination_items}
|
172
|
-
#
|
173
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for an ellipsis item which is used in {govuk_pagination_items}
|
174
|
-
|
175
|
-
def govuk_pagination_item_ellipsis
|
176
|
-
tag.li('⋯', class: 'govuk-pagination__item govuk-pagination__item--ellipses')
|
177
|
-
end
|
178
|
-
|
179
|
-
# Generates the number item HTML for {govuk_pagination_items}
|
180
|
-
#
|
181
|
-
# @param govuk_pagination_item [Hash] options that will be used in customising the HTML
|
182
|
-
#
|
183
|
-
# @option govuk_pagination_item [String] :href the URL for the link
|
184
|
-
# @option govuk_pagination_item [String] :number the number for the link
|
185
|
-
# @option govuk_pagination_item [String] :current is this item the current page
|
186
|
-
# @option govuk_pagination_item [Hash] :attributes ({aria: { label: 'Page <NUMBER>' } })
|
187
|
-
# any additional attributes that will added as part of the HTML
|
188
|
-
#
|
189
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for an number item which is used in {govuk_pagination_items}
|
190
|
-
|
191
|
-
def govuk_pagination_item_number(govuk_pagination_item)
|
192
|
-
govuk_pagination_item_classes = ['govuk-pagination__item']
|
193
|
-
(govuk_pagination_item[:attributes] ||= {})[:aria] ||= {}
|
194
|
-
govuk_pagination_item[:attributes][:aria][:label] ||= "Page #{govuk_pagination_item[:number]}"
|
195
|
-
|
196
|
-
if govuk_pagination_item[:current]
|
197
|
-
govuk_pagination_item_classes << 'govuk-pagination__item--current'
|
198
|
-
govuk_pagination_item[:attributes][:aria][:current] = 'page'
|
199
|
-
end
|
200
|
-
|
201
|
-
tag.li(class: govuk_pagination_item_classes) do
|
202
|
-
link_to(govuk_pagination_item[:number], govuk_pagination_item[:href], class: 'govuk-link govuk-pagination__link', **govuk_pagination_item[:attributes])
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
# The paths for the pagination next and previous icons
|
207
|
-
|
208
|
-
PAGINATION_ICON_PATHS = {
|
209
|
-
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',
|
210
|
-
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'
|
211
|
-
}.freeze
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|