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
@@ -1,25 +1,23 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'action_view'
|
4
2
|
|
5
3
|
module CCS
|
6
|
-
module
|
7
|
-
module
|
4
|
+
module Components
|
5
|
+
module CCS
|
8
6
|
# = CCS Logo
|
9
7
|
#
|
10
|
-
# This
|
8
|
+
# This is used for generating the logo component from the
|
11
9
|
# {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/logo CCS - Components - Logo}
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
include ActionView::Helpers::TextHelper
|
11
|
+
class Logo
|
12
|
+
extend ActionView::Context
|
13
|
+
extend ActionView::Helpers
|
17
14
|
|
18
|
-
# Generates the
|
15
|
+
# Generates the HTML for the CCS Logo.
|
16
|
+
# Used in {CCS::Components::CCS::Header Header} and {CCS::Components::CCS::Footer Footer}
|
19
17
|
#
|
20
|
-
# @return [ActiveSupport::SafeBuffer]
|
18
|
+
# @return [ActiveSupport::SafeBuffer]
|
21
19
|
|
22
|
-
def
|
20
|
+
def self.render
|
23
21
|
tag.span(class: 'ccs-logo') do
|
24
22
|
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
|
25
23
|
CCS_LOGO_PATHS.each { |ccs_logo_path_attributes| concat(tag.path(**ccs_logo_path_attributes)) }
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module CCS
|
2
|
+
module Components
|
3
|
+
module GovUK
|
4
|
+
class Accordion < Base
|
5
|
+
class Section
|
6
|
+
# = GOV.UK Accordion Section Content
|
7
|
+
#
|
8
|
+
# The individual accordion section content
|
9
|
+
#
|
10
|
+
# @!attribute [r] section
|
11
|
+
# @return [Hash] Attributes for the accordion section
|
12
|
+
# @!attribute [r] accordion_id
|
13
|
+
# @return [String] ID of the accordion
|
14
|
+
# @!attribute [r] index
|
15
|
+
# @return [Integer] Index of the accordion section
|
16
|
+
|
17
|
+
class Content
|
18
|
+
include ActionView::Context
|
19
|
+
include ActionView::Helpers
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :section, :accordion_id, :index
|
24
|
+
|
25
|
+
public
|
26
|
+
|
27
|
+
# @param section [Hash] attributes for the accordion section
|
28
|
+
# @param accordion_id [String] ID of the accordion
|
29
|
+
# @param index [Integer] the index of the accordion section
|
30
|
+
#
|
31
|
+
# @option (see CCS::Components::GovUK::Accordion::Section)
|
32
|
+
|
33
|
+
def initialize(section:, accordion_id:, index:)
|
34
|
+
@section = section
|
35
|
+
@accordion_id = accordion_id
|
36
|
+
@index = index
|
37
|
+
end
|
38
|
+
|
39
|
+
# Generates the HTML for the GOV.UK Accordion Section Content
|
40
|
+
#
|
41
|
+
# @return [ActiveSupport::SafeBuffer]
|
42
|
+
|
43
|
+
def render
|
44
|
+
tag.div(class: 'govuk-accordion__section-content', id: "#{accordion_id}-content-#{index}", aria: { labelledby: "#{accordion_id}-heading-#{index}" }) do
|
45
|
+
section[:content] || tag.p(section[:text], class: 'govuk-body')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module CCS
|
2
|
+
module Components
|
3
|
+
module GovUK
|
4
|
+
class Accordion < Base
|
5
|
+
class Section
|
6
|
+
# = GOV.UK Accordion Section Header
|
7
|
+
#
|
8
|
+
# The individual accordion section header
|
9
|
+
#
|
10
|
+
# @!attribute [r] section
|
11
|
+
# @return [Hash] Attributes for the accordion section
|
12
|
+
# @!attribute [r] accordion_id
|
13
|
+
# @return [String] ID of the accordion
|
14
|
+
# @!attribute [r] index
|
15
|
+
# @return [Integer] Index of the accordion section
|
16
|
+
# @!attribute [r] heading_level
|
17
|
+
# @return [Integer] The heading level for the accordion section
|
18
|
+
|
19
|
+
class Header
|
20
|
+
include ActionView::Context
|
21
|
+
include ActionView::Helpers
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :section, :accordion_id, :index, :heading_level
|
26
|
+
|
27
|
+
public
|
28
|
+
|
29
|
+
# @param (see CCS::Components::GovUK::Accordion::Section)
|
30
|
+
#
|
31
|
+
# @option (see CCS::Components::GovUK::Accordion::Section)
|
32
|
+
|
33
|
+
def initialize(section:, accordion_id:, index:, heading_level:)
|
34
|
+
@section = section
|
35
|
+
@accordion_id = accordion_id
|
36
|
+
@index = index
|
37
|
+
@heading_level = heading_level
|
38
|
+
end
|
39
|
+
|
40
|
+
# Generates the HTML for the GOV.UK Accordion Section Header
|
41
|
+
#
|
42
|
+
# @return [ActiveSupport::SafeBuffer]
|
43
|
+
|
44
|
+
def render
|
45
|
+
tag.div(class: 'govuk-accordion__section-header') do
|
46
|
+
concat(tag.send("h#{heading_level}", class: 'govuk-accordion__section-heading') do
|
47
|
+
tag.span(section[:heading], class: 'govuk-accordion__section-button', id: "#{accordion_id}-heading-#{index}")
|
48
|
+
end)
|
49
|
+
concat(tag.div(section[:summary], class: 'govuk-accordion__section-summary govuk-body', id: "#{accordion_id}-summary-#{index}")) if section[:summary]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative 'section/header'
|
2
|
+
require_relative 'section/content'
|
3
|
+
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
class Accordion < Base
|
8
|
+
# = GOV.UK Accordion Section
|
9
|
+
#
|
10
|
+
# The individual accordion section
|
11
|
+
#
|
12
|
+
# @!attribute [r] header
|
13
|
+
# @return [Header] Initialised accordion section header
|
14
|
+
# @!attribute [r] content
|
15
|
+
# @return [Content] Initialised accordion section content
|
16
|
+
# @!attribute [r] section_is_expanded
|
17
|
+
# @return [Boolean] flag to indicate of the section should be expanded
|
18
|
+
|
19
|
+
class Section
|
20
|
+
include ActionView::Context
|
21
|
+
include ActionView::Helpers
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :header, :content, :section_is_expanded
|
26
|
+
|
27
|
+
public
|
28
|
+
|
29
|
+
# @param section [Hash] attributes for the accordion section
|
30
|
+
# @param accordion_id [String] ID of the accordion
|
31
|
+
# @param index [Integer] the index of the accordion section
|
32
|
+
# @param heading_level [Integer] heading level, from 1 to 6
|
33
|
+
#
|
34
|
+
# @option section [Boolean] :expanded sets whether the section should be expanded
|
35
|
+
# when the page loads for the first time.
|
36
|
+
# @option section [String] :heading the heading text for the accordion
|
37
|
+
# @option section [String] :summary (nil) optional summary text for the accordion header
|
38
|
+
# @option section [ActiveSupport::SafeBuffer] :content the content within the accordion section
|
39
|
+
# @option section [String] : text if +:content+ is +nil+ then the text will be rendered
|
40
|
+
|
41
|
+
def initialize(section:, accordion_id:, index:, heading_level:)
|
42
|
+
@section_is_expanded = section[:expanded]
|
43
|
+
@header = Header.new(section: section, accordion_id: accordion_id, index: index, heading_level: heading_level)
|
44
|
+
@content = Content.new(section: section, accordion_id: accordion_id, index: index)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Generates the HTML for the GOV.UK Accordion Section
|
48
|
+
#
|
49
|
+
# @return [ActiveSupport::SafeBuffer]
|
50
|
+
|
51
|
+
def render
|
52
|
+
tag.div(class: "govuk-accordion__section #{'govuk-accordion__section--expanded' if section_is_expanded}".rstrip) do
|
53
|
+
concat(header.render)
|
54
|
+
concat(content.render)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'accordion/section'
|
3
|
+
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK Accordion
|
8
|
+
#
|
9
|
+
# This is used for generating the accordion component from the
|
10
|
+
# {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
|
11
|
+
#
|
12
|
+
# @!attribute [r] accordion_sections
|
13
|
+
# @return [Array<Section>] An array of the initialised accordion sections
|
14
|
+
|
15
|
+
class Accordion < Base
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :accordion_sections
|
19
|
+
|
20
|
+
public
|
21
|
+
|
22
|
+
# @param accordion_id [String] used as an id in the HTML for the accordion as a whole,
|
23
|
+
# and also as a prefix for the ids of the section contents
|
24
|
+
# and the buttons that open them
|
25
|
+
# @param accordion_sections [Array<Hash>] an array of accordion section attributes.
|
26
|
+
# See {Components::GovUK::Accordion::Section#initialize Section#initialize} for details of the items in the array.
|
27
|
+
# @param options [Hash] options that will be used in customising the HTML
|
28
|
+
#
|
29
|
+
# @option options [String] :classes additional CSS classes for the accordion HTML
|
30
|
+
# @option options [Integer] :heading_level (2) heading level, from 1 to 6
|
31
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
32
|
+
|
33
|
+
def initialize(accordion_id:, accordion_sections:, **options)
|
34
|
+
super(**options)
|
35
|
+
|
36
|
+
@options[:attributes][:id] = accordion_id
|
37
|
+
@options[:heading_level] ||= 2
|
38
|
+
|
39
|
+
@accordion_sections = accordion_sections.map.with_index(1) { |accordion_section, index| Section.new(section: accordion_section, accordion_id: accordion_id, index: index, heading_level: @options[:heading_level]) }
|
40
|
+
end
|
41
|
+
|
42
|
+
# Generates the HTML for the GOV.UK Accordion component
|
43
|
+
#
|
44
|
+
# @return [ActiveSupport::SafeBuffer]
|
45
|
+
|
46
|
+
def render
|
47
|
+
tag.div(**options[:attributes]) do
|
48
|
+
accordion_sections.each { |accordion_section| concat(accordion_section.render) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# The default attributes for the accordion
|
53
|
+
|
54
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-accordion', data: { module: 'govuk-accordion' } }.freeze
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Back Link
|
7
|
+
#
|
8
|
+
# This is used to generate the back link component from the
|
9
|
+
# {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the back link
|
13
|
+
# @!attribute [r] href
|
14
|
+
# @return [String] The href for the back link
|
15
|
+
|
16
|
+
class BackLink < Base
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :text, :href
|
20
|
+
|
21
|
+
public
|
22
|
+
|
23
|
+
# @param text [String] the text for the back link
|
24
|
+
# @param href [String] the href for the back link
|
25
|
+
# @param options [Hash] options that will be used in customising the HTML
|
26
|
+
#
|
27
|
+
# @option options [String] :classes additional CSS classes for the back link HTML
|
28
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
29
|
+
|
30
|
+
def initialize(text:, href:, **options)
|
31
|
+
super(**options)
|
32
|
+
|
33
|
+
@text = text
|
34
|
+
@href = href
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates the HTML for the GOV.UK Back link component
|
38
|
+
#
|
39
|
+
# @return [ActiveSupport::SafeBuffer]
|
40
|
+
|
41
|
+
def render
|
42
|
+
link_to(text, href, **options[:attributes])
|
43
|
+
end
|
44
|
+
|
45
|
+
# The default attributes for the back link
|
46
|
+
|
47
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-back-link' }.freeze
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Breadcrumbs < Base
|
7
|
+
# = GOV.UK Breadcrumbs Link
|
8
|
+
#
|
9
|
+
# The individual list item for the breadcrumbs
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the breadcrumb link
|
13
|
+
# @!attribute [r] href
|
14
|
+
# @return [String] The href for the breadcrumb link
|
15
|
+
|
16
|
+
class Link < Base
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :text, :href
|
20
|
+
|
21
|
+
public
|
22
|
+
|
23
|
+
# @param text [String] the text for the breadcrumb link
|
24
|
+
# @param href [String] the href for the breadcrumb link.
|
25
|
+
# If blank it is assumed that this item relates to current page
|
26
|
+
# @param options [Hash] options that will be used in customising the HTML
|
27
|
+
#
|
28
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
|
29
|
+
# If the link is blank then it defaults to +{ aria: { current: 'page' } }+
|
30
|
+
|
31
|
+
def initialize(text:, href: nil, **options)
|
32
|
+
super(**options)
|
33
|
+
|
34
|
+
@text = text
|
35
|
+
@href = href
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generates the HTML for the GOV.UK Breadcrumbs link
|
39
|
+
#
|
40
|
+
# @return [ActiveSupport::SafeBuffer]
|
41
|
+
|
42
|
+
def render
|
43
|
+
if href.present?
|
44
|
+
options[:attributes][:class] = 'govuk-breadcrumbs__link'
|
45
|
+
|
46
|
+
tag.li(class: 'govuk-breadcrumbs__list-item') do
|
47
|
+
link_to(text, href, **options[:attributes])
|
48
|
+
end
|
49
|
+
else
|
50
|
+
tag.li(text, class: 'govuk-breadcrumbs__list-item', aria: { current: 'page' })
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'breadcrumbs/link'
|
3
|
+
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK Breadcrumbs
|
8
|
+
#
|
9
|
+
# This is used to generate the breadcrumbs component from the
|
10
|
+
# {https://design-system.service.gov.uk/components/breadcrumbs GDS - Components - Breadcrumbs}
|
11
|
+
#
|
12
|
+
# @!attribute [r] breadcrumb_links
|
13
|
+
# @return [Array<Link>] An array of the initialised breadcrumb links
|
14
|
+
|
15
|
+
class Breadcrumbs < Base
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :breadcrumb_links
|
19
|
+
|
20
|
+
public
|
21
|
+
|
22
|
+
# @param breadcrumb_links [Array<Hash>] An array of links for the breadcrumbs list.
|
23
|
+
# See {Components::GovUK::Breadcrumbs::Link#initialize Link#initialize} for details of the items in the array.
|
24
|
+
# @param options [Hash] options that will be used in customising the HTML
|
25
|
+
#
|
26
|
+
# @option options [String] :classes additional CSS classes for the breadcrumbs HTML
|
27
|
+
# @option options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
|
28
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
29
|
+
|
30
|
+
def initialize(breadcrumb_links:, **options)
|
31
|
+
super(**options)
|
32
|
+
@options[:attributes][:class] << ' govuk-breadcrumbs--collapse-on-mobile' if @options[:collapse_on_mobile]
|
33
|
+
|
34
|
+
@breadcrumb_links = breadcrumb_links.map { |breadcrumb_link| Link.new(context: @context, **breadcrumb_link) }
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates the HTML for the GOV.UK breadcrumbs component
|
38
|
+
#
|
39
|
+
# @return [ActiveSupport::SafeBuffer]
|
40
|
+
|
41
|
+
def render
|
42
|
+
tag.div(**options[:attributes]) do
|
43
|
+
tag.ol(class: 'govuk-breadcrumbs__list') do
|
44
|
+
breadcrumb_links.each { |breadcrumb_link| concat(breadcrumb_link.render) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# The default attributes for the breadcrumbs
|
50
|
+
|
51
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-breadcrumbs' }.freeze
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Button
|
7
|
+
#
|
8
|
+
# This is used to generate the button component from the
|
9
|
+
# {https://design-system.service.gov.uk/components/button GDS - Components - Button}
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the button
|
13
|
+
# @!attribute [r] render_method
|
14
|
+
# @return [String] The method that will be used to render the button
|
15
|
+
|
16
|
+
class Button < Base
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :text, :render_method
|
20
|
+
|
21
|
+
public
|
22
|
+
|
23
|
+
# @param text [String] the text that will be shown in the button
|
24
|
+
# @param options [Hash] options that will be used in customising the HTML
|
25
|
+
#
|
26
|
+
# @option options [String] :classes additional CSS classes for the button HTML
|
27
|
+
# @option options [Boolean] :is_start_button indicates if it is a start button
|
28
|
+
# @option options [String] :href the URI that will be used in anchor tag
|
29
|
+
# @option options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
|
30
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
31
|
+
|
32
|
+
def initialize(text:, **options)
|
33
|
+
super(**options)
|
34
|
+
|
35
|
+
@options[:attributes][:class] << ' govuk-button--disabled' if @options[:attributes][:disabled]
|
36
|
+
@options[:attributes][:class] << ' govuk-button--start' if @options[:is_start_button]
|
37
|
+
|
38
|
+
@text = text
|
39
|
+
@render_method = :"render_#{if @options[:href]
|
40
|
+
:link
|
41
|
+
elsif @options[:form]
|
42
|
+
:submit
|
43
|
+
else
|
44
|
+
:button
|
45
|
+
end}"
|
46
|
+
end
|
47
|
+
|
48
|
+
# Generates the HTML for the GOV.UK Back link component
|
49
|
+
#
|
50
|
+
# @return [ActiveSupport::SafeBuffer]
|
51
|
+
|
52
|
+
def render
|
53
|
+
send(@render_method)
|
54
|
+
end
|
55
|
+
|
56
|
+
# The default attributes for the button
|
57
|
+
|
58
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-button', data: { module: 'govuk-button' } }.freeze
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# Generates the HTML for the GOV.UK button component as an anchor tag.
|
63
|
+
#
|
64
|
+
# @return [ActiveSupport::SafeBuffer]
|
65
|
+
|
66
|
+
def render_link
|
67
|
+
@options[:attributes][:role] = :button
|
68
|
+
@options[:attributes][:draggable] = false
|
69
|
+
|
70
|
+
link_to(@options[:href], **@options[:attributes]) do
|
71
|
+
concat(text)
|
72
|
+
concat(start_button_icon) if @options[:is_start_button]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Generates the HTML for the GOV.UK button component as a button.
|
77
|
+
#
|
78
|
+
# @return [ActiveSupport::SafeBuffer]
|
79
|
+
|
80
|
+
def render_button
|
81
|
+
button_tag(**@options[:attributes]) do
|
82
|
+
concat(text)
|
83
|
+
concat(start_button_icon) if @options[:is_start_button]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Generates the HTML for the GOV.UK button component as an input.
|
88
|
+
#
|
89
|
+
# @return [ActiveSupport::SafeBuffer]
|
90
|
+
|
91
|
+
def render_submit
|
92
|
+
@options[:form].submit(text, **@options[:attributes])
|
93
|
+
end
|
94
|
+
|
95
|
+
# Generates the arrow if the button is a start button
|
96
|
+
#
|
97
|
+
# @return [ActiveSupport::SafeBuffer]
|
98
|
+
|
99
|
+
def start_button_icon
|
100
|
+
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
|
101
|
+
tag.path(fill: 'currentColor', d: 'M0 0h13l20 20-20 20H0l20-20z')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
require_relative '../button'
|
3
|
+
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
class CookieBanner < Base
|
8
|
+
# = GOV.UK Cookie Banner Action
|
9
|
+
#
|
10
|
+
# The individual cookie banner action.
|
11
|
+
# It defaults to creating button unless a +href+ is set which will create a link
|
12
|
+
#
|
13
|
+
# @!attribute [r] text
|
14
|
+
# @return [String] Text for the action
|
15
|
+
# @!attribute [r] href
|
16
|
+
# @return [String] The href for the action
|
17
|
+
|
18
|
+
class Action < Base
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :text, :href
|
22
|
+
|
23
|
+
public
|
24
|
+
|
25
|
+
# @param text [String] the button or link text
|
26
|
+
# @param href [String] the href for a link
|
27
|
+
# @param options [Hash] options that will be used in customising the HTML
|
28
|
+
#
|
29
|
+
# @option options [String] : classes additional CSS classes for the cookie action button or link
|
30
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
|
31
|
+
# If the +:type+ key is present with a value of +:button+,
|
32
|
+
# the action will be rendered as a button
|
33
|
+
|
34
|
+
def initialize(text:, href: nil, **options)
|
35
|
+
super(**options)
|
36
|
+
|
37
|
+
@text = text
|
38
|
+
@href = href
|
39
|
+
end
|
40
|
+
|
41
|
+
# Generates the HTML for a cookie banner message action
|
42
|
+
#
|
43
|
+
# @return [ActiveSupport::SafeBuffer]
|
44
|
+
|
45
|
+
def render
|
46
|
+
if href && options[:attributes][:type] != :button
|
47
|
+
link_to(text, href, **options[:attributes])
|
48
|
+
else
|
49
|
+
Button.new(text: text, href: href, context: context, **options).render
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# The default attributes for the cookie banner action
|
54
|
+
|
55
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-link' }.freeze
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
require_relative 'action'
|
3
|
+
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
class CookieBanner < Base
|
8
|
+
# = GOV.UK Cookie Banner Message
|
9
|
+
#
|
10
|
+
# The individual cookie banner message
|
11
|
+
#
|
12
|
+
# @!attribute [r] heading_text
|
13
|
+
# @return [String] Heading text for the message
|
14
|
+
# @!attribute [r] content
|
15
|
+
# @return [ActiveSupport::SafeBuffer] HTML for the message
|
16
|
+
# @!attribute [r] text
|
17
|
+
# @return [String] Text for the message
|
18
|
+
# @!attribute [r] actions
|
19
|
+
# @return [Array<Action>] Array of initialised cookie banner actions
|
20
|
+
|
21
|
+
class Message < Base
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :heading_text, :content, :text, :actions
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
# @param heading_text [String] the heading text that displays in the message
|
29
|
+
# @param content [ActiveSupport::SafeBuffer] HTML to use as content for the message
|
30
|
+
# @param text [String] if +:content+ is blank then this is the text used for the message
|
31
|
+
# @param actions [Array<Hash>] the buttons and/or links that you want to display in the message.
|
32
|
+
# See {Components::GovUK::CookieBanner::Action#initialize Action#initialize} for details of the items in the array.
|
33
|
+
# @param options [Hash] options that will be used in customising the HTML
|
34
|
+
#
|
35
|
+
# @option options [String] :classes additional CSS classes for the cookie message HTML
|
36
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
37
|
+
|
38
|
+
def initialize(heading_text: nil, content: nil, text: nil, actions: nil, **options)
|
39
|
+
super(**options)
|
40
|
+
|
41
|
+
@heading_text = heading_text
|
42
|
+
@content = content
|
43
|
+
@text = text
|
44
|
+
@actions = actions.map { |action| Action.new(context: @context, **action) } if actions
|
45
|
+
end
|
46
|
+
|
47
|
+
# rubocop:disable Metrics/AbcSize
|
48
|
+
|
49
|
+
# Generates the HTML for the GOV.UK Cookie Banner Message
|
50
|
+
#
|
51
|
+
# @return [ActiveSupport::SafeBuffer]
|
52
|
+
|
53
|
+
def render
|
54
|
+
tag.div(**options[:attributes]) do
|
55
|
+
concat(tag.div(class: 'govuk-grid-row') do
|
56
|
+
tag.div(class: 'govuk-grid-column-two-thirds') do
|
57
|
+
concat(tag.h2(heading_text, class: 'govuk-cookie-banner__heading govuk-heading-m')) if heading_text
|
58
|
+
concat(tag.div(class: 'govuk-cookie-banner__content') do
|
59
|
+
content || tag.p(text, class: 'govuk-body')
|
60
|
+
end)
|
61
|
+
end
|
62
|
+
end)
|
63
|
+
if actions
|
64
|
+
concat(tag.div(class: 'govuk-button-group') do
|
65
|
+
actions.each { |action| concat(action.render) }
|
66
|
+
end)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# rubocop:enable Metrics/AbcSize
|
72
|
+
|
73
|
+
# The default attributes for the cookie banner message
|
74
|
+
|
75
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-cookie-banner__message govuk-width-container' }.freeze
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|