crown_marketplace_utils 0.1.0.beta.5 → 0.1.0.beta.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +10 -10
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +91 -89
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +24 -22
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/breadcrumbs.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/button.rb +109 -107
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/details.rb +33 -31
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/error_message.rb +49 -47
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/character_count.rb +144 -142
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/checkboxes.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb +126 -124
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +75 -73
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb +137 -135
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/radios.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb +111 -109
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +86 -84
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +181 -179
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/fieldset.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/form_group.rb +37 -35
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/header.rb +142 -140
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/hint.rb +25 -23
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +69 -67
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/notification_banner.rb +121 -119
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +290 -288
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/step_by_step_navigation.rb +187 -185
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/tag.rb +29 -27
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +39 -37
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper.rb +31 -29
- data/lib/crown_marketplace_utils/version.rb +1 -1
- metadata +2 -2
@@ -2,71 +2,73 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK Fieldset
|
9
|
+
#
|
10
|
+
# This helper is used for generating the fieldset component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/fieldset GDS - Components - Fieldset}
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
module Fieldset
|
14
|
+
include ActionView::Context
|
15
|
+
include ActionView::Helpers::TagHelper
|
16
|
+
include ActionView::Helpers::TextHelper
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
# Generates the HTML for the GOV.UK Fieldset component
|
19
|
+
#
|
20
|
+
# @param govuk_fieldset_options [Hash] options that will be used in customising the HTML
|
21
|
+
#
|
22
|
+
# @option govuk_fieldset_options [String] :classes additional CSS classes for the fieldset HTML
|
23
|
+
# @option govuk_fieldset_options [Hash] :legend options for the legend which are used in {#govuk_legend}
|
24
|
+
# @option govuk_fieldset_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
25
|
+
#
|
26
|
+
# @yield HTML that will be contained within the 'govuk-fieldset' div and under the legend
|
27
|
+
#
|
28
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Fieldset
|
29
|
+
# which can then be rendered on the page
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def govuk_fieldset(**govuk_fieldset_options)
|
32
|
+
govuk_fieldset_classes = ['govuk-fieldset']
|
33
|
+
govuk_fieldset_classes << govuk_fieldset_options[:classes]
|
34
|
+
govuk_fieldset_options[:attributes] ||= {}
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
tag.fieldset(class: govuk_fieldset_classes, **govuk_fieldset_options[:attributes]) do
|
37
|
+
capture do
|
38
|
+
concat(govuk_legend(govuk_fieldset_options[:legend])) if govuk_fieldset_options[:legend]
|
39
|
+
yield
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
|
-
end
|
42
43
|
|
43
|
-
|
44
|
+
private
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
46
|
+
# Generates the HTML for the Legend as part of {#govuk_fieldset}
|
47
|
+
#
|
48
|
+
# @param govuk_legend_options [Hash] options that will be used in the legend
|
49
|
+
#
|
50
|
+
# @option govuk_legend_options [String] :classes additional CSS classes for the legend HTML
|
51
|
+
# @option govuk_legend_options [String] :text the text for the legend
|
52
|
+
# @option govuk_legend_options [boolean] :is_page_heading (false) if the legend is also the heading it will rendered in a h1
|
53
|
+
# @option govuk_legend_options [Hash] :caption an optional hash with the +text+ and +classes+ that will be used
|
54
|
+
# to render a caption before the h1 if the legend is a page heading
|
55
|
+
#
|
56
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Fieldset
|
57
|
+
# which can then be rendered on the page
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def govuk_legend(govuk_legend_options)
|
60
|
+
govuk_legend_classes = ['govuk-fieldset__legend']
|
61
|
+
govuk_legend_classes << govuk_legend_options[:classes]
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
tag.legend(class: govuk_legend_classes) do
|
64
|
+
if govuk_legend_options[:is_page_heading]
|
65
|
+
capture do
|
66
|
+
concat(tag.span(govuk_legend_options[:caption][:text], class: govuk_legend_options[:caption][:classes])) if govuk_legend_options[:caption]
|
67
|
+
concat(tag.h1(govuk_legend_options[:text], class: 'govuk-fieldset__heading'))
|
68
|
+
end
|
69
|
+
else
|
70
|
+
govuk_legend_options[:text]
|
67
71
|
end
|
68
|
-
else
|
69
|
-
govuk_legend_options[:text]
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
@@ -2,46 +2,48 @@
|
|
2
2
|
|
3
3
|
require_relative 'error_message'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK FormGroup
|
9
|
+
#
|
10
|
+
# This helper is used for generating the form group component from the Government Design Systems
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
module FormGroup
|
13
|
+
include ErrorMessage
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
# Generates the HTML for the GOV.UK Form Group component
|
16
|
+
#
|
17
|
+
# @param attribute [String, Symbol] the attribute that the form group is for
|
18
|
+
# @param govuk_form_group_options [Hash] options that will be used in customising the HTML
|
19
|
+
#
|
20
|
+
# @option govuk_form_group_options [String] :classes additional CSS classes for the form group HTML
|
21
|
+
# @option govuk_form_group_options [String] :error_message (nil) the error message to be displayed
|
22
|
+
# @option govuk_form_group_options [ActiveModel] :model (nil) model that will be used to find an error message
|
23
|
+
# @option govuk_form_group_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
24
|
+
#
|
25
|
+
# @yield HTML that will be contained within the 'govuk-form-group' div
|
26
|
+
#
|
27
|
+
# @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the HTML for the error message (if there is one)
|
28
|
+
#
|
29
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Form Group
|
30
|
+
# which can then be rendered on the page
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def govuk_form_group(attribute, **govuk_form_group_options)
|
33
|
+
error_message = if govuk_form_group_options[:model]
|
34
|
+
model.errors[attribute].first
|
35
|
+
else
|
36
|
+
govuk_form_group_options[:error_message]
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
govuk_form_group_classes = ['govuk-form-group']
|
40
|
+
govuk_form_group_classes += ['govuk-form-group--error'] if error_message
|
41
|
+
govuk_form_group_classes << govuk_form_group_options[:classes]
|
42
|
+
govuk_form_group_options[:attributes] ||= {}
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
tag.div(class: govuk_form_group_classes, id: "#{attribute}-form-group", **govuk_form_group_options[:attributes]) do
|
45
|
+
yield((govuk_error_message(error_message, attribute) if error_message))
|
46
|
+
end
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -2,168 +2,170 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
# This helper is used for generating the header component from the
|
10
|
-
# {https://design-system.service.gov.uk/components/header GDS - Components - Header}
|
11
|
-
|
12
|
-
module Header
|
13
|
-
include ActionView::Context
|
14
|
-
include ActionView::Helpers::FormTagHelper
|
15
|
-
include ActionView::Helpers::TagHelper
|
16
|
-
include ActionView::Helpers::TextHelper
|
17
|
-
include ActionView::Helpers::UrlHelper
|
18
|
-
|
19
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
20
|
-
|
21
|
-
# Generates the HTML for the GOV.UK Header component
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK Header
|
22
9
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
10
|
+
# This helper is used for generating the header component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/header GDS - Components - Header}
|
12
|
+
|
13
|
+
module Header
|
14
|
+
include ActionView::Context
|
15
|
+
include ActionView::Helpers::FormTagHelper
|
16
|
+
include ActionView::Helpers::TagHelper
|
17
|
+
include ActionView::Helpers::TextHelper
|
18
|
+
include ActionView::Helpers::UrlHelper
|
19
|
+
|
20
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
21
|
+
|
22
|
+
# Generates the HTML for the GOV.UK Header component
|
23
|
+
#
|
24
|
+
# @param govuk_header_options [Hash] options that will be used in customising the HTML
|
25
|
+
#
|
26
|
+
# @option govuk_header_options [String] :classes additional CSS classes for the header HTML
|
27
|
+
# @option govuk_header_options [Hash] :container_options (see: {govuk_header_container})
|
28
|
+
# @option govuk_header_options [Hash] :service_options (see: {govuk_header_service_name})
|
29
|
+
# @option govuk_header_options [Hash] :navigation_options (see: {govuk_header_navigation})
|
30
|
+
# @option govuk_header_options [Hash] :attributes ({data: { module: 'govuk-header' }})
|
31
|
+
# any additional attributes that will added as part of the HTML
|
32
|
+
#
|
33
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Header
|
34
|
+
# which can then be rendered on the page
|
35
|
+
|
36
|
+
def govuk_header(**govuk_header_options)
|
37
|
+
govuk_header_classes = ['govuk-header']
|
38
|
+
govuk_header_classes << govuk_header_options[:classes]
|
39
|
+
govuk_header_options[:attributes] ||= {}
|
40
|
+
(govuk_header_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-header' })
|
41
|
+
|
42
|
+
tag.header(class: govuk_header_classes, role: 'banner', **govuk_header_options[:attributes]) do
|
43
|
+
capture do
|
44
|
+
concat(govuk_header_container(govuk_header_options[:container_options] || {}))
|
45
|
+
if govuk_header_options[:service_options].present? || govuk_header_options[:navigation_options].present?
|
46
|
+
concat(tag.div(class: 'govuk-header__content') do
|
47
|
+
capture do
|
48
|
+
concat(govuk_header_service_name(govuk_header_options[:service_options])) if govuk_header_options[:service_options].present?
|
49
|
+
concat(govuk_header_navigation(govuk_header_options[:navigation_options])) if govuk_header_options[:navigation_options].present?
|
50
|
+
end
|
51
|
+
end)
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
54
|
-
end
|
55
56
|
|
56
|
-
|
57
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
57
58
|
|
58
|
-
|
59
|
+
private
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
61
|
+
# Generates the header container with the logo for {govuk_header}
|
62
|
+
#
|
63
|
+
# @param container_options [Hash] options that will be used in customising the HTML
|
64
|
+
#
|
65
|
+
# @option container_options [String] :classes additional CSS classes for the container HTML
|
66
|
+
# @option container_options [String] :home_url the URL of the homepage. Defaults to +/+
|
67
|
+
# @option container_options [String] :product_name used when the product name follows on directly from ‘GOV.UK’
|
68
|
+
# @option container_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
69
|
+
#
|
70
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the header container which is used in {govuk_header}
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def govuk_header_container(container_options)
|
73
|
+
govuk_header_classes = ['govuk-header__container']
|
74
|
+
govuk_header_classes << (container_options[:classes] || 'govuk-width-container')
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
76
|
+
tag.div(class: govuk_header_classes) do
|
77
|
+
tag.div(class: 'govuk-header__logo') do
|
78
|
+
link_to(container_options[:home_url] || '/', class: 'govuk-header__link govuk-header__link--homepage') do
|
79
|
+
capture do
|
80
|
+
concat(tag.span(class: 'govuk-header__logotype') do
|
81
|
+
capture do
|
82
|
+
concat(tag.svg(class: 'govuk-header__logotype-crown', xmlns: 'http://www.w3.org/2000/svg', height: '30', width: '36', aria: { hidden: 'true' }, focusable: 'false', viewBox: '0 0 132 97') do
|
83
|
+
tag.path(fill: 'currentColor', 'fill-rule': 'evenodd', d: 'M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-3.6 1.5-7.8-.2-9.2-3.8-1.5-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.3 3.5-.4 7.6-3.9 9.1zM89.3 35.8c-3.6 1.5-7.8-.2-9.2-3.8-1.4-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.4 3.6-.3 7.7-3.9 9.1zM69.7 17.7l8.9 4.7V9.3l-8.9 2.8c-.2-.3-.5-.6-.9-.9L72.4 0H59.6l3.5 11.2c-.3.3-.6.5-.9.9l-8.8-2.8v13.1l8.8-4.7c.3.3.6.7.9.9l-5 15.4v.1c-.2.8-.4 1.6-.4 2.4 0 4.1 3.1 7.5 7 8.1h.2c.3 0 .7.1 1 .1.4 0 .7 0 1-.1h.2c4-.6 7.1-4.1 7.1-8.1 0-.8-.1-1.7-.4-2.4V34l-5.1-15.4c.4-.2.7-.6 1-.9zM66 92.8c16.9 0 32.8 1.1 47.1 3.2 4-16.9 8.9-26.7 14-33.5l-9.6-3.4c1 4.9 1.1 7.2 0 10.2-1.5-1.4-3-4.3-4.2-8.7L108.6 76c2.8-2 5-3.2 7.5-3.3-4.4 9.4-10 11.9-13.6 11.2-4.3-.8-6.3-4.6-5.6-7.9 1-4.7 5.7-5.9 8-.5 4.3-8.7-3-11.4-7.6-8.8 7.1-7.2 7.9-13.5 2.1-21.1-8 6.1-8.1 12.3-4.5 20.8-4.7-5.4-12.1-2.5-9.5 6.2 3.4-5.2 7.9-2 7.2 3.1-.6 4.3-6.4 7.8-13.5 7.2-10.3-.9-10.9-8-11.2-13.8 2.5-.5 7.1 1.8 11 7.3L80.2 60c-4.1 4.4-8 5.3-12.3 5.4 1.4-4.4 8-11.6 8-11.6H55.5s6.4 7.2 7.9 11.6c-4.2-.1-8-1-12.3-5.4l1.4 16.4c3.9-5.5 8.5-7.7 10.9-7.3-.3 5.8-.9 12.8-11.1 13.8-7.2.6-12.9-2.9-13.5-7.2-.7-5 3.8-8.3 7.1-3.1 2.7-8.7-4.6-11.6-9.4-6.2 3.7-8.5 3.6-14.7-4.6-20.8-5.8 7.6-5 13.9 2.2 21.1-4.7-2.6-11.9.1-7.7 8.8 2.3-5.5 7.1-4.2 8.1.5.7 3.3-1.3 7.1-5.7 7.9-3.5.7-9-1.8-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z')
|
84
|
+
end)
|
85
|
+
concat(tag.span('GOV.UK', class: 'govuk-header__logotype-text'))
|
86
|
+
end
|
87
|
+
end)
|
88
|
+
concat(tag.span(container_options[:product_name], class: 'govuk-header__product-name')) if container_options[:product_name]
|
89
|
+
end
|
88
90
|
end
|
89
91
|
end
|
90
92
|
end
|
91
93
|
end
|
92
|
-
end
|
93
94
|
|
94
|
-
|
95
|
+
# rubocop:enable Metrics/AbcSize
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
97
|
+
# Generates the service name for {govuk_header}
|
98
|
+
#
|
99
|
+
# @param service_options [Hash] options that will be used in customising the HTML
|
100
|
+
#
|
101
|
+
# @option service_options [String] :service_name the name of your service, included in the header
|
102
|
+
# @option service_options [String] :service_url URL for the service name anchor
|
103
|
+
#
|
104
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the service name which is used in {govuk_header}
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
106
|
+
def govuk_header_service_name(service_options)
|
107
|
+
if service_options[:service_url]
|
108
|
+
link_to(service_options[:service_name], service_options[:service_url], class: 'govuk-header__link govuk-header__service-name')
|
109
|
+
else
|
110
|
+
tag.span(service_options[:service_name], class: 'govuk-header__service-name')
|
111
|
+
end
|
110
112
|
end
|
111
|
-
end
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
114
|
+
# Generates the navigation section for {govuk_header}
|
115
|
+
#
|
116
|
+
# @param navigation_options [Hash] options that will be used in customising the HTML
|
117
|
+
#
|
118
|
+
# @option navigation_options [String] :classes additional CSS classes for the navigation HTML
|
119
|
+
# @option navigation_options [String] :menu_button_text text of the button that opens the mobile navigation menu.
|
120
|
+
# By default, this is set to +'Menu'+.
|
121
|
+
# @option navigation_options [String] :menu_button_label text for the aria-label attribute of the button that opens the mobile navigation.
|
122
|
+
# Defaults to +'Show or hide menu'+.
|
123
|
+
# @option navigation_options [Array] :items the navigation items that will be rendered on the page (see {govuk_header_navigation_item})
|
124
|
+
#
|
125
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the navigation section which is used in {govuk_header}
|
126
|
+
|
127
|
+
def govuk_header_navigation(navigation_options)
|
128
|
+
menu_button_text = navigation_options[:menu_button_text] || 'Menu'
|
129
|
+
menu_button_label = navigation_options[:menu_button_label] || 'Show or hide menu'
|
130
|
+
|
131
|
+
govuk_header_navigation_classes = ['govuk-header__navigation']
|
132
|
+
govuk_header_navigation_classes << navigation_options[:classes]
|
133
|
+
|
134
|
+
tag.nav(class: govuk_header_navigation_classes, aria: { label: menu_button_text }) do
|
135
|
+
capture do
|
136
|
+
concat(button_tag(menu_button_text, class: 'govuk-header__menu-button govuk-js-header-toggle', type: 'button', hidden: true, aria: { controls: 'navigation', label: menu_button_label, }))
|
137
|
+
concat(tag.ul(id: 'navigation', class: 'govuk-header__navigation-list') do
|
138
|
+
capture do
|
139
|
+
navigation_options[:items].each do |navigation_item|
|
140
|
+
concat(govuk_header_navigation_item(navigation_item))
|
141
|
+
end
|
140
142
|
end
|
141
|
-
end
|
142
|
-
end
|
143
|
+
end)
|
144
|
+
end
|
143
145
|
end
|
144
146
|
end
|
145
|
-
end
|
146
|
-
|
147
|
-
# Generates a navigation item for {govuk_header_navigation}
|
148
|
-
#
|
149
|
-
# @param navigation_item [Hash] options that will be used in customising the HTML
|
150
|
-
#
|
151
|
-
# @option navigation_item [Boolean] :active flag to mark the navigation item as active or not
|
152
|
-
# @option navigation_item [String] :text text for the navigation item
|
153
|
-
# @option navigation_item [String] :href URL of the navigation item anchor
|
154
|
-
# @option navigation_item [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
155
|
-
#
|
156
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for a navigation item which is used in {govuk_header_navigation}
|
157
|
-
|
158
|
-
def govuk_header_navigation_item(navigation_item)
|
159
|
-
govuk_header_navigation_item_classes = ['govuk-header__navigation-item']
|
160
|
-
govuk_header_navigation_item_classes << 'govuk-header__navigation-item--active' if navigation_item[:active]
|
161
147
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
148
|
+
# Generates a navigation item for {govuk_header_navigation}
|
149
|
+
#
|
150
|
+
# @param navigation_item [Hash] options that will be used in customising the HTML
|
151
|
+
#
|
152
|
+
# @option navigation_item [Boolean] :active flag to mark the navigation item as active or not
|
153
|
+
# @option navigation_item [String] :text text for the navigation item
|
154
|
+
# @option navigation_item [String] :href URL of the navigation item anchor
|
155
|
+
# @option navigation_item [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
156
|
+
#
|
157
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for a navigation item which is used in {govuk_header_navigation}
|
158
|
+
|
159
|
+
def govuk_header_navigation_item(navigation_item)
|
160
|
+
govuk_header_navigation_item_classes = ['govuk-header__navigation-item']
|
161
|
+
govuk_header_navigation_item_classes << 'govuk-header__navigation-item--active' if navigation_item[:active]
|
162
|
+
|
163
|
+
tag.li(class: govuk_header_navigation_item_classes) do
|
164
|
+
if navigation_item[:href]
|
165
|
+
link_to(navigation_item[:text], navigation_item[:href], class: 'govuk-header__link', **(navigation_item[:attributes] || {}))
|
166
|
+
else
|
167
|
+
concat(navigation_item[:text])
|
168
|
+
end
|
167
169
|
end
|
168
170
|
end
|
169
171
|
end
|
@@ -2,33 +2,35 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK Hint
|
9
|
+
#
|
10
|
+
# This helper is used for generating the hint text component from the Government Design Systems
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
module Hint
|
13
|
+
include ActionView::Context
|
14
|
+
include ActionView::Helpers::TagHelper
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
# Generates the HTML for the GOV.UK Hint component
|
17
|
+
#
|
18
|
+
# @param hint_text [String] the hint text
|
19
|
+
# @param govuk_hint_options [Hash] options that will be used in customising the HTML
|
20
|
+
#
|
21
|
+
# @option govuk_hint_options [String] :classes additional CSS classes for the hint HTML
|
22
|
+
# @option govuk_hint_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
23
|
+
#
|
24
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Hint
|
25
|
+
# which can then be rendered on the page
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def govuk_hint(hint_text, **govuk_hint_options)
|
28
|
+
govuk_hint_classes = ['govuk-hint']
|
29
|
+
govuk_hint_classes << govuk_hint_options[:classes]
|
30
|
+
govuk_hint_options[:attributes] ||= {}
|
30
31
|
|
31
|
-
|
32
|
+
tag.div(hint_text, class: govuk_hint_classes, **govuk_hint_options[:attributes])
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|