ccs-frontend_helpers 0.1.0.rc.7 → 0.1.0

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 +1 -5
  3. data/CHANGELOG.md +2 -4
  4. data/Gemfile +1 -15
  5. data/Gemfile.lock +80 -81
  6. data/ccs-frontend_helpers.gemspec +10 -0
  7. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
  8. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +119 -6
  9. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +183 -6
  10. data/lib/ccs/{components/ccs → frontend_helpers/ccs_frontend}/logo.rb +12 -10
  11. data/lib/ccs/frontend_helpers/ccs_frontend.rb +4 -2
  12. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +95 -8
  13. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -6
  14. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +54 -6
  15. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +105 -6
  16. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +114 -6
  17. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +23 -7
  18. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -11
  19. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +65 -13
  20. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
  21. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
  22. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
  23. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
  24. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
  25. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
  26. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
  27. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
  28. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
  29. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +48 -7
  30. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +161 -6
  31. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +24 -13
  32. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +139 -6
  33. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -8
  34. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +21 -7
  35. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +70 -7
  36. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +113 -7
  37. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +314 -6
  38. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +28 -7
  39. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +27 -8
  40. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +18 -6
  41. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +186 -7
  42. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +204 -6
  43. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +100 -11
  44. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +73 -6
  45. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +21 -7
  46. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +30 -7
  47. data/lib/ccs/frontend_helpers/govuk_frontend.rb +19 -17
  48. data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
  49. data/lib/ccs/frontend_helpers/version.rb +1 -1
  50. metadata +142 -112
  51. data/.ruby-version +0 -1
  52. data/lib/ccs/components/base.rb +0 -64
  53. data/lib/ccs/components/ccs/dashboard_section/panel.rb +0 -57
  54. data/lib/ccs/components/ccs/dashboard_section.rb +0 -71
  55. data/lib/ccs/components/ccs/footer/link.rb +0 -55
  56. data/lib/ccs/components/ccs/footer/meta.rb +0 -59
  57. data/lib/ccs/components/ccs/footer/navigation.rb +0 -60
  58. data/lib/ccs/components/ccs/footer.rb +0 -95
  59. data/lib/ccs/components/ccs/header/link.rb +0 -60
  60. data/lib/ccs/components/ccs/header/navigation.rb +0 -98
  61. data/lib/ccs/components/ccs/header/service_authentication.rb +0 -53
  62. data/lib/ccs/components/ccs/header.rb +0 -110
  63. data/lib/ccs/components/govuk/accordion/section/content.rb +0 -53
  64. data/lib/ccs/components/govuk/accordion/section/header.rb +0 -57
  65. data/lib/ccs/components/govuk/accordion/section.rb +0 -61
  66. data/lib/ccs/components/govuk/accordion.rb +0 -58
  67. data/lib/ccs/components/govuk/back_link.rb +0 -51
  68. data/lib/ccs/components/govuk/breadcrumbs/link.rb +0 -57
  69. data/lib/ccs/components/govuk/breadcrumbs.rb +0 -55
  70. data/lib/ccs/components/govuk/button.rb +0 -107
  71. data/lib/ccs/components/govuk/cookie_banner/action.rb +0 -60
  72. data/lib/ccs/components/govuk/cookie_banner/message.rb +0 -80
  73. data/lib/ccs/components/govuk/cookie_banner.rb +0 -55
  74. data/lib/ccs/components/govuk/details.rb +0 -53
  75. data/lib/ccs/components/govuk/error_message.rb +0 -60
  76. data/lib/ccs/components/govuk/error_summary/item.rb +0 -54
  77. data/lib/ccs/components/govuk/error_summary.rb +0 -70
  78. data/lib/ccs/components/govuk/field/input/character_count.rb +0 -129
  79. data/lib/ccs/components/govuk/field/input/file_upload.rb +0 -44
  80. data/lib/ccs/components/govuk/field/input/select.rb +0 -82
  81. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +0 -55
  82. data/lib/ccs/components/govuk/field/input/text_input.rb +0 -97
  83. data/lib/ccs/components/govuk/field/input/textarea.rb +0 -59
  84. data/lib/ccs/components/govuk/field/input.rb +0 -62
  85. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +0 -69
  86. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +0 -65
  87. data/lib/ccs/components/govuk/field/inputs/date_input.rb +0 -89
  88. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +0 -47
  89. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +0 -43
  90. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +0 -50
  91. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +0 -50
  92. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +0 -44
  93. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +0 -43
  94. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +0 -50
  95. data/lib/ccs/components/govuk/field/inputs/item.rb +0 -111
  96. data/lib/ccs/components/govuk/field/inputs/radios.rb +0 -69
  97. data/lib/ccs/components/govuk/field/inputs.rb +0 -57
  98. data/lib/ccs/components/govuk/field.rb +0 -108
  99. data/lib/ccs/components/govuk/fieldset/legend.rb +0 -65
  100. data/lib/ccs/components/govuk/fieldset.rb +0 -54
  101. data/lib/ccs/components/govuk/footer/link.rb +0 -55
  102. data/lib/ccs/components/govuk/footer/meta.rb +0 -59
  103. data/lib/ccs/components/govuk/footer/navigation.rb +0 -60
  104. data/lib/ccs/components/govuk/footer.rb +0 -131
  105. data/lib/ccs/components/govuk/form_group.rb +0 -60
  106. data/lib/ccs/components/govuk/header/link.rb +0 -56
  107. data/lib/ccs/components/govuk/header/navigation.rb +0 -71
  108. data/lib/ccs/components/govuk/header.rb +0 -107
  109. data/lib/ccs/components/govuk/hint.rb +0 -49
  110. data/lib/ccs/components/govuk/inset_text.rb +0 -52
  111. data/lib/ccs/components/govuk/label.rb +0 -85
  112. data/lib/ccs/components/govuk/notification_banner.rb +0 -107
  113. data/lib/ccs/components/govuk/pagination/increment/next.rb +0 -44
  114. data/lib/ccs/components/govuk/pagination/increment/previous.rb +0 -43
  115. data/lib/ccs/components/govuk/pagination/increment.rb +0 -98
  116. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +0 -28
  117. data/lib/ccs/components/govuk/pagination/item/form.rb +0 -49
  118. data/lib/ccs/components/govuk/pagination/item/tag.rb +0 -47
  119. data/lib/ccs/components/govuk/pagination/item.rb +0 -64
  120. data/lib/ccs/components/govuk/pagination.rb +0 -96
  121. data/lib/ccs/components/govuk/panel.rb +0 -62
  122. data/lib/ccs/components/govuk/phase_banner.rb +0 -69
  123. data/lib/ccs/components/govuk/skip_link.rb +0 -51
  124. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +0 -53
  125. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +0 -50
  126. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +0 -45
  127. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +0 -63
  128. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +0 -69
  129. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +0 -56
  130. data/lib/ccs/components/govuk/step_by_step_navigation.rb +0 -59
  131. data/lib/ccs/components/govuk/summary_list/action/link.rb +0 -59
  132. data/lib/ccs/components/govuk/summary_list/card/actions.rb +0 -59
  133. data/lib/ccs/components/govuk/summary_list/card/title.rb +0 -51
  134. data/lib/ccs/components/govuk/summary_list/card.rb +0 -63
  135. data/lib/ccs/components/govuk/summary_list/row/actions.rb +0 -59
  136. data/lib/ccs/components/govuk/summary_list/row/key.rb +0 -47
  137. data/lib/ccs/components/govuk/summary_list/row/value.rb +0 -47
  138. data/lib/ccs/components/govuk/summary_list/row.rb +0 -67
  139. data/lib/ccs/components/govuk/summary_list.rb +0 -74
  140. data/lib/ccs/components/govuk/table/body/data_cell.rb +0 -53
  141. data/lib/ccs/components/govuk/table/body/head_cell.rb +0 -52
  142. data/lib/ccs/components/govuk/table/header/head_cell.rb +0 -54
  143. data/lib/ccs/components/govuk/table.rb +0 -111
  144. data/lib/ccs/components/govuk/tabs/panel.rb +0 -58
  145. data/lib/ccs/components/govuk/tabs/tab.rb +0 -56
  146. data/lib/ccs/components/govuk/tabs.rb +0 -66
  147. data/lib/ccs/components/govuk/tag.rb +0 -51
  148. data/lib/ccs/components/govuk/warning_text.rb +0 -61
  149. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +0 -27
  150. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +0 -28
  151. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +0 -28
  152. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +0 -28
  153. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +0 -28
  154. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +0 -28
  155. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +0 -28
  156. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +0 -28
  157. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +0 -28
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/phase_banner'
3
+ require_relative 'tag'
4
4
 
5
5
  module CCS
6
6
  module FrontendHelpers
@@ -11,18 +11,37 @@ 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
+
14
17
  # Generates the HTML for the GOV.UK Phase banner component
15
18
  #
16
- # @param (see CCS::Components::GovUK::PhaseBanner#initialize)
17
- #
18
- # @option (see CCS::Components::GovUK::PhaseBanner#initialize)
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
19
26
  #
20
- # @yield (see CCS::Components::GovUK::PhaseBanner#render)
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
21
29
  #
22
- # @return (see CCS::Components::GovUK::PhaseBanner#render)
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]}"
23
38
 
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)
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
26
45
  end
27
46
  end
28
47
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/skip_link'
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
4
6
 
5
7
  module CCS
6
8
  module FrontendHelpers
@@ -11,16 +13,26 @@ module CCS
11
13
  # {https://design-system.service.gov.uk/components/skip-link GDS - Components - Skip link}
12
14
 
13
15
  module SkipLink
16
+ include SharedMethods
17
+ include ActionView::Helpers::UrlHelper
18
+
14
19
  # Generates the HTML for the GOV.UK Skip link component
15
20
  #
16
- # @param (see CCS::Components::GovUK::SkipLink#initialize)
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
17
24
  #
18
- # @option (see CCS::Components::GovUK::SkipLink#initialize)
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
19
27
  #
20
- # @return (see CCS::Components::GovUK::SkipLink#render)
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')
21
34
 
22
- def govuk_skip_link(text, href = nil, **options)
23
- Components::GovUK::SkipLink.new(context: self, text: text, href: href, **options).render
35
+ link_to(text, href, **govuk_skip_link_options[:attributes])
24
36
  end
25
37
  end
26
38
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/step_by_step_navigation'
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
4
6
 
5
7
  module CCS
6
8
  module FrontendHelpers
@@ -19,17 +21,194 @@ module CCS
19
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}
20
22
 
21
23
  module StepByStepNavigation
22
- # Generates the HTML for the GOV.UK Step by step navigation component
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}
23
153
  #
24
- # @param (see CCS::Components::GovUK::StepByStepNavigation#initialize)
154
+ # @param items [Array] an array of the list items,
155
+ # see {govuk_step_by_step_navigation_list_item} for more details
25
156
  #
26
- # @option (see CCS::Components::GovUK::StepByStepNavigation#initialize)
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}
27
169
  #
28
- # @return (see CCS::Components::GovUK::StepByStepNavigation#render)
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
29
179
 
30
- def govuk_step_by_step_navigation(step_by_step_navigation_sections, **options)
31
- Components::GovUK::StepByStepNavigation.new(context: self, step_by_step_navigation_sections: step_by_step_navigation_sections, **options).render
180
+ tag.li(class: list_item_classes) do
181
+ tag.span(text)
182
+ end
32
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
210
+
211
+ DEFAULT_SHOW_HIDE_TEXT = { 'show-text': 'Show', 'hide-text': 'Hide', 'show-all-text': 'Show all', 'hide-all-text': 'Hide all' }.freeze
33
212
  end
34
213
  end
35
214
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/summary_list'
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
4
6
 
5
7
  module CCS
6
8
  module FrontendHelpers
@@ -11,16 +13,212 @@ module CCS
11
13
  # {https://design-system.service.gov.uk/components/summary-list GDS - Components - Summary list}
12
14
 
13
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
+
14
22
  # Generates the HTML for the GOV.UK Summary list component
15
23
  #
16
- # @param (see CCS::Components::GovUK::SummaryList#initialize)
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}
17
211
  #
18
- # @option (see CCS::Components::GovUK::SummaryList#initialize)
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}
19
217
  #
20
- # @return (see CCS::Components::GovUK::SummaryList#render)
218
+ # @return [String] the classes for a summary list cell
21
219
 
22
- def govuk_summary_list(summary_list_items, **options)
23
- Components::GovUK::SummaryList.new(context: self, summary_list_items: summary_list_items, **options).render
220
+ def govuk_summary_list_cell_classes(type, summary_list_item)
221
+ "govuk-summary-list__#{type} #{summary_list_item[type][:classes]}".rstrip
24
222
  end
25
223
  end
26
224
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/table'
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
4
6
 
5
7
  module CCS
6
8
  module FrontendHelpers
@@ -11,23 +13,110 @@ module CCS
11
13
  # {https://design-system.service.gov.uk/components/table GDS - Components - Table}
12
14
 
13
15
  module Table
16
+ include SharedMethods
17
+ include ActionView::Context
18
+ include ActionView::Helpers::TagHelper
19
+ include ActionView::Helpers::TextHelper
20
+
14
21
  # Generates the HTML for the GOV.UK Table component
15
22
  #
16
- # @param (see CCS::Components::GovUK::Table#initialize)
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 caption [NilClass,Hash] options for a table caption. See {govuk_table_caption}
26
+ # @param govuk_table_options [Hash] options that will be used in customising the HTML
27
+ #
28
+ # @option govuk_table_options [String] :classes additional CSS classes for the table HTML
29
+ # @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
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, caption = 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(caption)) if 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
17
65
  #
18
- # @option (see CCS::Components::GovUK::Table#initialize)
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
19
70
  #
20
- # @return (see CCS::Components::GovUK::Table#render)
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'
21
81
 
22
- def govuk_table(head_cells_or_rows, rows = nil, **options)
23
- if rows.nil?
24
- rows = head_cells_or_rows
25
- head_cells = nil
26
- else
27
- head_cells = head_cells_or_rows
82
+ concat(tag.th(cell[:text], **cell[:attributes]))
83
+ end
84
+ end
28
85
  end
86
+ end
29
87
 
30
- Components::GovUK::Table.new(context: self, rows: rows, head_cells: head_cells, **options).render
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 head [String] :text the text of the cell
94
+ # @option head [String] :classes additional CSS classes for the cell
95
+ # @option head [String] :format specify format of a cell
96
+ # @option head [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
116
+
117
+ concat(tag.send(tag_type, cell[:text], **cell[:attributes]))
118
+ end
119
+ end
31
120
  end
32
121
  end
33
122
  end