ccs-frontend_helpers 0.1.0.rc.1 → 0.1.0.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -1
- data/Gemfile.lock +71 -71
- data/lib/ccs/components/base.rb +64 -0
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +55 -0
- data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
- data/lib/ccs/components/ccs/footer/link.rb +53 -0
- data/lib/ccs/components/ccs/footer/meta.rb +58 -0
- data/lib/ccs/components/ccs/footer/navigation.rb +59 -0
- data/lib/ccs/components/ccs/footer.rb +93 -0
- data/lib/ccs/components/ccs/header/link.rb +58 -0
- data/lib/ccs/components/ccs/header/navigation.rb +97 -0
- data/lib/ccs/components/ccs/header/service_authentication.rb +52 -0
- data/lib/ccs/components/ccs/header.rb +108 -0
- data/lib/ccs/components/ccs/logo.rb +45 -0
- 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 +60 -0
- data/lib/ccs/components/govuk/accordion.rb +56 -0
- data/lib/ccs/components/govuk/back_link.rb +49 -0
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +55 -0
- data/lib/ccs/components/govuk/breadcrumbs.rb +53 -0
- data/lib/ccs/components/govuk/button.rb +105 -0
- data/lib/ccs/components/govuk/cookie_banner/action.rb +58 -0
- data/lib/ccs/components/govuk/cookie_banner/message.rb +78 -0
- data/lib/ccs/components/govuk/cookie_banner.rb +53 -0
- data/lib/ccs/components/govuk/details.rb +51 -0
- data/lib/ccs/components/govuk/error_message.rb +58 -0
- data/lib/ccs/components/govuk/error_summary/item.rb +52 -0
- data/lib/ccs/components/govuk/error_summary.rb +68 -0
- data/lib/ccs/components/govuk/field/input/character_count.rb +127 -0
- data/lib/ccs/components/govuk/field/input/file_upload.rb +42 -0
- data/lib/ccs/components/govuk/field/input/select.rb +80 -0
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +53 -0
- data/lib/ccs/components/govuk/field/input/text_input.rb +95 -0
- data/lib/ccs/components/govuk/field/input/textarea.rb +57 -0
- data/lib/ccs/components/govuk/field/input.rb +60 -0
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +67 -0
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +63 -0
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +87 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +45 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +41 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +48 -0
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +48 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +42 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +41 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +48 -0
- data/lib/ccs/components/govuk/field/inputs/item.rb +109 -0
- data/lib/ccs/components/govuk/field/inputs/radios.rb +67 -0
- data/lib/ccs/components/govuk/field/inputs.rb +55 -0
- data/lib/ccs/components/govuk/field.rb +106 -0
- data/lib/ccs/components/govuk/fieldset/legend.rb +63 -0
- data/lib/ccs/components/govuk/fieldset.rb +52 -0
- data/lib/ccs/components/govuk/footer/link.rb +53 -0
- data/lib/ccs/components/govuk/footer/meta.rb +58 -0
- data/lib/ccs/components/govuk/footer/navigation.rb +59 -0
- data/lib/ccs/components/govuk/footer.rb +129 -0
- data/lib/ccs/components/govuk/form_group.rb +58 -0
- data/lib/ccs/components/govuk/header/link.rb +54 -0
- data/lib/ccs/components/govuk/header/navigation.rb +70 -0
- data/lib/ccs/components/govuk/header.rb +105 -0
- data/lib/ccs/components/govuk/hint.rb +47 -0
- data/lib/ccs/components/govuk/inset_text.rb +50 -0
- data/lib/ccs/components/govuk/label.rb +83 -0
- data/lib/ccs/components/govuk/notification_banner.rb +105 -0
- data/lib/ccs/components/govuk/pagination/increment/next.rb +42 -0
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +41 -0
- data/lib/ccs/components/govuk/pagination/increment.rb +96 -0
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +26 -0
- data/lib/ccs/components/govuk/pagination/item/form.rb +47 -0
- data/lib/ccs/components/govuk/pagination/item/tag.rb +45 -0
- data/lib/ccs/components/govuk/pagination/item.rb +62 -0
- data/lib/ccs/components/govuk/pagination.rb +94 -0
- data/lib/ccs/components/govuk/panel.rb +60 -0
- data/lib/ccs/components/govuk/phase_banner.rb +67 -0
- data/lib/ccs/components/govuk/skip_link.rb +49 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +51 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +48 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +43 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +61 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +67 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +54 -0
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +57 -0
- data/lib/ccs/components/govuk/summary_list/action/link.rb +57 -0
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +57 -0
- data/lib/ccs/components/govuk/summary_list/card/title.rb +49 -0
- data/lib/ccs/components/govuk/summary_list/card.rb +61 -0
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +57 -0
- data/lib/ccs/components/govuk/summary_list/row/key.rb +45 -0
- data/lib/ccs/components/govuk/summary_list/row/value.rb +45 -0
- data/lib/ccs/components/govuk/summary_list/row.rb +63 -0
- data/lib/ccs/components/govuk/summary_list.rb +72 -0
- data/lib/ccs/components/govuk/table/body/data_cell.rb +51 -0
- data/lib/ccs/components/govuk/table/body/head_cell.rb +50 -0
- data/lib/ccs/components/govuk/table/header/head_cell.rb +52 -0
- data/lib/ccs/components/govuk/table.rb +109 -0
- data/lib/ccs/components/govuk/tabs/panel.rb +56 -0
- data/lib/ccs/components/govuk/tabs/tab.rb +54 -0
- data/lib/ccs/components/govuk/tabs.rb +64 -0
- data/lib/ccs/components/govuk/tag.rb +49 -0
- data/lib/ccs/components/govuk/warning_text.rb +59 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +25 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +16 -131
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +16 -195
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +16 -105
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +16 -29
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +16 -66
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +16 -117
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +16 -126
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +18 -36
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +31 -54
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +32 -86
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +18 -61
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +16 -173
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +26 -39
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +16 -151
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +18 -34
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +17 -82
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +18 -126
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +16 -326
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +18 -41
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +18 -39
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +16 -30
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +23 -204
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +16 -216
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +16 -114
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +16 -85
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +16 -32
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +18 -43
- data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +110 -14
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
- data/lib/ccs/frontend_helpers/ccs_frontend/logo.rb +0 -49
- 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,56 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'accordion/section'
|
3
|
+
|
4
|
+
module CCS::Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Accordion
|
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
|
27
|
+
#
|
28
|
+
# @option options [String] :classes additional CSS classes for the accordion HTML
|
29
|
+
# @option options [Integer] :heading_level (2) heading level, from 1 to 6
|
30
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
31
|
+
|
32
|
+
def initialize(accordion_id:, accordion_sections:, **options)
|
33
|
+
super(**options)
|
34
|
+
|
35
|
+
@options[:attributes][:id] = accordion_id
|
36
|
+
@options[:heading_level] ||= 2
|
37
|
+
|
38
|
+
@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]) }
|
39
|
+
end
|
40
|
+
|
41
|
+
# Generates the HTML for the GOV.UK Accordion component
|
42
|
+
#
|
43
|
+
# @return [ActiveSupport::SafeBuffer]
|
44
|
+
|
45
|
+
def render
|
46
|
+
tag.div(**options[:attributes]) do
|
47
|
+
accordion_sections.each { |accordion_section| concat(accordion_section.render) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# The default attributes for the accordion
|
52
|
+
|
53
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-accordion', data: { module: 'govuk-accordion' } }.freeze
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
# = GOV.UK Back Link
|
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
|
25
|
+
#
|
26
|
+
# @option options [String] :classes additional CSS classes for the back link HTML
|
27
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
28
|
+
|
29
|
+
def initialize(text:, href:, **options)
|
30
|
+
super(**options)
|
31
|
+
|
32
|
+
@text = text
|
33
|
+
@href = href
|
34
|
+
end
|
35
|
+
|
36
|
+
# Generates the HTML for the GOV.UK Back link component
|
37
|
+
#
|
38
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
|
+
|
40
|
+
def render
|
41
|
+
link_to(text, href, **options[:attributes])
|
42
|
+
end
|
43
|
+
|
44
|
+
# The default attributes for the back link
|
45
|
+
|
46
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-back-link' }.freeze
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
class Breadcrumbs < Base
|
6
|
+
# = GOV.UK Breadcrumbs Link
|
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
|
26
|
+
#
|
27
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
|
28
|
+
# If the link is blank then it defaults to +{ aria: { current: 'page' } }+
|
29
|
+
|
30
|
+
def initialize(text:, href: nil, **options)
|
31
|
+
super(**options)
|
32
|
+
|
33
|
+
@text = text
|
34
|
+
@href = href
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates the HTML for the GOV.UK Breadcrumbs link
|
38
|
+
#
|
39
|
+
# @return [ActiveSupport::SafeBuffer]
|
40
|
+
|
41
|
+
def render
|
42
|
+
if href.present?
|
43
|
+
options[:attributes][:class] = 'govuk-breadcrumbs__link'
|
44
|
+
|
45
|
+
tag.li(class: 'govuk-breadcrumbs__list-item') do
|
46
|
+
link_to(text, href, **options[:attributes])
|
47
|
+
end
|
48
|
+
else
|
49
|
+
tag.li(text, class: 'govuk-breadcrumbs__list-item', aria: { current: 'page' })
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'breadcrumbs/link'
|
3
|
+
|
4
|
+
module CCS::Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Breadcrumbs
|
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
|
24
|
+
#
|
25
|
+
# @option options [String] :classes additional CSS classes for the breadcrumbs HTML
|
26
|
+
# @option options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
|
27
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
28
|
+
|
29
|
+
def initialize(breadcrumb_links:, **options)
|
30
|
+
super(**options)
|
31
|
+
@options[:attributes][:class] << ' govuk-breadcrumbs--collapse-on-mobile' if @options[:collapse_on_mobile]
|
32
|
+
|
33
|
+
@breadcrumb_links = breadcrumb_links.map { |breadcrumb_link| Link.new(context: @context, **breadcrumb_link) }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Generates the HTML for the GOV.UK breadcrumbs component
|
37
|
+
#
|
38
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
|
+
|
40
|
+
def render
|
41
|
+
tag.div(**options[:attributes]) do
|
42
|
+
tag.ol(class: 'govuk-breadcrumbs__list') do
|
43
|
+
breadcrumb_links.each { |breadcrumb_link| concat(breadcrumb_link.render) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# The default attributes for the breadcrumbs
|
49
|
+
|
50
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-breadcrumbs' }.freeze
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
# = GOV.UK Button
|
6
|
+
#
|
7
|
+
# This is used to generate the button component from the
|
8
|
+
# {https://design-system.service.gov.uk/components/button GDS - Components - Button}
|
9
|
+
#
|
10
|
+
# @!attribute [r] text
|
11
|
+
# @return [String] Text for the button
|
12
|
+
# @!attribute [r] render_method
|
13
|
+
# @return [String] The method that will be used to render the button
|
14
|
+
|
15
|
+
class Button < Base
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :text, :render_method
|
19
|
+
|
20
|
+
public
|
21
|
+
|
22
|
+
# @param text [String] the text that will be shown in the button
|
23
|
+
# @param options [Hash] options that will be used in customising the HTML
|
24
|
+
#
|
25
|
+
# @option options [String] :classes additional CSS classes for the button HTML
|
26
|
+
# @option options [Boolean] :is_start_button indicates if it is a start button
|
27
|
+
# @option options [String] :href the URI that will be used in anchor tag
|
28
|
+
# @option options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
|
29
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
30
|
+
|
31
|
+
def initialize(text:, **options)
|
32
|
+
super(**options)
|
33
|
+
|
34
|
+
@options[:attributes][:class] << ' govuk-button--disabled' if @options[:attributes][:disabled]
|
35
|
+
@options[:attributes][:class] << ' govuk-button--start' if @options[:is_start_button]
|
36
|
+
|
37
|
+
@text = text
|
38
|
+
@render_method = :"render_#{if @options[:href]
|
39
|
+
:link
|
40
|
+
elsif @options[:form]
|
41
|
+
:submit
|
42
|
+
else
|
43
|
+
:button
|
44
|
+
end}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Generates the HTML for the GOV.UK Back link component
|
48
|
+
#
|
49
|
+
# @return [ActiveSupport::SafeBuffer]
|
50
|
+
|
51
|
+
def render
|
52
|
+
send(@render_method)
|
53
|
+
end
|
54
|
+
|
55
|
+
# The default attributes for the button
|
56
|
+
|
57
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-button', data: { module: 'govuk-button' } }.freeze
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Generates the HTML for the GOV.UK button component as an anchor tag.
|
62
|
+
#
|
63
|
+
# @return [ActiveSupport::SafeBuffer]
|
64
|
+
|
65
|
+
def render_link
|
66
|
+
@options[:attributes][:role] = :button
|
67
|
+
@options[:attributes][:draggable] = false
|
68
|
+
|
69
|
+
link_to(@options[:href], **@options[:attributes]) do
|
70
|
+
concat(text)
|
71
|
+
concat(start_button_icon) if @options[:is_start_button]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Generates the HTML for the GOV.UK button component as a button.
|
76
|
+
#
|
77
|
+
# @return [ActiveSupport::SafeBuffer]
|
78
|
+
|
79
|
+
def render_button
|
80
|
+
button_tag(**@options[:attributes]) do
|
81
|
+
concat(text)
|
82
|
+
concat(start_button_icon) if @options[:is_start_button]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Generates the HTML for the GOV.UK button component as an input.
|
87
|
+
#
|
88
|
+
# @return [ActiveSupport::SafeBuffer]
|
89
|
+
|
90
|
+
def render_submit
|
91
|
+
@options[:form].submit(text, **@options[:attributes])
|
92
|
+
end
|
93
|
+
|
94
|
+
# Generates the arrow if the button is a start button
|
95
|
+
#
|
96
|
+
# @return [ActiveSupport::SafeBuffer]
|
97
|
+
|
98
|
+
def start_button_icon
|
99
|
+
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
|
100
|
+
tag.path(fill: 'currentColor', d: 'M0 0h13l20 20-20 20H0l20-20z')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
require_relative '../button'
|
3
|
+
|
4
|
+
module CCS::Components
|
5
|
+
module GovUK
|
6
|
+
class CookieBanner < Base
|
7
|
+
# = GOV.UK Cookie Banner Action
|
8
|
+
#
|
9
|
+
# The individual cookie banner action.
|
10
|
+
# It defaults to creating button unless a +href+ is set which will create a link
|
11
|
+
#
|
12
|
+
# @!attribute [r] text
|
13
|
+
# @return [String] Text for the action
|
14
|
+
# @!attribute [r] href
|
15
|
+
# @return [String] The href for the action
|
16
|
+
|
17
|
+
class Action < Base
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :text, :href
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
# @param text [String] the button or link text
|
25
|
+
# @param href [String] the href for a link
|
26
|
+
# @param options [Hash] options that will be used in customising the HTML
|
27
|
+
#
|
28
|
+
# @option options [String] : classes additional CSS classes for the cookie action button or link
|
29
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
|
30
|
+
# If the +:type+ key is present with a value of +:button+,
|
31
|
+
# the action will be rendered as a button
|
32
|
+
|
33
|
+
def initialize(text:, href: nil, **options)
|
34
|
+
super(**options)
|
35
|
+
|
36
|
+
@text = text
|
37
|
+
@href = href
|
38
|
+
end
|
39
|
+
|
40
|
+
# Generates the HTML for a cookie banner message action
|
41
|
+
#
|
42
|
+
# @return [ActiveSupport::SafeBuffer]
|
43
|
+
|
44
|
+
def render
|
45
|
+
if href && options[:attributes][:type] != :button
|
46
|
+
link_to(text, href, **options[:attributes])
|
47
|
+
else
|
48
|
+
Button.new(text: text, href: href, context: context, **options).render
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# The default attributes for the cookie banner action
|
53
|
+
|
54
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-link' }.freeze
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
require_relative 'action'
|
3
|
+
|
4
|
+
module CCS::Components
|
5
|
+
module GovUK
|
6
|
+
class CookieBanner < Base
|
7
|
+
# = GOV.UK Cookie Banner Message
|
8
|
+
#
|
9
|
+
# The individual cookie banner message
|
10
|
+
#
|
11
|
+
# @!attribute [r] heading_text
|
12
|
+
# @return [String] Heading text for the message
|
13
|
+
# @!attribute [r] content
|
14
|
+
# @return [ActiveSupport::SafeBuffer] HTML for the message
|
15
|
+
# @!attribute [r] text
|
16
|
+
# @return [String] Text for the message
|
17
|
+
# @!attribute [r] actions
|
18
|
+
# @return [Array<Action>] Array of initialised cookie banner actions
|
19
|
+
|
20
|
+
class Message < Base
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :heading_text, :content, :text, :actions
|
24
|
+
|
25
|
+
public
|
26
|
+
|
27
|
+
# @param heading_text [String] the heading text that displays in the message
|
28
|
+
# @param content [ActiveSupport::SafeBuffer] HTML to use as content for the message
|
29
|
+
# @param text [String] if +:content+ is blank then this is the text used for the message
|
30
|
+
# @param actions [Array<Hash>] the buttons and/or links that you want to display in the message.
|
31
|
+
# See {Components::GovUK::CookieBanner::Action#initialize Action#initialize} for details of the items in the array.
|
32
|
+
# @param options [Hash] options that will be used in customising the HTML
|
33
|
+
#
|
34
|
+
# @option options [String] :classes additional CSS classes for the cookie message HTML
|
35
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
36
|
+
|
37
|
+
def initialize(heading_text: nil, content: nil, text: nil, actions: nil, **options)
|
38
|
+
super(**options)
|
39
|
+
|
40
|
+
@heading_text = heading_text
|
41
|
+
@content = content
|
42
|
+
@text = text
|
43
|
+
@actions = actions.map { |action| Action.new(context: @context, **action) } if actions
|
44
|
+
end
|
45
|
+
|
46
|
+
# rubocop:disable Metrics/AbcSize
|
47
|
+
|
48
|
+
# Generates the HTML for the GOV.UK Cookie Banner Message
|
49
|
+
#
|
50
|
+
# @return [ActiveSupport::SafeBuffer]
|
51
|
+
|
52
|
+
def render
|
53
|
+
tag.div(**options[:attributes]) do
|
54
|
+
concat(tag.div(class: 'govuk-grid-row') do
|
55
|
+
tag.div(class: 'govuk-grid-column-two-thirds') do
|
56
|
+
concat(tag.h2(heading_text, class: 'govuk-cookie-banner__heading govuk-heading-m')) if heading_text
|
57
|
+
concat(tag.div(class: 'govuk-cookie-banner__content') do
|
58
|
+
content || tag.p(text, class: 'govuk-body')
|
59
|
+
end)
|
60
|
+
end
|
61
|
+
end)
|
62
|
+
if actions
|
63
|
+
concat(tag.div(class: 'govuk-button-group') do
|
64
|
+
actions.each { |action| concat(action.render) }
|
65
|
+
end)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# rubocop:enable Metrics/AbcSize
|
71
|
+
|
72
|
+
# The default attributes for the cookie banner message
|
73
|
+
|
74
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-cookie-banner__message govuk-width-container' }.freeze
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'cookie_banner/message'
|
3
|
+
|
4
|
+
module CCS::Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Cookie Banner
|
7
|
+
#
|
8
|
+
# This is used to generate the cookie banner component from the
|
9
|
+
# {https://design-system.service.gov.uk/components/cookie-banner GDS - Components - Cookie banner}
|
10
|
+
#
|
11
|
+
# @!attribute [r] messages
|
12
|
+
# @return [Array<Message>] An array of the initialised cookie banner messages
|
13
|
+
|
14
|
+
class CookieBanner < Base
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :messages
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
# @param messages [Array<Hash>] An array of messages for the cookie banner.
|
22
|
+
# See {Components::GovUK::CookieBanner::Message#initialize Message#initialize} for details of the items in the array.
|
23
|
+
# @param options [Hash] options that will be used in customising the HTML
|
24
|
+
#
|
25
|
+
# @option options [String] :classes additional CSS classes for the cookie banner HTML
|
26
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
27
|
+
|
28
|
+
def initialize(messages:, **options)
|
29
|
+
super(**options)
|
30
|
+
|
31
|
+
(@options[:attributes][:data] ||= {})[:nosnippet] = 'true'
|
32
|
+
@options[:attributes][:role] = 'region'
|
33
|
+
(@options[:attributes][:aria] ||= {})[:label] ||= 'Cookie banner'
|
34
|
+
|
35
|
+
@messages = messages.map { |message| Message.new(context: @context, **message) }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generates the HTML for the GOV.UK Cookie banner component
|
39
|
+
#
|
40
|
+
# @return [ActiveSupport::SafeBuffer]
|
41
|
+
|
42
|
+
def render
|
43
|
+
tag.div(**options[:attributes]) do
|
44
|
+
messages.each { |message| concat(message.render) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# The default attributes for the cookie banner
|
49
|
+
|
50
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-cookie-banner' }.freeze
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
# = GOV.UK Details
|
6
|
+
#
|
7
|
+
# This is used to generate the details component from the
|
8
|
+
# {https://design-system.service.gov.uk/components/details GDS - Components - Details}
|
9
|
+
#
|
10
|
+
# @!attribute [r] summary_text
|
11
|
+
# @return [String] Summary text for the details element
|
12
|
+
|
13
|
+
class Details < Base
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :summary_text
|
17
|
+
|
18
|
+
public
|
19
|
+
|
20
|
+
# @param summary_text [String] the summary text for the details element
|
21
|
+
# @param options [Hash] options that will be used in customising the HTML
|
22
|
+
#
|
23
|
+
# @option options [String] :classes additional CSS classes for the details HTML
|
24
|
+
# @option options [Hash] :attributes ({ data: { module: 'govuk-details' } }) any additional attributes that will added as part of the HTML
|
25
|
+
|
26
|
+
def initialize(summary_text:, **options)
|
27
|
+
super(**options)
|
28
|
+
|
29
|
+
@summary_text = summary_text
|
30
|
+
end
|
31
|
+
|
32
|
+
# Generates the HTML for the GOV.UK Details component
|
33
|
+
#
|
34
|
+
# @yield HTML that will be contained within the 'govuk-details__text' div
|
35
|
+
#
|
36
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Details
|
37
|
+
# which can then be rendered on the page
|
38
|
+
|
39
|
+
def render(&block)
|
40
|
+
tag.details(**options[:attributes]) do
|
41
|
+
concat(tag.summary(tag.span(summary_text, class: 'govuk-details__summary-text'), class: 'govuk-details__summary'))
|
42
|
+
concat(tag.div(class: 'govuk-details__text', &block))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# The default attributes for the details
|
47
|
+
|
48
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-details', data: { module: 'govuk-details' } }.freeze
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
# = GOV.UK Error Message
|
6
|
+
#
|
7
|
+
# This is used to generate the error message component from the
|
8
|
+
# {https://design-system.service.gov.uk/components/error-message GDS - Components - Error message}
|
9
|
+
#
|
10
|
+
# @!attribute [r] message
|
11
|
+
# @return [String] Text for the error message
|
12
|
+
# @!attribute [r] attribute
|
13
|
+
# @return [String,Symbol] The attribute that has an error
|
14
|
+
# @!attribute [r] visually_hidden_text
|
15
|
+
# @return [String] The visually hidden text before the error message
|
16
|
+
|
17
|
+
class ErrorMessage < Base
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :message, :attribute, :visually_hidden_text
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
# @param message [String] the message to be displayed
|
25
|
+
# @param attribute [String, Symbol] the attribute that has an error
|
26
|
+
# @param options [Hash] options that will be used in customising the HTML
|
27
|
+
#
|
28
|
+
# @option options [String] :classes additional CSS classes for the error message HTML
|
29
|
+
# @option options [String] :visually_hidden_text ('Error') visualy hidden text before the error message
|
30
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
|
31
|
+
|
32
|
+
def initialize(message:, attribute:, **options)
|
33
|
+
super(**options)
|
34
|
+
|
35
|
+
@options[:attributes][:id] ||= "#{attribute}-error"
|
36
|
+
|
37
|
+
@message = message
|
38
|
+
@attribute = attribute
|
39
|
+
@visually_hidden_text = @options[:visually_hidden_text] || 'Error'
|
40
|
+
end
|
41
|
+
|
42
|
+
# Generates the HTML for the GOV.UK Error message component
|
43
|
+
#
|
44
|
+
# @return [ActiveSupport::SafeBuffer]
|
45
|
+
|
46
|
+
def render
|
47
|
+
tag.p(**options[:attributes]) do
|
48
|
+
concat(tag.span("#{visually_hidden_text}: ", class: 'govuk-visually-hidden')) if visually_hidden_text.present?
|
49
|
+
concat(message)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# The default attributes for the error message
|
54
|
+
|
55
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-error-message' }.freeze
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
class ErrorSummary < Base
|
6
|
+
# = GOV.UK Error Summary Item
|
7
|
+
#
|
8
|
+
# The individual list item for the error summary
|
9
|
+
#
|
10
|
+
# @!attribute [r] text
|
11
|
+
# @return [String] Text for the error message item
|
12
|
+
# @!attribute [r] href
|
13
|
+
# @return [String] The href for the error message
|
14
|
+
|
15
|
+
class Item < Base
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :text, :href
|
19
|
+
|
20
|
+
public
|
21
|
+
|
22
|
+
# @param text [String] the text for the error link item
|
23
|
+
# @param href [String] the href for the error link item.
|
24
|
+
# If provided item will be a link
|
25
|
+
# @param options [Hash] options that will be used in customising the HTML
|
26
|
+
#
|
27
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
|
28
|
+
|
29
|
+
def initialize(text:, href: nil, **options)
|
30
|
+
super(**options)
|
31
|
+
|
32
|
+
@text = text
|
33
|
+
@href = href
|
34
|
+
end
|
35
|
+
|
36
|
+
# Generates the HTML for the GOV.UK Error Summary Item
|
37
|
+
#
|
38
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
|
+
|
40
|
+
def render
|
41
|
+
tag.li do
|
42
|
+
if href
|
43
|
+
link_to(text, href, **options[:attributes])
|
44
|
+
else
|
45
|
+
text
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|