ccs-frontend_helpers 0.1.0.rc.1 → 0.1.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +4 -1
  5. data/Gemfile.lock +71 -71
  6. data/lib/ccs/components/base.rb +64 -0
  7. data/lib/ccs/components/ccs/dashboard_section/panel.rb +55 -0
  8. data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
  9. data/lib/ccs/components/ccs/footer/link.rb +53 -0
  10. data/lib/ccs/components/ccs/footer/meta.rb +58 -0
  11. data/lib/ccs/components/ccs/footer/navigation.rb +59 -0
  12. data/lib/ccs/components/ccs/footer.rb +93 -0
  13. data/lib/ccs/components/ccs/header/link.rb +58 -0
  14. data/lib/ccs/components/ccs/header/navigation.rb +97 -0
  15. data/lib/ccs/components/ccs/header/service_authentication.rb +52 -0
  16. data/lib/ccs/components/ccs/header.rb +108 -0
  17. data/lib/ccs/components/ccs/logo.rb +45 -0
  18. data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
  19. data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
  20. data/lib/ccs/components/govuk/accordion/section.rb +60 -0
  21. data/lib/ccs/components/govuk/accordion.rb +56 -0
  22. data/lib/ccs/components/govuk/back_link.rb +49 -0
  23. data/lib/ccs/components/govuk/breadcrumbs/link.rb +55 -0
  24. data/lib/ccs/components/govuk/breadcrumbs.rb +53 -0
  25. data/lib/ccs/components/govuk/button.rb +105 -0
  26. data/lib/ccs/components/govuk/cookie_banner/action.rb +58 -0
  27. data/lib/ccs/components/govuk/cookie_banner/message.rb +78 -0
  28. data/lib/ccs/components/govuk/cookie_banner.rb +53 -0
  29. data/lib/ccs/components/govuk/details.rb +51 -0
  30. data/lib/ccs/components/govuk/error_message.rb +58 -0
  31. data/lib/ccs/components/govuk/error_summary/item.rb +52 -0
  32. data/lib/ccs/components/govuk/error_summary.rb +68 -0
  33. data/lib/ccs/components/govuk/field/input/character_count.rb +127 -0
  34. data/lib/ccs/components/govuk/field/input/file_upload.rb +42 -0
  35. data/lib/ccs/components/govuk/field/input/select.rb +80 -0
  36. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +53 -0
  37. data/lib/ccs/components/govuk/field/input/text_input.rb +95 -0
  38. data/lib/ccs/components/govuk/field/input/textarea.rb +57 -0
  39. data/lib/ccs/components/govuk/field/input.rb +60 -0
  40. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +67 -0
  41. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +63 -0
  42. data/lib/ccs/components/govuk/field/inputs/date_input.rb +87 -0
  43. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +45 -0
  44. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +41 -0
  45. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +48 -0
  46. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +48 -0
  47. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +42 -0
  48. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +41 -0
  49. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +48 -0
  50. data/lib/ccs/components/govuk/field/inputs/item.rb +109 -0
  51. data/lib/ccs/components/govuk/field/inputs/radios.rb +67 -0
  52. data/lib/ccs/components/govuk/field/inputs.rb +55 -0
  53. data/lib/ccs/components/govuk/field.rb +106 -0
  54. data/lib/ccs/components/govuk/fieldset/legend.rb +63 -0
  55. data/lib/ccs/components/govuk/fieldset.rb +52 -0
  56. data/lib/ccs/components/govuk/footer/link.rb +53 -0
  57. data/lib/ccs/components/govuk/footer/meta.rb +58 -0
  58. data/lib/ccs/components/govuk/footer/navigation.rb +59 -0
  59. data/lib/ccs/components/govuk/footer.rb +129 -0
  60. data/lib/ccs/components/govuk/form_group.rb +58 -0
  61. data/lib/ccs/components/govuk/header/link.rb +54 -0
  62. data/lib/ccs/components/govuk/header/navigation.rb +70 -0
  63. data/lib/ccs/components/govuk/header.rb +105 -0
  64. data/lib/ccs/components/govuk/hint.rb +47 -0
  65. data/lib/ccs/components/govuk/inset_text.rb +50 -0
  66. data/lib/ccs/components/govuk/label.rb +83 -0
  67. data/lib/ccs/components/govuk/notification_banner.rb +105 -0
  68. data/lib/ccs/components/govuk/pagination/increment/next.rb +42 -0
  69. data/lib/ccs/components/govuk/pagination/increment/previous.rb +41 -0
  70. data/lib/ccs/components/govuk/pagination/increment.rb +96 -0
  71. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +26 -0
  72. data/lib/ccs/components/govuk/pagination/item/form.rb +47 -0
  73. data/lib/ccs/components/govuk/pagination/item/tag.rb +45 -0
  74. data/lib/ccs/components/govuk/pagination/item.rb +62 -0
  75. data/lib/ccs/components/govuk/pagination.rb +94 -0
  76. data/lib/ccs/components/govuk/panel.rb +60 -0
  77. data/lib/ccs/components/govuk/phase_banner.rb +67 -0
  78. data/lib/ccs/components/govuk/skip_link.rb +49 -0
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +51 -0
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +48 -0
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +43 -0
  82. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +61 -0
  83. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +67 -0
  84. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +54 -0
  85. data/lib/ccs/components/govuk/step_by_step_navigation.rb +57 -0
  86. data/lib/ccs/components/govuk/summary_list/action/link.rb +57 -0
  87. data/lib/ccs/components/govuk/summary_list/card/actions.rb +57 -0
  88. data/lib/ccs/components/govuk/summary_list/card/title.rb +49 -0
  89. data/lib/ccs/components/govuk/summary_list/card.rb +61 -0
  90. data/lib/ccs/components/govuk/summary_list/row/actions.rb +57 -0
  91. data/lib/ccs/components/govuk/summary_list/row/key.rb +45 -0
  92. data/lib/ccs/components/govuk/summary_list/row/value.rb +45 -0
  93. data/lib/ccs/components/govuk/summary_list/row.rb +63 -0
  94. data/lib/ccs/components/govuk/summary_list.rb +72 -0
  95. data/lib/ccs/components/govuk/table/body/data_cell.rb +51 -0
  96. data/lib/ccs/components/govuk/table/body/head_cell.rb +50 -0
  97. data/lib/ccs/components/govuk/table/header/head_cell.rb +52 -0
  98. data/lib/ccs/components/govuk/table.rb +109 -0
  99. data/lib/ccs/components/govuk/tabs/panel.rb +56 -0
  100. data/lib/ccs/components/govuk/tabs/tab.rb +54 -0
  101. data/lib/ccs/components/govuk/tabs.rb +64 -0
  102. data/lib/ccs/components/govuk/tag.rb +49 -0
  103. data/lib/ccs/components/govuk/warning_text.rb +59 -0
  104. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +25 -0
  105. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +16 -131
  106. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +16 -195
  107. data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
  108. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +16 -105
  109. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +16 -29
  110. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +16 -66
  111. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +16 -117
  112. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +26 -0
  113. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +26 -0
  114. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +16 -126
  115. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +26 -0
  116. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +18 -36
  117. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +31 -54
  118. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +32 -86
  119. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +18 -61
  120. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +26 -0
  121. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +16 -173
  122. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +26 -39
  123. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +16 -151
  124. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -28
  125. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +26 -0
  126. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +18 -34
  127. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +17 -82
  128. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +18 -126
  129. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +16 -326
  130. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +18 -41
  131. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +18 -39
  132. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +26 -0
  133. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +26 -0
  134. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +16 -30
  135. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +23 -204
  136. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +16 -216
  137. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +16 -114
  138. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +16 -85
  139. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +16 -32
  140. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +26 -0
  141. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +18 -43
  142. data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
  143. data/lib/ccs/frontend_helpers/version.rb +1 -1
  144. metadata +110 -14
  145. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
  146. data/lib/ccs/frontend_helpers/ccs_frontend/logo.rb +0 -49
  147. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
  148. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
  149. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
  150. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
  151. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
  152. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
  153. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
  154. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
  155. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
  156. data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -1,214 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/step_by_step_navigation'
6
4
 
7
5
  module CCS
8
- module FrontendHelpers
9
- module GovUKFrontend
10
- # = GOV.UK Step by step navigation
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK Step by step navigation
8
+ #
9
+ # This helper is used for generating the Step by step navigation component from the
10
+ # {https://design-system.service.gov.uk/patterns/step-by-step-navigation/ GDS - Pages - Step by step navigation}
11
+ #
12
+ # To use this component you need the following from {https://github.com/alphagov/govuk_publishing_components GOV.UK Publishing Components}.
13
+ # For the SCSS components you should add:
14
+ # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss _step-by-step-nav.scss}
15
+ # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss _step-by-step-nav-related.scss}
16
+ # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss _step-by-step-nav-header.scss}
17
+ # For the JavaScript you should add:
18
+ # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js step-by-step-nav.js}
19
+
20
+ module StepByStepNavigation
21
+ # Generates the HTML for the GOV.UK Step by step navigation component
11
22
  #
12
- # This helper is used for generating the Step by step navigation component from the
13
- # {https://design-system.service.gov.uk/patterns/step-by-step-navigation/ GDS - Pages - Step by step navigation}
23
+ # @param (see CCS::Components::GovUK::StepByStepNavigation#initialize)
14
24
  #
15
- # To use this component you need the following from {https://github.com/alphagov/govuk_publishing_components GOV.UK Publishing Components}.
16
- # For the SCSS components you should add:
17
- # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss _step-by-step-nav.scss}
18
- # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss _step-by-step-nav-related.scss}
19
- # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss _step-by-step-nav-header.scss}
20
- # For the JavaScript you should add:
21
- # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js step-by-step-nav.js}
22
-
23
- module StepByStepNavigation
24
- include SharedMethods
25
- include ActionView::Helpers
26
- include ActionView::Context
27
-
28
- # Generates the HTML for the GOV.UK Step by step navigation component (experimental)
29
- #
30
- # @param step_by_step_sections [Array] the navigation items that will be rendered to the page.
31
- # See {govuk_step_by_step_navigation_section} for more details
32
- # @param govuk_step_by_step_navigation_options [Hash] options that will be used in customising the HTML
33
- #
34
- # @option govuk_step_by_step_navigation_options [String] :classes additional CSS classes for the step by step navigation HTML
35
- # @option govuk_step_by_step_navigation_options [Hash] :attributes ({data: { module: 'govuk-step-by-step-navigation', 'show-text': 'Show', 'hide-text': 'Hide', 'show-all-text': 'Show all', 'hide-all-text': 'Hide all' } })
36
- # any additional attributes that will added as part of the HTML
37
- #
38
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation
39
- # which can then be rendered on the page
40
-
41
- def govuk_step_by_step_navigation(step_by_step_sections, **govuk_step_by_step_navigation_options)
42
- initialise_attributes_and_set_classes(govuk_step_by_step_navigation_options, 'gem-c-step-nav gem-c-step-nav--large gem-c-step-nav--active')
43
- determine_step_by_step_navigation_attributes(govuk_step_by_step_navigation_options)
44
-
45
- tag.div(**govuk_step_by_step_navigation_options[:attributes]) do
46
- tag.ol(class: 'gem-c-step-nav__steps') do
47
- step_by_step_sections.each.with_index(1) { |step_by_step_section, section_index| concat(govuk_step_by_step_navigation_section(step_by_step_section, section_index.to_s)) }
48
- end
49
- end
50
- end
51
-
52
- private
53
-
54
- # The HTML for a section within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation}
55
- #
56
- # @param step_by_step_section [Hash] the parameters that will be used to create the section
57
- # @param section_index [String] the index of the section
58
- #
59
- # @option step_by_step_section [Hash] :heading the paramaters for the section heading,
60
- # see {govuk_step_by_step_navigation_heading} for more details
61
- # @option step_by_step_section [Array] :content the paramaters for the section content,
62
- # see {govuk_step_by_step_navigation_content} for more details
63
- #
64
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section
65
- # which is used in {govuk_step_by_step_navigation}
66
-
67
- def govuk_step_by_step_navigation_section(step_by_step_section, section_index)
68
- section_id = convert_to_id(step_by_step_section[:heading][:text])
69
-
70
- tag.li(class: 'gem-c-step-nav__step js-step', id: section_id) do
71
- concat(govuk_step_by_step_navigation_heading(step_by_step_section[:heading], section_index))
72
- concat(govuk_step_by_step_navigation_content(step_by_step_section[:content], section_id, section_index))
73
- end
74
- end
75
-
76
- # The HTML for a section heading within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation_section}
77
- #
78
- # @param section_heading [Hash] the parameters that will be used to create the heading
79
- # @param section_index [String] the index of the section
80
- #
81
- # @option section_heading [Hash] :text text for the section heading
82
- # @option section_heading [Hash] :logic (nil) text to show instead of a number in the sidebar
83
- #
84
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section heading
85
- # which is used in {govuk_step_by_step_navigation_section}
86
-
87
- def govuk_step_by_step_navigation_heading(section_heading, section_index)
88
- logic = section_heading[:logic]
89
-
90
- tag.div(class: 'gem-c-step-nav__header js-toggle-panel', data: { position: section_index }) do
91
- tag.h2(class: 'gem-c-step-nav__title') do
92
- concat(tag.span(class: "gem-c-step-nav__circle gem-c-step-nav__circle--#{logic ? 'logic' : 'number'}") do
93
- tag.span(class: 'gem-c-step-nav__circle-inner') do
94
- tag.span(class: 'gem-c-step-nav__circle-background') do
95
- concat(tag.span('Step', class: 'govuk-visually-hidden'))
96
- concat(logic || section_index)
97
- end
98
- end
99
- end)
100
- concat(tag.span(class: 'js-step-title') do
101
- tag.span(section_heading[:text], class: 'js-step-title-text')
102
- end)
103
- end
104
- end
105
- end
106
-
107
- # The HTML for a section content within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation_section}
108
- #
109
- # @param content [Array] an array of the content items that will be rendered within the section.
110
- # Only two types of content are allowed:
111
- # - +:paragraph+ - see {govuk_step_by_step_navigation_paragraph}
112
- # - +:list+ - see {govuk_step_by_step_navigation_list}
113
- # @param section_id [String] the id of the section
114
- # @param section_index [String] the index of the section
115
- #
116
- # @option content [Symbol] :type the type of content, either +:paragraph+ or +list+
117
- # @option content [Symbol] :text the text for the paragraph. Ignored unless the +type+ is +:list+
118
- # @option content [Symbol] :items the items for the list. Ignored unless the +type+ is +:paragraph+
119
- #
120
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section content
121
- # which is used in {govuk_step_by_step_navigation_section}
122
-
123
- def govuk_step_by_step_navigation_content(content, section_id, section_index)
124
- tag.div(class: 'gem-c-step-nav__panel js-panel', id: "step-panel-#{section_id}-#{section_index}") do
125
- content.each do |element|
126
- concat(
127
- case element[:type]
128
- when :paragraph
129
- govuk_step_by_step_navigation_paragraph(element[:text])
130
- when :list
131
- govuk_step_by_step_navigation_list(element[:items])
132
- end
133
- )
134
- end
135
- end
136
- end
137
-
138
- # The HTML for the paragraph item within the GOV.UK Step by step navigation content, used by {govuk_step_by_step_navigation_content}
139
- #
140
- # @param text [String] the text for the paragraph
141
- #
142
- # @return [ActiveSupport::SafeBuffer] the HTML for the paragraph
143
- # which is used in {govuk_step_by_step_navigation_content}
144
-
145
- def govuk_step_by_step_navigation_paragraph(text)
146
- tag.p(
147
- text,
148
- class: 'gem-c-step-nav__paragraph',
149
- )
150
- end
151
-
152
- # The HTML for the list items within the GOV.UK Step by step navigation content, used by {govuk_step_by_step_navigation_content}
153
- #
154
- # @param items [Array] an array of the list items,
155
- # see {govuk_step_by_step_navigation_list_item} for more details
156
- #
157
- # @return [ActiveSupport::SafeBuffer] the HTML for the list
158
- # which is used in {govuk_step_by_step_navigation_content}
159
-
160
- def govuk_step_by_step_navigation_list(items)
161
- tag.ul(class: 'gem-c-step-nav__list gem-c-step-nav__list--choice', data: { length: items.length.to_s }) do
162
- items.each do |item|
163
- concat(govuk_step_by_step_navigation_list_item(item[:text], item[:no_marker]))
164
- end
165
- end
166
- end
167
-
168
- # The HTML for a list item, used by {govuk_step_by_step_navigation_list}
169
- #
170
- # @param text [Symbol] the text of the list item
171
- # @param no_marker [Symbol] (nil) switch to hide the bullet marker
172
- #
173
- # @return [ActiveSupport::SafeBuffer] the HTML for the list item
174
- # which is used in {govuk_step_by_step_navigation_list}
175
-
176
- def govuk_step_by_step_navigation_list_item(text, no_marker)
177
- list_item_classes = ['gem-c-step-nav__list-item js-list-item']
178
- list_item_classes << 'gem-c-step-nav__list--no-marker' if no_marker
179
-
180
- tag.li(class: list_item_classes) do
181
- tag.span(text)
182
- end
183
- end
184
-
185
- # Converts the title text into a string to be used as the section id
186
- #
187
- # @param title [String] the section title that will be converted
188
- #
189
- # @return [String] the section id
190
-
191
- def convert_to_id(title)
192
- title.downcase.gsub(' ', '-').gsub('(', '').gsub(')', '')
193
- end
194
-
195
- # Generates a hash with the attributes used in {govuk_step_by_step_navigation}
196
- #
197
- # @param govuk_step_by_step_navigation_options [Hash] options that will be used in customising the HTML
198
- #
199
- # @option (see govuk_step_by_step_navigation)
200
- #
201
- # @return [Hash] contains the HTMl attributes used in {govuk_step_by_step_navigation}
202
-
203
- def determine_step_by_step_navigation_attributes(govuk_step_by_step_navigation_options)
204
- set_data_module(govuk_step_by_step_navigation_options, 'govuk-step-by-step-navigation')
205
-
206
- DEFAULT_SHOW_HIDE_TEXT.each { |key, value| govuk_step_by_step_navigation_options[:attributes][:data][key] ||= value }
207
- end
208
-
209
- # Default text for the show and hide buttons which are part of each section
25
+ # @option (see CCS::Components::GovUK::StepByStepNavigation#initialize)
26
+ #
27
+ # @return (see CCS::Components::GovUK::StepByStepNavigation#render)
210
28
 
211
- DEFAULT_SHOW_HIDE_TEXT = { 'show-text': 'Show', 'hide-text': 'Hide', 'show-all-text': 'Show all', 'hide-all-text': 'Hide all' }.freeze
29
+ def govuk_step_by_step_navigation(step_by_step_navigation_sections, **options)
30
+ Components::GovUK::StepByStepNavigation.new(context: self, step_by_step_navigation_sections: step_by_step_navigation_sections, **options).render
212
31
  end
213
32
  end
214
33
  end
@@ -1,225 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/summary_list'
6
4
 
7
5
  module CCS
8
- module FrontendHelpers
9
- module GovUKFrontend
10
- # = GOV.UK Summary list
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK Summary list
8
+ #
9
+ # This helper is used for generating the summary list component from the
10
+ # {https://design-system.service.gov.uk/components/summary-list GDS - Components - Summary list}
11
+
12
+ module SummaryList
13
+ # Generates the HTML for the GOV.UK Summary list component
11
14
  #
12
- # This helper is used for generating the summary list component from the
13
- # {https://design-system.service.gov.uk/components/summary-list GDS - Components - Summary list}
14
-
15
- module SummaryList
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
- include ActionView::Helpers::UrlHelper
21
-
22
- # Generates the HTML for the GOV.UK Summary list component
23
- #
24
- # @param summary_list_items [Array] the list of summary items. See {govuk_summary_list_row}
25
- # @param govuk_summary_list_options [Hash] options that will be used in customising the HTML
26
- #
27
- # @option govuk_summary_list_options [String] :classes additional CSS classes for the summary list HTML
28
- # @option govuk_summary_list_options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
29
- #
30
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Summary list
31
- # which can then be rendered on the page
32
-
33
- def govuk_summary_list(summary_list_items, **govuk_summary_list_options)
34
- if govuk_summary_list_options[:card]
35
- govuk_summary_card(**govuk_summary_list_options[:card]) do
36
- _govuk_summary_list(summary_list_items, govuk_summary_list_options)
37
- end
38
- else
39
- _govuk_summary_list(summary_list_items, govuk_summary_list_options)
40
- end
41
- end
42
-
43
- private
44
-
45
- # Generates the HTML for the GOV.UK Summary list.
46
- # Used in {govuk_summary_list} to gererate the actual summary list.
47
- #
48
- # @param (see govuk_summary_list)
49
- #
50
- # @option (see govuk_summary_list)
51
- #
52
- # @return (see govuk_summary_list)
53
-
54
- def _govuk_summary_list(summary_list_items, govuk_summary_list_options)
55
- initialise_attributes_and_set_classes(govuk_summary_list_options, 'govuk-summary-list')
56
-
57
- any_row_has_actions = summary_list_items.any? { |summary_list_item| summary_list_item.dig(:actions, :items).present? }
58
-
59
- tag.dl(**govuk_summary_list_options[:attributes]) do
60
- summary_list_items.each do |summary_list_item|
61
- concat(govuk_summary_list_row(summary_list_item, any_row_has_actions))
62
- end
63
- end
64
- end
65
-
66
- # rubocop:disable Metrics/AbcSize
67
-
68
- # Generates the HTML for a summary list row used in {govuk_summary_list}
69
- #
70
- # @param summary_list_item [Hash] the list of summary items
71
- # @param any_row_has_actions [Boolean] flag to indicate if any rows have actioms
72
- #
73
- # @option summary_list_item [String] :classes additional CSS classes for the summary row HTML
74
- # @option summary_list_item [Hash] :key the key for the summary list.
75
- # Has the following options:
76
- # - +:text+ - the text for the key
77
- # - +:classes+ - additional classes for the key
78
- # @option summary_list_item [Hash] :value the value for the summary list.
79
- # Has the following options:
80
- # - +:text+ - the text for the value
81
- # - +:classes+ - additional classes for the value
82
- # @option summary_list_item [Hash] :actions the actions for the summary list.
83
- # Has the following options:
84
- # - +:items+ - the action items (see {govuk_summary_list_action_link})
85
- # - +:classes+ - additional classes for the actions
86
- #
87
- # @return [ActiveSupport::SafeBuffer] the HTML for a summary list row
88
- # used in {govuk_summary_list}
89
-
90
- def govuk_summary_list_row(summary_list_item, any_row_has_actions)
91
- item_has_actions = summary_list_item.dig(:actions, :items).present?
92
- summary_list_item_classes = "govuk-summary-list__row #{'govuk-summary-list__row--no-actions' if any_row_has_actions && !item_has_actions}".rstrip
93
- summary_list_item_classes += " #{summary_list_item[:classes]}".rstrip
94
-
95
- tag.div(class: summary_list_item_classes) do
96
- concat(tag.dt(summary_list_item[:key][:text], class: govuk_summary_list_cell_classes(:key, summary_list_item)))
97
- concat(tag.dd(summary_list_item[:value][:text], class: govuk_summary_list_cell_classes(:value, summary_list_item)))
98
- concat(tag.dd(govuk_summary_list_actions(summary_list_item[:actions]), class: govuk_summary_list_cell_classes(:actions, summary_list_item))) if item_has_actions
99
- end
100
- end
101
-
102
- # rubocop:enable Metrics/AbcSize
103
-
104
- # Generates the HTML for a summary list actions used in {govuk_summary_list_row}
105
- #
106
- # @param summary_list_actions [Hash] the actions for the summary list
107
- #
108
- # @option summary_list_actions [Hash] :items the action items (see {govuk_summary_list_action_link})
109
- # @option summary_list_actions [String] :classes additional CSS classes for the summary row HTML
110
- #
111
- # @return [ActiveSupport::SafeBuffer] the HTML for the summary list actions
112
- # used in {govuk_summary_list_row}
113
-
114
- def govuk_summary_list_actions(summary_list_actions)
115
- if summary_list_actions[:items].length == 1
116
- govuk_summary_list_action_link(summary_list_actions[:items].first)
117
- else
118
- tag.ul(class: 'govuk-summary-list__actions-list') do
119
- summary_list_actions[:items].each do |summary_list_actions_item|
120
- concat(tag.li(govuk_summary_list_action_link(summary_list_actions_item), class: 'govuk-summary-list__actions-list-item'))
121
- end
122
- end
123
- end
124
- end
125
-
126
- # Generates the HTML for a summary list action link used in {govuk_summary_list_actions}
127
- #
128
- # @param summary_list_action_item [Hash] an individual action ite,
129
- #
130
- # @option summary_list_action_item [String] :text text for the link
131
- # @option summary_list_action_item [String] :href href for the link
132
- # @option summary_list_action_item [String] :classes additional CSS classes for the summary link HTML
133
- # @option summary_list_action_item [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
134
- #
135
- # @return [ActiveSupport::SafeBuffer] the HTML for the summary list action link
136
- # used in {govuk_summary_list_row}
137
-
138
- def govuk_summary_list_action_link(summary_list_action_item)
139
- initialise_attributes_and_set_classes(summary_list_action_item, 'govuk-link')
140
-
141
- link_to(summary_list_action_item[:href], **summary_list_action_item[:attributes]) do
142
- concat(summary_list_action_item[:text])
143
- concat(tag.span(summary_list_action_item[:visually_hidden_text], class: 'govuk-visually-hidden')) if summary_list_action_item[:visually_hidden_text]
144
- end
145
- end
146
-
147
- # rubocop:disable Metrics/AbcSize
148
-
149
- # Creates the wrapper for the govuk summary card used in {govuk_summary_list}
150
- #
151
- # @param govuk_summary_card_options [Hash] options for the summary card
152
- #
153
- # @option govuk_summary_card_options [Hash] :title options for the title section of the card header
154
- # @option govuk_summary_card_options [Hash] :actions options for the summary card actions section (see {govuk_summary_card_actions})
155
- # @option govuk_summary_card_options [String] :classes additional CSS classes for the summary card HTML
156
- # @option govuk_summary_card_options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
157
- #
158
- # @option title [String] :text the title of the card
159
- # @option title [String] :heading_level (2) heading level, from 1 to 6
160
- # @option title [String] :classes additional classes to add to the title wrapper
161
- #
162
- # @yield HTML for the summary list (see {_govuk_summary_list})
163
- #
164
- # @return [ActiveSupport::SafeBuffer] the HTML for the summary card that
165
- # wraps round {_govuk_summary_list} and
166
- # used in {govuk_summary_list}
167
-
168
- def govuk_summary_card(**govuk_summary_card_options, &block)
169
- initialise_attributes_and_set_classes(govuk_summary_card_options, 'govuk-summary-card')
170
-
171
- tag.div(**govuk_summary_card_options[:attributes]) do
172
- concat(tag.div(class: 'govuk-summary-card__title-wrapper') do
173
- if govuk_summary_card_options[:title]
174
- govuk_summary_card_options[:title][:heading_level] ||= 2
175
-
176
- concat(tag.send(:"h#{govuk_summary_card_options[:title][:heading_level]}", govuk_summary_card_options[:title][:text], class: "govuk-summary-card__title #{govuk_summary_card_options[:title][:classes]}".rstrip))
177
- end
178
- concat(govuk_summary_card_actions(govuk_summary_card_options[:actions])) if govuk_summary_card_options[:actions]
179
- end)
180
- concat(tag.div(class: 'govuk-summary-card__content', &block))
181
- end
182
- end
183
-
184
- # rubocop:enable Metrics/AbcSize
185
-
186
- # Generates the HTML for a summary card actions used in {govuk_summary_card}
187
- #
188
- # @param actions [Hash] options for the summary card actions
189
- #
190
- # @option actions [String] :classes additional CSS classes for the summary card actions HTML
191
- # @option actions [Array] :items the action item objects which are passed to {govuk_summary_list_action_link}
192
- #
193
- # @return [ActiveSupport::SafeBuffer] the HTML for the summary card actions
194
- # used in {govuk_summary_card}
195
-
196
- def govuk_summary_card_actions(actions)
197
- action_classes = "govuk-summary-card__actions #{actions[:classes]}".rstrip
198
-
199
- if actions[:items].length == 1
200
- tag.div(class: action_classes) do
201
- govuk_summary_list_action_link(actions[:items][0])
202
- end
203
- else
204
- tag.ul(class: action_classes) do
205
- actions[:items].each { |action_item| concat(tag.li(govuk_summary_list_action_link(action_item), class: 'govuk-summary-card__action')) }
206
- end
207
- end
208
- end
209
-
210
- # Generates a string containing the classes for the cell used in {govuk_summary_list_row}
211
- #
212
- # @param type [String] the type of the row. One of:
213
- # - +'key'+
214
- # - +'value'+
215
- # - +'actions'+
216
- # @param summary_list_item [Hash] see {govuk_summary_list_row}
217
- #
218
- # @return [String] the classes for a summary list cell
15
+ # @param (see CCS::Components::GovUK::SummaryList#initialize)
16
+ #
17
+ # @option (see CCS::Components::GovUK::SummaryList#initialize)
18
+ #
19
+ # @return (see CCS::Components::GovUK::SummaryList#render)
219
20
 
220
- def govuk_summary_list_cell_classes(type, summary_list_item)
221
- "govuk-summary-list__#{type} #{summary_list_item[type][:classes]}".rstrip
222
- end
21
+ def govuk_summary_list(summary_list_items, **options)
22
+ Components::GovUK::SummaryList.new(context: self, summary_list_items: summary_list_items, **options).render
223
23
  end
224
24
  end
225
25
  end
@@ -1,123 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/table'
6
4
 
7
5
  module CCS
8
- module FrontendHelpers
9
- module GovUKFrontend
10
- # = GOV.UK Table
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK Table
8
+ #
9
+ # This helper is used for generating the table component from the
10
+ # {https://design-system.service.gov.uk/components/table GDS - Components - Table}
11
+
12
+ module Table
13
+ # Generates the HTML for the GOV.UK Table component
11
14
  #
12
- # This helper is used for generating the table component from the
13
- # {https://design-system.service.gov.uk/components/table GDS - Components - Table}
14
-
15
- module Table
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 Table component
22
- #
23
- # @param rows [Array] array of table rows and cells. See {govuk_table_row}
24
- # @param head [NilClass,Array] array of table head cells. See {govuk_table_head}
25
- # @param govuk_table_options [Hash] options that will be used in customising the HTML
26
- #
27
- # @option govuk_table_options [String] :classes additional CSS classes for the table HTML
28
- # @option govuk_table_options [String] :first_cell_is_header if set to true, first cell in table row will be a TH instead of a TD
29
- # @option govuk_table_options [Hash] :caption options for a table caption. See {govuk_table_caption}
30
- # @option govuk_table_options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
31
- #
32
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Table
33
- # which can then be rendered on the page
34
-
35
- def govuk_table(rows, head = nil, **govuk_table_options)
36
- initialise_attributes_and_set_classes(govuk_table_options, 'govuk-table')
37
-
38
- tag.table(**govuk_table_options[:attributes]) do
39
- concat(govuk_table_caption(govuk_table_options[:caption])) if govuk_table_options[:caption]
40
- concat(govuk_table_head(head)) if head
41
- concat(tag.tbody(class: 'govuk-table__body') do
42
- rows.each { |row| concat(govuk_table_row(row, govuk_table_options[:first_cell_is_header])) }
43
- end)
44
- end
45
- end
46
-
47
- private
48
-
49
- # Generates the HTML for the the table caption used in {govuk_table}
50
- #
51
- # @param caption [Hash] options that are used to define the caption
52
- #
53
- # @option caption [String] :text the caption text
54
- # @option caption [String] :classes additional CSS classes for the table caption
55
- #
56
- # @return [ActiveSupport::SafeBuffer] the HTML for the table caption used in {govuk_table}
57
-
58
- def govuk_table_caption(caption)
59
- tag.caption(caption[:text], class: "govuk-table__caption #{caption[:classes]}".rstrip)
60
- end
61
-
62
- # Generates the HTML for the table head used in {govuk_table}
63
- #
64
- # @param head [Array] an array of table head cells
65
- #
66
- # @option head [String] :text the text of the cell
67
- # @option head [String] :classes additional CSS classes for the cell
68
- # @option head [String] :format specify format of a cell
69
- # @option head [Hash] :attributes ({}) any additional attributes that will be added as part of the cell
70
- #
71
- # @return [ActiveSupport::SafeBuffer] the HTML for the table head used in {govuk_table}
72
-
73
- def govuk_table_head(head)
74
- tag.thead(class: 'govuk-table__head') do
75
- tag.tr(class: 'govuk-table__row') do
76
- head.each do |cell|
77
- initialise_attributes_and_set_classes(cell, 'govuk-table__header')
78
-
79
- cell[:attributes][:class] += " govuk-table__header--#{cell[:format]}" if cell[:format]
80
- cell[:attributes][:scope] = 'col'
81
-
82
- concat(tag.th(cell[:text], **cell[:attributes]))
83
- end
84
- end
85
- end
86
- end
87
-
88
- # Generates the HTML for a table row used in {govuk_table}
89
- #
90
- # @param row [Array] an array of a rows cells
91
- # @param first_cell_is_header [Boolean] if set to true, first cell in the row will be a TH instead of a TD
92
- #
93
- # @option row [String] :text the text of the cell
94
- # @option row [String] :classes additional CSS classes for the cell
95
- # @option row [String] :format specify format of a cell
96
- # @option row [Hash] :attributes ({}) any additional attributes that will be added as part of the cell
97
- #
98
- # @return [ActiveSupport::SafeBuffer] the HTML for a table row used in {govuk_table}
99
-
100
- def govuk_table_row(row, first_cell_is_header)
101
- tag.tr(class: 'govuk-table__row') do
102
- row.each.with_index do |cell, index|
103
- tag_type = if first_cell_is_header && index.zero?
104
- initialise_attributes_and_set_classes(cell, 'govuk-table__header')
105
-
106
- cell[:attributes][:scope] = 'row'
107
-
108
- :th
109
- else
110
- initialise_attributes_and_set_classes(cell, 'govuk-table__cell')
111
-
112
- cell[:attributes][:class] += " govuk-table__cell--#{cell[:format]}" if cell[:format]
113
-
114
- :td
115
- end
15
+ # @param (see CCS::Components::GovUK::Table#initialize)
16
+ #
17
+ # @option (see CCS::Components::GovUK::Table#initialize)
18
+ #
19
+ # @return (see CCS::Components::GovUK::Table#render)
116
20
 
117
- concat(tag.send(tag_type, cell[:text], **cell[:attributes]))
118
- end
119
- end
120
- end
21
+ def govuk_table(rows, head_cells = nil, **options)
22
+ Components::GovUK::Table.new(context: self, rows: rows, head_cells: head_cells, **options).render
121
23
  end
122
24
  end
123
25
  end