ccs-frontend_helpers 0.1.0.rc.1

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.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +127 -0
  4. data/CHANGELOG.md +44 -0
  5. data/Gemfile +10 -0
  6. data/Gemfile.lock +241 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +102 -0
  9. data/Rakefile +10 -0
  10. data/ccs-frontend_helpers.gemspec +47 -0
  11. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
  12. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +141 -0
  13. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +205 -0
  14. data/lib/ccs/frontend_helpers/ccs_frontend/logo.rb +49 -0
  15. data/lib/ccs/frontend_helpers/ccs_frontend.rb +20 -0
  16. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +115 -0
  17. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +39 -0
  18. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +76 -0
  19. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +127 -0
  20. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +136 -0
  21. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +46 -0
  22. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +67 -0
  23. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +100 -0
  24. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
  25. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
  26. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
  27. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
  28. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
  29. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
  30. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
  31. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
  32. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
  33. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +71 -0
  34. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +183 -0
  35. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +50 -0
  36. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +161 -0
  37. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +38 -0
  38. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +44 -0
  39. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +92 -0
  40. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +136 -0
  41. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +336 -0
  42. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +51 -0
  43. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +49 -0
  44. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +40 -0
  45. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +215 -0
  46. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +226 -0
  47. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +124 -0
  48. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +95 -0
  49. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +42 -0
  50. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +53 -0
  51. data/lib/ccs/frontend_helpers/govuk_frontend.rb +82 -0
  52. data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
  53. data/lib/ccs/frontend_helpers/version.rb +7 -0
  54. data/lib/ccs/frontend_helpers.rb +20 -0
  55. data/sig/ccs/frontend_helpers.rbs +6 -0
  56. metadata +241 -0
@@ -0,0 +1,336 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
6
+
7
+ module CCS
8
+ module FrontendHelpers
9
+ module GovUKFrontend
10
+ # rubocop:disable Metrics/ModuleLength
11
+
12
+ # = GOV.UK Pagination
13
+ #
14
+ # This helper is used for generating the pagination component from the
15
+ # {https://design-system.service.gov.uk/components/pagination GDS - Components - Pagination}
16
+
17
+ module Pagination
18
+ include SharedMethods
19
+ include ActionView::Context
20
+ include ActionView::Helpers::TagHelper
21
+ include ActionView::Helpers::TextHelper
22
+ include ActionView::Helpers::UrlHelper
23
+
24
+ # Generates the HTML for the GOV.UK Pagination component
25
+ #
26
+ # @param (see _govuk_pagination)
27
+ #
28
+ # @option (see _govuk_pagination)
29
+ #
30
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Pagination
31
+ # which can then be rendered on the page
32
+
33
+ def govuk_pagination(**govuk_pagination_options)
34
+ _govuk_pagination(**govuk_pagination_options) do |block_is_level|
35
+ concat(govuk_pagination_previous(block_is_level, form: govuk_pagination_options[:form], **govuk_pagination_options[:previous])) if govuk_pagination_options[:previous]
36
+ concat(govuk_pagination_items(govuk_pagination_options[:items], form: govuk_pagination_options[:form])) if govuk_pagination_options[:items]
37
+ concat(govuk_pagination_next(block_is_level, form: govuk_pagination_options[:form], **govuk_pagination_options[:next])) if govuk_pagination_options[:next]
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ # Wrapper method used by {govuk_pagination}
44
+ #
45
+ # @param govuk_pagination_options [Hash] options that will be used in customising the HTML
46
+ #
47
+ # @option govuk_pagination_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create pagination buttons
48
+ # @option govuk_pagination_options [String] :classes additional CSS classes for the pagination HTML
49
+ # @option govuk_pagination_options [Array] :items an array of items for the pagination (see: {govuk_pagination_items})
50
+ # @option govuk_pagination_options [Hash] :previous the previous link (see: {govuk_pagination_previous})
51
+ # @option govuk_pagination_options [Hash] :next the next link (see: {govuk_pagination_next})
52
+ # @option govuk_pagination_options [Hash] :attributes ({role: 'navigation', aria: { label: 'results' }})
53
+ # any additional attributes that will added as part of the HTML
54
+ #
55
+ # @yield the pagination HTML generated by {govuk_pagination}
56
+ #
57
+ # @yieldparam block_is_level [Boolean] flag to indicate if there are no items
58
+ #
59
+ # @return [ActiveSupport::SafeBuffer] the HTML for the Pagination
60
+ # which is used in {govuk_pagination}
61
+
62
+ def _govuk_pagination(**govuk_pagination_options)
63
+ initialise_attributes_and_set_classes(govuk_pagination_options, 'govuk-pagination')
64
+
65
+ block_is_level = govuk_pagination_options[:items].blank? && (govuk_pagination_options[:next].present? || govuk_pagination_options[:previous].present?)
66
+
67
+ govuk_pagination_options[:attributes][:class] << ' govuk-pagination--block' if block_is_level
68
+
69
+ govuk_pagination_options[:attributes][:role] = 'navigation'
70
+ (govuk_pagination_options[:attributes][:aria] ||= {})[:label] ||= 'results'
71
+
72
+ tag.nav(**govuk_pagination_options[:attributes]) do
73
+ yield(block_is_level)
74
+ end
75
+ end
76
+
77
+ # Generates the previous link for {govuk_pagination}
78
+ #
79
+ # @param (see govuk_pagination_previous_content)
80
+ #
81
+ # @option (see govuk_pagination_previous_content)
82
+ #
83
+ # @return [ActiveSupport::SafeBuffer] the HTML for the previous link which is used in {govuk_pagination}
84
+
85
+ def govuk_pagination_previous(block_is_level, **govuk_pagination_previous_options)
86
+ govuk_pagination_previous_options[:attributes] ||= {}
87
+ govuk_pagination_previous_options[:attributes][:class] = "govuk-link govuk-pagination__link #{'pagination--button_as_link' if govuk_pagination_previous_options[:form]}".rstrip
88
+ govuk_pagination_previous_options[:attributes][:rel] = 'prev'
89
+
90
+ pagination_previous_content = govuk_pagination_previous_content(block_is_level, govuk_pagination_previous_options)
91
+
92
+ tag.div(class: 'govuk-pagination__prev') do
93
+ if govuk_pagination_previous_options[:form]
94
+ govuk_pagination_previous_options[:form].button(pagination_previous_content, **govuk_pagination_previous_options[:attributes])
95
+ else
96
+ link_to(pagination_previous_content, govuk_pagination_previous_options[:href], **govuk_pagination_previous_options[:attributes])
97
+ end
98
+ end
99
+ end
100
+
101
+ # Used by {govuk_pagination_previous}
102
+ # to generate the previous link content
103
+ #
104
+ # @param block_is_level [Boolean] when there are no items, this will be true and will add extra classes
105
+ # to the link to make the next and previous pagination links level
106
+ # @param govuk_pagination_previous_options [Hash] options that will be used in customising the HTML
107
+ #
108
+ # @option govuk_pagination_previous_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create previous button
109
+ # @option govuk_pagination_previous_options [String] :href the URL for the link
110
+ # @option govuk_pagination_previous_options [String] :text ('Previous') the text for the link
111
+ # @option govuk_pagination_previous_options [String] :lable_text additional text for the link when the pagination block is level
112
+ # @option govuk_pagination_previous_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
113
+ #
114
+ # @return [ActiveSupport::SafeBuffer] the HTML for the previous link/button
115
+
116
+ def govuk_pagination_previous_content(block_is_level, govuk_pagination_previous_options)
117
+ capture do
118
+ concat(govuk_pagination_icon(:prev))
119
+ concat(tag.span(govuk_pagination_previous_options[:text] || 'Previous', class: pagination_next_and_previous_classes(block_is_level, govuk_pagination_previous_options)))
120
+ concat(govuk_pagination_icon_label_text(block_is_level, govuk_pagination_previous_options[:lable_text]))
121
+ end
122
+ end
123
+
124
+ # Generates the next link for {govuk_pagination}
125
+ #
126
+ # @param (see govuk_pagination_next_content)
127
+ #
128
+ # @option (see govuk_pagination_next_content)
129
+ #
130
+ # @return [ActiveSupport::SafeBuffer] the HTML for the next link which is used in {govuk_pagination}
131
+
132
+ def govuk_pagination_next(block_is_level, **govuk_pagination_next_options)
133
+ govuk_pagination_next_options[:attributes] ||= {}
134
+ govuk_pagination_next_options[:attributes][:class] = "govuk-link govuk-pagination__link #{'pagination--button_as_link' if govuk_pagination_next_options[:form]}".rstrip
135
+ govuk_pagination_next_options[:attributes][:rel] = 'next'
136
+
137
+ pagination_next_content = govuk_pagination_next_content(block_is_level, **govuk_pagination_next_options)
138
+
139
+ tag.div(class: 'govuk-pagination__next') do
140
+ if govuk_pagination_next_options[:form]
141
+ govuk_pagination_next_options[:form].button(pagination_next_content, **govuk_pagination_next_options[:attributes])
142
+ else
143
+ link_to(pagination_next_content, govuk_pagination_next_options[:href], **govuk_pagination_next_options[:attributes])
144
+ end
145
+ end
146
+ end
147
+
148
+ # Used by {govuk_pagination_next} to generate the next link content
149
+ #
150
+ # @param block_is_level [Boolean] when there are no items, this will be true and will add extra classe
151
+ # to the link to make the next and previous pagination links level
152
+ # @param govuk_pagination_next_options [Hash] options that will be used in customising the HTML
153
+ #
154
+ # @option govuk_pagination_next_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create next button
155
+ # @option govuk_pagination_next_options [String] :href the URL for the link
156
+ # @option govuk_pagination_next_options [String] :text ('Next') the text for the link
157
+ # @option govuk_pagination_next_options [String] :lable_text additional text for the link when the pagination block is level
158
+ # @option govuk_pagination_next_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
159
+ #
160
+ # @return [ActiveSupport::SafeBuffer] the HTML for the next link/button
161
+
162
+ def govuk_pagination_next_content(block_is_level, **govuk_pagination_next_options)
163
+ capture do
164
+ concat(govuk_pagination_icon(:next)) if block_is_level
165
+ concat(tag.span(govuk_pagination_next_options[:text] || 'Next', class: pagination_next_and_previous_classes(block_is_level, govuk_pagination_next_options)))
166
+ concat(govuk_pagination_icon_label_text(block_is_level, govuk_pagination_next_options[:lable_text]))
167
+ concat(govuk_pagination_icon(:next)) unless block_is_level
168
+ end
169
+ end
170
+
171
+ # Returns the classes for the previous and next link/button label
172
+ #
173
+ # @param (see govuk_pagination_next_content)
174
+
175
+ def pagination_next_and_previous_classes(block_is_level, govuk_pagination_options)
176
+ "govuk-pagination__link-title #{'govuk-pagination__link-title--decorated' if block_is_level && !govuk_pagination_options[:lable_text]}".rstrip
177
+ end
178
+
179
+ # Generates the item links for {govuk_pagination}
180
+ #
181
+ # @param (see _govuk_pagination_items)
182
+ # @param form [ActionView::Helpers::FormBuilder] optional form builder used to create the item buttons
183
+ #
184
+ # @return [ActiveSupport::SafeBuffer] the HTML for the lits of items which is used in {govuk_pagination}
185
+
186
+ def govuk_pagination_items(govuk_pagination_items, form:)
187
+ if form
188
+ _govuk_pagination_items(govuk_pagination_items) do |govuk_pagination_item|
189
+ govuk_pagination_item_number_form(form, govuk_pagination_item)
190
+ end
191
+ else
192
+ _govuk_pagination_items(govuk_pagination_items) do |govuk_pagination_item|
193
+ govuk_pagination_item_number_tag(govuk_pagination_item)
194
+ end
195
+ end
196
+ end
197
+
198
+ # Wrapper method used by {govuk_pagination_items}
199
+ # to generate the pagination items HTML
200
+ #
201
+ # @param govuk_pagination_items [Array(Hash)] an array of item hashes for the pagination.
202
+ # There are two types of item:
203
+ # - {govuk_pagination_item_ellipsis ellipsis item}
204
+ # - {govuk_pagination_item_number_tag number item}
205
+ #
206
+ # @yield the pagination number item HTML generated by {govuk_pagination_items}
207
+ #
208
+ # @yieldparam govuk_pagination_item [Hash] the current pagination item in the loop
209
+ #
210
+ # @return [ActiveSupport::SafeBuffer] the HTML for the lits of items which is
211
+ # used in {govuk_pagination_items}
212
+
213
+ def _govuk_pagination_items(govuk_pagination_items)
214
+ tag.ul(class: 'govuk-pagination__list') 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
+
226
+ # Generates the icon for:
227
+ # - {govuk_pagination_previous}
228
+ # - {govuk_pagination_next}
229
+ #
230
+ # @param type [Symbol] the type of the pagination icon (+:prev+ or +:next+)
231
+ #
232
+ # @return [ActiveSupport::SafeBuffer]
233
+
234
+ def govuk_pagination_icon(type)
235
+ 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
236
+ tag.path(d: PAGINATION_ICON_PATHS[type])
237
+ end
238
+ end
239
+
240
+ # Generates the label text for:
241
+ # - {govuk_pagination_previous}
242
+ # - {govuk_pagination_next}
243
+ #
244
+ # @param block_is_level [Boolean] when there are no items, this will be true
245
+ # @param label_text [String] the additional text for the link
246
+ #
247
+ # @return [ActiveSupport::SafeBuffer]
248
+
249
+ def govuk_pagination_icon_label_text(block_is_level, label_text)
250
+ return unless block_is_level && label_text
251
+
252
+ concat(tag.span(':', class: 'govuk-visually-hidden'))
253
+ concat(tag.span(label_text, class: 'govuk-pagination__link-label'))
254
+ end
255
+
256
+ # Generates the ellipsis HTML for {govuk_pagination_items}
257
+ #
258
+ # @return [ActiveSupport::SafeBuffer] the HTML for an ellipsis item which is used in {govuk_pagination_items}
259
+
260
+ def govuk_pagination_item_ellipsis
261
+ tag.li('⋯', class: 'govuk-pagination__item govuk-pagination__item--ellipses')
262
+ end
263
+
264
+ # Generates the number item HTML for {govuk_pagination_items}
265
+ #
266
+ # @param (see _govuk_pagination_item_number)
267
+ #
268
+ # @option (see _govuk_pagination_item_number)
269
+ #
270
+ # @return [ActiveSupport::SafeBuffer] the HTML for an number item which is used in {govuk_pagination_items}
271
+
272
+ def govuk_pagination_item_number_tag(govuk_pagination_item)
273
+ _govuk_pagination_item_number(govuk_pagination_item) do
274
+ link_to(govuk_pagination_item[:number], govuk_pagination_item[:href], **govuk_pagination_item[:attributes])
275
+ end
276
+ end
277
+
278
+ # Generates the number item HTML for {govuk_pagination_items} when there is a ActionView::Helpers::FormBuilder
279
+ #
280
+ # @param form [ActionView::Helpers::FormBuilder] the form builder used to create the item button
281
+ # @param (see _govuk_pagination_item_number)
282
+ #
283
+ # @option (see _govuk_pagination_item_number)
284
+ #
285
+ # @return (see govuk_pagination_item_number_tag)
286
+
287
+ def govuk_pagination_item_number_form(form, govuk_pagination_item)
288
+ govuk_pagination_item[:classes] = 'pagination-number--button_as_link'
289
+
290
+ _govuk_pagination_item_number(govuk_pagination_item) do
291
+ form.button(govuk_pagination_item[:number], **govuk_pagination_item[:attributes])
292
+ end
293
+ end
294
+
295
+ # Wrapper method used by {govuk_pagination_item_number_tag} and {govuk_pagination_item_number_form}
296
+ # to generate the pagination number item HTML
297
+ #
298
+ # @param govuk_pagination_item [Hash] options that will be used in customising the HTML
299
+ #
300
+ # @option govuk_pagination_item [String] :href the URL for the link
301
+ # @option govuk_pagination_item [String] :number the number for the link
302
+ # @option govuk_pagination_item [String] :current is this item the current page
303
+ # @option govuk_pagination_item [Hash] :attributes ({aria: { label: 'Page <NUMBER>' } })
304
+ # any additional attributes that will added as part of the HTML
305
+ #
306
+ # @yield the pagination number item link (when {govuk_pagination_item_number_tag}) or button (when {govuk_pagination_item_number_form})
307
+ #
308
+ # @return [ActiveSupport::SafeBuffer] the HTML for an number item which is used
309
+ # in {govuk_pagination_item_number_tag} or {govuk_pagination_item_number_form}
310
+
311
+ def _govuk_pagination_item_number(govuk_pagination_item, &block)
312
+ initialise_attributes_and_set_classes(govuk_pagination_item, 'govuk-link govuk-pagination__link')
313
+
314
+ (govuk_pagination_item[:attributes][:aria] ||= {})[:label] ||= "Page #{govuk_pagination_item[:number]}"
315
+
316
+ govuk_pagination_list_classes = +'govuk-pagination__item'
317
+
318
+ if govuk_pagination_item[:current]
319
+ govuk_pagination_list_classes << ' govuk-pagination__item--current'
320
+ govuk_pagination_item[:attributes][:aria][:current] = 'page'
321
+ end
322
+
323
+ tag.li(class: govuk_pagination_list_classes, &block)
324
+ end
325
+
326
+ # The paths for the pagination next and previous icons
327
+
328
+ PAGINATION_ICON_PATHS = {
329
+ 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',
330
+ 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'
331
+ }.freeze
332
+ end
333
+ # rubocop:enable Metrics/ModuleLength
334
+ end
335
+ end
336
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
6
+
7
+ module CCS
8
+ module FrontendHelpers
9
+ module GovUKFrontend
10
+ # = GOV.UK Panel
11
+ #
12
+ # This helper is used for generating the panel component from the
13
+ # {https://design-system.service.gov.uk/components/panel GDS - Components - Panel}
14
+
15
+ module Panel
16
+ include SharedMethods
17
+ include ActionView::Context
18
+ include ActionView::Helpers::TagHelper
19
+ include ActionView::Helpers::TextHelper
20
+
21
+ # Generates the HTML for the GOV.UK Panel component
22
+ #
23
+ # @param title_text [String] title text for the panel which will be contained in haeding tags
24
+ # @param panel_text [String] text to use within the panel component
25
+ # @param govuk_panel_options [Hash] options that will be used in customising the HTML
26
+ #
27
+ # @option govuk_panel_options [String] :classes additional CSS classes for the panel HTML
28
+ # @option govuk_panel_options [Integer,String] :heading_level (default: 1) heading level for the panel title text
29
+ # @option govuk_panel_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
30
+ #
31
+ # @yield HTML that will be contained within the panel body. Ignored if panel text is given
32
+ #
33
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Panel
34
+ # which can then be rendered on the page
35
+
36
+ def govuk_panel(title_text, panel_text = nil, **govuk_panel_options)
37
+ initialise_attributes_and_set_classes(govuk_panel_options, 'govuk-panel govuk-panel--confirmation')
38
+
39
+ tag.div(**govuk_panel_options[:attributes]) do
40
+ concat(tag.send(:"h#{govuk_panel_options[:heading_level] || 1}", title_text, class: 'govuk-panel__title'))
41
+ if panel_text || block_given?
42
+ concat(tag.div(class: 'govuk-panel__body') do
43
+ panel_text || yield
44
+ end)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'tag'
4
+
5
+ module CCS
6
+ module FrontendHelpers
7
+ module GovUKFrontend
8
+ # = GOV.UK Phase banner
9
+ #
10
+ # This helper is used for generating the phase banner component from the
11
+ # {https://design-system.service.gov.uk/components/phase-banner GDS - Components - Phase banner}
12
+
13
+ module PhaseBanner
14
+ include ActionView::Helpers::TextHelper
15
+ include Tag
16
+
17
+ # Generates the HTML for the GOV.UK Phase banner component
18
+ #
19
+ # @param text [String] the text for the phase banner
20
+ # @param tag_options [Hash] paramters for the govuk tag (see {govuk_tag}).
21
+ # options are:
22
+ # - +text+
23
+ # - +colour+
24
+ # - +options+
25
+ # @param govuk_phase_banner_options [Hash] options that will be used in customising the HTML
26
+ #
27
+ # @option govuk_phase_banner_options [String] :classes additional CSS classes for the phase banner HTML
28
+ # @option govuk_phase_banner_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
29
+ #
30
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Phase banner
31
+ # which can then be rendered on the page
32
+
33
+ def govuk_phase_banner(text, tag_options, **govuk_phase_banner_options)
34
+ initialise_attributes_and_set_classes(govuk_phase_banner_options, 'govuk-phase-banner')
35
+
36
+ tag_options[:options] ||= {}
37
+ tag_options[:options][:classes] = "govuk-phase-banner__content__tag #{tag_options[:options][:classes]}"
38
+
39
+ tag.div(**govuk_phase_banner_options[:attributes]) do
40
+ tag.p(class: 'govuk-phase-banner__content') do
41
+ concat(govuk_tag(tag_options[:text], tag_options[:colour], **tag_options[:options]))
42
+ concat(tag.span(text, class: 'govuk-phase-banner__text'))
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
6
+
7
+ module CCS
8
+ module FrontendHelpers
9
+ module GovUKFrontend
10
+ # = GOV.UK Skip Link
11
+ #
12
+ # This helper is used for generating the skip link component from the
13
+ # {https://design-system.service.gov.uk/components/skip-link GDS - Components - Skip link}
14
+
15
+ module SkipLink
16
+ include SharedMethods
17
+ include ActionView::Helpers::UrlHelper
18
+
19
+ # Generates the HTML for the GOV.UK Skip link component
20
+ #
21
+ # @param text [String] the text for the skip link
22
+ # @param href [String] the href for the skip link
23
+ # @param govuk_skip_link_options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option govuk_skip_link_options [String] :classes additional CSS classes for the skip link HTML
26
+ # @option govuk_skip_link_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
27
+ #
28
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Skip link
29
+ # which can then be rendered on the page
30
+
31
+ def govuk_skip_link(text, href = '#content', **govuk_skip_link_options)
32
+ initialise_attributes_and_set_classes(govuk_skip_link_options, 'govuk-skip-link')
33
+ set_data_module(govuk_skip_link_options, 'govuk-skip-link')
34
+
35
+ link_to(text, href, **govuk_skip_link_options[:attributes])
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end