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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -5
- data/CHANGELOG.md +2 -4
- data/Gemfile +1 -15
- data/Gemfile.lock +80 -81
- data/ccs-frontend_helpers.gemspec +10 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +119 -6
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +183 -6
- data/lib/ccs/{components/ccs → frontend_helpers/ccs_frontend}/logo.rb +12 -10
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +4 -2
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +95 -8
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +54 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +105 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +114 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +23 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -11
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +65 -13
- data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +48 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +161 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +24 -13
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +139 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -8
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +21 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +70 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +113 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +314 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +28 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +27 -8
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +18 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +186 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +204 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +100 -11
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +73 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +21 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +30 -7
- data/lib/ccs/frontend_helpers/govuk_frontend.rb +19 -17
- data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +142 -112
- data/.ruby-version +0 -1
- data/lib/ccs/components/base.rb +0 -64
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +0 -57
- data/lib/ccs/components/ccs/dashboard_section.rb +0 -71
- data/lib/ccs/components/ccs/footer/link.rb +0 -55
- data/lib/ccs/components/ccs/footer/meta.rb +0 -59
- data/lib/ccs/components/ccs/footer/navigation.rb +0 -60
- data/lib/ccs/components/ccs/footer.rb +0 -95
- data/lib/ccs/components/ccs/header/link.rb +0 -60
- data/lib/ccs/components/ccs/header/navigation.rb +0 -98
- data/lib/ccs/components/ccs/header/service_authentication.rb +0 -53
- data/lib/ccs/components/ccs/header.rb +0 -110
- data/lib/ccs/components/govuk/accordion/section/content.rb +0 -53
- data/lib/ccs/components/govuk/accordion/section/header.rb +0 -57
- data/lib/ccs/components/govuk/accordion/section.rb +0 -61
- data/lib/ccs/components/govuk/accordion.rb +0 -58
- data/lib/ccs/components/govuk/back_link.rb +0 -51
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +0 -57
- data/lib/ccs/components/govuk/breadcrumbs.rb +0 -55
- data/lib/ccs/components/govuk/button.rb +0 -107
- data/lib/ccs/components/govuk/cookie_banner/action.rb +0 -60
- data/lib/ccs/components/govuk/cookie_banner/message.rb +0 -80
- data/lib/ccs/components/govuk/cookie_banner.rb +0 -55
- data/lib/ccs/components/govuk/details.rb +0 -53
- data/lib/ccs/components/govuk/error_message.rb +0 -60
- data/lib/ccs/components/govuk/error_summary/item.rb +0 -54
- data/lib/ccs/components/govuk/error_summary.rb +0 -70
- data/lib/ccs/components/govuk/field/input/character_count.rb +0 -129
- data/lib/ccs/components/govuk/field/input/file_upload.rb +0 -44
- data/lib/ccs/components/govuk/field/input/select.rb +0 -82
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +0 -55
- data/lib/ccs/components/govuk/field/input/text_input.rb +0 -97
- data/lib/ccs/components/govuk/field/input/textarea.rb +0 -59
- data/lib/ccs/components/govuk/field/input.rb +0 -62
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +0 -69
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +0 -65
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +0 -89
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +0 -47
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +0 -43
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +0 -50
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +0 -50
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +0 -44
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +0 -43
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +0 -50
- data/lib/ccs/components/govuk/field/inputs/item.rb +0 -111
- data/lib/ccs/components/govuk/field/inputs/radios.rb +0 -69
- data/lib/ccs/components/govuk/field/inputs.rb +0 -57
- data/lib/ccs/components/govuk/field.rb +0 -108
- data/lib/ccs/components/govuk/fieldset/legend.rb +0 -65
- data/lib/ccs/components/govuk/fieldset.rb +0 -54
- data/lib/ccs/components/govuk/footer/link.rb +0 -55
- data/lib/ccs/components/govuk/footer/meta.rb +0 -59
- data/lib/ccs/components/govuk/footer/navigation.rb +0 -60
- data/lib/ccs/components/govuk/footer.rb +0 -131
- data/lib/ccs/components/govuk/form_group.rb +0 -60
- data/lib/ccs/components/govuk/header/link.rb +0 -56
- data/lib/ccs/components/govuk/header/navigation.rb +0 -71
- data/lib/ccs/components/govuk/header.rb +0 -107
- data/lib/ccs/components/govuk/hint.rb +0 -49
- data/lib/ccs/components/govuk/inset_text.rb +0 -52
- data/lib/ccs/components/govuk/label.rb +0 -85
- data/lib/ccs/components/govuk/notification_banner.rb +0 -107
- data/lib/ccs/components/govuk/pagination/increment/next.rb +0 -44
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +0 -43
- data/lib/ccs/components/govuk/pagination/increment.rb +0 -98
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +0 -28
- data/lib/ccs/components/govuk/pagination/item/form.rb +0 -49
- data/lib/ccs/components/govuk/pagination/item/tag.rb +0 -47
- data/lib/ccs/components/govuk/pagination/item.rb +0 -64
- data/lib/ccs/components/govuk/pagination.rb +0 -96
- data/lib/ccs/components/govuk/panel.rb +0 -62
- data/lib/ccs/components/govuk/phase_banner.rb +0 -69
- data/lib/ccs/components/govuk/skip_link.rb +0 -51
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +0 -53
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +0 -50
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +0 -45
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +0 -63
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +0 -69
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +0 -56
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +0 -59
- data/lib/ccs/components/govuk/summary_list/action/link.rb +0 -59
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +0 -59
- data/lib/ccs/components/govuk/summary_list/card/title.rb +0 -51
- data/lib/ccs/components/govuk/summary_list/card.rb +0 -63
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +0 -59
- data/lib/ccs/components/govuk/summary_list/row/key.rb +0 -47
- data/lib/ccs/components/govuk/summary_list/row/value.rb +0 -47
- data/lib/ccs/components/govuk/summary_list/row.rb +0 -67
- data/lib/ccs/components/govuk/summary_list.rb +0 -74
- data/lib/ccs/components/govuk/table/body/data_cell.rb +0 -53
- data/lib/ccs/components/govuk/table/body/head_cell.rb +0 -52
- data/lib/ccs/components/govuk/table/header/head_cell.rb +0 -54
- data/lib/ccs/components/govuk/table.rb +0 -111
- data/lib/ccs/components/govuk/tabs/panel.rb +0 -58
- data/lib/ccs/components/govuk/tabs/tab.rb +0 -56
- data/lib/ccs/components/govuk/tabs.rb +0 -66
- data/lib/ccs/components/govuk/tag.rb +0 -51
- data/lib/ccs/components/govuk/warning_text.rb +0 -61
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +0 -27
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +0 -28
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'logo'
|
4
|
+
require_relative '../shared_methods'
|
4
5
|
|
5
6
|
module CCS
|
6
7
|
module FrontendHelpers
|
@@ -11,16 +12,192 @@ module CCS
|
|
11
12
|
# {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/header CCS - Components - Header}
|
12
13
|
|
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
|
+
|
14
22
|
# Generates the HTML for the CCS Header component
|
15
23
|
#
|
16
|
-
# @param
|
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)
|
17
91
|
#
|
18
|
-
# @
|
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}
|
19
101
|
#
|
20
|
-
# @
|
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')
|
21
198
|
|
22
|
-
|
23
|
-
|
199
|
+
ccs_header_options[:attributes][:role] = 'banner'
|
200
|
+
ccs_header_options[:container_classes] ||= 'govuk-width-container'
|
24
201
|
end
|
25
202
|
end
|
26
203
|
end
|
@@ -1,23 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'action_view'
|
2
4
|
|
3
5
|
module CCS
|
4
|
-
module
|
5
|
-
module
|
6
|
+
module FrontendHelpers
|
7
|
+
module CCSFrontend
|
6
8
|
# = CCS Logo
|
7
9
|
#
|
8
|
-
# This is used for generating the logo component from the
|
10
|
+
# This helper is used for generating the logo component from the
|
9
11
|
# {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/logo CCS - Components - Logo}
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
module Logo
|
14
|
+
include ActionView::Context
|
15
|
+
include ActionView::Helpers::TagHelper
|
16
|
+
include ActionView::Helpers::TextHelper
|
14
17
|
|
15
|
-
# Generates the
|
16
|
-
# Used in {CCS::Components::CCS::Header Header} and {CCS::Components::CCS::Footer Footer}
|
18
|
+
# Generates the CCS logo used in {ccs_header} and {ccs_footer}
|
17
19
|
#
|
18
|
-
# @return [ActiveSupport::SafeBuffer]
|
20
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the logo used in {ccs_header} and {ccs_footer}
|
19
21
|
|
20
|
-
def
|
22
|
+
def ccs_logo
|
21
23
|
tag.span(class: 'ccs-logo') do
|
22
24
|
concat(tag.svg(class: 'ccs-logo__svg', xmlns: 'http://www.w3.org/2000/svg', height: '101', width: '121', aria: { hidden: 'true' }, focusable: 'false', viewBox: '0 0 121 101') do
|
23
25
|
CCS_LOGO_PATHS.each { |ccs_logo_path_attributes| concat(tag.path(**ccs_logo_path_attributes)) }
|
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'ccs_frontend/dashboard_section'
|
4
3
|
require_relative 'ccs_frontend/footer'
|
5
4
|
require_relative 'ccs_frontend/header'
|
5
|
+
require_relative 'ccs_frontend/logo'
|
6
|
+
require_relative 'ccs_frontend/dashboard_panels'
|
6
7
|
|
7
8
|
module CCS
|
8
9
|
module FrontendHelpers
|
@@ -10,9 +11,10 @@ module CCS
|
|
10
11
|
# These are a collection of view helpers to help render CCS components
|
11
12
|
|
12
13
|
module CCSFrontend
|
13
|
-
include
|
14
|
+
include DashboardPanels
|
14
15
|
include Footer
|
15
16
|
include Header
|
17
|
+
include Logo
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
require_relative '../shared_methods'
|
4
6
|
|
5
7
|
module CCS
|
6
8
|
module FrontendHelpers
|
@@ -8,19 +10,104 @@ module CCS
|
|
8
10
|
# = GOV.UK Accordion
|
9
11
|
#
|
10
12
|
# This helper is used for generating the accordion component from the
|
11
|
-
# {https://design-system.service.gov.uk/
|
13
|
+
# {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
|
12
14
|
|
13
15
|
module Accordion
|
14
|
-
|
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}
|
15
94
|
#
|
16
|
-
# @param
|
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
|
17
97
|
#
|
18
|
-
# @option (see
|
98
|
+
# @option (see govuk_accordion_section)
|
19
99
|
#
|
20
|
-
# @return
|
100
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an accordion sections content
|
101
|
+
# which is used in {govuk_accordion_section}
|
21
102
|
|
22
|
-
def
|
23
|
-
|
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
|
24
111
|
end
|
25
112
|
end
|
26
113
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
require_relative '../shared_methods'
|
4
6
|
|
5
7
|
module CCS
|
6
8
|
module FrontendHelpers
|
@@ -11,16 +13,25 @@ module CCS
|
|
11
13
|
# {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
|
12
14
|
|
13
15
|
module BackLink
|
16
|
+
include SharedMethods
|
17
|
+
include ActionView::Helpers::UrlHelper
|
18
|
+
|
14
19
|
# Generates the HTML for the GOV.UK Back link component
|
15
20
|
#
|
16
|
-
# @param
|
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
|
17
24
|
#
|
18
|
-
# @option
|
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
|
19
27
|
#
|
20
|
-
# @return
|
28
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Back link
|
29
|
+
# which can then be rendered on the page
|
30
|
+
|
31
|
+
def govuk_back_link(text, href, **govuk_back_link_options)
|
32
|
+
initialise_attributes_and_set_classes(govuk_back_link_options, 'govuk-back-link')
|
21
33
|
|
22
|
-
|
23
|
-
Components::GovUK::BackLink.new(context: self, text: text, href: href, **options).render
|
34
|
+
link_to(text, href, **govuk_back_link_options[:attributes])
|
24
35
|
end
|
25
36
|
end
|
26
37
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
require_relative '../shared_methods'
|
4
6
|
|
5
7
|
module CCS
|
6
8
|
module FrontendHelpers
|
@@ -11,16 +13,62 @@ module CCS
|
|
11
13
|
# {https://design-system.service.gov.uk/components/breadcrumbs GDS - Components - Breadcrumbs}
|
12
14
|
|
13
15
|
module Breadcrumbs
|
16
|
+
include SharedMethods
|
17
|
+
include ActionView::Context
|
18
|
+
include ActionView::Helpers::TagHelper
|
19
|
+
include ActionView::Helpers::TextHelper
|
20
|
+
include ActionView::Helpers::UrlHelper
|
21
|
+
|
14
22
|
# Generates the HTML for the GOV.UK breadcrumbs component
|
15
23
|
#
|
16
|
-
# @param
|
24
|
+
# @param govuk_breadcrumb_items [Array<Hash>] An array of links for the breadcrumbs list. See {#govuk_breadcrumb_link} for details of the items in the array.
|
25
|
+
# @param govuk_breadcrumbs_options [Hash] options that will be used in customising the HTML
|
26
|
+
#
|
27
|
+
# @option govuk_breadcrumbs_options [String] :classes additional CSS classes for the breadcrumbs HTML
|
28
|
+
# @option govuk_breadcrumbs_options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
|
29
|
+
# @option govuk_breadcrumbs_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
30
|
+
#
|
31
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Breadcrumbs
|
32
|
+
# which can then be rendered on the page
|
33
|
+
|
34
|
+
def govuk_breadcrumbs(govuk_breadcrumb_items, **govuk_breadcrumbs_options)
|
35
|
+
initialise_attributes_and_set_classes(govuk_breadcrumbs_options, 'govuk-breadcrumbs')
|
36
|
+
|
37
|
+
govuk_breadcrumbs_options[:attributes][:class] << ' govuk-breadcrumbs--collapse-on-mobile' if govuk_breadcrumbs_options[:collapse_on_mobile]
|
38
|
+
|
39
|
+
tag.div(**govuk_breadcrumbs_options[:attributes]) do
|
40
|
+
tag.ol(class: 'govuk-breadcrumbs__list') do
|
41
|
+
govuk_breadcrumb_items.each { |govuk_breadcrumb_item| concat(govuk_breadcrumb_link(govuk_breadcrumb_item)) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Generates the HTML for each link in the breadcrumbs.
|
49
|
+
# It is called by {#govuk_breadcrumbs} which will pass in the breadcrum item.
|
50
|
+
#
|
51
|
+
# @param govuk_breadcrumb_item [Hash] a hash containg options for the breadcrumb item
|
17
52
|
#
|
18
|
-
# @option
|
53
|
+
# @option govuk_breadcrumb_item [String] :text the text for the link
|
54
|
+
# @option govuk_breadcrumb_item [String] :href the URI for the link. If blank it is assumed that this item relates to current page
|
55
|
+
# @option govuk_breadcrumb_item [Hash] :attributes any additional attributes that will added as part of the HTML.
|
56
|
+
# If the link is blank then it defaults to +{ aria: { current: 'page' } }+
|
19
57
|
#
|
20
|
-
# @return
|
58
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Breadcrumb list item
|
59
|
+
|
60
|
+
def govuk_breadcrumb_link(govuk_breadcrumb_item)
|
61
|
+
if govuk_breadcrumb_item[:href].present?
|
62
|
+
(govuk_breadcrumb_item[:attributes] ||= {})[:class] = 'govuk-breadcrumbs__link'
|
21
63
|
|
22
|
-
|
23
|
-
|
64
|
+
tag.li(class: 'govuk-breadcrumbs__list-item') do
|
65
|
+
link_to(govuk_breadcrumb_item[:text], govuk_breadcrumb_item[:href], **govuk_breadcrumb_item[:attributes])
|
66
|
+
end
|
67
|
+
else
|
68
|
+
tag.li(class: 'govuk-breadcrumbs__list-item', aria: { current: 'page' }) do
|
69
|
+
govuk_breadcrumb_item[:text]
|
70
|
+
end
|
71
|
+
end
|
24
72
|
end
|
25
73
|
end
|
26
74
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
require_relative '../shared_methods'
|
4
6
|
|
5
7
|
module CCS
|
6
8
|
module FrontendHelpers
|
@@ -11,16 +13,113 @@ module CCS
|
|
11
13
|
# {https://design-system.service.gov.uk/components/button GDS - Components - Button}
|
12
14
|
|
13
15
|
module Button
|
16
|
+
include SharedMethods
|
17
|
+
include ActionView::Context
|
18
|
+
include ActionView::Helpers::TagHelper
|
19
|
+
include ActionView::Helpers::TextHelper
|
20
|
+
include ActionView::Helpers::UrlHelper
|
21
|
+
include ActionView::Helpers::FormTagHelper
|
22
|
+
|
14
23
|
# Generates the HTML for the GOV.UK button component
|
15
24
|
#
|
16
|
-
# @param
|
25
|
+
# @param text [String] the text that will be shown in the button
|
26
|
+
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
17
27
|
#
|
18
|
-
# @option
|
28
|
+
# @option govuk_button_options [String] :classes additional CSS classes for the button HTML
|
29
|
+
# @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
|
30
|
+
# @option govuk_button_options [String] :href the URI that will be used in anchor tag
|
31
|
+
# @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
|
32
|
+
# @option govuk_button_options [Hash] :attributes ({ data: { module: 'govuk-button' } }) any additional attributes that will added as part of the HTML
|
33
|
+
#
|
34
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button
|
35
|
+
# which can then be rendered on the page
|
36
|
+
|
37
|
+
def govuk_button(text, **govuk_button_options)
|
38
|
+
initialise_attributes_and_set_classes(govuk_button_options, 'govuk-button')
|
39
|
+
set_data_module(govuk_button_options, 'govuk-button')
|
40
|
+
|
41
|
+
govuk_button_options[:attributes][:class] << ' govuk-button--disabled' if govuk_button_options[:attributes][:disabled]
|
42
|
+
govuk_button_options[:attributes][:class] << ' govuk-button--start' if govuk_button_options[:is_start_button]
|
43
|
+
|
44
|
+
button_method = if govuk_button_options[:href]
|
45
|
+
:govuk_button_link
|
46
|
+
elsif govuk_button_options[:form]
|
47
|
+
:govuk_button_submit
|
48
|
+
else
|
49
|
+
:govuk_button_button
|
50
|
+
end
|
51
|
+
|
52
|
+
send(button_method, text, **govuk_button_options)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# Generates the HTML for the GOV.UK button component as an anchor tag.
|
58
|
+
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
59
|
+
#
|
60
|
+
# @param text [String] the text that will be shown in the button
|
61
|
+
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
62
|
+
#
|
63
|
+
# @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
|
64
|
+
# @option govuk_button_options [String] :href the URI that will be used in anchor tag
|
65
|
+
# @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
66
|
+
#
|
67
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an anchor element
|
68
|
+
# which can then be rendered on the page
|
69
|
+
|
70
|
+
def govuk_button_link(text, **govuk_button_options)
|
71
|
+
govuk_button_options[:attributes][:role] = :button
|
72
|
+
govuk_button_options[:attributes][:draggable] = false
|
73
|
+
|
74
|
+
link_to(govuk_button_options[:href], **govuk_button_options[:attributes]) do
|
75
|
+
concat(text)
|
76
|
+
concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Generates the HTML for the GOV.UK button component as a button.
|
81
|
+
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
82
|
+
#
|
83
|
+
# @param text [String] the text that will be shown in the button
|
84
|
+
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
85
|
+
#
|
86
|
+
# @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
|
87
|
+
# @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
88
|
+
#
|
89
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as a button element
|
90
|
+
# which can then be rendered on the page
|
91
|
+
|
92
|
+
def govuk_button_button(text, **govuk_button_options)
|
93
|
+
button_tag(**govuk_button_options[:attributes]) do
|
94
|
+
concat(text)
|
95
|
+
concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Generates the HTML for the GOV.UK button component as an input.
|
100
|
+
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
101
|
+
#
|
102
|
+
# @param text [String] the text that will be shown in the input
|
103
|
+
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
104
|
+
#
|
105
|
+
# @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
|
106
|
+
# @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
107
|
+
#
|
108
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an input element
|
109
|
+
# which can then be rendered on the page
|
110
|
+
|
111
|
+
def govuk_button_submit(text, **govuk_button_options)
|
112
|
+
govuk_button_options[:form].submit(text, **govuk_button_options[:attributes])
|
113
|
+
end
|
114
|
+
|
115
|
+
# Generates the arrow for the start button option as part of {#govuk_button}
|
19
116
|
#
|
20
|
-
# @return
|
117
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the arrow for the start button
|
21
118
|
|
22
|
-
def
|
23
|
-
|
119
|
+
def govuk_start_button_icon
|
120
|
+
tag.svg(class: 'govuk-button__start-icon', xmlns: 'http://www.w3.org/2000/svg', width: 17.5, height: 19, viewBox: '0 0 33 40', aria: { hidden: true }, focusable: false) do
|
121
|
+
tag.path(fill: 'currentColor', d: 'M0 0h13l20 20-20 20H0l20-20z')
|
122
|
+
end
|
24
123
|
end
|
25
124
|
end
|
26
125
|
end
|