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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/Gemfile.lock +1 -1
  4. data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
  5. data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
  6. data/lib/ccs/components/ccs/footer/link.rb +41 -39
  7. data/lib/ccs/components/ccs/footer/meta.rb +49 -48
  8. data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
  9. data/lib/ccs/components/ccs/footer.rb +69 -67
  10. data/lib/ccs/components/ccs/header/link.rb +47 -45
  11. data/lib/ccs/components/ccs/header/navigation.rb +85 -84
  12. data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
  13. data/lib/ccs/components/ccs/header.rb +87 -85
  14. data/lib/ccs/components/ccs/logo.rb +36 -34
  15. data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
  16. data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
  17. data/lib/ccs/components/govuk/accordion/section.rb +49 -48
  18. data/lib/ccs/components/govuk/accordion.rb +43 -41
  19. data/lib/ccs/components/govuk/back_link.rb +39 -37
  20. data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
  21. data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
  22. data/lib/ccs/components/govuk/button.rb +83 -81
  23. data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
  24. data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
  25. data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
  26. data/lib/ccs/components/govuk/details.rb +38 -36
  27. data/lib/ccs/components/govuk/error_message.rb +46 -44
  28. data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
  29. data/lib/ccs/components/govuk/error_summary.rb +49 -47
  30. data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
  31. data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
  32. data/lib/ccs/components/govuk/field/input/select.rb +61 -59
  33. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
  34. data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
  35. data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
  36. data/lib/ccs/components/govuk/field/input.rb +46 -44
  37. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
  38. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
  39. data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
  40. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
  41. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
  42. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
  43. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
  44. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
  45. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
  46. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
  47. data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
  48. data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
  49. data/lib/ccs/components/govuk/field/inputs.rb +42 -40
  50. data/lib/ccs/components/govuk/field.rb +90 -88
  51. data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
  52. data/lib/ccs/components/govuk/fieldset.rb +40 -38
  53. data/lib/ccs/components/govuk/footer/link.rb +41 -39
  54. data/lib/ccs/components/govuk/footer/meta.rb +49 -48
  55. data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
  56. data/lib/ccs/components/govuk/footer.rb +105 -103
  57. data/lib/ccs/components/govuk/form_group.rb +45 -43
  58. data/lib/ccs/components/govuk/header/link.rb +41 -39
  59. data/lib/ccs/components/govuk/header/navigation.rb +54 -53
  60. data/lib/ccs/components/govuk/header.rb +84 -82
  61. data/lib/ccs/components/govuk/hint.rb +33 -31
  62. data/lib/ccs/components/govuk/inset_text.rb +39 -37
  63. data/lib/ccs/components/govuk/label.rb +61 -59
  64. data/lib/ccs/components/govuk/notification_banner.rb +83 -81
  65. data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
  66. data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
  67. data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
  68. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
  69. data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
  70. data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
  71. data/lib/ccs/components/govuk/pagination/item.rb +47 -45
  72. data/lib/ccs/components/govuk/pagination.rb +69 -67
  73. data/lib/ccs/components/govuk/panel.rb +49 -47
  74. data/lib/ccs/components/govuk/phase_banner.rb +50 -48
  75. data/lib/ccs/components/govuk/skip_link.rb +39 -37
  76. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
  77. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
  78. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
  82. data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
  83. data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
  84. data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
  85. data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
  86. data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
  87. data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
  88. data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
  89. data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
  90. data/lib/ccs/components/govuk/summary_list/row.rb +47 -45
  91. data/lib/ccs/components/govuk/summary_list.rb +48 -46
  92. data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
  93. data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
  94. data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
  95. data/lib/ccs/components/govuk/table.rb +83 -81
  96. data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
  97. data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
  98. data/lib/ccs/components/govuk/tabs.rb +48 -46
  99. data/lib/ccs/components/govuk/tag.rb +39 -37
  100. data/lib/ccs/components/govuk/warning_text.rb +49 -47
  101. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
  102. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
  103. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
  104. data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
  105. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
  106. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
  107. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
  108. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
  109. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
  110. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
  111. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
  112. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
  113. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
  114. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
  115. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
  116. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
  117. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
  118. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
  119. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
  120. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
  121. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
  122. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
  123. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
  124. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
  125. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
  126. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
  127. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
  128. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
  129. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
  130. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
  131. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
  132. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
  133. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
  134. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
  135. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
  136. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
  137. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
  138. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
  139. data/lib/ccs/frontend_helpers/version.rb +1 -1
  140. metadata +2 -2
@@ -3,89 +3,91 @@ require_relative 'logo'
3
3
  require_relative 'footer/navigation'
4
4
  require_relative 'footer/meta'
5
5
 
6
- module CCS::Components
7
- module CCS
8
- # = CCS Footer
9
- #
10
- # This is used for generating the footer component from the
11
- # {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/footer CCS - Components - Footer}
12
- #
13
- # @!attribute [r] navigation
14
- # @return [Array<Navigation>] An array of the initialised navigation sections
15
- # @!attribute [r] meta
16
- # @return [Meta] The initialised meta section
17
-
18
- class Footer < Base
19
- private
20
-
21
- attr_reader :navigation, :meta
22
-
23
- public
24
-
25
- # @param navigation [Array<Hash>] an array of sections for the footer navigation.
26
- # See {Components::CCS::Footer::Navigation#initialize Navigation#initialize} for details of the items in the array.
27
- # @param meta [Hash] ptions for the meta section of the footer.
28
- # See {Components::CCS::Footer::Meta#initialize Meta#initialize} for details of the options.
29
- # @param options [Hash] options that will be used in customising the HTML
6
+ module CCS
7
+ module Components
8
+ module CCS
9
+ # = CCS Footer
30
10
  #
31
- # @option options [String] :classes additional CSS classes for the footer HTML
32
- # @option options [String] :container_class classes that can be added to the inner container
33
- # @option options [ActiveSupport::SafeBuffer,String] :copyright The copyright information, (default: '© Crown copyright')
34
- # @option options [Hash] :attributes additional attributes that will added as part of the HTML
11
+ # This is used for generating the footer component from the
12
+ # {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/footer CCS - Components - Footer}
13
+ #
14
+ # @!attribute [r] navigation
15
+ # @return [Array<Navigation>] An array of the initialised navigation sections
16
+ # @!attribute [r] meta
17
+ # @return [Meta] The initialised meta section
35
18
 
36
- def initialize(navigation: nil, meta: nil, **options)
37
- super(**options)
19
+ class Footer < Base
20
+ private
38
21
 
39
- @options[:attributes][:role] = 'contentinfo'
40
- @options[:copyright] ||= '© Crown copyright'
22
+ attr_reader :navigation, :meta
41
23
 
42
- @navigation = navigation&.map { |navigation_item| Navigation.new(context: @context, **navigation_item) }
43
- @meta = Meta.new(context: @context, **meta) if meta
44
- end
24
+ public
45
25
 
46
- # rubocop:disable Metrics/AbcSize
26
+ # @param navigation [Array<Hash>] an array of sections for the footer navigation.
27
+ # See {Components::CCS::Footer::Navigation#initialize Navigation#initialize} for details of the items in the array.
28
+ # @param meta [Hash] ptions for the meta section of the footer.
29
+ # See {Components::CCS::Footer::Meta#initialize Meta#initialize} for details of the options.
30
+ # @param options [Hash] options that will be used in customising the HTML
31
+ #
32
+ # @option options [String] :classes additional CSS classes for the footer HTML
33
+ # @option options [String] :container_class classes that can be added to the inner container
34
+ # @option options [ActiveSupport::SafeBuffer,String] :copyright The copyright information, (default: '© Crown copyright')
35
+ # @option options [Hash] :attributes additional attributes that will added as part of the HTML
47
36
 
48
- # Generates the HTML for the CCS Footer component
49
- #
50
- # @return [ActiveSupport::SafeBuffer]
51
-
52
- def render
53
- tag.footer(**options[:attributes]) do
54
- tag.div(class: "govuk-width-container #{options[:container_classes]}".rstrip) do
55
- if navigation
56
- concat(tag.div(class: 'ccs-footer__navigation') do
57
- navigation.each { |navigation_item| concat(navigation_item.render) }
37
+ def initialize(navigation: nil, meta: nil, **options)
38
+ super(**options)
39
+
40
+ @options[:attributes][:role] = 'contentinfo'
41
+ @options[:copyright] ||= '© Crown copyright'
42
+
43
+ @navigation = navigation&.map { |navigation_item| Navigation.new(context: @context, **navigation_item) }
44
+ @meta = Meta.new(context: @context, **meta) if meta
45
+ end
46
+
47
+ # rubocop:disable Metrics/AbcSize
48
+
49
+ # Generates the HTML for the CCS Footer component
50
+ #
51
+ # @return [ActiveSupport::SafeBuffer]
52
+
53
+ def render
54
+ tag.footer(**options[:attributes]) do
55
+ tag.div(class: "govuk-width-container #{options[:container_classes]}".rstrip) do
56
+ if navigation
57
+ concat(tag.div(class: 'ccs-footer__navigation') do
58
+ navigation.each { |navigation_item| concat(navigation_item.render) }
59
+ end)
60
+ concat(tag.hr(class: 'ccs-footer__section-break'))
61
+ end
62
+ concat(tag.div(class: 'ccs-footer__meta') do
63
+ concat(tag.div(class: 'ccs-footer__meta-item') do
64
+ concat(tag.div(Logo.render, class: 'ccs-footer__logo'))
65
+ concat(footer_copyright)
66
+ end)
67
+ concat(tag.div(class: 'ccs-footer__meta-item ccs-footer__meta-item--grow') do
68
+ concat(meta.render) if meta
69
+ end)
58
70
  end)
59
- concat(tag.hr(class: 'ccs-footer__section-break'))
60
71
  end
61
- concat(tag.div(class: 'ccs-footer__meta') do
62
- concat(tag.div(class: 'ccs-footer__meta-item') do
63
- concat(tag.div(Logo.render, class: 'ccs-footer__logo'))
64
- concat(footer_copyright)
65
- end)
66
- concat(tag.div(class: 'ccs-footer__meta-item ccs-footer__meta-item--grow') do
67
- concat(meta.render) if meta
68
- end)
69
- end)
70
72
  end
71
73
  end
72
- end
73
74
 
74
- # rubocop:enable Metrics/AbcSize
75
+ # rubocop:enable Metrics/AbcSize
75
76
 
76
- # The default attributes for the breadcrumbs
77
+ # The default attributes for the breadcrumbs
77
78
 
78
- DEFAULT_ATTRIBUTES = { class: 'ccs-footer' }.freeze
79
+ DEFAULT_ATTRIBUTES = { class: 'ccs-footer' }.freeze
79
80
 
80
- private
81
+ private
81
82
 
82
- # Generates the copyright used in the footer
83
- #
84
- # @return [ActiveSupport::SafeBuffer]
83
+ # Generates the copyright used in the footer
84
+ #
85
+ # @return [ActiveSupport::SafeBuffer]
85
86
 
86
- def footer_copyright
87
- tag.div(class: 'ccs-footer__copyright') do
88
- link_to(options[:copyright], 'https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/', class: 'ccs-footer__link')
87
+ def footer_copyright
88
+ tag.div(class: 'ccs-footer__copyright') do
89
+ link_to(options[:copyright], 'https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/', class: 'ccs-footer__link')
90
+ end
89
91
  end
90
92
  end
91
93
  end
@@ -1,54 +1,56 @@
1
1
  require_relative '../../base'
2
2
 
3
- module CCS::Components
4
- module CCS
5
- class Header < Base
6
- # = CCS Header link
7
- #
8
- # The individual header link item
9
- #
10
- # @!attribute [r] text
11
- # @return [String] Text for the header link
12
- # @!attribute [r] li_class
13
- # @return [String] The class for the li elements
14
- # @!attribute [r] href
15
- # @return [String] The href for the header link
16
-
17
- class Link < Base
18
- private
19
-
20
- attr_reader :text, :li_class, :href
21
-
22
- public
23
-
24
- # @param text [String] the text for the header link
25
- # @param li_class [String] class for the li elements
26
- # @param href [String] the href for the header link
27
- # @param options [Hash] options that will be used in customising the HTML
3
+ module CCS
4
+ module Components
5
+ module CCS
6
+ class Header < Base
7
+ # = CCS Header link
28
8
  #
29
- # @option options [Boolean] :active flag to mark the navigation item as active or not
30
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
31
-
32
- def initialize(text:, li_class:, href: nil, **options)
33
- super(**options)
34
-
35
- @text = text
36
- @href = href
37
- @li_class = li_class
38
- end
39
-
40
- # Generates the HTML for the CCS Header link
9
+ # The individual header link item
41
10
  #
42
- # @return [ActiveSupport::SafeBuffer]
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the header link
13
+ # @!attribute [r] li_class
14
+ # @return [String] The class for the li elements
15
+ # @!attribute [r] href
16
+ # @return [String] The href for the header link
17
+
18
+ class Link < Base
19
+ private
20
+
21
+ attr_reader :text, :li_class, :href
22
+
23
+ public
24
+
25
+ # @param text [String] the text for the header link
26
+ # @param li_class [String] class for the li elements
27
+ # @param href [String] the href for the header link
28
+ # @param options [Hash] options that will be used in customising the HTML
29
+ #
30
+ # @option options [Boolean] :active flag to mark the navigation item as active or not
31
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
32
+
33
+ def initialize(text:, li_class:, href: nil, **options)
34
+ super(**options)
35
+
36
+ @text = text
37
+ @href = href
38
+ @li_class = li_class
39
+ end
40
+
41
+ # Generates the HTML for the CCS Header link
42
+ #
43
+ # @return [ActiveSupport::SafeBuffer]
43
44
 
44
- def render
45
- tag.li(class: "#{li_class} #{'ccs-header__navigation-item--active' if options[:active]}".rstrip) do
46
- if href
47
- options[:attributes][:class] = 'ccs-header__link'
45
+ def render
46
+ tag.li(class: "#{li_class} #{'ccs-header__navigation-item--active' if options[:active]}".rstrip) do
47
+ if href
48
+ options[:attributes][:class] = 'ccs-header__link'
48
49
 
49
- link_to(text, href, **options[:attributes])
50
- else
51
- text
50
+ link_to(text, href, **options[:attributes])
51
+ else
52
+ text
53
+ end
52
54
  end
53
55
  end
54
56
  end
@@ -1,96 +1,97 @@
1
- require_relative '../../base'
2
1
  require_relative 'link'
3
2
 
4
- module CCS::Components
5
- module CCS
6
- class Header < Base
7
- # = CCS Header navigation
8
- #
9
- # The header navigation section
10
- #
11
- # @!attribute [r] primary_links
12
- # @return [Array<Link>] An array of the initialised primary navigation links
13
- # @!attribute [r] secondary_links
14
- # @return [Array<Link>] An array of the initialised secondary navigation links
15
- # @!attribute [r] navigation_label
16
- # @return [String] The aria label for the navigation
17
- # @!attribute [r] navigation_classes
18
- # @return [String] The classes for the navigation
19
- # @!attribute [r] menu_button
20
- # @return [Hash] The options for the menu button
21
-
22
- class Navigation
23
- include ActionView::Context
24
- include ActionView::Helpers
25
-
26
- private
27
-
28
- attr_reader :primary_links, :secondary_links, :navigation_label, :navigation_classes, :menu_button
29
-
30
- public
31
-
32
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
33
-
34
- # @param navigation [Hash] options for the navigation
35
- # @param menu_button [Hash] options for the menu button
36
- # @param context [ActionView::Base] the view context
3
+ module CCS
4
+ module Components
5
+ module CCS
6
+ class Header < Base
7
+ # = CCS Header navigation
37
8
  #
38
- # @option navigation [Array] :primary_items an array of primary links for the navigation section.
39
- # See {Components::CCS::Header::Link#initialize Link#initialize} for details of the items in the array.
40
- # @option navigation [Array] :secondary_items an array of secondary links for the navigation section.
41
- # See {Components::CCS::Header::Link#initialize Link#initialize} for details of the items in the array.
42
- # @option navigation [String] :classes additional CSS classes for the navigation HTML
43
- # @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text
9
+ # The header navigation section
44
10
  #
45
- # @option menu_button [String] :text text for the button that opens the mobile navigation menu.
46
- # By default, this is set to +Menu+.
47
- # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation.
48
- # Defaults to +Show or hide menu+.
49
-
50
- def initialize(navigation:, serivce_name_present:, context:, menu_button: nil)
51
- menu_button ||= {}
52
- menu_button[:text] ||= 'Menu'
53
- menu_button[:label] ||= 'Show or hide menu'
54
-
55
- @menu_button = menu_button
56
- @primary_links = navigation[:primary_items]&.map { |navigation_link| Link.new(li_class: LI_CLASS, context: context, **navigation_link) }
57
- @secondary_links = navigation[:secondary_items]&.map { |navigation_link| Link.new(li_class: LI_CLASS, context: context, **navigation_link) }
58
- @navigation_label = navigation[:label] || menu_button[:text]
59
- @navigation_classes = "ccs-header__navigation #{navigation[:classes]}".rstrip
60
- @navigation_classes << ' ccs-header__navigation--no-service-name' unless serivce_name_present
61
- end
62
-
63
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
64
-
65
- # rubocop:disable Metrics/AbcSize
11
+ # @!attribute [r] primary_links
12
+ # @return [Array<Link>] An array of the initialised primary navigation links
13
+ # @!attribute [r] secondary_links
14
+ # @return [Array<Link>] An array of the initialised secondary navigation links
15
+ # @!attribute [r] navigation_label
16
+ # @return [String] The aria label for the navigation
17
+ # @!attribute [r] navigation_classes
18
+ # @return [String] The classes for the navigation
19
+ # @!attribute [r] menu_button
20
+ # @return [Hash] The options for the menu button
21
+
22
+ class Navigation
23
+ include ActionView::Context
24
+ include ActionView::Helpers
25
+
26
+ private
27
+
28
+ attr_reader :primary_links, :secondary_links, :navigation_label, :navigation_classes, :menu_button
29
+
30
+ public
31
+
32
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
33
+
34
+ # @param navigation [Hash] options for the navigation
35
+ # @param menu_button [Hash] options for the menu button
36
+ # @param context [ActionView::Base] the view context
37
+ #
38
+ # @option navigation [Array] :primary_items an array of primary links for the navigation section.
39
+ # See {Components::CCS::Header::Link#initialize Link#initialize} for details of the items in the array.
40
+ # @option navigation [Array] :secondary_items an array of secondary links for the navigation section.
41
+ # See {Components::CCS::Header::Link#initialize Link#initialize} for details of the items in the array.
42
+ # @option navigation [String] :classes additional CSS classes for the navigation HTML
43
+ # @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text
44
+ #
45
+ # @option menu_button [String] :text text for the button that opens the mobile navigation menu.
46
+ # By default, this is set to +Menu+.
47
+ # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation.
48
+ # Defaults to +Show or hide menu+.
49
+
50
+ def initialize(navigation:, serivce_name_present:, context:, menu_button: nil)
51
+ menu_button ||= {}
52
+ menu_button[:text] ||= 'Menu'
53
+ menu_button[:label] ||= 'Show or hide menu'
54
+
55
+ @menu_button = menu_button
56
+ @primary_links = navigation[:primary_items]&.map { |navigation_link| Link.new(li_class: LI_CLASS, context: context, **navigation_link) }
57
+ @secondary_links = navigation[:secondary_items]&.map { |navigation_link| Link.new(li_class: LI_CLASS, context: context, **navigation_link) }
58
+ @navigation_label = navigation[:label] || menu_button[:text]
59
+ @navigation_classes = "ccs-header__navigation #{navigation[:classes]}".rstrip
60
+ @navigation_classes << ' ccs-header__navigation--no-service-name' unless serivce_name_present
61
+ end
66
62
 
67
- # Generates the HTML for the GOV.UK Navigation
68
- #
69
- # @return [ActiveSupport::SafeBuffer]
70
-
71
- def render
72
- tag.nav(aria: { label: navigation_label }, class: navigation_classes) do
73
- concat(button_tag(menu_button[:text], type: :button, class: 'ccs-header__menu-button ccs-js-header-toggle', aria: { controls: 'navigation', label: menu_button[:label] }, hidden: true))
74
- concat(tag.div(id: 'navigation', class: 'ccs-header__navigation-lists') do
75
- if secondary_links
76
- concat(tag.ul(id: 'navigation-secondary', class: "ccs-header__navigation-secondary-list #{'ccs-header__navigation--no-second-list' unless primary_links}".rstrip) do
77
- secondary_links.each { |secondary_link| concat(secondary_link.render) }
78
- end)
79
- end
80
- if primary_links
81
- concat(tag.ul(id: 'navigation-primary', class: "ccs-header__navigation-primary-list #{'ccs-header__navigation--no-second-list' unless secondary_links}".rstrip) do
82
- primary_links.each { |primary_link| concat(primary_link.render) }
83
- end)
84
- end
85
- end)
63
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
64
+
65
+ # rubocop:disable Metrics/AbcSize
66
+
67
+ # Generates the HTML for the GOV.UK Navigation
68
+ #
69
+ # @return [ActiveSupport::SafeBuffer]
70
+
71
+ def render
72
+ tag.nav(aria: { label: navigation_label }, class: navigation_classes) do
73
+ concat(button_tag(menu_button[:text], type: :button, class: 'ccs-header__menu-button ccs-js-header-toggle', aria: { controls: 'navigation', label: menu_button[:label] }, hidden: true))
74
+ concat(tag.div(id: 'navigation', class: 'ccs-header__navigation-lists') do
75
+ if secondary_links
76
+ concat(tag.ul(id: 'navigation-secondary', class: "ccs-header__navigation-secondary-list #{'ccs-header__navigation--no-second-list' unless primary_links}".rstrip) do
77
+ secondary_links.each { |secondary_link| concat(secondary_link.render) }
78
+ end)
79
+ end
80
+ if primary_links
81
+ concat(tag.ul(id: 'navigation-primary', class: "ccs-header__navigation-primary-list #{'ccs-header__navigation--no-second-list' unless secondary_links}".rstrip) do
82
+ primary_links.each { |primary_link| concat(primary_link.render) }
83
+ end)
84
+ end
85
+ end)
86
+ end
86
87
  end
87
- end
88
88
 
89
- # rubocop:enable Metrics/AbcSize
89
+ # rubocop:enable Metrics/AbcSize
90
90
 
91
- # The li class for the navigation links
91
+ # The li class for the navigation links
92
92
 
93
- LI_CLASS = 'ccs-header__navigation-item'.freeze
93
+ LI_CLASS = 'ccs-header__navigation-item'.freeze
94
+ end
94
95
  end
95
96
  end
96
97
  end
@@ -1,47 +1,48 @@
1
- require_relative '../../base'
2
1
  require_relative 'link'
3
2
 
4
- module CCS::Components
5
- module CCS
6
- class Header < Base
7
- # = CCS Header Service Authentication
8
- #
9
- # The individual footer navigation item
10
- #
11
- # @!attribute [r] service_authentication_links
12
- # @return [Array<Link>] An array of the initialised service authentication links
13
- # @!attribute [r] container_classes
14
- # @return [String] classes for the container
3
+ module CCS
4
+ module Components
5
+ module CCS
6
+ class Header < Base
7
+ # = CCS Header Service Authentication
8
+ #
9
+ # The individual footer navigation item
10
+ #
11
+ # @!attribute [r] service_authentication_links
12
+ # @return [Array<Link>] An array of the initialised service authentication links
13
+ # @!attribute [r] container_classes
14
+ # @return [String] classes for the container
15
15
 
16
- class ServiceAuthentication
17
- include ActionView::Context
18
- include ActionView::Helpers
16
+ class ServiceAuthentication
17
+ include ActionView::Context
18
+ include ActionView::Helpers
19
19
 
20
- private
20
+ private
21
21
 
22
- attr_reader :service_authentication_links, :container_classes
22
+ attr_reader :service_authentication_links, :container_classes
23
23
 
24
- public
24
+ public
25
25
 
26
- # @param service_authentication_items [Array<Hash>] an array of links for the service authentication section.
27
- # See {Components::CCS::Header::Link#initialize Link#initialize} for details of the items in the array.
28
- # @param container_classes [String] classes for the container
29
- # @param context [ActionView::Base] the view context
26
+ # @param service_authentication_items [Array<Hash>] an array of links for the service authentication section.
27
+ # See {Components::CCS::Header::Link#initialize Link#initialize} for details of the items in the array.
28
+ # @param container_classes [String] classes for the container
29
+ # @param context [ActionView::Base] the view context
30
30
 
31
- def initialize(service_authentication_items:, context:, container_classes: nil)
32
- @service_authentication_links = service_authentication_items&.map { |service_authentication_link| Link.new(li_class: 'ccs-header__service-authentication-item', active: false, context: context, **service_authentication_link) }
33
- @container_classes = container_classes
34
- end
31
+ def initialize(service_authentication_items:, context:, container_classes: nil)
32
+ @service_authentication_links = service_authentication_items&.map { |service_authentication_link| Link.new(li_class: 'ccs-header__service-authentication-item', active: false, context: context, **service_authentication_link) }
33
+ @container_classes = container_classes
34
+ end
35
35
 
36
- # Generates the HTML for the CCS Footer Meta sections
37
- #
38
- # @return [ActiveSupport::SafeBuffer]
36
+ # Generates the HTML for the CCS Footer Meta sections
37
+ #
38
+ # @return [ActiveSupport::SafeBuffer]
39
39
 
40
- def render
41
- tag.div(class: 'ccs-header__service-authentication') do
42
- tag.div(class: "ccs-header__service-authentication-container #{container_classes}".rstrip) do
43
- tag.ul(class: 'ccs-header__service-authentication-list') do
44
- service_authentication_links.each { |service_authentication_link| concat(service_authentication_link.render) }
40
+ def render
41
+ tag.div(class: 'ccs-header__service-authentication') do
42
+ tag.div(class: "ccs-header__service-authentication-container #{container_classes}".rstrip) do
43
+ tag.ul(class: 'ccs-header__service-authentication-list') do
44
+ service_authentication_links.each { |service_authentication_link| concat(service_authentication_link.render) }
45
+ end
45
46
  end
46
47
  end
47
48
  end