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,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CCS
4
- # Components for the GOV.UK Frontend and CCS Frontend using an Object Oriented pattern
5
- # These are then used in the {CCS::FrontendHelpers FrontendHelpers}
6
- # to create view helpers that can be used in a Ruby on Rails project
7
-
8
- module Components
9
- # Component base class that all components will inherit from.
10
- #
11
- # It's main purpose is to handle the initialisation of the options
12
- # which is very similar between components
13
- #
14
- # @!attribute [r] options
15
- # @return [Hash] Options for the component which defaults to +{ attributes: {} }+
16
- # where +attributes+ are HTML attributes
17
- # @!attribute [r] context
18
- # @return [ActionView::Base] View context where the components are being rendered
19
-
20
- class Base
21
- private
22
-
23
- attr_accessor :options, :context
24
-
25
- public
26
-
27
- delegate :button_tag, :concat, :label_tag, :link_to, :tag, to: :context
28
-
29
- # @param context [ActionView::Base] the view context where the components are being rendered
30
- # @param options [Hash] options for the component
31
-
32
- def initialize(context:, **options)
33
- options[:attributes] ||= {}
34
- options[:attributes][:class] = "#{default_attributes[:class]} #{options[:classes]}".strip if default_attributes[:class] || options[:classes]
35
- (options[:attributes][:data] ||= {})[:module] = default_attributes[:data][:module] if default_attributes.dig(:data, :module)
36
-
37
- @context = context
38
- @options = options
39
- end
40
-
41
- # The default attributes for the component
42
-
43
- DEFAULT_ATTRIBUTES = {}.freeze
44
-
45
- private
46
-
47
- # The default attributes for the component
48
- #
49
- # @return [Hash]
50
-
51
- def default_attributes
52
- self.class::DEFAULT_ATTRIBUTES
53
- end
54
-
55
- # Sanitizes string used as HTML tag id
56
- #
57
- # @return [String]
58
-
59
- def sanitize_to_id(...)
60
- @context.send(:sanitize_to_id, ...)
61
- end
62
- end
63
- end
64
- end
@@ -1,57 +0,0 @@
1
- require_relative '../../base'
2
-
3
- module CCS
4
- module Components
5
- module CCS
6
- class DashboardSection < Base
7
- # = CCS Dashboard Section Panel
8
- #
9
- # The individual panel within a dashboard section
10
- #
11
- # @!attribute [r] title
12
- # @return [String] Text for the panel title
13
- # @!attribute [r] href
14
- # @return [String] The href for the panel
15
- # @!attribute [r] description
16
- # @return [String] Description text for the panel
17
-
18
- class Panel < Base
19
- private
20
-
21
- attr_reader :title, :href, :description
22
-
23
- public
24
-
25
- # @param title [String] the text for the panel title
26
- # @param href [String] the href for the panel
27
- # @param description [String] the description text for the panel
28
- # @param options [Hash] options that will be used in customising the HTML
29
- #
30
- # @option options [String] :width (default: 'one-third') the width of the panel
31
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
32
-
33
- def initialize(title:, href:, description:, **options)
34
- super(**options)
35
-
36
- @options[:attributes][:class] = "ccs-dashboard-section__panel govuk-grid-column-#{@options[:width] || 'one-third'}"
37
-
38
- @title = title
39
- @href = href
40
- @description = description
41
- end
42
-
43
- # Generates the HTML for the CCS Dashboard Section Panel
44
- #
45
- # @return [ActiveSupport::SafeBuffer]
46
-
47
- def render
48
- tag.div(**options[:attributes]) do
49
- concat(link_to(title, href, class: 'ccs-dashboard-section__panel-title'))
50
- concat(tag.p(description, class: 'ccs-dashboard-section__panel-description'))
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,71 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'dashboard_section/panel'
3
-
4
- module CCS
5
- module Components
6
- module CCS
7
- # = CCS Dashboard Section
8
- #
9
- # This is used for generating the dashboard section component
10
- #
11
- # @!attribute [r] dashboard_section_panels
12
- # @return [Array<Link>] An array of the initialised dashboard section panels
13
- # @!attribute [r] title_text
14
- # @return [String] Text for the title of a dashboard section
15
-
16
- class DashboardSection < Base
17
- private
18
-
19
- attr_reader :dashboard_section_panels, :title_text
20
-
21
- public
22
-
23
- # @param dashboard_section_panels [Array<Hash>] An array of options for the dashboard section panels,
24
- # See {Components::CCS::DashboardSection::Panel#initialize Panel#initialize} for details of the items in the array.
25
- # @param title_text [String] text for the title of a dashboard section
26
- # @param options [Hash] options that will be used in customising the HTML
27
- #
28
- # @option options [String] :classes additional CSS classes for the dashboard section HTML
29
- # @option options [String] :width (default: 'full') the width of the dashboard section
30
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
31
-
32
- def initialize(dashboard_section_panels:, title_text: nil, **options)
33
- super(**options)
34
-
35
- @options[:width] ||= 'full'
36
-
37
- @dashboard_section_panels = dashboard_section_panels.map { |dashboard_section_panel| Panel.new(context: @context, **dashboard_section_panel) }
38
- @title_text = title_text
39
- end
40
-
41
- # rubocop:disable Metrics/AbcSize
42
-
43
- # Generates the HTML for the CCS dashboard section component
44
- #
45
- # @return [ActiveSupport::SafeBuffer]
46
-
47
- def render
48
- tag.div(**options[:attributes]) do
49
- tag.div(class: 'govuk-grid-row') do
50
- tag.div(class: "govuk-grid-column-#{options[:width]}") do
51
- if title_text
52
- concat(tag.h2(title_text, class: 'ccs-dashboard-section__heading govuk-heading-m'))
53
- concat(tag.hr(class: 'ccs-dashboard-section__heading-section-break govuk-section-break govuk-section-break--visible'))
54
- end
55
- concat(tag.div(class: 'govuk-grid-row ccs-dashboard-section__container') do
56
- dashboard_section_panels.each { |dashboard_section_panel| concat(dashboard_section_panel.render) }
57
- end)
58
- end
59
- end
60
- end
61
- end
62
-
63
- # rubocop:enable Metrics/AbcSize
64
-
65
- # The default attributes for the dashboard section
66
-
67
- DEFAULT_ATTRIBUTES = { class: 'ccs-dashboard-section' }.freeze
68
- end
69
- end
70
- end
71
- end
@@ -1,55 +0,0 @@
1
- require_relative '../../base'
2
-
3
- module CCS
4
- module Components
5
- module CCS
6
- class Footer < Base
7
- # = CCS Footer link
8
- #
9
- # The individual footer footer link item
10
- #
11
- # @!attribute [r] text
12
- # @return [String] Text for the footer link
13
- # @!attribute [r] href
14
- # @return [String] The href for the footer link
15
- # @!attribute [r] li_class
16
- # @return [String] The class for the li elements
17
-
18
- class Link < Base
19
- private
20
-
21
- attr_reader :text, :href, :li_class
22
-
23
- public
24
-
25
- # @param text [String] the text for the footer link
26
- # @param href [String] the href for the footer link
27
- # @param li_class [String] class for the li elements
28
- # @param options [Hash] options that will be used in customising the HTML
29
- #
30
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
31
-
32
- def initialize(text:, href:, li_class:, **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 Footer link
41
- #
42
- # @return [ActiveSupport::SafeBuffer]
43
-
44
- def render
45
- tag.li(class: li_class) do
46
- options[:attributes][:class] = 'ccs-footer__link'
47
-
48
- link_to(text, href, **options[:attributes])
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,59 +0,0 @@
1
- require_relative 'link'
2
-
3
- module CCS
4
- module Components
5
- module CCS
6
- class Footer < Base
7
- # = CCS Footer Meta
8
- #
9
- # The footer meta section
10
- #
11
- # @!attribute [r] meta_links
12
- # @return [Array<Link>] An array of the initialised meta links
13
- # @!attribute [r] visually_hidden_title
14
- # @return [String] Title for the meta section
15
- # @!attribute [r] text
16
- # @return [String] Text to add to the meta section of the footer
17
-
18
- class Meta
19
- include ActionView::Context
20
- include ActionView::Helpers
21
-
22
- private
23
-
24
- attr_reader :meta_links, :visually_hidden_title, :text
25
-
26
- public
27
-
28
- # @param items [Array<Hash>] an array of links for the meta section.
29
- # See {Components::CCS::Footer::Link#initialize Link#initialize} for details of the items in the array.
30
- # @param visually_hidden_title [String] ('Support links') title for the meta section
31
- # @param text [String] text to add to the meta section of the footer
32
- # @param context [ActionView::Base] the view context
33
-
34
- def initialize(context:, items: nil, visually_hidden_title: nil, text: nil)
35
- @meta_links = items&.map { |meta_link| Link.new(li_class: 'ccs-footer__inline-list-item', context: context, **meta_link) }
36
- @visually_hidden_title = visually_hidden_title || 'Support links'
37
- @text = text
38
- end
39
-
40
- # Generates the HTML for the CCS Footer Meta sections
41
- #
42
- # @return [ActiveSupport::SafeBuffer]
43
-
44
- def render
45
- capture do
46
- concat(tag.h2(visually_hidden_title, class: 'govuk-visually-hidden'))
47
- if meta_links
48
- concat(tag.ul(class: 'ccs-footer__inline-list') do
49
- meta_links.each { |meta_link| concat(meta_link.render) }
50
- end)
51
- end
52
- concat(tag.div(text, class: 'ccs-footer__meta-custom')) if text
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,60 +0,0 @@
1
- require_relative 'link'
2
-
3
- module CCS
4
- module Components
5
- module CCS
6
- class Footer < Base
7
- # = CCS Footer Navigation
8
- #
9
- # The individual footer navigation item
10
- #
11
- # @!attribute [r] title
12
- # @return [String] Title for the navigation section
13
- # @!attribute [r] navigation_links
14
- # @return [Array<Link>] An array of the initialised navigation links
15
- # @!attribute [r] width
16
- # @return [String] Width of the navigation section
17
- # @!attribute [r] columns
18
- # @return [Integer] Number of columns to display the links in
19
-
20
- class Navigation
21
- include ActionView::Context
22
- include ActionView::Helpers
23
-
24
- private
25
-
26
- attr_reader :title, :navigation_links, :width, :columns
27
-
28
- public
29
-
30
- # @param title [String] the title for the navigation section
31
- # @param items [Array<Hash>] an array of links for the navigation section.
32
- # See {Components::CCS::Footer::Link#initialize Link#initialize} for details of the items in the array.
33
- # @param width [String] ('full') width of each navigation section in the footer
34
- # @param columns [Integer] (nil) number of columns to display the links
35
- # @param context [ActionView::Base] the view context
36
-
37
- def initialize(title:, items:, context:, width: nil, columns: nil)
38
- @title = title
39
- @navigation_links = items.map { |navigation_link| Link.new(li_class: 'ccs-footer__list-item', context: context, **navigation_link) }
40
- @width = width || 'full'
41
- @columns = columns
42
- end
43
-
44
- # Generates the HTML for the CCS Footer Navigation sections
45
- #
46
- # @return [ActiveSupport::SafeBuffer]
47
-
48
- def render
49
- tag.div(class: "ccs-footer__section govuk-grid-column-#{width}") do
50
- concat(tag.h2(title, class: 'ccs-footer__heading govuk-heading-m'))
51
- concat(tag.ul(class: "ccs-footer__list #{"ccs-footer__list--columns-#{columns}" if columns}".rstrip) do
52
- navigation_links.each { |navigation_link| concat(navigation_link.render) }
53
- end)
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,95 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'logo'
3
- require_relative 'footer/navigation'
4
- require_relative 'footer/meta'
5
-
6
- module CCS
7
- module Components
8
- module CCS
9
- # = CCS Footer
10
- #
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
18
-
19
- class Footer < Base
20
- private
21
-
22
- attr_reader :navigation, :meta
23
-
24
- public
25
-
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
36
-
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)
70
- end)
71
- end
72
- end
73
- end
74
-
75
- # rubocop:enable Metrics/AbcSize
76
-
77
- # The default attributes for the breadcrumbs
78
-
79
- DEFAULT_ATTRIBUTES = { class: 'ccs-footer' }.freeze
80
-
81
- private
82
-
83
- # Generates the copyright used in the footer
84
- #
85
- # @return [ActiveSupport::SafeBuffer]
86
-
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
91
- end
92
- end
93
- end
94
- end
95
- end
@@ -1,60 +0,0 @@
1
- require_relative '../../base'
2
-
3
- module CCS
4
- module Components
5
- module CCS
6
- class Header < Base
7
- # = CCS Header link
8
- #
9
- # The individual header link item
10
- #
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]
44
-
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'
49
-
50
- link_to(text, href, **options[:attributes])
51
- else
52
- text
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,98 +0,0 @@
1
- require_relative 'link'
2
-
3
- module CCS
4
- module 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
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
62
-
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
87
- end
88
-
89
- # rubocop:enable Metrics/AbcSize
90
-
91
- # The li class for the navigation links
92
-
93
- LI_CLASS = 'ccs-header__navigation-item'.freeze
94
- end
95
- end
96
- end
97
- end
98
- end
@@ -1,53 +0,0 @@
1
- require_relative 'link'
2
-
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
-
16
- class ServiceAuthentication
17
- include ActionView::Context
18
- include ActionView::Helpers
19
-
20
- private
21
-
22
- attr_reader :service_authentication_links, :container_classes
23
-
24
- public
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
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
35
-
36
- # Generates the HTML for the CCS Footer Meta sections
37
- #
38
- # @return [ActiveSupport::SafeBuffer]
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) }
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end