crown_marketplace_utils 0.1.0.beta.3 → 0.1.0.beta.5
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/.rubocop.yml +1 -1
- data/Gemfile.lock +5 -5
- data/README.md +3 -4
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +116 -0
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +34 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/breadcrumbs.rb +2 -2
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/button.rb +13 -19
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/details.rb +1 -1
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/error_message.rb +1 -1
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/character_count.rb +40 -68
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/checkboxes.rb +65 -71
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb +153 -0
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +94 -0
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb +156 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/radios.rb +65 -67
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb +134 -0
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +105 -0
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +215 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/fieldset.rb +2 -2
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/form_group.rb +10 -21
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/header.rb +3 -3
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/hint.rb +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +88 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/notification_banner.rb +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +338 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/step_by_step_navigation.rb +1 -1
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/tag.rb +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +52 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper.rb → helpers/gov_uk_helper.rb} +11 -1
- data/lib/crown_marketplace_utils/version.rb +1 -1
- data/lib/crown_marketplace_utils.rb +1 -1
- metadata +28 -23
- data/lib/crown_marketplace_utils/gov_uk_helper/field/input.rb +0 -160
- data/lib/crown_marketplace_utils/gov_uk_helper/field/select.rb +0 -166
- data/lib/crown_marketplace_utils/gov_uk_helper/field/textarea.rb +0 -127
- data/lib/crown_marketplace_utils/gov_uk_helper/field.rb +0 -263
- data/lib/crown_marketplace_utils/gov_uk_helper/label.rb +0 -97
- data/lib/crown_marketplace_utils/gov_uk_helper/pagination.rb +0 -214
@@ -1,160 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../field'
|
4
|
-
|
5
|
-
module CrownMarketplaceUtils
|
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 error_message [String] the error message to be displayed
|
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 [Hash] :form_group_options see {govuk_field}
|
25
|
-
# @option govuk_input_options [Hash] :label see {govuk_field}
|
26
|
-
# @option govuk_input_options [Hash] :hint see {govuk_field}
|
27
|
-
# @option govuk_input_options [Hash] :input_options ({}) the options that will be used when rendering the input.
|
28
|
-
# See {govuk_input_field} for more details.
|
29
|
-
#
|
30
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Input
|
31
|
-
# which can then be rendered on the page
|
32
|
-
|
33
|
-
def govuk_input(attribute, error_message = nil, **govuk_input_options)
|
34
|
-
govuk_field(:input, attribute, error_message, **govuk_input_options) do |govuk_field_options|
|
35
|
-
concat(govuk_input_field(attribute, error_message, **govuk_field_options))
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Generates the HTML for the GOV.UK input component using an ActionView::Helpers::FormBuilder.
|
40
|
-
# Unlike {govuk_input}, the method will be able to automatically determine if the error message needs to be shown.
|
41
|
-
#
|
42
|
-
# @param form [ActionView::Helpers::FormBuilder] :form the form builder used to create the input
|
43
|
-
# @param attribute [String, Symbol] the attribute of the input
|
44
|
-
# @param govuk_input_options [Hash] options that will be used for the parts of the form group, label, hint and input
|
45
|
-
#
|
46
|
-
# @option govuk_input_options [Hash] :form_group_options see {govuk_field_with_form}
|
47
|
-
# @option govuk_input_options [Hash] :label see {govuk_field_with_form}
|
48
|
-
# @option govuk_input_options [Hash] :hint see {govuk_field_with_form}
|
49
|
-
# @option govuk_input_options [Hash] :input_options ({}) the options that will be used when rendering the input.
|
50
|
-
# See {govuk_input_field_with_form} for more details.
|
51
|
-
#
|
52
|
-
# @return (see govuk_input)
|
53
|
-
|
54
|
-
def govuk_input_with_form(form, attribute, **govuk_input_options)
|
55
|
-
govuk_field_with_form(:input, form, attribute, **govuk_input_options) do |govuk_field_options, error_message|
|
56
|
-
concat(govuk_input_field_with_form(form, attribute, error_message, **govuk_field_options))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
# Generates the input HTML for {govuk_input}
|
63
|
-
#
|
64
|
-
# @param attribute [String, Symbol] the attribute of the input
|
65
|
-
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
66
|
-
# @param govuk_text_input_options [Hash] options that will be used in customising the HTML
|
67
|
-
#
|
68
|
-
# @option (see _govuk_input_field)
|
69
|
-
#
|
70
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {govuk_input}
|
71
|
-
|
72
|
-
def govuk_input_field(attribute, error_message, **govuk_text_input_options)
|
73
|
-
_govuk_input_field(error_message, **govuk_text_input_options) do |govuk_text_input_classes, govuk_text_input_attributes|
|
74
|
-
text_field_tag(attribute, govuk_text_input_options[:value], class: govuk_text_input_classes, **govuk_text_input_attributes)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Generates the input HTML for {govuk_input_with_form}
|
79
|
-
#
|
80
|
-
# @param form [ActionView::Helpers::FormBuilder] :form the form builder used to create the input
|
81
|
-
# @param attribute [String, Symbol] the attribute of the input
|
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 (see _govuk_input_field)
|
86
|
-
#
|
87
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {govuk_input_with_form}
|
88
|
-
|
89
|
-
def govuk_input_field_with_form(form, attribute, error_message, **govuk_text_input_options)
|
90
|
-
_govuk_input_field(error_message, **govuk_text_input_options) do |govuk_text_input_classes, govuk_text_input_attributes|
|
91
|
-
form.text_field(attribute, class: govuk_text_input_classes, **govuk_text_input_attributes)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# Wrapper method used by {govuk_input_field} and {govuk_input_field_with_form} to generate the Input HTML
|
96
|
-
#
|
97
|
-
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
98
|
-
# @param govuk_text_input_options [Hash] options that will be used in customising the HTML
|
99
|
-
#
|
100
|
-
# @option govuk_text_input_options [String] :classes additional CSS classes for the input HTML
|
101
|
-
# @option govuk_text_input_options [String] :value (nil) the value of the input
|
102
|
-
# @option govuk_text_input_options [Hash] :prefix (nil) optional prefix for the input field. See {govuk_fix} for more details.
|
103
|
-
# @option govuk_text_input_options [Hash] :suffix (nil) optional suffix for the input field. See {govuk_fix} for more details.
|
104
|
-
# @option govuk_text_input_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
105
|
-
#
|
106
|
-
# @yield the input HTML generated by {govuk_input_field} or {govuk_input_field_with_form}
|
107
|
-
#
|
108
|
-
# @yieldparam govuk_text_input_classes [Array] the classes for the input HTML
|
109
|
-
# @yieldparam govuk_text_input_attributes [Hash] additional attributes that will added as part of the HTML
|
110
|
-
#
|
111
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {govuk_input_field} or {govuk_input_field_with_form}
|
112
|
-
|
113
|
-
def _govuk_input_field(error_message, **govuk_text_input_options)
|
114
|
-
govuk_text_input_classes = ['govuk-input']
|
115
|
-
govuk_text_input_classes += ['govuk-input--error'] if error_message
|
116
|
-
govuk_text_input_classes << govuk_text_input_options[:classes]
|
117
|
-
govuk_text_input_options[:attributes] ||= {}
|
118
|
-
|
119
|
-
input_html = yield(govuk_text_input_classes, govuk_text_input_options[:attributes])
|
120
|
-
|
121
|
-
prefix = govuk_text_input_options[:prefix]
|
122
|
-
suffix = govuk_text_input_options[:suffix]
|
123
|
-
|
124
|
-
if prefix || suffix
|
125
|
-
tag.div(class: 'govuk-input__wrapper') do
|
126
|
-
capture do
|
127
|
-
concat(govuk_fix('pre', prefix)) if prefix
|
128
|
-
concat(input_html)
|
129
|
-
concat(govuk_fix('suf', suffix)) if suffix
|
130
|
-
end
|
131
|
-
end
|
132
|
-
else
|
133
|
-
input_html
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Generates the prefix and suffix HTML for {_govuk_input_field}
|
138
|
-
#
|
139
|
-
# @param fix [String] either +"pre"+ or +"suf"+
|
140
|
-
# @param govuk_fix_options [Hash] options that will be used in customising the HTML
|
141
|
-
#
|
142
|
-
# @option govuk_fix_options [String] :classes additional CSS classes for the input HTML
|
143
|
-
# @option govuk_text_input_options [Hash] :attributes ({ aria: { hidden: true } }) any additional attributes that will added as part of the HTML
|
144
|
-
#
|
145
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {govuk_input_field} or {govuk_input_field_with_form}
|
146
|
-
|
147
|
-
def govuk_fix(fix, govuk_fix_options)
|
148
|
-
govuk_fix_classes = ["govuk-input__#{fix}fix"]
|
149
|
-
govuk_fix_classes << govuk_fix_options[:classes]
|
150
|
-
govuk_fix_options[:attributes] ||= {}
|
151
|
-
(govuk_fix_options[:attributes][:aria] ||= {}).merge!({ hidden: true })
|
152
|
-
|
153
|
-
tag.div(govuk_fix_options[:text], class: govuk_fix_classes, **govuk_fix_options[:attributes])
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
|
@@ -1,166 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'action_view'
|
4
|
-
require_relative '../field'
|
5
|
-
|
6
|
-
module CrownMarketplaceUtils
|
7
|
-
module GovUkHelper
|
8
|
-
module Field
|
9
|
-
# = GOV.UK Select
|
10
|
-
#
|
11
|
-
# This helper is used for generating the select component from the
|
12
|
-
# {https://design-system.service.gov.uk/components/select GDS - Components - Select}
|
13
|
-
#
|
14
|
-
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
15
|
-
|
16
|
-
module Select
|
17
|
-
include ActionView::Helpers::FormOptionsHelper
|
18
|
-
include Field
|
19
|
-
|
20
|
-
# Generates the HTML for the GOV.UK Select component
|
21
|
-
#
|
22
|
-
# @param attribute [String, Symbol] the attribute of the select field
|
23
|
-
# @param items [Array] array of option items for the select, see {govuk_map_select_items}
|
24
|
-
# @param error_message [String] the error message to be displayed
|
25
|
-
# @param govuk_select_options [Hash] options that will be used for the parts of the form group, label, hint and select
|
26
|
-
#
|
27
|
-
# @option govuk_select_options [Hash] :form_group_options see {govuk_field}
|
28
|
-
# @option govuk_select_options [Hash] :label see {govuk_field}
|
29
|
-
# @option govuk_select_options [Hash] :hint see {govuk_field}
|
30
|
-
# @option govuk_select_options [Hash] :select_options ({}) the options that will be used when rendering the select field.
|
31
|
-
# See {govuk_select_field} for more details.
|
32
|
-
#
|
33
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Select
|
34
|
-
# which can then be rendered on the page
|
35
|
-
|
36
|
-
def govuk_select(attribute, items, error_message = nil, **govuk_select_options)
|
37
|
-
govuk_field(:select, attribute, error_message, **govuk_select_options) do |govuk_field_options|
|
38
|
-
concat(govuk_select_field(attribute, items, error_message, **govuk_field_options))
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Generates the HTML for the GOV.UK Select component using an ActionView::Helpers::FormBuilder.
|
43
|
-
# Unlike {govuk_select}, the method will be able to automatically determine if the error message needs to be shown.
|
44
|
-
#
|
45
|
-
# @param form [ActionView::Helpers::FormBuilder] :form the form builder used to create the select field
|
46
|
-
# @param attribute [String, Symbol] the attribute of the select field
|
47
|
-
# @param items [Array] array of option items for the select, see {govuk_map_select_items}
|
48
|
-
# @param govuk_select_options [Hash] options that will be used for the parts of the form group, label, hint and select
|
49
|
-
#
|
50
|
-
# @option govuk_select_options [Hash] :form_group_options see {govuk_field_with_form}
|
51
|
-
# @option govuk_select_options [Hash] :label see {govuk_field_with_form}
|
52
|
-
# @option govuk_select_options [Hash] :hint see {govuk_field_with_form}
|
53
|
-
# @option govuk_select_options [Hash] :select_options ({}) the options that will be used when rendering the select field.
|
54
|
-
# See {govuk_select_field_with_form} for more details.
|
55
|
-
#
|
56
|
-
# @return (see govuk_select)
|
57
|
-
|
58
|
-
def govuk_select_with_form(form, attribute, items, **govuk_select_options)
|
59
|
-
govuk_field_with_form(:select, form, attribute, **govuk_select_options) do |govuk_field_options, error_message|
|
60
|
-
concat(govuk_select_field_with_form(form, attribute, items, error_message, **govuk_field_options))
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
# Generates the select HTML for {govuk_select}
|
67
|
-
#
|
68
|
-
# @param attribute [String, Symbol] the attribute of the select field
|
69
|
-
# @param items [Array] array of option items for the select, see {govuk_map_select_items}
|
70
|
-
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
71
|
-
# @param govuk_select_options [Hash] options that will be used in customising the HTML
|
72
|
-
#
|
73
|
-
# @option (see _govuk_select_field)
|
74
|
-
#
|
75
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the select field which is used in {govuk_select}
|
76
|
-
|
77
|
-
def govuk_select_field(attribute, items, error_message, **govuk_select_options)
|
78
|
-
_govuk_select_field(error_message, **govuk_select_options) do |govuk_select_classes, govuk_select_attributes|
|
79
|
-
select_tag(
|
80
|
-
attribute,
|
81
|
-
options_for_select(
|
82
|
-
govuk_map_select_items(items),
|
83
|
-
govuk_select_options[:selected]
|
84
|
-
),
|
85
|
-
class: govuk_select_classes,
|
86
|
-
**govuk_select_attributes
|
87
|
-
)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# Generates the select HTML for {govuk_select_with_form}
|
92
|
-
#
|
93
|
-
# @param form [ActionView::Helpers::FormBuilder] :form the form builder used to create the select field
|
94
|
-
# @param attribute [String, Symbol] the attribute of the select field
|
95
|
-
# @param items [Array] array of option items for the select, see {govuk_map_select_items}
|
96
|
-
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
97
|
-
# @param govuk_select_options [Hash] options that will be used in customising the HTML
|
98
|
-
#
|
99
|
-
# @option (see _govuk_select_field)
|
100
|
-
#
|
101
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the select field which is used in {govuk_select_with_form}
|
102
|
-
|
103
|
-
def govuk_select_field_with_form(form, attribute, items, error_message, **govuk_select_options)
|
104
|
-
_govuk_select_field(error_message, **govuk_select_options) do |govuk_select_classes, govuk_select_attributes|
|
105
|
-
form.select(
|
106
|
-
attribute,
|
107
|
-
govuk_map_select_items(items),
|
108
|
-
govuk_select_options[:select_options] || {},
|
109
|
-
class: govuk_select_classes,
|
110
|
-
**govuk_select_attributes
|
111
|
-
)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Wrapper method used by {govuk_select_field} and {govuk_select_field_with_form} to generate the select HTML
|
116
|
-
#
|
117
|
-
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
118
|
-
# @param govuk_select_options [Hash] options that will be used in customising the HTML
|
119
|
-
#
|
120
|
-
# @option govuk_select_options [String] :classes additional CSS classes for the select HTML
|
121
|
-
# @option govuk_select_options [String] :selected (nil) the selected option
|
122
|
-
# @option govuk_select_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
123
|
-
#
|
124
|
-
# @yield the select HTML generated by {govuk_select_field} or {govuk_select_field_with_form}
|
125
|
-
#
|
126
|
-
# @yieldparam govuk_select_classes [Array] the classes for the select HTML
|
127
|
-
# @yieldparam govuk_select_attributes [Hash] additional attributes that will added as part of the HTML
|
128
|
-
#
|
129
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the select field which is used in {govuk_select_field} or {govuk_select_field_with_form}
|
130
|
-
|
131
|
-
def _govuk_select_field(error_message, **govuk_select_options)
|
132
|
-
govuk_select_classes = ['govuk-select']
|
133
|
-
govuk_select_classes += ['govuk-select--error'] if error_message
|
134
|
-
govuk_select_classes << govuk_select_options[:classes]
|
135
|
-
govuk_select_options[:attributes] ||= {}
|
136
|
-
|
137
|
-
yield(govuk_select_classes, govuk_select_options[:attributes])
|
138
|
-
end
|
139
|
-
|
140
|
-
# Maps the items into an array that can be used to generate the options for
|
141
|
-
# {govuk_select_field} and {govuk_select_field_with_form}
|
142
|
-
#
|
143
|
-
# @param items [Array] array of option items for the select
|
144
|
-
#
|
145
|
-
# @option items [String] :text the text of the option item.
|
146
|
-
# If this is blank the value is used
|
147
|
-
# @option items [String] :value the value of the option item
|
148
|
-
# @option items [Hash] :attributes ({}) any additional attributes that will added as part of the option HTML
|
149
|
-
#
|
150
|
-
# @return [Array] array of option params that are used in {govuk_select_field} and {govuk_select_field_with_form}
|
151
|
-
|
152
|
-
def govuk_map_select_items(items)
|
153
|
-
items.map do |item|
|
154
|
-
[
|
155
|
-
item[:text] || item[:value],
|
156
|
-
item[:value],
|
157
|
-
(item[:attributes] || {})
|
158
|
-
]
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
|
@@ -1,127 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../field'
|
4
|
-
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module GovUkHelper
|
7
|
-
module Field
|
8
|
-
# = GOV.UK Textarea
|
9
|
-
#
|
10
|
-
# This helper is used for generating the textarea component from the
|
11
|
-
# {https://design-system.service.gov.uk/components/textarea GDS - Components - Textarea}
|
12
|
-
#
|
13
|
-
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
14
|
-
|
15
|
-
module Textarea
|
16
|
-
include Field
|
17
|
-
|
18
|
-
# Generates the HTML for the GOV.UK textarea component
|
19
|
-
#
|
20
|
-
# @param attribute [String, Symbol] the attribute of the textarea
|
21
|
-
# @param error_message [String] the error message to be displayed
|
22
|
-
# @param govuk_textarea_options [Hash] options that will be used for the parts of the form group, label, hint and textarea
|
23
|
-
#
|
24
|
-
# @option govuk_textarea_options [Hash] :form_group_options see {govuk_field}
|
25
|
-
# @option govuk_textarea_options [Hash] :label see {govuk_field}
|
26
|
-
# @option govuk_textarea_options [Hash] :hint see {govuk_field}
|
27
|
-
# @option govuk_textarea_options [Hash] :textarea_options ({}) the options that will be used when rendering the textarea.
|
28
|
-
# See {govuk_textarea_field} for more details.
|
29
|
-
#
|
30
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK textarea
|
31
|
-
# which can then be rendered on the page
|
32
|
-
|
33
|
-
def govuk_textarea(attribute, error_message = nil, **govuk_textarea_options)
|
34
|
-
govuk_field(:textarea, attribute, error_message, **govuk_textarea_options) do |govuk_field_options|
|
35
|
-
concat(govuk_textarea_field(attribute, error_message, **govuk_field_options))
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Generates the HTML for the GOV.UK textarea component using an ActionView::Helpers::FormBuilder.
|
40
|
-
# Unlike {#govuk_textarea}, the method will be able to automatically determine if the error message needs to be shown.
|
41
|
-
#
|
42
|
-
# @param form [ActionView::Helpers::FormBuilder] :form the form builder used to create the textarea
|
43
|
-
# @param attribute [String, Symbol] the attribute of the textarea
|
44
|
-
# @param govuk_textarea_options [Hash] options that will be used for the parts of the form group, label, hint and textarea
|
45
|
-
#
|
46
|
-
# @option govuk_textarea_options [Hash] :form_group_options see {govuk_field_with_form}
|
47
|
-
# @option govuk_textarea_options [Hash] :label see {govuk_field_with_form}
|
48
|
-
# @option govuk_textarea_options [Hash] :hint see {govuk_field_with_form}
|
49
|
-
# @option govuk_textarea_options [Hash] :textarea_options ({}) the options that will be used when rendering the textarea.
|
50
|
-
# See {govuk_textarea_field_with_form} for more details.
|
51
|
-
#
|
52
|
-
# @return (see govuk_textarea)
|
53
|
-
|
54
|
-
def govuk_textarea_with_form(form, attribute, **govuk_textarea_options)
|
55
|
-
govuk_field_with_form(:textarea, form, attribute, **govuk_textarea_options) do |govuk_field_options, error_message|
|
56
|
-
concat(govuk_textarea_field_with_form(form, attribute, error_message, **govuk_field_options))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
# Generates the textarea HTML for {govuk_textarea}
|
63
|
-
#
|
64
|
-
# @param attribute [String, Symbol] the attribute of the textarea
|
65
|
-
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
66
|
-
# @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
|
67
|
-
#
|
68
|
-
# @option (see _govuk_textarea_field)
|
69
|
-
#
|
70
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the textarea field which is used in {govuk_textarea}
|
71
|
-
|
72
|
-
def govuk_textarea_field(attribute, error_message, **govuk_text_textarea_options)
|
73
|
-
_govuk_textarea_field(error_message, **govuk_text_textarea_options) do |govuk_text_textarea_classes, govuk_text_textarea_rows, govuk_text_textarea_attributes|
|
74
|
-
text_area_tag(attribute, govuk_text_textarea_options[:content], class: govuk_text_textarea_classes, rows: govuk_text_textarea_rows, **govuk_text_textarea_attributes)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Generates the textarea HTML for {govuk_textarea_with_form}
|
79
|
-
#
|
80
|
-
# @param form [ActionView::Helpers::FormBuilder] :form the form builder used to create the textarea
|
81
|
-
# @param attribute [String, Symbol] the attribute of the textarea
|
82
|
-
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
83
|
-
# @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
|
84
|
-
#
|
85
|
-
# @option (see _govuk_textarea_field)
|
86
|
-
#
|
87
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the textarea field which is used in {govuk_textarea_with_form}
|
88
|
-
|
89
|
-
def govuk_textarea_field_with_form(form, attribute, error_message, **govuk_text_textarea_options)
|
90
|
-
_govuk_textarea_field(error_message, **govuk_text_textarea_options) do |govuk_text_textarea_classes, govuk_text_textarea_rows, govuk_text_textarea_attributes|
|
91
|
-
form.text_area(attribute, class: govuk_text_textarea_classes, rows: govuk_text_textarea_rows, **govuk_text_textarea_attributes)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# Wrapper method used by {govuk_textarea_field} and {govuk_textarea_field_with_form} to generate the textarea HTML
|
96
|
-
#
|
97
|
-
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
98
|
-
# @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
|
99
|
-
#
|
100
|
-
# @option govuk_text_textarea_options [String] :classes additional CSS classes for the textarea HTML
|
101
|
-
# @option govuk_text_textarea_options [String] :content (nil) the content of the textarea
|
102
|
-
# @option govuk_text_textarea_options [String] :rows (5) the number of rows for the text area
|
103
|
-
# @option govuk_text_textarea_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
104
|
-
#
|
105
|
-
# @yield the textarea HTML generated by {govuk_textarea_field} or {govuk_textarea_field_with_form}
|
106
|
-
#
|
107
|
-
# @yieldparam govuk_text_textarea_classes [Array] the classes for the label HTML
|
108
|
-
# @yieldparam govuk_text_textarea_rows [Integer, String] (5) the number of rows for the text area
|
109
|
-
# @yieldparam govuk_text_textarea_attributes [Hash] additional attributes that will added as part of the HTML
|
110
|
-
#
|
111
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the textarea field which is used in {govuk_textarea_field} or {govuk_textarea_field_with_form}
|
112
|
-
|
113
|
-
def _govuk_textarea_field(error_message, **govuk_text_textarea_options)
|
114
|
-
govuk_text_textarea_classes = ['govuk-textarea']
|
115
|
-
govuk_text_textarea_classes += ['govuk-textarea--error'] if error_message
|
116
|
-
govuk_text_textarea_classes << govuk_text_textarea_options[:classes]
|
117
|
-
govuk_text_textarea_options[:attributes] ||= {}
|
118
|
-
govuk_text_textarea_options[:rows] ||= 5
|
119
|
-
|
120
|
-
yield(govuk_text_textarea_classes, govuk_text_textarea_options[:rows], govuk_text_textarea_options[:attributes])
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
|