ccs-frontend_helpers 0.1.0.rc.2 → 0.1.0.rc.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Gemfile.lock +1 -1
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
- data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
- data/lib/ccs/components/ccs/footer/link.rb +41 -39
- data/lib/ccs/components/ccs/footer/meta.rb +49 -48
- data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
- data/lib/ccs/components/ccs/footer.rb +69 -67
- data/lib/ccs/components/ccs/header/link.rb +47 -45
- data/lib/ccs/components/ccs/header/navigation.rb +85 -84
- data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
- data/lib/ccs/components/ccs/header.rb +87 -85
- data/lib/ccs/components/ccs/logo.rb +36 -34
- data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
- data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
- data/lib/ccs/components/govuk/accordion/section.rb +49 -48
- data/lib/ccs/components/govuk/accordion.rb +43 -41
- data/lib/ccs/components/govuk/back_link.rb +39 -37
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
- data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
- data/lib/ccs/components/govuk/button.rb +83 -81
- data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
- data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
- data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
- data/lib/ccs/components/govuk/details.rb +38 -36
- data/lib/ccs/components/govuk/error_message.rb +46 -44
- data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
- data/lib/ccs/components/govuk/error_summary.rb +49 -47
- data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
- data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
- data/lib/ccs/components/govuk/field/input/select.rb +61 -59
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
- data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
- data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
- data/lib/ccs/components/govuk/field/input.rb +46 -44
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
- data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
- data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
- data/lib/ccs/components/govuk/field/inputs.rb +42 -40
- data/lib/ccs/components/govuk/field.rb +90 -88
- data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
- data/lib/ccs/components/govuk/fieldset.rb +40 -38
- data/lib/ccs/components/govuk/footer/link.rb +41 -39
- data/lib/ccs/components/govuk/footer/meta.rb +49 -48
- data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
- data/lib/ccs/components/govuk/footer.rb +105 -103
- data/lib/ccs/components/govuk/form_group.rb +45 -43
- data/lib/ccs/components/govuk/header/link.rb +41 -39
- data/lib/ccs/components/govuk/header/navigation.rb +54 -53
- data/lib/ccs/components/govuk/header.rb +84 -82
- data/lib/ccs/components/govuk/hint.rb +33 -31
- data/lib/ccs/components/govuk/inset_text.rb +39 -37
- data/lib/ccs/components/govuk/label.rb +61 -59
- data/lib/ccs/components/govuk/notification_banner.rb +83 -81
- data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
- data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
- data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
- data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
- data/lib/ccs/components/govuk/pagination/item.rb +47 -45
- data/lib/ccs/components/govuk/pagination.rb +69 -67
- data/lib/ccs/components/govuk/panel.rb +49 -47
- data/lib/ccs/components/govuk/phase_banner.rb +50 -48
- data/lib/ccs/components/govuk/skip_link.rb +39 -37
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
- data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
- data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
- data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
- data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
- data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
- data/lib/ccs/components/govuk/summary_list/row.rb +47 -45
- data/lib/ccs/components/govuk/summary_list.rb +48 -46
- data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
- data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
- data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
- data/lib/ccs/components/govuk/table.rb +83 -81
- data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
- data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
- data/lib/ccs/components/govuk/tabs.rb +48 -46
- data/lib/ccs/components/govuk/tag.rb +39 -37
- data/lib/ccs/components/govuk/warning_text.rb +49 -47
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +2 -2
@@ -1,57 +1,58 @@
|
|
1
|
-
require_relative '../../base'
|
2
1
|
require_relative 'section/header'
|
3
2
|
require_relative 'section/content'
|
4
3
|
|
5
|
-
module CCS
|
6
|
-
module
|
7
|
-
|
8
|
-
|
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
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
class Accordion < Base
|
8
|
+
# = GOV.UK Accordion Section
|
33
9
|
#
|
34
|
-
#
|
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
|
10
|
+
# The individual accordion section
|
48
11
|
#
|
49
|
-
#
|
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
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
@@ -1,56 +1,58 @@
|
|
1
1
|
require_relative '../base'
|
2
2
|
require_relative 'accordion/section'
|
3
3
|
|
4
|
-
module CCS
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
# This is used for generating the accordion component from the
|
9
|
-
# {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
|
10
|
-
#
|
11
|
-
# @!attribute [r] accordion_sections
|
12
|
-
# @return [Array<Section>] An array of the initialised accordion sections
|
13
|
-
|
14
|
-
class Accordion < Base
|
15
|
-
private
|
16
|
-
|
17
|
-
attr_reader :accordion_sections
|
18
|
-
|
19
|
-
public
|
20
|
-
|
21
|
-
# @param accordion_id [String] used as an id in the HTML for the accordion as a whole,
|
22
|
-
# and also as a prefix for the ids of the section contents
|
23
|
-
# and the buttons that open them
|
24
|
-
# @param accordion_sections [Array<Hash>] an array of accordion section attributes.
|
25
|
-
# See {Components::GovUK::Accordion::Section#initialize Section#initialize} for details of the items in the array.
|
26
|
-
# @param options [Hash] options that will be used in customising the HTML
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK Accordion
|
27
8
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
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
|
31
14
|
|
32
|
-
|
33
|
-
|
15
|
+
class Accordion < Base
|
16
|
+
private
|
34
17
|
|
35
|
-
|
36
|
-
@options[:heading_level] ||= 2
|
18
|
+
attr_reader :accordion_sections
|
37
19
|
|
38
|
-
|
39
|
-
end
|
20
|
+
public
|
40
21
|
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
44
38
|
|
45
|
-
|
46
|
-
tag.div(**options[:attributes]) do
|
47
|
-
accordion_sections.each { |accordion_section| concat(accordion_section.render) }
|
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]) }
|
48
40
|
end
|
49
|
-
end
|
50
41
|
|
51
|
-
|
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
|
52
51
|
|
53
|
-
|
52
|
+
# The default attributes for the accordion
|
53
|
+
|
54
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-accordion', data: { module: 'govuk-accordion' } }.freeze
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
@@ -1,49 +1,51 @@
|
|
1
1
|
require_relative '../base'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
# This is used to generate the back link component from the
|
8
|
-
# {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
|
9
|
-
#
|
10
|
-
# @!attribute [r] text
|
11
|
-
# @return [String] Text for the back link
|
12
|
-
# @!attribute [r] href
|
13
|
-
# @return [String] The href for the back link
|
14
|
-
|
15
|
-
class BackLink < Base
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :text, :href
|
19
|
-
|
20
|
-
public
|
21
|
-
|
22
|
-
# @param text [String] the text for the back link
|
23
|
-
# @param href [String] the href for the back link
|
24
|
-
# @param options [Hash] options that will be used in customising the HTML
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Back Link
|
25
7
|
#
|
26
|
-
#
|
27
|
-
#
|
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
|
28
15
|
|
29
|
-
|
30
|
-
|
16
|
+
class BackLink < Base
|
17
|
+
private
|
31
18
|
|
32
|
-
|
33
|
-
@href = href
|
34
|
-
end
|
19
|
+
attr_reader :text, :href
|
35
20
|
|
36
|
-
|
37
|
-
#
|
38
|
-
# @return [ActiveSupport::SafeBuffer]
|
21
|
+
public
|
39
22
|
|
40
|
-
|
41
|
-
|
42
|
-
|
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)
|
43
32
|
|
44
|
-
|
33
|
+
@text = text
|
34
|
+
@href = href
|
35
|
+
end
|
45
36
|
|
46
|
-
|
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
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -1,52 +1,54 @@
|
|
1
1
|
require_relative '../../base'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# The individual list item for the breadcrumbs
|
9
|
-
#
|
10
|
-
# @!attribute [r] text
|
11
|
-
# @return [String] Text for the breadcrumb link
|
12
|
-
# @!attribute [r] href
|
13
|
-
# @return [String] The href for the breadcrumb link
|
14
|
-
|
15
|
-
class Link < Base
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :text, :href
|
19
|
-
|
20
|
-
public
|
21
|
-
|
22
|
-
# @param text [String] the text for the breadcrumb link
|
23
|
-
# @param href [String] the href for the breadcrumb link.
|
24
|
-
# If blank it is assumed that this item relates to current page
|
25
|
-
# @param options [Hash] options that will be used in customising the HTML
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Breadcrumbs < Base
|
7
|
+
# = GOV.UK Breadcrumbs Link
|
26
8
|
#
|
27
|
-
#
|
28
|
-
#
|
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
|
29
15
|
|
30
|
-
|
31
|
-
|
16
|
+
class Link < Base
|
17
|
+
private
|
32
18
|
|
33
|
-
|
34
|
-
@href = href
|
35
|
-
end
|
19
|
+
attr_reader :text, :href
|
36
20
|
|
37
|
-
|
38
|
-
|
39
|
-
|
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]
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def render
|
43
|
+
if href.present?
|
44
|
+
options[:attributes][:class] = 'govuk-breadcrumbs__link'
|
44
45
|
|
45
|
-
|
46
|
-
|
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' })
|
47
51
|
end
|
48
|
-
else
|
49
|
-
tag.li(text, class: 'govuk-breadcrumbs__list-item', aria: { current: 'page' })
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
@@ -1,53 +1,55 @@
|
|
1
1
|
require_relative '../base'
|
2
2
|
require_relative 'breadcrumbs/link'
|
3
3
|
|
4
|
-
module CCS
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
# This is used to generate the breadcrumbs component from the
|
9
|
-
# {https://design-system.service.gov.uk/components/breadcrumbs GDS - Components - Breadcrumbs}
|
10
|
-
#
|
11
|
-
# @!attribute [r] breadcrumb_links
|
12
|
-
# @return [Array<Link>] An array of the initialised breadcrumb links
|
13
|
-
|
14
|
-
class Breadcrumbs < Base
|
15
|
-
private
|
16
|
-
|
17
|
-
attr_reader :breadcrumb_links
|
18
|
-
|
19
|
-
public
|
20
|
-
|
21
|
-
# @param breadcrumb_links [Array<Hash>] An array of links for the breadcrumbs list.
|
22
|
-
# See {Components::GovUK::Breadcrumbs::Link#initialize Link#initialize} for details of the items in the array.
|
23
|
-
# @param options [Hash] options that will be used in customising the HTML
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK Breadcrumbs
|
24
8
|
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
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
|
28
14
|
|
29
|
-
|
30
|
-
|
31
|
-
@options[:attributes][:class] << ' govuk-breadcrumbs--collapse-on-mobile' if @options[:collapse_on_mobile]
|
15
|
+
class Breadcrumbs < Base
|
16
|
+
private
|
32
17
|
|
33
|
-
|
34
|
-
end
|
18
|
+
attr_reader :breadcrumb_links
|
35
19
|
|
36
|
-
|
37
|
-
|
38
|
-
|
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]
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
44
46
|
end
|
45
47
|
end
|
46
|
-
end
|
47
48
|
|
48
|
-
|
49
|
+
# The default attributes for the breadcrumbs
|
49
50
|
|
50
|
-
|
51
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-breadcrumbs' }.freeze
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|