ccs-frontend_helpers 0.1.0 → 0.1.1.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -2
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -1
- data/Gemfile +15 -1
- data/Gemfile.lock +153 -114
- data/ccs-frontend_helpers.gemspec +1 -11
- data/lib/ccs/components/base.rb +64 -0
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +57 -0
- data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
- data/lib/ccs/components/ccs/footer/link.rb +55 -0
- data/lib/ccs/components/ccs/footer/meta.rb +59 -0
- data/lib/ccs/components/ccs/footer/navigation.rb +60 -0
- data/lib/ccs/components/ccs/footer.rb +95 -0
- data/lib/ccs/components/ccs/header/link.rb +60 -0
- data/lib/ccs/components/ccs/header/navigation.rb +98 -0
- data/lib/ccs/components/ccs/header/service_authentication.rb +53 -0
- data/lib/ccs/components/ccs/header.rb +110 -0
- data/lib/ccs/{frontend_helpers/ccs_frontend → components/ccs}/logo.rb +10 -12
- data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
- data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
- data/lib/ccs/components/govuk/accordion/section.rb +61 -0
- data/lib/ccs/components/govuk/accordion.rb +58 -0
- data/lib/ccs/components/govuk/back_link.rb +51 -0
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +57 -0
- data/lib/ccs/components/govuk/breadcrumbs.rb +55 -0
- data/lib/ccs/components/govuk/button.rb +107 -0
- data/lib/ccs/components/govuk/cookie_banner/action.rb +60 -0
- data/lib/ccs/components/govuk/cookie_banner/message.rb +80 -0
- data/lib/ccs/components/govuk/cookie_banner.rb +55 -0
- data/lib/ccs/components/govuk/details.rb +53 -0
- data/lib/ccs/components/govuk/error_message.rb +60 -0
- data/lib/ccs/components/govuk/error_summary/item.rb +54 -0
- data/lib/ccs/components/govuk/error_summary.rb +70 -0
- data/lib/ccs/components/govuk/field/input/character_count.rb +129 -0
- data/lib/ccs/components/govuk/field/input/file_upload.rb +44 -0
- data/lib/ccs/components/govuk/field/input/select.rb +82 -0
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +55 -0
- data/lib/ccs/components/govuk/field/input/text_input.rb +97 -0
- data/lib/ccs/components/govuk/field/input/textarea.rb +59 -0
- data/lib/ccs/components/govuk/field/input.rb +62 -0
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +69 -0
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +65 -0
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +89 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +47 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +43 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +50 -0
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +50 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +44 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +43 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +50 -0
- data/lib/ccs/components/govuk/field/inputs/item.rb +111 -0
- data/lib/ccs/components/govuk/field/inputs/radios.rb +69 -0
- data/lib/ccs/components/govuk/field/inputs.rb +57 -0
- data/lib/ccs/components/govuk/field.rb +108 -0
- data/lib/ccs/components/govuk/fieldset/legend.rb +65 -0
- data/lib/ccs/components/govuk/fieldset.rb +54 -0
- data/lib/ccs/components/govuk/footer/link.rb +55 -0
- data/lib/ccs/components/govuk/footer/meta.rb +59 -0
- data/lib/ccs/components/govuk/footer/navigation.rb +60 -0
- data/lib/ccs/components/govuk/footer.rb +131 -0
- data/lib/ccs/components/govuk/form_group.rb +60 -0
- data/lib/ccs/components/govuk/header/link.rb +56 -0
- data/lib/ccs/components/govuk/header/navigation.rb +71 -0
- data/lib/ccs/components/govuk/header.rb +107 -0
- data/lib/ccs/components/govuk/hint.rb +49 -0
- data/lib/ccs/components/govuk/inset_text.rb +52 -0
- data/lib/ccs/components/govuk/label.rb +85 -0
- data/lib/ccs/components/govuk/notification_banner.rb +107 -0
- data/lib/ccs/components/govuk/pagination/increment/next.rb +44 -0
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +43 -0
- data/lib/ccs/components/govuk/pagination/increment.rb +98 -0
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +28 -0
- data/lib/ccs/components/govuk/pagination/item/form.rb +49 -0
- data/lib/ccs/components/govuk/pagination/item/tag.rb +47 -0
- data/lib/ccs/components/govuk/pagination/item.rb +64 -0
- data/lib/ccs/components/govuk/pagination.rb +96 -0
- data/lib/ccs/components/govuk/panel.rb +62 -0
- data/lib/ccs/components/govuk/phase_banner.rb +69 -0
- data/lib/ccs/components/govuk/skip_link.rb +51 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +53 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +50 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +45 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +63 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +69 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +56 -0
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/action/link.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/card/title.rb +51 -0
- data/lib/ccs/components/govuk/summary_list/card.rb +63 -0
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/row/key.rb +47 -0
- data/lib/ccs/components/govuk/summary_list/row/value.rb +47 -0
- data/lib/ccs/components/govuk/summary_list/row.rb +67 -0
- data/lib/ccs/components/govuk/summary_list.rb +74 -0
- data/lib/ccs/components/govuk/table/body/data_cell.rb +53 -0
- data/lib/ccs/components/govuk/table/body/head_cell.rb +52 -0
- data/lib/ccs/components/govuk/table/header/head_cell.rb +54 -0
- data/lib/ccs/components/govuk/table.rb +111 -0
- data/lib/ccs/components/govuk/tabs/panel.rb +58 -0
- data/lib/ccs/components/govuk/tabs/tab.rb +56 -0
- data/lib/ccs/components/govuk/tabs.rb +66 -0
- data/lib/ccs/components/govuk/tag.rb +51 -0
- data/lib/ccs/components/govuk/warning_text.rb +61 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +27 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +6 -119
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +6 -183
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +8 -95
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +6 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +6 -54
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +6 -105
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +6 -114
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +7 -23
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +11 -32
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +13 -65
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +7 -48
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +6 -161
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +13 -24
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +6 -139
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +8 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +7 -21
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +7 -70
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +7 -113
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +6 -314
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +7 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +8 -27
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +6 -18
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +7 -186
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +6 -204
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +11 -100
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +6 -73
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +7 -21
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +7 -30
- data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +117 -147
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
- data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
- data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
- data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
- data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
- data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
- data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
- data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
- data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
- data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
- data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -0,0 +1,71 @@
|
|
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
|
@@ -0,0 +1,55 @@
|
|
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
|
@@ -0,0 +1,59 @@
|
|
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
|
@@ -0,0 +1,60 @@
|
|
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
|
@@ -0,0 +1,95 @@
|
|
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
|
@@ -0,0 +1,60 @@
|
|
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
|
@@ -0,0 +1,98 @@
|
|
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
|
@@ -0,0 +1,53 @@
|
|
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
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'logo'
|
3
|
+
require_relative 'header/service_authentication'
|
4
|
+
require_relative 'header/navigation'
|
5
|
+
|
6
|
+
module CCS
|
7
|
+
module Components
|
8
|
+
module CCS
|
9
|
+
# = CCS Header
|
10
|
+
#
|
11
|
+
# This 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
|
+
# @!attribute [r] service_authentication
|
15
|
+
# @return [ServiceAuthentication] The initialised service authentication section
|
16
|
+
# @!attribute [r] navigation
|
17
|
+
# @return [Navigation] The initialised navigation section
|
18
|
+
# @!attribute [r] service
|
19
|
+
# @return [Hash] The options for the service section
|
20
|
+
|
21
|
+
class Header < Base
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :service_authentication, :navigation, :service
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
# @param service_authentication_items [Array<Hash>] An array of links for the service authentication section of the header.
|
29
|
+
# See {Components::CCS::Header::ServiceAuthentication#initialize ServiceAuthentication#initialize} for details of the items in the array.
|
30
|
+
# @param navigation [Hash] options for the navigation section of the header.
|
31
|
+
# See {Components::CCS::Header::Navigation#initialize Navigation#initialize} for details of the options.
|
32
|
+
# @param menu_button [Hash] options for the menu button in the header.
|
33
|
+
# See {Components::CCS::Header::Navigation#initialize Navigation#initialize} for details of the options.
|
34
|
+
# @param service [Hash] options for the service name
|
35
|
+
# @param options [Hash] options that will be used in customising the HTML
|
36
|
+
#
|
37
|
+
# @option service [String] :name the name of the service, included in the header
|
38
|
+
# @option service [String] :href URL for the service name anchor
|
39
|
+
#
|
40
|
+
# @option options [String] :classes additional CSS classes for the header HTML
|
41
|
+
# @option options [String] :container_classes classes for the container
|
42
|
+
# @option options [String] :homepage_url URL of the homepage. Defaults to +/https://www.crowncommercial.gov.uk+
|
43
|
+
# @option options [Hash] :attributes additional attributes that will added as part of the header HTML
|
44
|
+
|
45
|
+
def initialize(service_authentication_items: nil, navigation: nil, menu_button: nil, service: nil, **options)
|
46
|
+
super(**options)
|
47
|
+
|
48
|
+
@options[:attributes][:role] = 'banner'
|
49
|
+
@options[:container_classes] ||= 'govuk-width-container'
|
50
|
+
@options[:homepage_url] ||= 'https://www.crowncommercial.gov.uk'
|
51
|
+
|
52
|
+
@service_authentication = ServiceAuthentication.new(service_authentication_items: service_authentication_items, container_classes: @options[:container_classes], context: @context) if service_authentication_items
|
53
|
+
@navigation = Navigation.new(navigation: navigation, serivce_name_present: service, menu_button: menu_button, context: @context) if navigation
|
54
|
+
@service = service
|
55
|
+
end
|
56
|
+
|
57
|
+
# rubocop:disable Metrics/AbcSize
|
58
|
+
|
59
|
+
# Generates the HTML for the CCS Header component
|
60
|
+
#
|
61
|
+
# @return [ActiveSupport::SafeBuffer]
|
62
|
+
|
63
|
+
def render
|
64
|
+
tag.header(**options[:attributes]) do
|
65
|
+
concat(service_authentication.render) if service_authentication
|
66
|
+
concat(tag.div(class: "ccs-header__container #{options[:container_classes]}".rstrip) do
|
67
|
+
concat(header_logo)
|
68
|
+
if service || navigation
|
69
|
+
concat(tag.div(class: 'ccs-header__content') do
|
70
|
+
concat(header_service_name) if service
|
71
|
+
concat(navigation.render) if navigation
|
72
|
+
end)
|
73
|
+
end
|
74
|
+
end)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# rubocop:enable Metrics/AbcSize
|
79
|
+
|
80
|
+
# The default attributes for the breadcrumbs
|
81
|
+
|
82
|
+
DEFAULT_ATTRIBUTES = { class: 'ccs-header', data: { module: 'ccs-header' } }.freeze
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
# Generates the logo for header
|
87
|
+
#
|
88
|
+
# @return [ActiveSupport::SafeBuffer]
|
89
|
+
|
90
|
+
def header_logo
|
91
|
+
tag.div(class: 'ccs-header__logo') do
|
92
|
+
link_to(Logo.render, options[:homepage_url], class: 'ccs-header__link ccs-header__link--homepage', aria: { label: 'Crown Commercial Service' })
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Generates the service name section
|
97
|
+
#
|
98
|
+
# @return [ActiveSupport::SafeBuffer]
|
99
|
+
|
100
|
+
def header_service_name
|
101
|
+
if service[:href]
|
102
|
+
link_to(service[:name], service[:href], class: 'ccs-header__link ccs-header__link--service-name')
|
103
|
+
else
|
104
|
+
tag.span(service[:name], class: 'ccs-header__link--service-name')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|