crown_marketplace_utils 0.1.0.beta.6 → 0.1.0.beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,121 +2,123 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
# This helper is used for generating the button component from the
|
10
|
-
# {https://design-system.service.gov.uk/components/button GDS - Components - Button}
|
11
|
-
|
12
|
-
module Button
|
13
|
-
include ActionView::Context
|
14
|
-
include ActionView::Helpers::TagHelper
|
15
|
-
include ActionView::Helpers::TextHelper
|
16
|
-
include ActionView::Helpers::UrlHelper
|
17
|
-
include ActionView::Helpers::FormTagHelper
|
18
|
-
|
19
|
-
# Generates the HTML for the GOV.UK button component
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK Button
|
20
9
|
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
govuk_button_options[
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
# @option govuk_button_options [String] :href the URI that will be used in anchor tag
|
64
|
-
# @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
65
|
-
#
|
66
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an anchor element
|
67
|
-
# which can then be rendered on the page
|
68
|
-
|
69
|
-
def govuk_button_link(text, classes, **govuk_button_options)
|
70
|
-
link_to(govuk_button_options[:href], class: classes, role: :button, draggable: false, **govuk_button_options[:attributes]) do
|
71
|
-
concat(text)
|
72
|
-
concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
|
10
|
+
# This helper is used for generating the button component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/button GDS - Components - Button}
|
12
|
+
|
13
|
+
module Button
|
14
|
+
include ActionView::Context
|
15
|
+
include ActionView::Helpers::TagHelper
|
16
|
+
include ActionView::Helpers::TextHelper
|
17
|
+
include ActionView::Helpers::UrlHelper
|
18
|
+
include ActionView::Helpers::FormTagHelper
|
19
|
+
|
20
|
+
# Generates the HTML for the GOV.UK button component
|
21
|
+
#
|
22
|
+
# @param text [String] the text that will be shown in the button
|
23
|
+
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
24
|
+
#
|
25
|
+
# @option govuk_button_options [String] :classes additional CSS classes for the button HTML
|
26
|
+
# @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
|
27
|
+
# @option govuk_button_options [String] :href the URI that will be used in anchor tag
|
28
|
+
# @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
|
29
|
+
# @option govuk_button_options [Hash] :attributes ({ data: { module: 'govuk-button' } }) any additional attributes that will added as part of the HTML
|
30
|
+
#
|
31
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button
|
32
|
+
# which can then be rendered on the page
|
33
|
+
|
34
|
+
def govuk_button(text, **govuk_button_options)
|
35
|
+
govuk_button_classes = ['govuk-button']
|
36
|
+
govuk_button_classes << govuk_button_options[:classes]
|
37
|
+
govuk_button_options[:attributes] ||= {}
|
38
|
+
govuk_button_classes << 'govuk-button--disabled' if govuk_button_options[:attributes][:disabled]
|
39
|
+
govuk_button_classes << 'govuk-button--start' if govuk_button_options[:is_start_button]
|
40
|
+
|
41
|
+
(govuk_button_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-button' })
|
42
|
+
|
43
|
+
button_method = if govuk_button_options[:href]
|
44
|
+
:govuk_button_link
|
45
|
+
elsif govuk_button_options[:form]
|
46
|
+
:govuk_button_submit
|
47
|
+
else
|
48
|
+
:govuk_button_button
|
49
|
+
end
|
50
|
+
|
51
|
+
send(button_method, text, govuk_button_classes, **govuk_button_options)
|
73
52
|
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Generates the HTML for the GOV.UK button component as a button.
|
77
|
-
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
78
|
-
#
|
79
|
-
# @param text [String] the text that will be shown in the button
|
80
|
-
# @param classes [String] additional CSS classes for the button HTML
|
81
|
-
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
82
|
-
#
|
83
|
-
# @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
|
84
|
-
# @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
85
|
-
#
|
86
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as a button element
|
87
|
-
# which can then be rendered on the page
|
88
53
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
54
|
+
private
|
55
|
+
|
56
|
+
# Generates the HTML for the GOV.UK button component as an anchor tag.
|
57
|
+
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
58
|
+
#
|
59
|
+
# @param text [String] the text that will be shown in the button
|
60
|
+
# @param classes [String] additional CSS classes for the button HTML
|
61
|
+
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
62
|
+
#
|
63
|
+
# @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
|
64
|
+
# @option govuk_button_options [String] :href the URI that will be used in anchor tag
|
65
|
+
# @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
66
|
+
#
|
67
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an anchor element
|
68
|
+
# which can then be rendered on the page
|
69
|
+
|
70
|
+
def govuk_button_link(text, classes, **govuk_button_options)
|
71
|
+
link_to(govuk_button_options[:href], class: classes, role: :button, draggable: false, **govuk_button_options[:attributes]) do
|
72
|
+
concat(text)
|
73
|
+
concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
|
74
|
+
end
|
93
75
|
end
|
94
|
-
end
|
95
76
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
77
|
+
# Generates the HTML for the GOV.UK button component as a button.
|
78
|
+
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
79
|
+
#
|
80
|
+
# @param text [String] the text that will be shown in the button
|
81
|
+
# @param classes [String] additional CSS classes for the button HTML
|
82
|
+
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
83
|
+
#
|
84
|
+
# @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
|
85
|
+
# @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
86
|
+
#
|
87
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as a button element
|
88
|
+
# which can then be rendered on the page
|
89
|
+
|
90
|
+
def govuk_button_button(text, classes, **govuk_button_options)
|
91
|
+
button_tag(class: classes, **govuk_button_options[:attributes]) do
|
92
|
+
concat(text)
|
93
|
+
concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
|
94
|
+
end
|
95
|
+
end
|
108
96
|
|
109
|
-
|
110
|
-
|
111
|
-
|
97
|
+
# Generates the HTML for the GOV.UK button component as an input.
|
98
|
+
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
99
|
+
#
|
100
|
+
# @param text [String] the text that will be shown in the input
|
101
|
+
# @param classes [String] additional CSS classes for the button HTML
|
102
|
+
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
103
|
+
#
|
104
|
+
# @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
|
105
|
+
# @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
106
|
+
#
|
107
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an input element
|
108
|
+
# which can then be rendered on the page
|
109
|
+
|
110
|
+
def govuk_button_submit(text, classes, **govuk_button_options)
|
111
|
+
govuk_button_options[:form].submit(text, class: classes, **govuk_button_options[:attributes])
|
112
|
+
end
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
|
114
|
+
# Generates the arrow for the start button option as part of {#govuk_button}
|
115
|
+
#
|
116
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the arrow for the start button
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
def govuk_start_button_icon
|
119
|
+
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
|
120
|
+
tag.path(fill: 'currentColor', d: 'M0 0h13l20 20-20 20H0l20-20z')
|
121
|
+
end
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
@@ -2,41 +2,43 @@
|
|
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 Details
|
9
|
+
#
|
10
|
+
# This helper is used for generating the details component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/details GDS - Components - Details}
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
module Details
|
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 Details component
|
19
|
+
#
|
20
|
+
# @param summary_text [String] the summary text for the details element
|
21
|
+
# @param govuk_details_options [Hash] options that will be used in customising the HTML
|
22
|
+
#
|
23
|
+
# @option govuk_details_options [String] :classes additional CSS classes for the details HTML
|
24
|
+
# @option govuk_details_options [Hash] :attributes ({ data: { module: 'govuk-details' } }) any additional attributes that will added as part of the HTML
|
25
|
+
#
|
26
|
+
# @yield HTML that will be contained within the 'govuk-details__text' div
|
27
|
+
#
|
28
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Details
|
29
|
+
# which can then be rendered on the page
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
def govuk_details(summary_text, **govuk_details_options, &block)
|
32
|
+
govuk_details_classes = ['govuk-details']
|
33
|
+
govuk_details_classes << govuk_details_options[:classes]
|
34
|
+
govuk_details_options[:attributes] ||= {}
|
35
|
+
(govuk_details_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-details' })
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
tag.details(class: govuk_details_classes, **govuk_details_options[:attributes]) do
|
38
|
+
capture do
|
39
|
+
concat(tag.summary(tag.span(summary_text, class: 'govuk-details__summary-text'), class: 'govuk-details__summary'))
|
40
|
+
concat(tag.div(class: 'govuk-details__text', &block))
|
41
|
+
end
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -2,57 +2,59 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
# This helper is used for generating the error message component from the
|
10
|
-
# {https://design-system.service.gov.uk/components/error-message GDS - Components - Error message}
|
11
|
-
|
12
|
-
module ErrorMessage
|
13
|
-
include ActionView::Context
|
14
|
-
include ActionView::Helpers::TagHelper
|
15
|
-
include ActionView::Helpers::TextHelper
|
16
|
-
|
17
|
-
# Generates the HTML for the GOV.UK Error message component
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK Error Message
|
18
9
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
govuk_error_message_options[
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
10
|
+
# This helper is used for generating the error message component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/error-message GDS - Components - Error message}
|
12
|
+
|
13
|
+
module ErrorMessage
|
14
|
+
include ActionView::Context
|
15
|
+
include ActionView::Helpers::TagHelper
|
16
|
+
include ActionView::Helpers::TextHelper
|
17
|
+
|
18
|
+
# Generates the HTML for the GOV.UK Error message component
|
19
|
+
#
|
20
|
+
# @param message [String] the message to be displayed
|
21
|
+
# @param attribute [String, Symbol] the attribute that has an error
|
22
|
+
# @param govuk_error_message_options [Hash] options that will be used in customising the HTML
|
23
|
+
#
|
24
|
+
# @option govuk_error_message_options [String] :classes additional CSS classes for the error message HTML
|
25
|
+
# @option govuk_error_message_options [String] :visually_hidden_text ('Error') visualy hidden text before the error message
|
26
|
+
# @option govuk_error_message_options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
|
27
|
+
#
|
28
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Error message
|
29
|
+
# which can then be rendered on the page
|
30
|
+
|
31
|
+
def govuk_error_message(message, attribute, **govuk_error_message_options)
|
32
|
+
class_list = ['govuk-error-message']
|
33
|
+
class_list << govuk_error_message_options[:classes]
|
34
|
+
visually_hidden_text = govuk_error_message_options[:visually_hidden_text] || 'Error'
|
35
|
+
govuk_error_message_options[:attributes] ||= {}
|
36
|
+
|
37
|
+
tag.p(id: "#{attribute}-error", class: class_list, **govuk_error_message_options[:attributes]) do
|
38
|
+
capture do
|
39
|
+
concat(tag.span("#{visually_hidden_text}: ", class: 'govuk-visually-hidden')) if visually_hidden_text.present?
|
40
|
+
concat(message)
|
41
|
+
end
|
40
42
|
end
|
41
43
|
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Generates the HTML for the GOV.UK Error message component using the error messages in an ActiveModel
|
45
|
-
#
|
46
|
-
# @param model [ActiveModel] model that will be used to find the error message
|
47
|
-
# @param attribute [String, Symbol] the attribute that has an error
|
48
|
-
# @param govuk_error_message_options [Hash] options that will be used in customising the HTML
|
49
|
-
#
|
50
|
-
# @option (see #govuk_error_message)
|
51
|
-
#
|
52
|
-
# @return (see #govuk_error_message)
|
53
44
|
|
54
|
-
|
55
|
-
|
45
|
+
# Generates the HTML for the GOV.UK Error message component using the error messages in an ActiveModel
|
46
|
+
#
|
47
|
+
# @param model [ActiveModel] model that will be used to find the error message
|
48
|
+
# @param attribute [String, Symbol] the attribute that has an error
|
49
|
+
# @param govuk_error_message_options [Hash] options that will be used in customising the HTML
|
50
|
+
#
|
51
|
+
# @option (see #govuk_error_message)
|
52
|
+
#
|
53
|
+
# @return (see #govuk_error_message)
|
54
|
+
|
55
|
+
def govuk_error_message_with_model(model, attribute, **govuk_error_message_options)
|
56
|
+
govuk_error_message(model.errors[attribute].first, attribute, **govuk_error_message_options)
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|