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
@@ -0,0 +1,56 @@
1
+ require_relative '../../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Tabs < Base
7
+ # = GOV.UK Tabs tab
8
+ #
9
+ # The individual tab
10
+ #
11
+ # @!attribute [r] index
12
+ # @return [Integer] The index of the tab
13
+ # @!attribute [r] label
14
+ # @return [String] Text for the tab
15
+ # @!attribute [r] href
16
+ # @return [String] The href for the tab panel
17
+
18
+ class Tab < Base
19
+ private
20
+
21
+ attr_reader :index, :label, :href
22
+
23
+ public
24
+
25
+ # @param index [Integer] the index of the tab
26
+ # @param id_prefix [Integer] prefix used for the id of a panel if no id is specified
27
+ # @param label [String] the text for the tab
28
+ # @param panel [Hash] used to find the id of the panel. See {Components::GovUK::Tabs::Panel#initialize Panel#initialize} for more details
29
+ # @param options [Hash] options that will be used in customising the HTML
30
+ #
31
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
32
+
33
+ def initialize(index:, id_prefix:, label:, panel:, **options)
34
+ super(**options)
35
+
36
+ @options[:attributes][:class] = 'govuk-tabs__tab'
37
+
38
+ @index = index
39
+ @label = label
40
+ @href = "##{panel.dig(:attributes, :id) || "#{id_prefix}-#{index}"}"
41
+ end
42
+
43
+ # Generates the HTML for the GOV.UK Tabs tab
44
+ #
45
+ # @return [ActiveSupport::SafeBuffer]
46
+
47
+ def render
48
+ tag.li(class: "govuk-tabs__list-item #{'govuk-tabs__list-item--selected' if index == 1}".rstrip) do
49
+ link_to(label, href, **options[:attributes])
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,66 @@
1
+ require_relative '../base'
2
+ require_relative 'tabs/tab'
3
+ require_relative 'tabs/panel'
4
+
5
+ module CCS
6
+ module Components
7
+ module GovUK
8
+ # = GOV.UK Tabs
9
+ #
10
+ # This is used to generate the tabs component from the
11
+ # {https://design-system.service.gov.uk/components/tabs GDS - Components - Tabs}
12
+ #
13
+ # @!attribute [r] title
14
+ # @return [String] Title for the tabs table of contents
15
+ # @!attribute [r] tabs
16
+ # @return [Array<Tabs::Tab>] an array of initialised tabs
17
+ # @!attribute [r] panels
18
+ # @return [Array<Tabs::Panel>] an array of initialised panel
19
+
20
+ class Tabs < Base
21
+ private
22
+
23
+ attr_reader :title, :tabs, :panels
24
+
25
+ public
26
+
27
+ # @param items [Array<Hash>] array of the tab items.
28
+ # See {Components::GovUK::Tabs::Tab#initialize Tab#initialize}
29
+ # and {Components::GovUK::Tabs::Panel#initialize Panel#initialize} for details of the items in the array.
30
+ # @param title [NilClass,String] title for the tabs table of contents
31
+ # @param id_prefix [String] prefix id for each tab item if no id is specified on each item
32
+ # @param options [Hash] options that will be used in customising the HTML
33
+ #
34
+ # @option options [String] :classes additional CSS classes for the tabs HTML
35
+ # @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
36
+
37
+ def initialize(items:, title: nil, id_prefix: nil, **options)
38
+ super(**options)
39
+
40
+ @title = title || 'Contents'
41
+ id_prefix ||= sanitize_to_id(@title.downcase)
42
+ @tabs = items.map.with_index(1) { |item, index| Tab.new(index: index, id_prefix: id_prefix, context: @context, **item) }
43
+ @panels = items.map.with_index(1) { |item, index| Panel.new(index: index, id_prefix: id_prefix, context: @context, **item[:panel]) }
44
+ end
45
+
46
+ # Generates the HTML for the GOV.UK Tabs component
47
+ #
48
+ # @return [ActiveSupport::SafeBuffer]
49
+
50
+ def render
51
+ tag.div(**options[:attributes]) do
52
+ concat(tag.h2(title, class: 'govuk-tabs__title'))
53
+ concat(tag.ul(class: 'govuk-tabs__list') do
54
+ @tabs.each { |tab| concat(tab.render) }
55
+ end)
56
+ @panels.each { |panel| concat(panel.render) }
57
+ end
58
+ end
59
+
60
+ # The default attributes for the tabs
61
+
62
+ DEFAULT_ATTRIBUTES = { class: 'govuk-tabs', data: { module: 'govuk-tabs' } }.freeze
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ # = GOV.UK Tag
7
+ #
8
+ # This is used to generate the tag component from the
9
+ # {https://design-system.service.gov.uk/components/tag GDS - Components - Tag}
10
+ #
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the tag
13
+
14
+ class Tag < Base
15
+ private
16
+
17
+ attr_reader :text
18
+
19
+ public
20
+
21
+ # @param text [String] the text for the tag
22
+ # @param colour [String] optional colour for the tag,
23
+ # see {https://design-system.service.gov.uk/components/tag/#additional-colours Tag - Additional colours}
24
+ # for available colours in GOV.UK Frontend
25
+ # @param options [Hash] options that will be used in customising the HTML
26
+ #
27
+ # @option options [String] :classes additional CSS classes for the tag HTML
28
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
29
+
30
+ def initialize(text:, colour: nil, **options)
31
+ super(**options)
32
+ @options[:attributes][:class][..8] = "govuk-tag govuk-tag--#{colour}" if colour
33
+
34
+ @text = text
35
+ end
36
+
37
+ # Generates the HTML for the GOV.UK Tag component
38
+ #
39
+ # @return [ActiveSupport::SafeBuffer]
40
+
41
+ def render
42
+ tag.strong(text, **options[:attributes])
43
+ end
44
+
45
+ # The default attributes for the tag
46
+
47
+ DEFAULT_ATTRIBUTES = { class: 'govuk-tag' }.freeze
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,61 @@
1
+ require_relative '../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ # = GOV.UK Warning text
7
+ #
8
+ # This helper is used for generating the warning text component from the
9
+ # {https://design-system.service.gov.uk/components/warning-text GDS - Components - Warning text}
10
+ #
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the warning text
13
+
14
+ class WarningText < Base
15
+ private
16
+
17
+ attr_reader :text
18
+
19
+ public
20
+
21
+ # @param text [String] (nil) the text for the warning
22
+ # If nil, then a block will be rendered
23
+ # @param options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option options [String] :classes additional CSS classes for the tag HTML
26
+ # @option options [String] :icon_fallback_text the fallback text for the icon (default: +'Warning'+)
27
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
28
+
29
+ def initialize(text: nil, **options)
30
+ super(**options)
31
+
32
+ @text = text
33
+ end
34
+
35
+ # Generates the HTML for the GOV.UK Warning text component
36
+ #
37
+ # @yield HTML that will be used in the warning text. Ignored if text is passed.
38
+ #
39
+ # @return [ActiveSupport::SafeBuffer]
40
+
41
+ def render
42
+ tag.div(**options[:attributes]) do
43
+ concat(tag.span('!', class: 'govuk-warning-text__icon', aria: { hidden: true }))
44
+ concat(tag.strong(class: 'govuk-warning-text__text') do
45
+ concat(tag.span(options[:icon_fallback_text] || 'Warning', class: 'govuk-warning-text__assistive'))
46
+ if text
47
+ concat(text)
48
+ else
49
+ yield
50
+ end
51
+ end)
52
+ end
53
+ end
54
+
55
+ # The default attributes for the warning text
56
+
57
+ DEFAULT_ATTRIBUTES = { class: 'govuk-warning-text' }.freeze
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../components/ccs/dashboard_section'
4
+
5
+ module CCS
6
+ module FrontendHelpers
7
+ module CCSFrontend
8
+ # = CCS Dashboard Section
9
+ #
10
+ # This helper is used for generating the dashboard section component
11
+
12
+ module DashboardSection
13
+ # Generates the HTML for the CCS Dashboard Section component
14
+ #
15
+ # @param (see CCS::Components::CCS::DashboardSection#initialize)
16
+ #
17
+ # @option (see CCS::Components::CCS::DashboardSection#initialize)
18
+ #
19
+ # @return (see CCS::Components::CCS::DashboardSection#render)
20
+
21
+ def ccs_dashboard_section(dashboard_section_panels, title_text = nil, **options)
22
+ Components::CCS::DashboardSection.new(context: self, dashboard_section_panels: dashboard_section_panels, title_text: title_text, **options).render
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'logo'
4
- require_relative '../shared_methods'
3
+ require_relative '../../components/ccs/footer'
5
4
 
6
5
  module CCS
7
6
  module FrontendHelpers
@@ -12,128 +11,16 @@ module CCS
12
11
  # {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/footer CCS - Components - Footer}
13
12
 
14
13
  module Footer
15
- include SharedMethods
16
- include Logo
17
- include ActionView::Helpers::FormTagHelper
18
- include ActionView::Helpers::UrlHelper
19
-
20
- # rubocop:disable Metrics/AbcSize
21
-
22
14
  # Generates the HTML for the CCS Footer component
23
15
  #
24
- # @param ccs_footer_options [Hash] options that will be used in customising the HTML
25
- #
26
- # @option ccs_footer_options [String] :classes additional CSS classes for the footer HTML
27
- # @option ccs_footer_options [String] :container_class classes that can be added to the inner container
28
- # @option ccs_footer_options [Array] :navigation (see: {ccs_footer_navigation})
29
- # @option ccs_footer_options [Hash] :meta (see: {ccs_footer_meta})
30
- # @option ccs_footer_options [ActiveSupport::SafeBuffer,String] :copyright The copyright information. See {ccs_footer_copyright}
31
- # @option ccs_footer_options [Hash] :attributes additional attributes that will added as part of the HTML
32
- #
33
- # @return [ActiveSupport::SafeBuffer] the HTML for the CCS Footer
34
- # which can then be rendered on the page
35
-
36
- def ccs_footer(**ccs_footer_options)
37
- initialise_attributes_and_set_classes(ccs_footer_options, 'ccs-footer')
38
-
39
- ccs_footer_options[:attributes][:role] = 'contentinfo'
40
-
41
- tag.footer(**ccs_footer_options[:attributes]) do
42
- tag.div(class: "govuk-width-container #{ccs_footer_options[:container_classes]}".rstrip) do
43
- if ccs_footer_options[:navigation]
44
- concat(tag.div(class: 'ccs-footer__navigation') do
45
- ccs_footer_options[:navigation].each { |navigation_item| concat(ccs_footer_navigation(navigation_item)) }
46
- end)
47
- concat(tag.hr(class: 'ccs-footer__section-break'))
48
- end
49
- concat(tag.div(class: 'ccs-footer__meta') do
50
- concat(tag.div(class: 'ccs-footer__meta-item') do
51
- concat(tag.div(ccs_logo, class: 'ccs-footer__logo'))
52
- concat(ccs_footer_copyright(ccs_footer_options[:copyright]))
53
- end)
54
- concat(tag.div(class: 'ccs-footer__meta-item ccs-footer__meta-item--grow') do
55
- concat(ccs_footer_meta(ccs_footer_options[:meta])) if ccs_footer_options[:meta]
56
- end)
57
- end)
58
- end
59
- end
60
- end
61
-
62
- private
63
-
64
- # Generates the HTML for the navigation section in {ccs_footer}
65
- #
66
- # @param navigation_item [Hash] options that will be used for the navigation section
67
- #
68
- # @option navigation_item [String] :title title for a section
69
- # @option navigation_item [String] :width (default: 'fall') width of each navigation section in the footer
70
- # @option navigation_item [Integer] :columns amount of columns to display items in navigation section of the footer
71
- # @option navigation_item [Array] :items array of items to display in the list in navigation section of the footer.
72
- # Each item can have the following options:
73
- # - +:text+ list item text
74
- # - +:href+ list item href
75
- # - +:attributes+ HTML attributes to add to the link
76
- #
77
- # @return [ActiveSupport::SafeBuffer] the HTML for the navigation section in {ccs_footer}
78
-
79
- def ccs_footer_navigation(navigation_item)
80
- tag.div(class: "ccs-footer__section govuk-grid-column-#{navigation_item[:width] || 'full'}") do
81
- concat(tag.h2(navigation_item[:title], class: 'ccs-footer__heading govuk-heading-m'))
82
- concat(tag.ul(class: "ccs-footer__list #{"ccs-footer__list--columns-#{navigation_item[:columns]}" if navigation_item[:columns]}".rstrip) do
83
- navigation_item[:items].each do |item|
84
- concat(tag.li(class: 'ccs-footer__list-item') do
85
- (item[:attributes] ||= {})[:class] = 'ccs-footer__link'
86
-
87
- link_to(item[:text], item[:href], **item[:attributes])
88
- end)
89
- end
90
- end)
91
- end
92
- end
93
-
94
- # Generates the HTML for the meta section in {ccs_footer}
95
- #
96
- # @param meta [Hash] options that will be used for the meta section
97
- #
98
- # @option meta [String] :visually_hidden_title (default: 'Support links') title for a meta item section
99
- # @option meta [ActiveSupport::SafeBuffer,String] :text text to add to the meta section of the footer,
100
- # which will appear below any links specified using meta.items
101
- # @option meta [Array] :items array of items to display in the list in meta section of the footer.
102
- # Each item can have the following options:
103
- # - +:text+ list item text
104
- # - +:href+ list item href
105
- # - +:attributes+ HTML attributes to add to the link
106
- #
107
- # @return [ActiveSupport::SafeBuffer] the HTML for the meta section in {ccs_footer}
108
-
109
- def ccs_footer_meta(meta)
110
- concat(tag.h2(meta[:visually_hidden_title] || 'Support links', class: 'govuk-visually-hidden'))
111
- if meta[:items]
112
- concat(tag.ul(class: 'ccs-footer__inline-list') do
113
- meta[:items].each do |meta_item|
114
- concat(tag.li(class: 'ccs-footer__inline-list-item') do
115
- (meta_item[:attributes] ||= {})[:class] = 'ccs-footer__link'
116
-
117
- link_to(meta_item[:text], meta_item[:href], **meta_item[:attributes])
118
- end)
119
- end
120
- end)
121
- end
122
- concat(tag.div(meta[:text], class: 'ccs-footer__meta-custom')) if meta[:text]
123
- end
124
-
125
- # rubocop:enable Metrics/AbcSize
126
-
127
- # Generates the copyright used in {ccs_footer}
16
+ # @param (see CCS::Components::CCS::Footer#initialize)
128
17
  #
129
- # @param copyright [ActiveSupport::SafeBuffer,String] the copyright information, this defaults to Crown Copyright
18
+ # @option (see CCS::Components::CCS::Footer#initialize)
130
19
  #
131
- # @return [ActiveSupport::SafeBuffer] the HTML for the copyright used in {ccs_footer}
20
+ # @return (see CCS::Components::CCS::Footer#render)
132
21
 
133
- def ccs_footer_copyright(copyright)
134
- tag.div(class: 'ccs-footer__copyright') do
135
- link_to(copyright || '© Crown copyright', 'https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/', class: 'ccs-footer__link')
136
- end
22
+ def ccs_footer(**options)
23
+ Components::CCS::Footer.new(context: self, **options).render
137
24
  end
138
25
  end
139
26
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'logo'
4
- require_relative '../shared_methods'
3
+ require_relative '../../components/ccs/header'
5
4
 
6
5
  module CCS
7
6
  module FrontendHelpers
@@ -12,192 +11,16 @@ module CCS
12
11
  # {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/header CCS - Components - Header}
13
12
 
14
13
  module Header
15
- include SharedMethods
16
- include Logo
17
- include ActionView::Helpers::FormTagHelper
18
- include ActionView::Helpers::UrlHelper
19
-
20
- # rubocop:disable Metrics/AbcSize
21
-
22
14
  # Generates the HTML for the CCS Header component
23
15
  #
24
- # @param ccs_header_options [Hash] options that will be used to generate the header
25
- #
26
- # @option ccs_header_options [String] :classes additional CSS classes for the header HTML
27
- # @option ccs_header_options [Hash] :attributes additional attributes that will added as part of the header HTML
28
- # @option ccs_header_options [String] :container_classes classes for the container
29
- # @option ccs_header_options [String] :homepage_url URL of the homepage. Defaults to +https://www.crowncommercial.gov.uk+
30
- # @option ccs_header_options [Array] :service_authentication see {ccs_service_authentication}
31
- # @option ccs_header_options [Hash] :service see {ccs_header_service_name}
32
- # @option ccs_header_options [Hash] :navigation see {ccs_header_navigation}
33
- # @option ccs_header_options [Hash] :menu_button see {ccs_header_navigation}
34
- #
35
- # @return [ActiveSupport::SafeBuffer] the HTML for the CCS Header
36
- # which can then be rendered on the page
37
-
38
- def ccs_header(**ccs_header_options)
39
- determine_ccs_header_attributes(ccs_header_options)
40
-
41
- tag.header(**ccs_header_options[:attributes]) do
42
- concat(ccs_service_authentication(ccs_header_options[:service_authentication], ccs_header_options[:container_classes])) if ccs_header_options[:service_authentication]
43
- concat(tag.div(class: "ccs-header__container #{ccs_header_options[:container_classes]}") do
44
- concat(ccs_header_logo(**ccs_header_options))
45
- if ccs_header_options[:service] || ccs_header_options[:navigation]
46
- concat(tag.div(class: 'ccs-header__content') do
47
- concat(ccs_header_service_name(ccs_header_options[:service])) if ccs_header_options[:service]
48
- concat(ccs_header_navigation(ccs_header_options[:navigation], ccs_header_options[:menu_button], ccs_header_options[:service])) if ccs_header_options[:navigation]
49
- end)
50
- end
51
- end)
52
- end
53
- end
54
-
55
- # rubocop:enable Metrics/AbcSize
56
-
57
- private
58
-
59
- # Generates the service authentication section for {ccs_header}
60
- #
61
- # @param service_authentication [Array] array of service authentication items (see {ccs_header_navigation_item})
62
- # @param container_classes [String] classes for the container
63
- #
64
- # @return [ActiveSupport::SafeBuffer] the HTML for the service authentication section which is used in {ccs_header}
65
-
66
- def ccs_service_authentication(service_authentication, container_classes)
67
- tag.div(class: 'ccs-header__service-authentication') do
68
- tag.div(class: "ccs-header__service-authentication-container #{container_classes}") do
69
- tag.ul(class: 'ccs-header__service-authentication-list') do
70
- service_authentication.each do |service_authentication_item|
71
- concat(tag.li(class: 'ccs-header__service-authentication-item') do
72
- if service_authentication_item[:href]
73
- (service_authentication_item[:attributes] ||= {})[:class] = 'ccs-header__link'
74
-
75
- link_to(service_authentication_item[:text], service_authentication_item[:href], **service_authentication_item[:attributes])
76
- else
77
- service_authentication_item[:text]
78
- end
79
- end)
80
- end
81
- end
82
- end
83
- end
84
- end
85
-
86
- # Generates the logo for {ccs_header}
87
- #
88
- # @param (see ccs_header)
89
- #
90
- # @option (see ccs_header)
16
+ # @param (see CCS::Components::CCS::Header#initialize)
91
17
  #
92
- # @return [ActiveSupport::SafeBuffer] the HTML for the logo used in {ccs_header}
93
-
94
- def ccs_header_logo(ccs_header_options)
95
- tag.div(class: 'ccs-header__logo') do
96
- link_to(ccs_logo, ccs_header_options[:homepage_url] || 'https://www.crowncommercial.gov.uk', class: 'ccs-header__link ccs-header__link--homepage', aria: { label: 'Crown Commercial Service' })
97
- end
98
- end
99
-
100
- # Generates the service name section for {ccs_header}
18
+ # @option (see CCS::Components::CCS::Header#initialize)
101
19
  #
102
- # @param service [Hash] options that will be used in the service name section
103
- #
104
- # @option service [String] :name the name of the service, included in the header
105
- # @option service [String] :href URL for the service name anchor
106
- #
107
- # @return [ActiveSupport::SafeBuffer] the HTML for the service name section which is used in {ccs_header}
108
-
109
- def ccs_header_service_name(service)
110
- if service[:href]
111
- link_to(service[:name], service[:href], class: 'ccs-header__link ccs-header__link--service-name')
112
- else
113
- tag.span(service[:name], class: 'ccs-header__link--service-name')
114
- end
115
- end
116
-
117
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
118
-
119
- # @option ccs_header_options [String] :navigation_label text for the aria-label attribute of the navigation.
120
- # Defaults to the same value as +:text+ in +:menu_button+
121
- # @option ccs_header_options [String] :navigation_classes classes for the navigation section of the header
122
-
123
- # Generates the navigation section for {ccs_header}
124
- #
125
- # @param navigation [Hash] options for the navigation
126
- # @param menu_button [Hash] options for the menu button
127
- # @param serivce_name_present [Boolean] flag to indicate if the service name section is present
128
- #
129
- # @option navigation [String] :label text for the aria-label attribute of the navigation.
130
- # Defaults to the same value as +:text+ in +:menu_button+
131
- # @option navigation [String] :classes classes for the navigation section of the header
132
- # @option navigation [Array] :primary_items primary navigation items that will be rendered on the page (see {ccs_header_navigation_item})
133
- # @option navigation [Array] :secondary_items secondary navigation items that will be rendered on the page (see {ccs_header_navigation_item})
134
- #
135
- # @option menu_button [String] :text text for the button that opens the mobile navigation menu.
136
- # By default, this is set to +Menu+.
137
- # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation.
138
- # Defaults to +Show or hide menu+.
139
- #
140
- # @return [ActiveSupport::SafeBuffer] the HTML for the navigation section which is used in {ccs_header}
141
-
142
- def ccs_header_navigation(navigation, menu_button, serivce_name_present)
143
- (menu_button ||= {})[:text] ||= 'Menu'
144
- navigation_classes = "ccs-header__navigation #{navigation[:classes]}".rstrip
145
- navigation_classes << ' ccs-header__navigation--no-service-name' unless serivce_name_present
146
-
147
- tag.nav(aria: { label: navigation[:label] || menu_button[:text] }, class: navigation_classes) do
148
- concat(button_tag(menu_button[:text], type: :button, class: 'ccs-header__menu-button ccs-js-header-toggle', aria: { controls: 'navigation', label: menu_button[:label] || 'Show or hide menu' }, hidden: true))
149
- concat(tag.div(id: 'navigation', class: 'ccs-header__navigation-lists') do
150
- if navigation[:secondary_items]
151
- concat(tag.ul(id: 'navigation-secondary', class: "ccs-header__navigation-secondary-list #{'ccs-header__navigation--no-second-list' unless navigation[:primary_items]}") do
152
- navigation[:secondary_items].each { |navigation_item| concat(ccs_header_navigation_item(navigation_item)) }
153
- end)
154
- end
155
- if navigation[:primary_items]
156
- concat(tag.ul(id: 'navigation-primary', class: "ccs-header__navigation-primary-list #{'ccs-header__navigation--no-second-list' unless navigation[:secondary_items]}") do
157
- navigation[:primary_items].each { |navigation_item| concat(ccs_header_navigation_item(navigation_item)) }
158
- end)
159
- end
160
- end)
161
- end
162
- end
163
-
164
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
165
-
166
- # Generates a navigation item for {ccs_header_navigation_item}
167
- #
168
- # @param navigation_item [Hash] options that will be used in customising the HTML
169
- #
170
- # @option navigation_item [Boolean] :active flag to mark the navigation item as active or not
171
- # @option navigation_item [String] :text text for the navigation item
172
- # @option navigation_item [String] :href URL of the navigation item anchor
173
- # @option navigation_item [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
174
- #
175
- # @return [ActiveSupport::SafeBuffer] the HTML for a navigation item which is used in {ccs_header_navigation_item}
176
-
177
- def ccs_header_navigation_item(navigation_item)
178
- tag.li(class: "ccs-header__navigation-item #{'ccs-header__navigation-item--active' if navigation_item[:active]}".rstrip) do
179
- if navigation_item[:href]
180
- (navigation_item[:attributes] ||= {})[:class] = 'ccs-header__link'
181
-
182
- link_to(navigation_item[:text], navigation_item[:href], **navigation_item[:attributes])
183
- else
184
- navigation_item[:text]
185
- end
186
- end
187
- end
188
-
189
- # Sets the default attributes for {ccs_header}
190
- #
191
- # @param ccs_header_options [Hash] options that will be used in customising the HTML
192
- #
193
- # @option (see ccs_header)
194
-
195
- def determine_ccs_header_attributes(ccs_header_options)
196
- initialise_attributes_and_set_classes(ccs_header_options, 'ccs-header')
197
- set_data_module(ccs_header_options, 'ccs-header')
20
+ # @return (see CCS::Components::CCS::Header#render)
198
21
 
199
- ccs_header_options[:attributes][:role] = 'banner'
200
- ccs_header_options[:container_classes] ||= 'govuk-width-container'
22
+ def ccs_header(**options)
23
+ Components::CCS::Header.new(context: self, **options).render
201
24
  end
202
25
  end
203
26
  end
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'ccs_frontend/dashboard_section'
3
4
  require_relative 'ccs_frontend/footer'
4
5
  require_relative 'ccs_frontend/header'
5
- require_relative 'ccs_frontend/logo'
6
- require_relative 'ccs_frontend/dashboard_panels'
7
6
 
8
7
  module CCS
9
8
  module FrontendHelpers
@@ -11,10 +10,9 @@ module CCS
11
10
  # These are a collection of view helpers to help render CCS components
12
11
 
13
12
  module CCSFrontend
14
- include DashboardPanels
13
+ include DashboardSection
15
14
  include Footer
16
15
  include Header
17
- include Logo
18
16
  end
19
17
  end
20
18
  end