crown_marketplace_utils 0.1.0.beta.6 → 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 +1 -1
- 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 +1 -1
@@ -2,85 +2,87 @@
|
|
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 label
|
9
|
+
#
|
10
|
+
# This helper is used for generating the label component from the Government Design Systems
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
module Label
|
13
|
+
include ActionView::Context
|
14
|
+
include ActionView::Helpers::TagHelper
|
15
|
+
include ActionView::Helpers::TextHelper
|
16
|
+
include ActionView::Helpers::FormTagHelper
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
18
|
+
# Generates the HTML for the GOV.UK label component
|
19
|
+
#
|
20
|
+
# @param attribute [String, Symbol] the attribute of the input that requires a label
|
21
|
+
# @param label_text [String] the label text, it is ignored if a block is given
|
22
|
+
# @param govuk_label_options [Hash] options that will be used in customising the HTML
|
23
|
+
#
|
24
|
+
# @option govuk_label_options [String] :classes additional CSS classes for the label HTML
|
25
|
+
# @option govuk_label_options [Boolean] :is_page_heading (false) if the legend is also the heading it will rendered in a h1
|
26
|
+
# @option govuk_label_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create the label
|
27
|
+
# @option govuk_label_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
28
|
+
#
|
29
|
+
# @yield HTML that will be contained within the 'govuk-label' label. Ignored if label text is given
|
30
|
+
#
|
31
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Label
|
32
|
+
# which can then be rendered on the page
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def govuk_label(attribute, label_text = nil, **govuk_label_options, &block)
|
35
|
+
govuk_label_options[:attributes] ||= {}
|
36
|
+
govuk_label_options[:attributes][:class] = "govuk-label #{govuk_label_options[:classes]}".rstrip
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
label_html = if govuk_label_options[:form]
|
39
|
+
govuk_label_form(attribute, label_text, **govuk_label_options, &block)
|
40
|
+
else
|
41
|
+
govuk_label_tag(attribute, label_text, **govuk_label_options, &block)
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
if govuk_label_options[:is_page_heading]
|
45
|
+
tag.h1(label_html, class: 'govuk-label-wrapper')
|
46
|
+
else
|
47
|
+
label_html
|
48
|
+
end
|
47
49
|
end
|
48
|
-
end
|
49
50
|
|
50
|
-
|
51
|
+
private
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
# Generates the HTML for the GOV.UK label component
|
54
|
+
# using the inbuilt rails method +label+
|
55
|
+
#
|
56
|
+
# @param (see govuk_label)
|
57
|
+
#
|
58
|
+
# @option (see govuk_label)
|
59
|
+
#
|
60
|
+
# @yield (see govuk_label)
|
61
|
+
#
|
62
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Label
|
63
|
+
# which can then be rendered on the page
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
def govuk_label_tag(attribute, label_text, **govuk_label_options)
|
66
|
+
label_tag(attribute, **govuk_label_options[:attributes]) do
|
67
|
+
label_text || yield
|
68
|
+
end
|
67
69
|
end
|
68
|
-
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
71
|
+
# Generates the HTML for the GOV.UK label component
|
72
|
+
# using the inbuilt rails ActionView::Helpers::FormBuilder
|
73
|
+
#
|
74
|
+
# @param (see govuk_label)
|
75
|
+
#
|
76
|
+
# @option (see govuk_label)
|
77
|
+
#
|
78
|
+
# @yield (see govuk_label)
|
79
|
+
#
|
80
|
+
# @return (see govuk_label_tag)
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
82
|
+
def govuk_label_form(attribute, label_text, **govuk_label_options)
|
83
|
+
govuk_label_options[:form].label(attribute, **govuk_label_options[:attributes]) do
|
84
|
+
label_text || yield
|
85
|
+
end
|
84
86
|
end
|
85
87
|
end
|
86
88
|
end
|
@@ -2,138 +2,140 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
# This helper is used for generating the notification banner component from the
|
10
|
-
# {https://design-system.service.gov.uk/components/notification-banner GDS - Components - Notification banner}
|
11
|
-
|
12
|
-
module NotificationBanner
|
13
|
-
include ActionView::Context
|
14
|
-
include ActionView::Helpers::TagHelper
|
15
|
-
include ActionView::Helpers::TextHelper
|
16
|
-
|
17
|
-
# Generates the HTML for the GOV.UK Notification banner component
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK Notification Banner
|
18
9
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
10
|
+
# This helper is used for generating the notification banner component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/notification-banner GDS - Components - Notification banner}
|
12
|
+
|
13
|
+
module NotificationBanner
|
14
|
+
include ActionView::Context
|
15
|
+
include ActionView::Helpers::TagHelper
|
16
|
+
include ActionView::Helpers::TextHelper
|
17
|
+
|
18
|
+
# Generates the HTML for the GOV.UK Notification banner component
|
19
|
+
#
|
20
|
+
# @param text [String] the text that will be used for the heading in the content section of the banner.
|
21
|
+
# It is ignored if a block is given
|
22
|
+
# @param success_banner [Boolean] will use the success banner options if this is set to true
|
23
|
+
# @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
|
24
|
+
#
|
25
|
+
# @option govuk_notification_banner_options [String] :classes additional CSS classes for the notification banner HTML
|
26
|
+
# @option govuk_notification_banner_options [String] :title_text ('Important') the title text shown at the top of the banner
|
27
|
+
# @option govuk_notification_banner_options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
|
28
|
+
# @option govuk_notification_banner_options [String] :role ('region') the role for the banner
|
29
|
+
# @option govuk_notification_banner_options [String] :heading_level (2) the heading level for the title text
|
30
|
+
# @option govuk_notification_banner_options [Hash] :attributes ({data: { module: 'govuk-notification-banner' }, aria: { labelledby: 'govuk-notification-banner-title' }})
|
31
|
+
# any additional attributes that will added as part of the HTML
|
32
|
+
#
|
33
|
+
# @yield HTML that will be contained within the 'govuk-notification-banner__content' div
|
34
|
+
#
|
35
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Notification banner
|
36
|
+
# which can then be rendered on the page
|
37
|
+
|
38
|
+
def govuk_notification_banner(text = nil, success_banner = false, **govuk_notification_banner_options)
|
39
|
+
banner_options = fetch_banner_options(success_banner, govuk_notification_banner_options)
|
40
|
+
govuk_notification_banner_classes = fetch_banner_classes(banner_options, govuk_notification_banner_options)
|
41
|
+
govuk_notification_banner_attributes = fetch_banner_attributes(banner_options, govuk_notification_banner_options)
|
42
|
+
|
43
|
+
tag.div(class: govuk_notification_banner_classes, role: banner_options[:role], **govuk_notification_banner_attributes) do
|
44
|
+
capture do
|
45
|
+
concat(tag.div(class: 'govuk-notification-banner__header') do
|
46
|
+
tag.send(:"h#{govuk_notification_banner_options[:heading_level] || 2}", banner_options[:title_text], class: 'govuk-notification-banner__title', id: banner_options[:title_id])
|
47
|
+
end)
|
48
|
+
concat(tag.div(class: 'govuk-notification-banner__content') do
|
49
|
+
if block_given?
|
50
|
+
yield
|
51
|
+
else
|
52
|
+
tag.p(text, class: 'govuk-notification-banner__heading')
|
53
|
+
end
|
54
|
+
end)
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
|
-
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
59
|
+
private
|
60
|
+
|
61
|
+
# Determines the banner options to be used for {#govuk_notification_banner}
|
62
|
+
#
|
63
|
+
# @param success_banner [Boolean] will use the success banner options if this is set to true
|
64
|
+
# @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
|
65
|
+
#
|
66
|
+
# @option govuk_notification_banner_options [String] :title_text ('Important') the title text shown at the top of the banner
|
67
|
+
# @option govuk_notification_banner_options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
|
68
|
+
# @option govuk_notification_banner_options [String] :role ('region') the role for the banner
|
69
|
+
#
|
70
|
+
# @return [Hash] contains the following options used in {#govuk_notification_banner}:
|
71
|
+
# - +classes+
|
72
|
+
# - +title_text+
|
73
|
+
# - +title_id+
|
74
|
+
# - +role+
|
75
|
+
|
76
|
+
def fetch_banner_options(success_banner, govuk_notification_banner_options)
|
77
|
+
banner_options = DEFAULT_OPTIONS.dup
|
78
|
+
|
79
|
+
banner_options.merge!(SUCCESS_BANNER_OPTIONS) if success_banner
|
80
|
+
|
81
|
+
govuk_notification_banner_options.each do |key, value|
|
82
|
+
banner_options[key] = value if banner_options.key?(key)
|
83
|
+
end
|
79
84
|
|
80
|
-
|
81
|
-
banner_options[key] = value if banner_options.key?(key)
|
85
|
+
banner_options
|
82
86
|
end
|
83
87
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
88
|
+
# Determines the banner classes to be used for {#govuk_notification_banner}
|
89
|
+
#
|
90
|
+
# @param banner_options [Hash] this is the return value from {#fetch_banner_options}
|
91
|
+
# @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
|
92
|
+
#
|
93
|
+
# @option govuk_notification_banner_options [String] :classes additional CSS classes for the notification banner HTML
|
94
|
+
#
|
95
|
+
# @return [Array<String>] an array of classes to be used in {#govuk_notification_banner}
|
96
|
+
|
97
|
+
def fetch_banner_classes(banner_options, govuk_notification_banner_options)
|
98
|
+
govuk_notification_banner_classes = ['govuk-notification-banner']
|
99
|
+
govuk_notification_banner_classes << govuk_notification_banner_options[:classes]
|
100
|
+
govuk_notification_banner_classes << banner_options[:classes]
|
101
|
+
|
102
|
+
govuk_notification_banner_classes
|
103
|
+
end
|
95
104
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
105
|
+
# Default HTML attributes for {#govuk_notification_banner}
|
106
|
+
#
|
107
|
+
# @param banner_options [Hash] this is the return value from {#fetch_banner_options}
|
108
|
+
# @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
|
109
|
+
#
|
110
|
+
# @option govuk_notification_banner_options [Hash] :attributes ({data: { module: 'govuk-notification-banner' }, aria: { labelledby: 'govuk-notification-banner-title' }})
|
111
|
+
# any additional attributes that will added as part of the HTML
|
112
|
+
#
|
113
|
+
# @return [Hash] contains the default attributes for {#govuk_notification_banner} and any additional attributes that were passed
|
114
|
+
|
115
|
+
def fetch_banner_attributes(banner_options, govuk_notification_banner_options)
|
116
|
+
govuk_notification_banner_attributes = govuk_notification_banner_options[:attributes] || {}
|
117
|
+
(govuk_notification_banner_attributes[:data] ||= {}).merge!({ module: 'govuk-notification-banner' })
|
118
|
+
(govuk_notification_banner_attributes[:aria] ||= {}).merge!({ labelledby: banner_options[:title_id] })
|
119
|
+
|
120
|
+
govuk_notification_banner_attributes
|
121
|
+
end
|
100
122
|
|
101
|
-
|
102
|
-
end
|
123
|
+
# Default options used in normal versions of {#govuk_notification_banner}
|
103
124
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# @option govuk_notification_banner_options [Hash] :attributes ({data: { module: 'govuk-notification-banner' }, aria: { labelledby: 'govuk-notification-banner-title' }})
|
110
|
-
# any additional attributes that will added as part of the HTML
|
111
|
-
#
|
112
|
-
# @return [Hash] contains the default attributes for {#govuk_notification_banner} and any additional attributes that were passed
|
125
|
+
DEFAULT_OPTIONS = {
|
126
|
+
title_text: 'Important',
|
127
|
+
title_id: 'govuk-notification-banner-title',
|
128
|
+
role: 'region'
|
129
|
+
}.freeze
|
113
130
|
|
114
|
-
|
115
|
-
govuk_notification_banner_attributes = govuk_notification_banner_options[:attributes] || {}
|
116
|
-
(govuk_notification_banner_attributes[:data] ||= {}).merge!({ module: 'govuk-notification-banner' })
|
117
|
-
(govuk_notification_banner_attributes[:aria] ||= {}).merge!({ labelledby: banner_options[:title_id] })
|
131
|
+
# Options specific for the success version of {#govuk_notification_banner}
|
118
132
|
|
119
|
-
|
133
|
+
SUCCESS_BANNER_OPTIONS = {
|
134
|
+
classes: 'govuk-notification-banner--success',
|
135
|
+
title_text: 'Success',
|
136
|
+
role: 'alert'
|
137
|
+
}.freeze
|
120
138
|
end
|
121
|
-
|
122
|
-
# Default options used in normal versions of {#govuk_notification_banner}
|
123
|
-
|
124
|
-
DEFAULT_OPTIONS = {
|
125
|
-
title_text: 'Important',
|
126
|
-
title_id: 'govuk-notification-banner-title',
|
127
|
-
role: 'region'
|
128
|
-
}.freeze
|
129
|
-
|
130
|
-
# Options specific for the success version of {#govuk_notification_banner}
|
131
|
-
|
132
|
-
SUCCESS_BANNER_OPTIONS = {
|
133
|
-
classes: 'govuk-notification-banner--success',
|
134
|
-
title_text: 'Success',
|
135
|
-
role: 'alert'
|
136
|
-
}.freeze
|
137
139
|
end
|
138
140
|
end
|
139
141
|
end
|