ccs-frontend_helpers 0.1.0 → 0.1.1.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +11 -2
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +4 -1
  5. data/Gemfile +15 -1
  6. data/Gemfile.lock +153 -114
  7. data/ccs-frontend_helpers.gemspec +1 -11
  8. data/lib/ccs/components/base.rb +64 -0
  9. data/lib/ccs/components/ccs/dashboard_section/panel.rb +57 -0
  10. data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
  11. data/lib/ccs/components/ccs/footer/link.rb +55 -0
  12. data/lib/ccs/components/ccs/footer/meta.rb +59 -0
  13. data/lib/ccs/components/ccs/footer/navigation.rb +60 -0
  14. data/lib/ccs/components/ccs/footer.rb +95 -0
  15. data/lib/ccs/components/ccs/header/link.rb +60 -0
  16. data/lib/ccs/components/ccs/header/navigation.rb +98 -0
  17. data/lib/ccs/components/ccs/header/service_authentication.rb +53 -0
  18. data/lib/ccs/components/ccs/header.rb +110 -0
  19. data/lib/ccs/{frontend_helpers/ccs_frontend → components/ccs}/logo.rb +10 -12
  20. data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
  21. data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
  22. data/lib/ccs/components/govuk/accordion/section.rb +61 -0
  23. data/lib/ccs/components/govuk/accordion.rb +58 -0
  24. data/lib/ccs/components/govuk/back_link.rb +51 -0
  25. data/lib/ccs/components/govuk/breadcrumbs/link.rb +57 -0
  26. data/lib/ccs/components/govuk/breadcrumbs.rb +55 -0
  27. data/lib/ccs/components/govuk/button.rb +107 -0
  28. data/lib/ccs/components/govuk/cookie_banner/action.rb +60 -0
  29. data/lib/ccs/components/govuk/cookie_banner/message.rb +80 -0
  30. data/lib/ccs/components/govuk/cookie_banner.rb +55 -0
  31. data/lib/ccs/components/govuk/details.rb +53 -0
  32. data/lib/ccs/components/govuk/error_message.rb +60 -0
  33. data/lib/ccs/components/govuk/error_summary/item.rb +54 -0
  34. data/lib/ccs/components/govuk/error_summary.rb +70 -0
  35. data/lib/ccs/components/govuk/field/input/character_count.rb +129 -0
  36. data/lib/ccs/components/govuk/field/input/file_upload.rb +44 -0
  37. data/lib/ccs/components/govuk/field/input/select.rb +82 -0
  38. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +55 -0
  39. data/lib/ccs/components/govuk/field/input/text_input.rb +97 -0
  40. data/lib/ccs/components/govuk/field/input/textarea.rb +59 -0
  41. data/lib/ccs/components/govuk/field/input.rb +62 -0
  42. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +69 -0
  43. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +65 -0
  44. data/lib/ccs/components/govuk/field/inputs/date_input.rb +89 -0
  45. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +47 -0
  46. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +43 -0
  47. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +50 -0
  48. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +50 -0
  49. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +44 -0
  50. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +43 -0
  51. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +50 -0
  52. data/lib/ccs/components/govuk/field/inputs/item.rb +111 -0
  53. data/lib/ccs/components/govuk/field/inputs/radios.rb +69 -0
  54. data/lib/ccs/components/govuk/field/inputs.rb +57 -0
  55. data/lib/ccs/components/govuk/field.rb +108 -0
  56. data/lib/ccs/components/govuk/fieldset/legend.rb +65 -0
  57. data/lib/ccs/components/govuk/fieldset.rb +54 -0
  58. data/lib/ccs/components/govuk/footer/link.rb +55 -0
  59. data/lib/ccs/components/govuk/footer/meta.rb +59 -0
  60. data/lib/ccs/components/govuk/footer/navigation.rb +60 -0
  61. data/lib/ccs/components/govuk/footer.rb +131 -0
  62. data/lib/ccs/components/govuk/form_group.rb +60 -0
  63. data/lib/ccs/components/govuk/header/link.rb +56 -0
  64. data/lib/ccs/components/govuk/header/navigation.rb +71 -0
  65. data/lib/ccs/components/govuk/header.rb +107 -0
  66. data/lib/ccs/components/govuk/hint.rb +49 -0
  67. data/lib/ccs/components/govuk/inset_text.rb +52 -0
  68. data/lib/ccs/components/govuk/label.rb +85 -0
  69. data/lib/ccs/components/govuk/notification_banner.rb +107 -0
  70. data/lib/ccs/components/govuk/pagination/increment/next.rb +44 -0
  71. data/lib/ccs/components/govuk/pagination/increment/previous.rb +43 -0
  72. data/lib/ccs/components/govuk/pagination/increment.rb +98 -0
  73. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +28 -0
  74. data/lib/ccs/components/govuk/pagination/item/form.rb +49 -0
  75. data/lib/ccs/components/govuk/pagination/item/tag.rb +47 -0
  76. data/lib/ccs/components/govuk/pagination/item.rb +64 -0
  77. data/lib/ccs/components/govuk/pagination.rb +96 -0
  78. data/lib/ccs/components/govuk/panel.rb +62 -0
  79. data/lib/ccs/components/govuk/phase_banner.rb +69 -0
  80. data/lib/ccs/components/govuk/skip_link.rb +51 -0
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +53 -0
  82. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +50 -0
  83. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +45 -0
  84. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +63 -0
  85. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +69 -0
  86. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +56 -0
  87. data/lib/ccs/components/govuk/step_by_step_navigation.rb +59 -0
  88. data/lib/ccs/components/govuk/summary_list/action/link.rb +59 -0
  89. data/lib/ccs/components/govuk/summary_list/card/actions.rb +59 -0
  90. data/lib/ccs/components/govuk/summary_list/card/title.rb +51 -0
  91. data/lib/ccs/components/govuk/summary_list/card.rb +63 -0
  92. data/lib/ccs/components/govuk/summary_list/row/actions.rb +59 -0
  93. data/lib/ccs/components/govuk/summary_list/row/key.rb +47 -0
  94. data/lib/ccs/components/govuk/summary_list/row/value.rb +47 -0
  95. data/lib/ccs/components/govuk/summary_list/row.rb +67 -0
  96. data/lib/ccs/components/govuk/summary_list.rb +74 -0
  97. data/lib/ccs/components/govuk/table/body/data_cell.rb +53 -0
  98. data/lib/ccs/components/govuk/table/body/head_cell.rb +52 -0
  99. data/lib/ccs/components/govuk/table/header/head_cell.rb +54 -0
  100. data/lib/ccs/components/govuk/table.rb +111 -0
  101. data/lib/ccs/components/govuk/tabs/panel.rb +58 -0
  102. data/lib/ccs/components/govuk/tabs/tab.rb +56 -0
  103. data/lib/ccs/components/govuk/tabs.rb +66 -0
  104. data/lib/ccs/components/govuk/tag.rb +51 -0
  105. data/lib/ccs/components/govuk/warning_text.rb +61 -0
  106. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +27 -0
  107. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +6 -119
  108. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +6 -183
  109. data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
  110. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +8 -95
  111. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +6 -17
  112. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +6 -54
  113. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +6 -105
  114. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +28 -0
  115. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +28 -0
  116. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +6 -114
  117. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +28 -0
  118. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +7 -23
  119. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +11 -32
  120. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +13 -65
  121. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +7 -48
  122. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +28 -0
  123. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +6 -161
  124. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +13 -24
  125. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +6 -139
  126. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +8 -17
  127. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +28 -0
  128. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +7 -21
  129. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +7 -70
  130. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +7 -113
  131. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +6 -314
  132. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +7 -28
  133. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +8 -27
  134. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +28 -0
  135. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +28 -0
  136. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +6 -18
  137. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +7 -186
  138. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +6 -204
  139. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +11 -100
  140. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +6 -73
  141. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +7 -21
  142. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +28 -0
  143. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +7 -30
  144. data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
  145. data/lib/ccs/frontend_helpers/version.rb +1 -1
  146. metadata +117 -147
  147. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
  148. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
  149. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
  150. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
  151. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
  152. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
  153. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
  154. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
  155. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
  156. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
  157. data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -1,336 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/pagination'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
9
7
  module GovUKFrontend
10
- # rubocop:disable Metrics/ModuleLength
11
-
12
8
  # = GOV.UK Pagination
13
9
  #
14
10
  # This helper is used for generating the pagination component from the
15
11
  # {https://design-system.service.gov.uk/components/pagination GDS - Components - Pagination}
16
12
 
17
13
  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
14
  # Generates the HTML for the GOV.UK Pagination component
25
15
  #
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
16
+ # @param (see CCS::Components::GovUK::Pagination#initialize)
58
17
  #
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}
18
+ # @option (see CCS::Components::GovUK::Pagination#initialize)
78
19
  #
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'
20
+ # @return (see CCS::Components::GovUK::Pagination#render)
89
21
 
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
22
+ def govuk_pagination(**options)
23
+ Components::GovUK::Pagination.new(context: self, **options).render
99
24
  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
25
  end
333
- # rubocop:enable Metrics/ModuleLength
334
26
  end
335
27
  end
336
28
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/panel'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -13,37 +11,18 @@ module CCS
13
11
  # {https://design-system.service.gov.uk/components/panel GDS - Components - Panel}
14
12
 
15
13
  module Panel
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
-
21
14
  # Generates the HTML for the GOV.UK Panel component
22
15
  #
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
16
+ # @param (see CCS::Components::GovUK::Panel#initialize)
26
17
  #
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
18
+ # @option (see CCS::Components::GovUK::Panel#initialize)
30
19
  #
31
- # @yield HTML that will be contained within the panel body. Ignored if panel text is given
20
+ # @yield (see CCS::Components::GovUK::Panel#render)
32
21
  #
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')
22
+ # @return (see CCS::Components::GovUK::Panel#render)
38
23
 
39
- tag.div(**govuk_panel_options[:attributes]) do
40
- concat(tag.send(:"h#{govuk_panel_options[:heading_level] || 1}", title_text))
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
24
+ def govuk_panel(title_text, panel_text = nil, **options, &block)
25
+ Components::GovUK::Panel.new(context: self, title_text: title_text, panel_text: panel_text, **options).render(&block)
47
26
  end
48
27
  end
49
28
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'tag'
3
+ require_relative '../../components/govuk/phase_banner'
4
4
 
5
5
  module CCS
6
6
  module FrontendHelpers
@@ -11,37 +11,18 @@ module CCS
11
11
  # {https://design-system.service.gov.uk/components/phase-banner GDS - Components - Phase banner}
12
12
 
13
13
  module PhaseBanner
14
- include ActionView::Helpers::TextHelper
15
- include Tag
16
-
17
14
  # Generates the HTML for the GOV.UK Phase banner component
18
15
  #
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
16
+ # @param (see CCS::Components::GovUK::PhaseBanner#initialize)
26
17
  #
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
18
+ # @option (see CCS::Components::GovUK::PhaseBanner#initialize)
29
19
  #
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]}"
20
+ # @yield (see CCS::Components::GovUK::PhaseBanner#render)
21
+ #
22
+ # @return (see CCS::Components::GovUK::PhaseBanner#render)
38
23
 
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
24
+ def govuk_phase_banner(tag_options, text = nil, **options, &block)
25
+ Components::GovUK::PhaseBanner.new(context: self, tag_options: tag_options, text: text, **options).render(&block)
45
26
  end
46
27
  end
47
28
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../components/govuk/field/inputs/radios'
4
+
5
+ module CCS
6
+ module FrontendHelpers
7
+ module GovUKFrontend
8
+ # = GOV.UK Radios
9
+ #
10
+ # This helper is used for generating the radios component from the
11
+ # {https://design-system.service.gov.uk/components/radios GDS - Components - Radios}
12
+
13
+ module Radios
14
+ # Generates the HTML for the GOV.UK Radios component
15
+ #
16
+ # @param (see CCS::Components::GovUK::Inputs::Radios#initialize)
17
+ #
18
+ # @option (see CCS::Components::GovUK::Inputs::Radios#initialize)
19
+ #
20
+ # @return (see CCS::Components::GovUK::Inputs::Radios#render)
21
+
22
+ def govuk_radios(attribute, radio_items, **options)
23
+ Components::GovUK::Field::Inputs::Radios.new(context: self, attribute: attribute, radio_items: radio_items, **options).render
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../components/govuk/field/input/select'
4
+
5
+ module CCS
6
+ module FrontendHelpers
7
+ module GovUKFrontend
8
+ # = GOV.UK Select
9
+ #
10
+ # This helper is used for generating the select component from the
11
+ # {https://design-system.service.gov.uk/components/select GDS - Components - Select}
12
+
13
+ module Select
14
+ # Generates the HTML for the GOV.UK Select component
15
+ #
16
+ # @param (see CCS::Components::GovUK::Input::Select#initialize)
17
+ #
18
+ # @option (see CCS::Components::GovUK::Input::Select#initialize)
19
+ #
20
+ # @return (see CCS::Components::GovUK::Input::Select#render)
21
+
22
+ def govuk_select(attribute, items, **options)
23
+ Components::GovUK::Field::Input::Select.new(context: self, attribute: attribute, items: items, **options).render
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/skip_link'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -13,26 +11,16 @@ module CCS
13
11
  # {https://design-system.service.gov.uk/components/skip-link GDS - Components - Skip link}
14
12
 
15
13
  module SkipLink
16
- include SharedMethods
17
- include ActionView::Helpers::UrlHelper
18
-
19
14
  # Generates the HTML for the GOV.UK Skip link component
20
15
  #
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
16
+ # @param (see CCS::Components::GovUK::SkipLink#initialize)
24
17
  #
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
18
+ # @option (see CCS::Components::GovUK::SkipLink#initialize)
27
19
  #
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')
20
+ # @return (see CCS::Components::GovUK::SkipLink#render)
34
21
 
35
- link_to(text, href, **govuk_skip_link_options[:attributes])
22
+ def govuk_skip_link(text, href = nil, **options)
23
+ Components::GovUK::SkipLink.new(context: self, text: text, href: href, **options).render
36
24
  end
37
25
  end
38
26
  end