crown_marketplace_utils 0.1.0.beta.4 → 0.1.0.beta.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +11 -11
- data/README.md +1 -3
- 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 +5 -5
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/button.rb +11 -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 +25 -50
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/checkboxes.rb +52 -68
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/date_input.rb +46 -127
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +94 -0
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/input.rb +34 -72
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/radios.rb +52 -68
- data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/select.rb +28 -64
- 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 +1 -1
- 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 +1 -1
- 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} +7 -1
- data/lib/crown_marketplace_utils/version.rb +1 -1
- data/lib/crown_marketplace_utils.rb +1 -1
- metadata +28 -25
- data/lib/crown_marketplace_utils/gov_uk_helper/field/file_upload.rb +0 -125
- data/lib/crown_marketplace_utils/gov_uk_helper/field/textarea.rb +0 -140
- data/lib/crown_marketplace_utils/gov_uk_helper/field.rb +0 -305
- data/lib/crown_marketplace_utils/gov_uk_helper/label.rb +0 -97
- data/lib/crown_marketplace_utils/gov_uk_helper/pagination.rb +0 -214
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e73452d7763d7859ed777fcf3fcb1b1c94f29d1b7847296a103cac6b75cb5be4
|
4
|
+
data.tar.gz: 9e68caffdbdaa5c2bd3c9b35cf867f59e2928945e74b0c537864bfe0441cd74b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 972d9d7bf8c15f1408500948595155932dc99d24ed43565762ce3e0d0f3b695328834f1685aff46c90d21afa8fe6a298551d1e00162d05cc21a91971600065ff
|
7
|
+
data.tar.gz: 16c588d4814694d494093134ff77098b0f1bf1a37ce019efeabef0780848cc17ea00bc6f356fa3206b668da507bf18038677152e21aad3d3c95dfd7eef775077
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
crown_marketplace_utils (0.1.0.beta.
|
4
|
+
crown_marketplace_utils (0.1.0.beta.6)
|
5
5
|
actionview (>= 6.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -93,7 +93,7 @@ GEM
|
|
93
93
|
activesupport (>= 5.0)
|
94
94
|
i18n (1.12.0)
|
95
95
|
concurrent-ruby (~> 1.0)
|
96
|
-
json (2.6.
|
96
|
+
json (2.6.3)
|
97
97
|
loofah (2.19.0)
|
98
98
|
crass (~> 1.0.2)
|
99
99
|
nokogiri (>= 1.5.9)
|
@@ -118,7 +118,7 @@ GEM
|
|
118
118
|
nokogiri (1.13.9-x86_64-linux)
|
119
119
|
racc (~> 1.4)
|
120
120
|
parallel (1.22.1)
|
121
|
-
parser (3.
|
121
|
+
parser (3.2.0.0)
|
122
122
|
ast (~> 2.4.1)
|
123
123
|
public_suffix (5.0.0)
|
124
124
|
racc (1.6.0)
|
@@ -168,32 +168,32 @@ GEM
|
|
168
168
|
diff-lcs (>= 1.2.0, < 2.0)
|
169
169
|
rspec-support (~> 3.12.0)
|
170
170
|
rspec-support (3.12.0)
|
171
|
-
rubocop (1.
|
171
|
+
rubocop (1.43.0)
|
172
172
|
json (~> 2.3)
|
173
173
|
parallel (~> 1.10)
|
174
|
-
parser (>= 3.
|
174
|
+
parser (>= 3.2.0.0)
|
175
175
|
rainbow (>= 2.2.2, < 4.0)
|
176
176
|
regexp_parser (>= 1.8, < 3.0)
|
177
177
|
rexml (>= 3.2.5, < 4.0)
|
178
|
-
rubocop-ast (>= 1.
|
178
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
179
179
|
ruby-progressbar (~> 1.7)
|
180
|
-
unicode-display_width (>=
|
181
|
-
rubocop-ast (1.
|
180
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
181
|
+
rubocop-ast (1.24.1)
|
182
182
|
parser (>= 3.1.1.0)
|
183
|
-
rubocop-rails (2.17.
|
183
|
+
rubocop-rails (2.17.4)
|
184
184
|
activesupport (>= 4.2.0)
|
185
185
|
rack (>= 1.1)
|
186
186
|
rubocop (>= 1.33.0, < 2.0)
|
187
187
|
rubocop-rake (0.6.0)
|
188
188
|
rubocop (~> 1.0)
|
189
|
-
rubocop-rspec (2.
|
189
|
+
rubocop-rspec (2.16.0)
|
190
190
|
rubocop (~> 1.33)
|
191
191
|
ruby-progressbar (1.11.0)
|
192
192
|
thor (1.2.1)
|
193
193
|
timeout (0.3.0)
|
194
194
|
tzinfo (2.0.5)
|
195
195
|
concurrent-ruby (~> 1.0)
|
196
|
-
unicode-display_width (2.
|
196
|
+
unicode-display_width (2.4.2)
|
197
197
|
webrick (1.7.0)
|
198
198
|
websocket-driver (0.7.5)
|
199
199
|
websocket-extensions (>= 0.1.0)
|
data/README.md
CHANGED
@@ -48,6 +48,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
48
48
|
At the moment this Gem only contains view helpers. It would be good in the future to add other kinds of modules to this gem so that they can be shared and managed in one place.
|
49
49
|
|
50
50
|
### Helpers to create
|
51
|
+
- ~~Accordion~~
|
51
52
|
- ~~Breadcrumbs~~
|
52
53
|
- ~~Button~~
|
53
54
|
- ~~Checkboxes~~
|
@@ -71,11 +72,8 @@ At the moment this Gem only contains view helpers. It would be good in the futur
|
|
71
72
|
- ~~Tag~~
|
72
73
|
|
73
74
|
### CCS Helpers to look at after first release
|
74
|
-
- Accordion
|
75
75
|
- CCS Panel
|
76
76
|
- CCS Header
|
77
|
-
- Conditioanl Checkboxes
|
78
|
-
- Conditioanl Radios
|
79
77
|
|
80
78
|
## Contributing
|
81
79
|
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
module CrownMarketplaceUtils::Helpers
|
6
|
+
module GovUkHelper
|
7
|
+
# = GOV.UK Accordion
|
8
|
+
#
|
9
|
+
# This helper is used for generating the accordion component from the
|
10
|
+
# {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
|
11
|
+
|
12
|
+
module Accordion
|
13
|
+
include ActionView::Context
|
14
|
+
include ActionView::Helpers::TagHelper
|
15
|
+
include ActionView::Helpers::TextHelper
|
16
|
+
|
17
|
+
# Generates the HTML for the GOV.UK accordion component
|
18
|
+
#
|
19
|
+
# @param accordion_id [String] used as an id in the HTML for the accordion as a whole,
|
20
|
+
# and also as a prefix for the ids of the section contents
|
21
|
+
# and the buttons that open them
|
22
|
+
# @param accordion_items [Array<Hash>] an array of accordion items.
|
23
|
+
# See {#govuk_accordion_section} for details of the items in the array.
|
24
|
+
# @param govuk_accordion_options [Hash] options that will be used in customising the HTML
|
25
|
+
#
|
26
|
+
# @option govuk_accordion_options [String] :classes additional CSS classes for the accordion HTML
|
27
|
+
# @option govuk_accordion_options [Integer] :heading_level (2) heading level, from 1 to 6
|
28
|
+
# @option govuk_accordion_options [Hash] :attributes ({ data: { module: 'govuk-accordion' } }) any additional
|
29
|
+
# attributes that will added as part of the HTML
|
30
|
+
#
|
31
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Accordion
|
32
|
+
# which can then be rendered on the page
|
33
|
+
|
34
|
+
def govuk_accordion(accordion_id, accordion_items, **govuk_accordion_options)
|
35
|
+
(govuk_accordion_options[:attributes] ||= {})[:data] ||= {}
|
36
|
+
govuk_accordion_options[:attributes][:class] = "govuk-accordion #{govuk_accordion_options[:classes]}".rstrip
|
37
|
+
govuk_accordion_options[:attributes][:id] = accordion_id
|
38
|
+
govuk_accordion_options[:attributes][:data][:module] = 'govuk-accordion'
|
39
|
+
govuk_accordion_options[:heading_level] ||= 2
|
40
|
+
|
41
|
+
tag.div(**govuk_accordion_options[:attributes]) do
|
42
|
+
capture do
|
43
|
+
accordion_items.each.with_index(1) { |accordion_item, index| concat(govuk_accordion_section(accordion_id, accordion_item, index, govuk_accordion_options[:heading_level])) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Generates the HTML for an accordion section, used by {govuk_accordion}
|
51
|
+
#
|
52
|
+
# @param accordion_id [String] used as an id in the HTML for the accordion
|
53
|
+
# @param index [Integer] the index of the accordion item
|
54
|
+
# @param heading_level [Integer] heading level, from 1 to 6
|
55
|
+
#
|
56
|
+
# @option accordion_item [Boolean] :expanded sets whether the section should be expanded
|
57
|
+
# when the page loads for the first time.
|
58
|
+
# @option accordion_item [String] :heading_level (2) Heading level, from 1 to 6
|
59
|
+
# @option accordion_item [String] :heading the heading text for the accordion
|
60
|
+
# @option accordion_item [String] :summary (nil) optional summary text for the accordion header
|
61
|
+
# @option accordion_item [String, ActiveSupport::SafeBuffer] the content within the accordion section
|
62
|
+
#
|
63
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an accordion section
|
64
|
+
# which is used in {govuk_accordion}
|
65
|
+
|
66
|
+
def govuk_accordion_section(accordion_id, accordion_item, index, heading_level)
|
67
|
+
tag.div(class: "govuk-accordion__section #{'govuk-accordion__section--expanded' if accordion_item[:expanded]}".rstrip) do
|
68
|
+
capture do
|
69
|
+
concat(govuk_accordion_section_header(accordion_id, accordion_item, index, heading_level))
|
70
|
+
concat(govuk_accordion_section_content(accordion_id, accordion_item, index))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Generates the HTML for an accordion section heading, used by {govuk_accordion_section}
|
76
|
+
#
|
77
|
+
# @param (see govuk_accordion_section)
|
78
|
+
#
|
79
|
+
# @option (see govuk_accordion_section)
|
80
|
+
#
|
81
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an accordion section heading
|
82
|
+
# which is used in {govuk_accordion_section}
|
83
|
+
|
84
|
+
def govuk_accordion_section_header(accordion_id, accordion_item, index, heading_level)
|
85
|
+
tag.div(class: 'govuk-accordion__section-header') do
|
86
|
+
capture do
|
87
|
+
concat(tag.send("h#{heading_level}", class: 'govuk-accordion__section-heading') do
|
88
|
+
tag.span(accordion_item[:heading], class: 'govuk-accordion__section-button', id: "#{accordion_id}-heading-#{index}")
|
89
|
+
end)
|
90
|
+
concat(tag.div(accordion_item[:summary], class: 'govuk-accordion__section-summary govuk-body', id: "#{accordion_id}-summary-#{index}")) if accordion_item[:summary]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Generates the HTML for an accordion sections content, used by {govuk_accordion_section}
|
96
|
+
#
|
97
|
+
# @param accordion_id [String] used as an id in the HTML for the accordion
|
98
|
+
# @param index [Integer] the index of the accordion item
|
99
|
+
#
|
100
|
+
# @option (see govuk_accordion_section)
|
101
|
+
#
|
102
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an accordion sections content
|
103
|
+
# which is used in {govuk_accordion_section}
|
104
|
+
|
105
|
+
def govuk_accordion_section_content(accordion_id, accordion_item, index)
|
106
|
+
tag.div(class: 'govuk-accordion__section-content', id: "#{accordion_id}-content-#{index}", aria: { labelledby: "#{accordion_id}-heading-#{index}" }) do
|
107
|
+
if accordion_item[:content].is_a? ActiveSupport::SafeBuffer
|
108
|
+
accordion_item[:content]
|
109
|
+
else
|
110
|
+
tag.p(accordion_item[:content], class: 'govuk-body')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
module CrownMarketplaceUtils::Helpers
|
6
|
+
module GovUkHelper
|
7
|
+
# = GOV.UK Back Link
|
8
|
+
#
|
9
|
+
# This helper is used for generating the back link component from the
|
10
|
+
# {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
|
11
|
+
|
12
|
+
module BackLink
|
13
|
+
include ActionView::Helpers::UrlHelper
|
14
|
+
|
15
|
+
# Generates the HTML for the GOV.UK Back link component
|
16
|
+
#
|
17
|
+
# @param text [String] the text for the back link
|
18
|
+
# @param href [String] the href for the back link
|
19
|
+
# @param govuk_back_link_options [Hash] options that will be used in customising the HTML
|
20
|
+
#
|
21
|
+
# @option govuk_back_link_options [String] :classes additional CSS classes for the tag HTML
|
22
|
+
# @option govuk_back_link_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
23
|
+
#
|
24
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Back link
|
25
|
+
# which can then be rendered on the page
|
26
|
+
|
27
|
+
def govuk_back_link(text, href, **govuk_back_link_options)
|
28
|
+
govuk_back_link_options[:class] = "govuk-back-link #{govuk_back_link_options[:classes]}".rstrip
|
29
|
+
|
30
|
+
link_to(text, href, class: govuk_back_link_options[:class], **(govuk_back_link_options[:attributes] || {}))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
5
|
+
module CrownMarketplaceUtils::Helpers
|
6
6
|
module GovUkHelper
|
7
7
|
# = GOV.UK Breadcrumbs
|
8
8
|
#
|
@@ -20,7 +20,7 @@ module CrownMarketplaceUtils
|
|
20
20
|
# @param govuk_breadcrumb_items [Array<Hash>] An array of links for the breadcrumbs list. See {#govuk_breadcrumb_link} for details of the items in the array.
|
21
21
|
# @param govuk_breadcrumbs_options [Hash] options that will be used in customising the HTML
|
22
22
|
#
|
23
|
-
# @option govuk_breadcrumbs_options [String] :classes additional CSS classes for the
|
23
|
+
# @option govuk_breadcrumbs_options [String] :classes additional CSS classes for the breadcrumbs HTML
|
24
24
|
# @option govuk_breadcrumbs_options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
|
25
25
|
# @option govuk_breadcrumbs_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
26
26
|
#
|
@@ -50,7 +50,7 @@ module CrownMarketplaceUtils
|
|
50
50
|
# @param govuk_breadcrumb_item [Hash] a hash containg options for the breadcrumb item
|
51
51
|
#
|
52
52
|
# @option govuk_breadcrumb_item [String] :text the text for the link
|
53
|
-
# @option govuk_breadcrumb_item [String] :
|
53
|
+
# @option govuk_breadcrumb_item [String] :href the URI for the link. If blank it is assumed that this item relates to current page
|
54
54
|
# @option govuk_breadcrumb_item [Hash] :attributes any additional attributes that will added as part of the HTML.
|
55
55
|
# If the link is blank then it defaults to +{ aria: { current: 'page' } }+
|
56
56
|
#
|
@@ -59,9 +59,9 @@ module CrownMarketplaceUtils
|
|
59
59
|
def govuk_breadcrumb_link(govuk_breadcrumb_item)
|
60
60
|
govuk_breadcrumb_item[:attributes] ||= {}
|
61
61
|
|
62
|
-
if govuk_breadcrumb_item[:
|
62
|
+
if govuk_breadcrumb_item[:href].present?
|
63
63
|
tag.li(class: 'govuk-breadcrumbs__list-item', **govuk_breadcrumb_item[:attributes]) do
|
64
|
-
link_to govuk_breadcrumb_item[:text], govuk_breadcrumb_item[:
|
64
|
+
link_to govuk_breadcrumb_item[:text], govuk_breadcrumb_item[:href], class: 'govuk-breadcrumbs__link'
|
65
65
|
end
|
66
66
|
else
|
67
67
|
(govuk_breadcrumb_item[:attributes][:aria] ||= {}).merge!({ current: 'page' })
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
5
|
+
module CrownMarketplaceUtils::Helpers
|
6
6
|
module GovUkHelper
|
7
7
|
# = GOV.UK Button
|
8
8
|
#
|
@@ -19,22 +19,18 @@ module CrownMarketplaceUtils
|
|
19
19
|
# Generates the HTML for the GOV.UK button component
|
20
20
|
#
|
21
21
|
# @param text [String] the text that will be shown in the button
|
22
|
-
# @param type [Symbol] the type of button that will be created.
|
23
|
-
# - :a will create a anchor tag
|
24
|
-
# - :submit will create a input with type submit
|
25
|
-
# - all other values will create a button with the type specified
|
26
22
|
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
27
23
|
#
|
28
24
|
# @option govuk_button_options [String] :classes additional CSS classes for the button HTML
|
29
25
|
# @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
|
30
|
-
# @option govuk_button_options [String] :href the URI that will be used in anchor tag
|
31
|
-
# @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
|
26
|
+
# @option govuk_button_options [String] :href the URI that will be used in anchor tag
|
27
|
+
# @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
|
32
28
|
# @option govuk_button_options [Hash] :attributes ({ data: { module: 'govuk-button' } }) any additional attributes that will added as part of the HTML
|
33
29
|
#
|
34
30
|
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button
|
35
31
|
# which can then be rendered on the page
|
36
32
|
|
37
|
-
def govuk_button(text,
|
33
|
+
def govuk_button(text, **govuk_button_options)
|
38
34
|
govuk_button_classes = ['govuk-button']
|
39
35
|
govuk_button_classes << govuk_button_options[:classes]
|
40
36
|
govuk_button_options[:attributes] ||= {}
|
@@ -43,16 +39,15 @@ module CrownMarketplaceUtils
|
|
43
39
|
|
44
40
|
(govuk_button_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-button' })
|
45
41
|
|
46
|
-
button_method =
|
47
|
-
when :a
|
42
|
+
button_method = if govuk_button_options[:href]
|
48
43
|
:govuk_button_link
|
49
|
-
|
44
|
+
elsif govuk_button_options[:form]
|
50
45
|
:govuk_button_submit
|
51
46
|
else
|
52
47
|
:govuk_button_button
|
53
48
|
end
|
54
49
|
|
55
|
-
send(button_method, text,
|
50
|
+
send(button_method, text, govuk_button_classes, **govuk_button_options)
|
56
51
|
end
|
57
52
|
|
58
53
|
private
|
@@ -61,7 +56,6 @@ module CrownMarketplaceUtils
|
|
61
56
|
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
62
57
|
#
|
63
58
|
# @param text [String] the text that will be shown in the button
|
64
|
-
# @param _type [Symbol] unused as type has already been determined
|
65
59
|
# @param classes [String] additional CSS classes for the button HTML
|
66
60
|
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
67
61
|
#
|
@@ -72,7 +66,7 @@ module CrownMarketplaceUtils
|
|
72
66
|
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an anchor element
|
73
67
|
# which can then be rendered on the page
|
74
68
|
|
75
|
-
def govuk_button_link(text,
|
69
|
+
def govuk_button_link(text, classes, **govuk_button_options)
|
76
70
|
link_to(govuk_button_options[:href], class: classes, role: :button, draggable: false, **govuk_button_options[:attributes]) do
|
77
71
|
concat(text)
|
78
72
|
concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
|
@@ -83,7 +77,6 @@ module CrownMarketplaceUtils
|
|
83
77
|
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
84
78
|
#
|
85
79
|
# @param text [String] the text that will be shown in the button
|
86
|
-
# @param type [Symbol] the type of attribute of the button
|
87
80
|
# @param classes [String] additional CSS classes for the button HTML
|
88
81
|
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
89
82
|
#
|
@@ -93,8 +86,8 @@ module CrownMarketplaceUtils
|
|
93
86
|
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as a button element
|
94
87
|
# which can then be rendered on the page
|
95
88
|
|
96
|
-
def govuk_button_button(text,
|
97
|
-
button_tag(class: classes,
|
89
|
+
def govuk_button_button(text, classes, **govuk_button_options)
|
90
|
+
button_tag(class: classes, **govuk_button_options[:attributes]) do
|
98
91
|
concat(text)
|
99
92
|
concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
|
100
93
|
end
|
@@ -104,7 +97,6 @@ module CrownMarketplaceUtils
|
|
104
97
|
# It is called by {#govuk_button} which will pass in the parameters, including any defaults.
|
105
98
|
#
|
106
99
|
# @param text [String] the text that will be shown in the input
|
107
|
-
# @param _type [Symbol] unused as type has already been determined
|
108
100
|
# @param classes [String] additional CSS classes for the button HTML
|
109
101
|
# @param govuk_button_options [Hash] options that will be used in customising the HTML
|
110
102
|
#
|
@@ -114,7 +106,7 @@ module CrownMarketplaceUtils
|
|
114
106
|
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an input element
|
115
107
|
# which can then be rendered on the page
|
116
108
|
|
117
|
-
def govuk_button_submit(text,
|
109
|
+
def govuk_button_submit(text, classes, **govuk_button_options)
|
118
110
|
govuk_button_options[:form].submit(text, class: classes, **govuk_button_options[:attributes])
|
119
111
|
end
|
120
112
|
|
data/lib/crown_marketplace_utils/{gov_uk_helper → helpers/gov_uk_helper}/field/character_count.rb
RENAMED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'textarea'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
5
|
+
module CrownMarketplaceUtils::Helpers
|
6
6
|
module GovUkHelper
|
7
7
|
module Field
|
8
8
|
# = GOV.UK Character count
|
@@ -19,9 +19,12 @@ module CrownMarketplaceUtils
|
|
19
19
|
# It works by warpping the govuk_textarea in HTML which will trigger the JavaScript to do the character count.
|
20
20
|
#
|
21
21
|
# @param attribute [String, Symbol] the attribute of the character count text area
|
22
|
-
# @param error_message [String] the error message to be displayed
|
23
22
|
# @param govuk_character_count_options [Hash] options that will be used for the parts of the form group, label, hint, textarea and the character count
|
24
23
|
#
|
24
|
+
# @option govuk_character_count_options [String] :error_message (nil) the error message to be displayed
|
25
|
+
# @option govuk_character_count_options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
26
|
+
# @option govuk_character_count_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
27
|
+
# the textarea tag and find the error message
|
25
28
|
# @option govuk_character_count_options [Hash] :form_group see {govuk_field}
|
26
29
|
# @option govuk_character_count_options [Hash] :label see {govuk_field}
|
27
30
|
# @option govuk_character_count_options [Hash] :hint see {govuk_field}
|
@@ -32,55 +35,27 @@ module CrownMarketplaceUtils
|
|
32
35
|
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK chracter count
|
33
36
|
# which can then be rendered on the page
|
34
37
|
|
35
|
-
def govuk_character_count(attribute,
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# @param attribute [String, Symbol] the attribute of the character count text area
|
47
|
-
# @param govuk_character_count_options [Hash] options that will be used for the parts of the form group, label, hint, textarea and the character count
|
48
|
-
#
|
49
|
-
# @option (see govuk_character_count)
|
50
|
-
#
|
51
|
-
# @return (see govuk_character_count)
|
52
|
-
|
53
|
-
def govuk_character_count_with_model(model, attribute, **govuk_character_count_options)
|
54
|
-
_govuk_character_count(attribute, **govuk_character_count_options) do |govuk_text_textarea_options|
|
55
|
-
govuk_textarea_with_model(model, attribute, **govuk_text_textarea_options)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Generates the HTML for the GOV.UK character count component using an ActionView::Helpers::FormBuilder.
|
60
|
-
# Unlike {#govuk_character_count}, the method will be able to automatically determine if the error message needs to be shown.
|
61
|
-
# It works by warpping the govuk_textarea in HTML which will trigger the JavaScript to do the character count.
|
62
|
-
#
|
63
|
-
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the character count textarea
|
64
|
-
# @param attribute [String, Symbol] the attribute of the character count text area
|
65
|
-
# @param govuk_character_count_options [Hash] options that will be used for the parts of the form group, label, hint, textarea and the character count
|
66
|
-
#
|
67
|
-
# @option (see govuk_character_count)
|
68
|
-
#
|
69
|
-
# @return (see govuk_character_count)
|
70
|
-
|
71
|
-
def govuk_character_count_with_form(form, attribute, **govuk_character_count_options)
|
72
|
-
_govuk_character_count(attribute, **govuk_character_count_options) do |govuk_text_textarea_options|
|
73
|
-
govuk_textarea_with_form(form, attribute, **govuk_text_textarea_options)
|
38
|
+
def govuk_character_count(attribute, **govuk_character_count_options)
|
39
|
+
character_count_attribute = govuk_character_count_options[:form] ? "#{form.object_name}_#{attribute}" : attribute
|
40
|
+
|
41
|
+
_govuk_character_count(character_count_attribute, **govuk_character_count_options) do |govuk_textarea_options|
|
42
|
+
govuk_textarea(
|
43
|
+
attribute,
|
44
|
+
error_message: govuk_character_count_options[:error_message],
|
45
|
+
model: govuk_character_count_options[:model],
|
46
|
+
form: govuk_character_count_options[:form],
|
47
|
+
**govuk_textarea_options
|
48
|
+
)
|
74
49
|
end
|
75
50
|
end
|
76
51
|
|
77
52
|
private
|
78
53
|
|
79
|
-
# Wrapper method used by {govuk_character_count}
|
54
|
+
# Wrapper method used by {govuk_character_count} to generate the character count HTML
|
80
55
|
#
|
81
56
|
# @param attribute [String, Symbol] the attribute of the character count
|
82
57
|
# @param govuk_character_count_options [Hash] options that will be used in customising the HTML.
|
83
|
-
# This includes everything described in {govuk_character_count}
|
58
|
+
# This includes everything described in {govuk_character_count}
|
84
59
|
# with the addition of the +:character_count+ which are described below
|
85
60
|
#
|
86
61
|
# @option govuk_character_count_options [String] :maxlength (required) - if +maxwords+ is set, this is not required.
|
@@ -91,20 +66,20 @@ module CrownMarketplaceUtils
|
|
91
66
|
# If +maxwords+ is provided, the +maxlength+ option will be ignored.
|
92
67
|
# @option govuk_character_count_options [String] :threshold the percentage value of the limit at which point the count message is displayed.
|
93
68
|
# If this attribute is set, the count message will be hidden by default.
|
94
|
-
# @option
|
69
|
+
# @option govuk_textarea_options [Hash] :fallback_hint ({}) additional parameters that will be used to create the hint containing the character count text.
|
95
70
|
# This includes all the options in {govuk_hint} plus +:count_message+.
|
96
71
|
# This will replace the default text for the count message.
|
97
72
|
# If you want the count number to appear, put %<count>s in the string and it will be replaced with the number
|
98
73
|
#
|
99
|
-
# @yield the textarea HTML generated by {govuk_character_count}
|
74
|
+
# @yield the textarea HTML generated by {govuk_character_count}
|
100
75
|
#
|
101
|
-
# @yieldparam
|
76
|
+
# @yieldparam govuk_textarea_options [Hash] the options used in the textarea called by {govuk_character_count}
|
102
77
|
#
|
103
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the chracter count which wrpas arround {govuk_character_count}
|
78
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the chracter count which wrpas arround {govuk_character_count}
|
104
79
|
|
105
80
|
def _govuk_character_count(attribute, **govuk_character_count_options)
|
106
81
|
deep_init_hash(govuk_character_count_options, :textarea, :attributes, :aria)
|
107
|
-
govuk_character_count_options[:textarea][:attributes][:aria][:describedby] = [govuk_character_count_options.dig(:textarea, :attributes, :aria, :describedby), "#{attribute}-
|
82
|
+
govuk_character_count_options[:textarea][:attributes][:aria][:describedby] = [govuk_character_count_options.dig(:textarea, :attributes, :aria, :describedby), "#{attribute}-info"].compact.join(' ')
|
108
83
|
|
109
84
|
govuk_character_count_options[:textarea][:classes] = "#{govuk_character_count_options[:textarea][:classes]} govuk-js-character-count".lstrip
|
110
85
|
|
@@ -133,7 +108,7 @@ module CrownMarketplaceUtils
|
|
133
108
|
fallback_hint_text = format(govuk_character_count_options[:character_count][:fallback_hint][:count_message] || fallback_hint_default, count: fallback_hint_length)
|
134
109
|
|
135
110
|
govuk_character_count_options[:character_count][:fallback_hint][:classes] = "#{govuk_character_count_options.dig(:character_count, :fallback_hint, :classes)} govuk-character-count__message".lstrip
|
136
|
-
govuk_character_count_options[:character_count][:fallback_hint][:attributes].merge!(id: "#{attribute}-
|
111
|
+
govuk_character_count_options[:character_count][:fallback_hint][:attributes].merge!(id: "#{attribute}-info")
|
137
112
|
|
138
113
|
govuk_hint(fallback_hint_text, **govuk_character_count_options[:character_count][:fallback_hint])
|
139
114
|
end
|
@@ -141,7 +116,7 @@ module CrownMarketplaceUtils
|
|
141
116
|
# Generates a hash with the character count attributes used in {_govuk_character_count}
|
142
117
|
#
|
143
118
|
# @param govuk_character_count_options [Hash] options that will be used in customising the HTML.
|
144
|
-
# This includes everything described in {govuk_character_count}
|
119
|
+
# This includes everything described in {govuk_character_count}
|
145
120
|
# with the addition of the +:character_count+ which are described below
|
146
121
|
#
|
147
122
|
# @option (see _govuk_character_count)
|