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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +91 -89
  4. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +24 -22
  5. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/breadcrumbs.rb +56 -54
  6. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/button.rb +109 -107
  7. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/details.rb +33 -31
  8. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/error_message.rb +49 -47
  9. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/character_count.rb +144 -142
  10. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/checkboxes.rb +176 -174
  11. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb +126 -124
  12. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +75 -73
  13. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb +137 -135
  14. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/radios.rb +176 -174
  15. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb +111 -109
  16. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +86 -84
  17. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +181 -179
  18. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/fieldset.rb +56 -54
  19. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/form_group.rb +37 -35
  20. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/header.rb +142 -140
  21. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/hint.rb +25 -23
  22. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +69 -67
  23. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/notification_banner.rb +121 -119
  24. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +290 -288
  25. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/step_by_step_navigation.rb +187 -185
  26. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/tag.rb +29 -27
  27. data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +39 -37
  28. data/lib/crown_marketplace_utils/helpers/gov_uk_helper.rb +31 -29
  29. data/lib/crown_marketplace_utils/version.rb +1 -1
  30. metadata +1 -1
@@ -2,152 +2,154 @@
2
2
 
3
3
  require_relative '../field'
4
4
 
5
- module CrownMarketplaceUtils::Helpers
6
- module GovUkHelper
7
- module Field
8
- # = GOV.UK Input
9
- #
10
- # This helper is used for generating the input component from the
11
- # {https://design-system.service.gov.uk/components/text-input GDS - Components - Text Input}
12
- #
13
- # This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
14
-
15
- module Input
16
- include Field
17
-
18
- # Generates the HTML for the GOV.UK input component
19
- #
20
- # @param attribute [String, Symbol] the attribute of the input
21
- # @param govuk_input_options [Hash] options that will be used for the parts of the form group, label, hint and input
22
- #
23
- # @option govuk_input_options [String] :error_message (nil) the error message to be displayed
24
- # @option govuk_input_options [ActiveModel] :model (nil) optional model that can be used to find an error message
25
- # @option govuk_label_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
26
- # the input tag and find the error message
27
- # @option govuk_input_options [Hash] :form_group see {govuk_field}
28
- # @option govuk_input_options [Hash] :label see {govuk_field}
29
- # @option govuk_input_options [Hash] :hint see {govuk_field}
30
- # @option govuk_input_options [Hash] :input ({}) the options that will be used when rendering the input.
31
- # See {_govuk_input_field} for more details.
32
- #
33
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Input
34
- # which can then be rendered on the page
35
-
36
- def govuk_input(attribute, **govuk_input_options)
37
- govuk_field(:input, attribute, **govuk_input_options) do |govuk_field_options, error_message|
38
- concat(_govuk_input_field(error_message, **govuk_field_options) do
39
- field_type = get_field_type(govuk_field_options[:field_type])
40
- govuk_field_options[:value] = govuk_input_options[:model].send(attribute) if govuk_input_options[:model]
41
-
42
- if govuk_input_options[:form]
43
- govuk_input_form(govuk_input_options[:form], field_type, attribute, **govuk_field_options)
44
- else
45
- govuk_input_tag(field_type, attribute, **govuk_field_options)
46
- end
47
- end)
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
- def govuk_input_tag(field_type, attribute, **govuk_text_input_options)
64
- send("#{field_type}_tag", attribute, govuk_text_input_options[:value], **govuk_text_input_options[:attributes])
65
- end
52
+ private
66
53
 
67
- # Generates the input HTML for {govuk_input} when there is a ActionView::Helpers::FormBuilder
68
- #
69
- # @param form [ActionView::Helpers::FormBuilder] the form builder used to create the input tag
70
- # @param (see govuk_input_tag)
71
- #
72
- # @option (see _govuk_input_field)
73
- #
74
- # @return (see govuk_input_tag)
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
- # Wrapper method used by {govuk_input} to generate the Input HTML
81
- #
82
- # @param error_message [String] used to indicate if there is an error which will add extra classes
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
- prefix = govuk_text_input_options[:prefix]
104
- suffix = govuk_text_input_options[:suffix]
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
- if prefix || suffix
107
- tag.div(class: 'govuk-input__wrapper') do
108
- capture do
109
- concat(govuk_fix('pre', prefix)) if prefix
110
- concat(input_html)
111
- concat(govuk_fix('suf', suffix)) if suffix
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
- # Generates the prefix and suffix HTML for {_govuk_input_field}
120
- #
121
- # @param fix [String] either +"pre"+ or +"suf"+
122
- # @param govuk_fix_options [Hash] options that will be used in customising the HTML
123
- #
124
- # @option govuk_fix_options [String] :classes additional CSS classes for the input HTML
125
- # @option govuk_text_input_options [Hash] :attributes ({ aria: { hidden: true } }) any additional attributes that will added as part of the HTML
126
- #
127
- # @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {_govuk_input_field}
128
-
129
- def govuk_fix(fix, govuk_fix_options)
130
- govuk_fix_classes = ["govuk-input__#{fix}fix"]
131
- govuk_fix_classes << govuk_fix_options[:classes]
132
- govuk_fix_options[:attributes] ||= {}
133
- (govuk_fix_options[:attributes][:aria] ||= {}).merge!({ hidden: true })
134
-
135
- tag.div(govuk_fix_options[:text], class: govuk_fix_classes, **govuk_fix_options[:attributes])
136
- end
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
- # Returns the field type used to create the rails input tag
139
- #
140
- # @param field_type [Symbol] the type of the field, defaults to text
141
- # Allowed values are:
142
- # - +:email+
143
- # - +:password+
144
-
145
- def get_field_type(field_type)
146
- case field_type
147
- when :email, :password
148
- :"#{field_type}_field"
149
- else
150
- :text_field
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