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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +4 -1
  5. data/Gemfile.lock +71 -71
  6. data/lib/ccs/components/base.rb +64 -0
  7. data/lib/ccs/components/ccs/dashboard_section/panel.rb +55 -0
  8. data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
  9. data/lib/ccs/components/ccs/footer/link.rb +53 -0
  10. data/lib/ccs/components/ccs/footer/meta.rb +58 -0
  11. data/lib/ccs/components/ccs/footer/navigation.rb +59 -0
  12. data/lib/ccs/components/ccs/footer.rb +93 -0
  13. data/lib/ccs/components/ccs/header/link.rb +58 -0
  14. data/lib/ccs/components/ccs/header/navigation.rb +97 -0
  15. data/lib/ccs/components/ccs/header/service_authentication.rb +52 -0
  16. data/lib/ccs/components/ccs/header.rb +108 -0
  17. data/lib/ccs/components/ccs/logo.rb +45 -0
  18. data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
  19. data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
  20. data/lib/ccs/components/govuk/accordion/section.rb +60 -0
  21. data/lib/ccs/components/govuk/accordion.rb +56 -0
  22. data/lib/ccs/components/govuk/back_link.rb +49 -0
  23. data/lib/ccs/components/govuk/breadcrumbs/link.rb +55 -0
  24. data/lib/ccs/components/govuk/breadcrumbs.rb +53 -0
  25. data/lib/ccs/components/govuk/button.rb +105 -0
  26. data/lib/ccs/components/govuk/cookie_banner/action.rb +58 -0
  27. data/lib/ccs/components/govuk/cookie_banner/message.rb +78 -0
  28. data/lib/ccs/components/govuk/cookie_banner.rb +53 -0
  29. data/lib/ccs/components/govuk/details.rb +51 -0
  30. data/lib/ccs/components/govuk/error_message.rb +58 -0
  31. data/lib/ccs/components/govuk/error_summary/item.rb +52 -0
  32. data/lib/ccs/components/govuk/error_summary.rb +68 -0
  33. data/lib/ccs/components/govuk/field/input/character_count.rb +127 -0
  34. data/lib/ccs/components/govuk/field/input/file_upload.rb +42 -0
  35. data/lib/ccs/components/govuk/field/input/select.rb +80 -0
  36. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +53 -0
  37. data/lib/ccs/components/govuk/field/input/text_input.rb +95 -0
  38. data/lib/ccs/components/govuk/field/input/textarea.rb +57 -0
  39. data/lib/ccs/components/govuk/field/input.rb +60 -0
  40. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +67 -0
  41. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +63 -0
  42. data/lib/ccs/components/govuk/field/inputs/date_input.rb +87 -0
  43. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +45 -0
  44. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +41 -0
  45. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +48 -0
  46. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +48 -0
  47. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +42 -0
  48. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +41 -0
  49. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +48 -0
  50. data/lib/ccs/components/govuk/field/inputs/item.rb +109 -0
  51. data/lib/ccs/components/govuk/field/inputs/radios.rb +67 -0
  52. data/lib/ccs/components/govuk/field/inputs.rb +55 -0
  53. data/lib/ccs/components/govuk/field.rb +106 -0
  54. data/lib/ccs/components/govuk/fieldset/legend.rb +63 -0
  55. data/lib/ccs/components/govuk/fieldset.rb +52 -0
  56. data/lib/ccs/components/govuk/footer/link.rb +53 -0
  57. data/lib/ccs/components/govuk/footer/meta.rb +58 -0
  58. data/lib/ccs/components/govuk/footer/navigation.rb +59 -0
  59. data/lib/ccs/components/govuk/footer.rb +129 -0
  60. data/lib/ccs/components/govuk/form_group.rb +58 -0
  61. data/lib/ccs/components/govuk/header/link.rb +54 -0
  62. data/lib/ccs/components/govuk/header/navigation.rb +70 -0
  63. data/lib/ccs/components/govuk/header.rb +105 -0
  64. data/lib/ccs/components/govuk/hint.rb +47 -0
  65. data/lib/ccs/components/govuk/inset_text.rb +50 -0
  66. data/lib/ccs/components/govuk/label.rb +83 -0
  67. data/lib/ccs/components/govuk/notification_banner.rb +105 -0
  68. data/lib/ccs/components/govuk/pagination/increment/next.rb +42 -0
  69. data/lib/ccs/components/govuk/pagination/increment/previous.rb +41 -0
  70. data/lib/ccs/components/govuk/pagination/increment.rb +96 -0
  71. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +26 -0
  72. data/lib/ccs/components/govuk/pagination/item/form.rb +47 -0
  73. data/lib/ccs/components/govuk/pagination/item/tag.rb +45 -0
  74. data/lib/ccs/components/govuk/pagination/item.rb +62 -0
  75. data/lib/ccs/components/govuk/pagination.rb +94 -0
  76. data/lib/ccs/components/govuk/panel.rb +60 -0
  77. data/lib/ccs/components/govuk/phase_banner.rb +67 -0
  78. data/lib/ccs/components/govuk/skip_link.rb +49 -0
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +51 -0
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +48 -0
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +43 -0
  82. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +61 -0
  83. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +67 -0
  84. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +54 -0
  85. data/lib/ccs/components/govuk/step_by_step_navigation.rb +57 -0
  86. data/lib/ccs/components/govuk/summary_list/action/link.rb +57 -0
  87. data/lib/ccs/components/govuk/summary_list/card/actions.rb +57 -0
  88. data/lib/ccs/components/govuk/summary_list/card/title.rb +49 -0
  89. data/lib/ccs/components/govuk/summary_list/card.rb +61 -0
  90. data/lib/ccs/components/govuk/summary_list/row/actions.rb +57 -0
  91. data/lib/ccs/components/govuk/summary_list/row/key.rb +45 -0
  92. data/lib/ccs/components/govuk/summary_list/row/value.rb +45 -0
  93. data/lib/ccs/components/govuk/summary_list/row.rb +63 -0
  94. data/lib/ccs/components/govuk/summary_list.rb +72 -0
  95. data/lib/ccs/components/govuk/table/body/data_cell.rb +51 -0
  96. data/lib/ccs/components/govuk/table/body/head_cell.rb +50 -0
  97. data/lib/ccs/components/govuk/table/header/head_cell.rb +52 -0
  98. data/lib/ccs/components/govuk/table.rb +109 -0
  99. data/lib/ccs/components/govuk/tabs/panel.rb +56 -0
  100. data/lib/ccs/components/govuk/tabs/tab.rb +54 -0
  101. data/lib/ccs/components/govuk/tabs.rb +64 -0
  102. data/lib/ccs/components/govuk/tag.rb +49 -0
  103. data/lib/ccs/components/govuk/warning_text.rb +59 -0
  104. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +25 -0
  105. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +16 -131
  106. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +16 -195
  107. data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
  108. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +16 -105
  109. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +16 -29
  110. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +16 -66
  111. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +16 -117
  112. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +26 -0
  113. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +26 -0
  114. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +16 -126
  115. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +26 -0
  116. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +18 -36
  117. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +31 -54
  118. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +32 -86
  119. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +18 -61
  120. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +26 -0
  121. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +16 -173
  122. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +26 -39
  123. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +16 -151
  124. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -28
  125. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +26 -0
  126. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +18 -34
  127. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +17 -82
  128. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +18 -126
  129. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +16 -326
  130. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +18 -41
  131. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +18 -39
  132. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +26 -0
  133. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +26 -0
  134. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +16 -30
  135. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +23 -204
  136. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +16 -216
  137. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +16 -114
  138. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +16 -85
  139. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +16 -32
  140. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +26 -0
  141. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +18 -43
  142. data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
  143. data/lib/ccs/frontend_helpers/version.rb +1 -1
  144. metadata +110 -14
  145. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
  146. data/lib/ccs/frontend_helpers/ccs_frontend/logo.rb +0 -49
  147. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
  148. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
  149. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
  150. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
  151. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
  152. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
  153. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
  154. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
  155. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
  156. data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -1,140 +1,25 @@
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
- module FrontendHelpers
8
- module CCSFrontend
9
- # = CCS Footer
6
+ module FrontendHelpers::CCSFrontend
7
+ # = CCS Footer
8
+ #
9
+ # This helper is used for generating the footer component from the
10
+ # {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/footer CCS - Components - Footer}
11
+
12
+ module Footer
13
+ # Generates the HTML for the CCS Footer component
10
14
  #
11
- # This helper 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
- 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
- # Generates the HTML for the CCS Footer component
23
- #
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}
128
- #
129
- # @param copyright [ActiveSupport::SafeBuffer,String] the copyright information, this defaults to Crown Copyright
130
- #
131
- # @return [ActiveSupport::SafeBuffer] the HTML for the copyright used in {ccs_footer}
15
+ # @param (see CCS::Components::CCS::Footer#initialize)
16
+ #
17
+ # @option (see CCS::Components::CCS::Footer#initialize)
18
+ #
19
+ # @return (see CCS::Components::CCS::Footer#render)
132
20
 
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
137
- end
21
+ def ccs_footer(**options)
22
+ Components::CCS::Footer.new(context: self, **options).render
138
23
  end
139
24
  end
140
25
  end
@@ -1,204 +1,25 @@
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
- module FrontendHelpers
8
- module CCSFrontend
9
- # = CCS Header
6
+ module FrontendHelpers::CCSFrontend
7
+ # = CCS Header
8
+ #
9
+ # This helper is used for generating the header component from the
10
+ # {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/header CCS - Components - Header}
11
+
12
+ module Header
13
+ # Generates the HTML for the CCS Header component
10
14
  #
11
- # This helper is used for generating the header component from the
12
- # {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/header CCS - Components - Header}
13
-
14
- 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
- # Generates the HTML for the CCS Header component
23
- #
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)
91
- #
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}
101
- #
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')
15
+ # @param (see CCS::Components::CCS::Header#initialize)
16
+ #
17
+ # @option (see CCS::Components::CCS::Header#initialize)
18
+ #
19
+ # @return (see CCS::Components::CCS::Header#render)
198
20
 
199
- ccs_header_options[:attributes][:role] = 'banner'
200
- ccs_header_options[:container_classes] ||= 'govuk-width-container'
201
- end
21
+ def ccs_header(**options)
22
+ Components::CCS::Header.new(context: self, **options).render
202
23
  end
203
24
  end
204
25
  end
@@ -2,8 +2,7 @@
2
2
 
3
3
  require_relative 'ccs_frontend/footer'
4
4
  require_relative 'ccs_frontend/header'
5
- require_relative 'ccs_frontend/logo'
6
- require_relative 'ccs_frontend/dashboard_panels'
5
+ require_relative 'ccs_frontend/dashboard_section'
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
@@ -1,114 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/accordion'
6
4
 
7
5
  module CCS
8
- module FrontendHelpers
9
- module GovUKFrontend
10
- # = GOV.UK Accordion
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK Accordion
8
+ #
9
+ # This helper is used for generating the accordion component from the
10
+ # {https://design-system.service.gov.uk/components/accordion GDS - Components - Accordion}
11
+
12
+ module Accordion
13
+ # Generates the HTML for the GOV.UK Accordion component
11
14
  #
12
- # This helper is used for generating the accordion component from the
13
- # {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
14
-
15
- module Accordion
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
-
21
- # Generates the HTML for the GOV.UK accordion component
22
- #
23
- # @param accordion_id [String] used as an id in the HTML for the accordion as a whole,
24
- # and also as a prefix for the ids of the section contents
25
- # and the buttons that open them
26
- # @param accordion_items [Array<Hash>] an array of accordion items.
27
- # See {#govuk_accordion_section} for details of the items in the array.
28
- # @param govuk_accordion_options [Hash] options that will be used in customising the HTML
29
- #
30
- # @option govuk_accordion_options [String] :classes additional CSS classes for the accordion HTML
31
- # @option govuk_accordion_options [Integer] :heading_level (2) heading level, from 1 to 6
32
- # @option govuk_accordion_options [Hash] :attributes ({ data: { module: 'govuk-accordion' } }) any additional
33
- # attributes that will added as part of the HTML
34
- #
35
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Accordion
36
- # which can then be rendered on the page
37
-
38
- def govuk_accordion(accordion_id, accordion_items, **govuk_accordion_options)
39
- initialise_attributes_and_set_classes(govuk_accordion_options, 'govuk-accordion')
40
- set_data_module(govuk_accordion_options, 'govuk-accordion')
41
-
42
- govuk_accordion_options[:attributes][:id] = accordion_id
43
- govuk_accordion_options[:heading_level] ||= 2
44
-
45
- tag.div(**govuk_accordion_options[:attributes]) do
46
- accordion_items.each.with_index(1) { |accordion_item, index| concat(govuk_accordion_section(accordion_id, accordion_item, index, govuk_accordion_options[:heading_level])) }
47
- end
48
- end
49
-
50
- private
51
-
52
- # Generates the HTML for an accordion section, used by {govuk_accordion}
53
- #
54
- # @param accordion_id [String] used as an id in the HTML for the accordion
55
- # @param index [Integer] the index of the accordion item
56
- # @param heading_level [Integer] heading level, from 1 to 6
57
- #
58
- # @option accordion_item [Boolean] :expanded sets whether the section should be expanded
59
- # when the page loads for the first time.
60
- # @option accordion_item [String] :heading_level (2) Heading level, from 1 to 6
61
- # @option accordion_item [String] :heading the heading text for the accordion
62
- # @option accordion_item [String] :summary (nil) optional summary text for the accordion header
63
- # @option accordion_item [String, ActiveSupport::SafeBuffer] the content within the accordion section
64
- #
65
- # @return [ActiveSupport::SafeBuffer] the HTML for an accordion section
66
- # which is used in {govuk_accordion}
67
-
68
- def govuk_accordion_section(accordion_id, accordion_item, index, heading_level)
69
- tag.div(class: "govuk-accordion__section #{'govuk-accordion__section--expanded' if accordion_item[:expanded]}".rstrip) do
70
- concat(govuk_accordion_section_header(accordion_id, accordion_item, index, heading_level))
71
- concat(govuk_accordion_section_content(accordion_id, accordion_item, index))
72
- end
73
- end
74
-
75
- # Generates the HTML for an accordion section heading, used by {govuk_accordion_section}
76
- #
77
- # @param (see govuk_accordion_section)
78
- #
79
- # @option (see govuk_accordion_section)
80
- #
81
- # @return [ActiveSupport::SafeBuffer] the HTML for an accordion section heading
82
- # which is used in {govuk_accordion_section}
83
-
84
- def govuk_accordion_section_header(accordion_id, accordion_item, index, heading_level)
85
- tag.div(class: 'govuk-accordion__section-header') do
86
- concat(tag.send("h#{heading_level}", class: 'govuk-accordion__section-heading') do
87
- tag.span(accordion_item[:heading], class: 'govuk-accordion__section-button', id: "#{accordion_id}-heading-#{index}")
88
- end)
89
- concat(tag.div(accordion_item[:summary], class: 'govuk-accordion__section-summary govuk-body', id: "#{accordion_id}-summary-#{index}")) if accordion_item[:summary]
90
- end
91
- end
92
-
93
- # Generates the HTML for an accordion sections content, used by {govuk_accordion_section}
94
- #
95
- # @param accordion_id [String] used as an id in the HTML for the accordion
96
- # @param index [Integer] the index of the accordion item
97
- #
98
- # @option (see govuk_accordion_section)
99
- #
100
- # @return [ActiveSupport::SafeBuffer] the HTML for an accordion sections content
101
- # which is used in {govuk_accordion_section}
15
+ # @param (see CCS::Components::GovUK::Accordion#initialize)
16
+ #
17
+ # @option (see CCS::Components::GovUK::Accordion#initialize)
18
+ #
19
+ # @return (see CCS::Components::GovUK::Accordion#render)
102
20
 
103
- def govuk_accordion_section_content(accordion_id, accordion_item, index)
104
- tag.div(class: 'govuk-accordion__section-content', id: "#{accordion_id}-content-#{index}", aria: { labelledby: "#{accordion_id}-heading-#{index}" }) do
105
- if accordion_item[:content].is_a? ActiveSupport::SafeBuffer
106
- accordion_item[:content]
107
- else
108
- tag.p(accordion_item[:content], class: 'govuk-body')
109
- end
110
- end
111
- end
21
+ def govuk_accordion(accordion_id, accordion_sections, **options)
22
+ Components::GovUK::Accordion.new(context: self, accordion_id: accordion_id, accordion_sections: accordion_sections, **options).render
112
23
  end
113
24
  end
114
25
  end
@@ -1,38 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/back_link'
6
4
 
7
5
  module CCS
8
- module FrontendHelpers
9
- module GovUKFrontend
10
- # = GOV.UK Back Link
11
- #
12
- # This helper is used for generating the back link component from the
13
- # {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
14
-
15
- module BackLink
16
- include SharedMethods
17
- include ActionView::Helpers::UrlHelper
18
-
19
- # Generates the HTML for the GOV.UK Back link component
20
- #
21
- # @param text [String] the text for the back link
22
- # @param href [String] the href for the back link
23
- # @param govuk_back_link_options [Hash] options that will be used in customising the HTML
24
- #
25
- # @option govuk_back_link_options [String] :classes additional CSS classes for the back link HTML
26
- # @option govuk_back_link_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
27
- #
28
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Back link
29
- # which can then be rendered on the page
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK Back Link
8
+ #
9
+ # This helper is used for generating the back link component from the
10
+ # {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
30
11
 
31
- def govuk_back_link(text, href, **govuk_back_link_options)
32
- initialise_attributes_and_set_classes(govuk_back_link_options, 'govuk-back-link')
12
+ module BackLink
13
+ # Generates the HTML for the GOV.UK Back link component
14
+ #
15
+ # @param (see CCS::Components::GovUK::BackLink#initialize)
16
+ #
17
+ # @option (see CCS::Components::GovUK::BackLink#initialize)
18
+ #
19
+ # @return (see CCS::Components::GovUK::BackLink#render)
33
20
 
34
- link_to(text, href, **govuk_back_link_options[:attributes])
35
- end
21
+ def govuk_back_link(text, href, **options)
22
+ Components::GovUK::BackLink.new(context: self, text: text, href: href, **options).render
36
23
  end
37
24
  end
38
25
  end