crown_marketplace_utils 0.1.0.beta.6 → 0.1.0.beta.8
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 +53 -46
- 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,152 +2,154 @@
|
|
2
2
|
|
3
3
|
require_relative '../field'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
module Field
|
9
|
+
# = GOV.UK Input
|
10
|
+
#
|
11
|
+
# This helper is used for generating the input component from the
|
12
|
+
# {https://design-system.service.gov.uk/components/text-input GDS - Components - Text Input}
|
13
|
+
#
|
14
|
+
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
15
|
+
|
16
|
+
module Input
|
17
|
+
include Field
|
18
|
+
|
19
|
+
# Generates the HTML for the GOV.UK input component
|
20
|
+
#
|
21
|
+
# @param attribute [String, Symbol] the attribute of the input
|
22
|
+
# @param govuk_input_options [Hash] options that will be used for the parts of the form group, label, hint and input
|
23
|
+
#
|
24
|
+
# @option govuk_input_options [String] :error_message (nil) the error message to be displayed
|
25
|
+
# @option govuk_input_options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
26
|
+
# @option govuk_label_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
27
|
+
# the input tag and find the error message
|
28
|
+
# @option govuk_input_options [Hash] :form_group see {govuk_field}
|
29
|
+
# @option govuk_input_options [Hash] :label see {govuk_field}
|
30
|
+
# @option govuk_input_options [Hash] :hint see {govuk_field}
|
31
|
+
# @option govuk_input_options [Hash] :input ({}) the options that will be used when rendering the input.
|
32
|
+
# See {_govuk_input_field} for more details.
|
33
|
+
#
|
34
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Input
|
35
|
+
# which can then be rendered on the page
|
36
|
+
|
37
|
+
def govuk_input(attribute, **govuk_input_options)
|
38
|
+
govuk_field(:input, attribute, **govuk_input_options) do |govuk_field_options, error_message|
|
39
|
+
concat(_govuk_input_field(error_message, **govuk_field_options) do
|
40
|
+
field_type = get_field_type(govuk_field_options[:field_type])
|
41
|
+
govuk_field_options[:value] = govuk_input_options[:model].send(attribute) if govuk_input_options[:model]
|
42
|
+
|
43
|
+
if govuk_input_options[:form]
|
44
|
+
govuk_input_form(govuk_input_options[:form], field_type, attribute, **govuk_field_options)
|
45
|
+
else
|
46
|
+
govuk_input_tag(field_type, attribute, **govuk_field_options)
|
47
|
+
end
|
48
|
+
end)
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
# Generates the input HTML for {govuk_input}
|
54
|
-
#
|
55
|
-
# @param field_type [String] the inout field type
|
56
|
-
# @param attribute [String, Symbol] the attribute of the input
|
57
|
-
# @param govuk_text_input_options [Hash] options that will be used in customising the HTML
|
58
|
-
#
|
59
|
-
# @option (see _govuk_input_field)
|
60
|
-
#
|
61
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {govuk_input}
|
62
51
|
|
63
|
-
|
64
|
-
send("#{field_type}_tag", attribute, govuk_text_input_options[:value], **govuk_text_input_options[:attributes])
|
65
|
-
end
|
52
|
+
private
|
66
53
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
def govuk_input_form(form, field_type, attribute, **govuk_text_input_options)
|
77
|
-
form.send(field_type, attribute, **govuk_text_input_options[:attributes])
|
78
|
-
end
|
54
|
+
# Generates the input HTML for {govuk_input}
|
55
|
+
#
|
56
|
+
# @param field_type [String] the inout field type
|
57
|
+
# @param attribute [String, Symbol] the attribute of the input
|
58
|
+
# @param govuk_text_input_options [Hash] options that will be used in customising the HTML
|
59
|
+
#
|
60
|
+
# @option (see _govuk_input_field)
|
61
|
+
#
|
62
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {govuk_input}
|
79
63
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
# @param govuk_text_input_options [Hash] options that will be used in customising the HTML
|
84
|
-
#
|
85
|
-
# @option govuk_text_input_options [String] :classes additional CSS classes for the input HTML
|
86
|
-
# @option govuk_text_input_options [String] :value (nil) the value of the input
|
87
|
-
# @option govuk_text_input_options [Symbol] :field_type the type of the input field, see {get_field_type} for options
|
88
|
-
# @option govuk_text_input_options [Hash] :prefix (nil) optional prefix for the input field. See {govuk_fix} for more details.
|
89
|
-
# @option govuk_text_input_options [Hash] :suffix (nil) optional suffix for the input field. See {govuk_fix} for more details.
|
90
|
-
# @option govuk_text_input_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
91
|
-
#
|
92
|
-
# @yield the input HTML generated by {govuk_input_tag} or {govuk_input_form}
|
93
|
-
#
|
94
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used by {govuk_input}
|
95
|
-
|
96
|
-
def _govuk_input_field(error_message, **govuk_text_input_options)
|
97
|
-
govuk_text_input_options[:attributes] ||= {}
|
98
|
-
govuk_text_input_options[:attributes][:class] = "govuk-input #{govuk_text_input_options[:classes]}".rstrip
|
99
|
-
govuk_text_input_options[:attributes][:class] << ' govuk-input--error' if error_message
|
100
|
-
|
101
|
-
input_html = yield
|
64
|
+
def govuk_input_tag(field_type, attribute, **govuk_text_input_options)
|
65
|
+
send("#{field_type}_tag", attribute, govuk_text_input_options[:value], **govuk_text_input_options[:attributes])
|
66
|
+
end
|
102
67
|
|
103
|
-
|
104
|
-
|
68
|
+
# Generates the input HTML for {govuk_input} when there is a ActionView::Helpers::FormBuilder
|
69
|
+
#
|
70
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the input tag
|
71
|
+
# @param (see govuk_input_tag)
|
72
|
+
#
|
73
|
+
# @option (see _govuk_input_field)
|
74
|
+
#
|
75
|
+
# @return (see govuk_input_tag)
|
76
|
+
|
77
|
+
def govuk_input_form(form, field_type, attribute, **govuk_text_input_options)
|
78
|
+
form.send(field_type, attribute, **govuk_text_input_options[:attributes])
|
79
|
+
end
|
105
80
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
81
|
+
# Wrapper method used by {govuk_input} to generate the Input HTML
|
82
|
+
#
|
83
|
+
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
84
|
+
# @param govuk_text_input_options [Hash] options that will be used in customising the HTML
|
85
|
+
#
|
86
|
+
# @option govuk_text_input_options [String] :classes additional CSS classes for the input HTML
|
87
|
+
# @option govuk_text_input_options [String] :value (nil) the value of the input
|
88
|
+
# @option govuk_text_input_options [Symbol] :field_type the type of the input field, see {get_field_type} for options
|
89
|
+
# @option govuk_text_input_options [Hash] :prefix (nil) optional prefix for the input field. See {govuk_fix} for more details.
|
90
|
+
# @option govuk_text_input_options [Hash] :suffix (nil) optional suffix for the input field. See {govuk_fix} for more details.
|
91
|
+
# @option govuk_text_input_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
92
|
+
#
|
93
|
+
# @yield the input HTML generated by {govuk_input_tag} or {govuk_input_form}
|
94
|
+
#
|
95
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used by {govuk_input}
|
96
|
+
|
97
|
+
def _govuk_input_field(error_message, **govuk_text_input_options)
|
98
|
+
govuk_text_input_options[:attributes] ||= {}
|
99
|
+
govuk_text_input_options[:attributes][:class] = "govuk-input #{govuk_text_input_options[:classes]}".rstrip
|
100
|
+
govuk_text_input_options[:attributes][:class] << ' govuk-input--error' if error_message
|
101
|
+
|
102
|
+
input_html = yield
|
103
|
+
|
104
|
+
prefix = govuk_text_input_options[:prefix]
|
105
|
+
suffix = govuk_text_input_options[:suffix]
|
106
|
+
|
107
|
+
if prefix || suffix
|
108
|
+
tag.div(class: 'govuk-input__wrapper') do
|
109
|
+
capture do
|
110
|
+
concat(govuk_fix('pre', prefix)) if prefix
|
111
|
+
concat(input_html)
|
112
|
+
concat(govuk_fix('suf', suffix)) if suffix
|
113
|
+
end
|
112
114
|
end
|
115
|
+
else
|
116
|
+
input_html
|
113
117
|
end
|
114
|
-
else
|
115
|
-
input_html
|
116
118
|
end
|
117
|
-
end
|
118
119
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
120
|
+
# Generates the prefix and suffix HTML for {_govuk_input_field}
|
121
|
+
#
|
122
|
+
# @param fix [String] either +"pre"+ or +"suf"+
|
123
|
+
# @param govuk_fix_options [Hash] options that will be used in customising the HTML
|
124
|
+
#
|
125
|
+
# @option govuk_fix_options [String] :classes additional CSS classes for the input HTML
|
126
|
+
# @option govuk_text_input_options [Hash] :attributes ({ aria: { hidden: true } }) any additional attributes that will added as part of the HTML
|
127
|
+
#
|
128
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {_govuk_input_field}
|
129
|
+
|
130
|
+
def govuk_fix(fix, govuk_fix_options)
|
131
|
+
govuk_fix_classes = ["govuk-input__#{fix}fix"]
|
132
|
+
govuk_fix_classes << govuk_fix_options[:classes]
|
133
|
+
govuk_fix_options[:attributes] ||= {}
|
134
|
+
(govuk_fix_options[:attributes][:aria] ||= {}).merge!({ hidden: true })
|
135
|
+
|
136
|
+
tag.div(govuk_fix_options[:text], class: govuk_fix_classes, **govuk_fix_options[:attributes])
|
137
|
+
end
|
137
138
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
139
|
+
# Returns the field type used to create the rails input tag
|
140
|
+
#
|
141
|
+
# @param field_type [Symbol] the type of the field, defaults to text
|
142
|
+
# Allowed values are:
|
143
|
+
# - +:email+
|
144
|
+
# - +:password+
|
145
|
+
|
146
|
+
def get_field_type(field_type)
|
147
|
+
case field_type
|
148
|
+
when :email, :password
|
149
|
+
:"#{field_type}_field"
|
150
|
+
else
|
151
|
+
:text_field
|
152
|
+
end
|
151
153
|
end
|
152
154
|
end
|
153
155
|
end
|