ccs-frontend_helpers 0.1.0.rc.2 → 0.1.0.rc.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Gemfile.lock +1 -1
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
- data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
- data/lib/ccs/components/ccs/footer/link.rb +41 -39
- data/lib/ccs/components/ccs/footer/meta.rb +49 -48
- data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
- data/lib/ccs/components/ccs/footer.rb +69 -67
- data/lib/ccs/components/ccs/header/link.rb +47 -45
- data/lib/ccs/components/ccs/header/navigation.rb +85 -84
- data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
- data/lib/ccs/components/ccs/header.rb +87 -85
- data/lib/ccs/components/ccs/logo.rb +36 -34
- data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
- data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
- data/lib/ccs/components/govuk/accordion/section.rb +49 -48
- data/lib/ccs/components/govuk/accordion.rb +43 -41
- data/lib/ccs/components/govuk/back_link.rb +39 -37
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
- data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
- data/lib/ccs/components/govuk/button.rb +83 -81
- data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
- data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
- data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
- data/lib/ccs/components/govuk/details.rb +38 -36
- data/lib/ccs/components/govuk/error_message.rb +46 -44
- data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
- data/lib/ccs/components/govuk/error_summary.rb +49 -47
- data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
- data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
- data/lib/ccs/components/govuk/field/input/select.rb +61 -59
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
- data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
- data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
- data/lib/ccs/components/govuk/field/input.rb +46 -44
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
- data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
- data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
- data/lib/ccs/components/govuk/field/inputs.rb +42 -40
- data/lib/ccs/components/govuk/field.rb +90 -88
- data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
- data/lib/ccs/components/govuk/fieldset.rb +40 -38
- data/lib/ccs/components/govuk/footer/link.rb +41 -39
- data/lib/ccs/components/govuk/footer/meta.rb +49 -48
- data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
- data/lib/ccs/components/govuk/footer.rb +105 -103
- data/lib/ccs/components/govuk/form_group.rb +45 -43
- data/lib/ccs/components/govuk/header/link.rb +41 -39
- data/lib/ccs/components/govuk/header/navigation.rb +54 -53
- data/lib/ccs/components/govuk/header.rb +84 -82
- data/lib/ccs/components/govuk/hint.rb +33 -31
- data/lib/ccs/components/govuk/inset_text.rb +39 -37
- data/lib/ccs/components/govuk/label.rb +61 -59
- data/lib/ccs/components/govuk/notification_banner.rb +83 -81
- data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
- data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
- data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
- data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
- data/lib/ccs/components/govuk/pagination/item.rb +47 -45
- data/lib/ccs/components/govuk/pagination.rb +69 -67
- data/lib/ccs/components/govuk/panel.rb +49 -47
- data/lib/ccs/components/govuk/phase_banner.rb +50 -48
- data/lib/ccs/components/govuk/skip_link.rb +39 -37
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
- data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
- data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
- data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
- data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
- data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
- data/lib/ccs/components/govuk/summary_list/row.rb +47 -45
- data/lib/ccs/components/govuk/summary_list.rb +48 -46
- data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
- data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
- data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
- data/lib/ccs/components/govuk/table.rb +83 -81
- data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
- data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
- data/lib/ccs/components/govuk/tabs.rb +48 -46
- data/lib/ccs/components/govuk/tag.rb +39 -37
- data/lib/ccs/components/govuk/warning_text.rb +49 -47
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +2 -2
@@ -1,58 +1,60 @@
|
|
1
1
|
require_relative '../base'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
# This is used to generate the error message component from the
|
8
|
-
# {https://design-system.service.gov.uk/components/error-message GDS - Components - Error message}
|
9
|
-
#
|
10
|
-
# @!attribute [r] message
|
11
|
-
# @return [String] Text for the error message
|
12
|
-
# @!attribute [r] attribute
|
13
|
-
# @return [String,Symbol] The attribute that has an error
|
14
|
-
# @!attribute [r] visually_hidden_text
|
15
|
-
# @return [String] The visually hidden text before the error message
|
16
|
-
|
17
|
-
class ErrorMessage < Base
|
18
|
-
private
|
19
|
-
|
20
|
-
attr_reader :message, :attribute, :visually_hidden_text
|
21
|
-
|
22
|
-
public
|
23
|
-
|
24
|
-
# @param message [String] the message to be displayed
|
25
|
-
# @param attribute [String, Symbol] the attribute that has an error
|
26
|
-
# @param options [Hash] options that will be used in customising the HTML
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Error Message
|
27
7
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
8
|
+
# This is used to generate the error message component from the
|
9
|
+
# {https://design-system.service.gov.uk/components/error-message GDS - Components - Error message}
|
10
|
+
#
|
11
|
+
# @!attribute [r] message
|
12
|
+
# @return [String] Text for the error message
|
13
|
+
# @!attribute [r] attribute
|
14
|
+
# @return [String,Symbol] The attribute that has an error
|
15
|
+
# @!attribute [r] visually_hidden_text
|
16
|
+
# @return [String] The visually hidden text before the error message
|
31
17
|
|
32
|
-
|
33
|
-
|
18
|
+
class ErrorMessage < Base
|
19
|
+
private
|
34
20
|
|
35
|
-
|
21
|
+
attr_reader :message, :attribute, :visually_hidden_text
|
36
22
|
|
37
|
-
|
38
|
-
@attribute = attribute
|
39
|
-
@visually_hidden_text = @options[:visually_hidden_text] || 'Error'
|
40
|
-
end
|
23
|
+
public
|
41
24
|
|
42
|
-
|
43
|
-
|
44
|
-
|
25
|
+
# @param message [String] the message to be displayed
|
26
|
+
# @param attribute [String, Symbol] the attribute that has an error
|
27
|
+
# @param options [Hash] options that will be used in customising the HTML
|
28
|
+
#
|
29
|
+
# @option options [String] :classes additional CSS classes for the error message HTML
|
30
|
+
# @option options [String] :visually_hidden_text ('Error') visualy hidden text before the error message
|
31
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
|
32
|
+
|
33
|
+
def initialize(message:, attribute:, **options)
|
34
|
+
super(**options)
|
35
|
+
|
36
|
+
@options[:attributes][:id] ||= "#{attribute}-error"
|
45
37
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
concat(message)
|
38
|
+
@message = message
|
39
|
+
@attribute = attribute
|
40
|
+
@visually_hidden_text = @options[:visually_hidden_text] || 'Error'
|
50
41
|
end
|
51
|
-
end
|
52
42
|
|
53
|
-
|
43
|
+
# Generates the HTML for the GOV.UK Error message component
|
44
|
+
#
|
45
|
+
# @return [ActiveSupport::SafeBuffer]
|
46
|
+
|
47
|
+
def render
|
48
|
+
tag.p(**options[:attributes]) do
|
49
|
+
concat(tag.span("#{visually_hidden_text}: ", class: 'govuk-visually-hidden')) if visually_hidden_text.present?
|
50
|
+
concat(message)
|
51
|
+
end
|
52
|
+
end
|
54
53
|
|
55
|
-
|
54
|
+
# The default attributes for the error message
|
55
|
+
|
56
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-error-message' }.freeze
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
@@ -1,48 +1,50 @@
|
|
1
1
|
require_relative '../../base'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# The individual list item for the error summary
|
9
|
-
#
|
10
|
-
# @!attribute [r] text
|
11
|
-
# @return [String] Text for the error message item
|
12
|
-
# @!attribute [r] href
|
13
|
-
# @return [String] The href for the error message
|
14
|
-
|
15
|
-
class Item < Base
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :text, :href
|
19
|
-
|
20
|
-
public
|
21
|
-
|
22
|
-
# @param text [String] the text for the error link item
|
23
|
-
# @param href [String] the href for the error link item.
|
24
|
-
# If provided item will be a link
|
25
|
-
# @param options [Hash] options that will be used in customising the HTML
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class ErrorSummary < Base
|
7
|
+
# = GOV.UK Error Summary Item
|
26
8
|
#
|
27
|
-
#
|
9
|
+
# The individual list item for the error summary
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the error message item
|
13
|
+
# @!attribute [r] href
|
14
|
+
# @return [String] The href for the error message
|
28
15
|
|
29
|
-
|
30
|
-
|
16
|
+
class Item < Base
|
17
|
+
private
|
31
18
|
|
32
|
-
|
33
|
-
@href = href
|
34
|
-
end
|
19
|
+
attr_reader :text, :href
|
35
20
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
21
|
+
public
|
22
|
+
|
23
|
+
# @param text [String] the text for the error link item
|
24
|
+
# @param href [String] the href for the error link item.
|
25
|
+
# If provided item will be a link
|
26
|
+
# @param options [Hash] options that will be used in customising the HTML
|
27
|
+
#
|
28
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
|
29
|
+
|
30
|
+
def initialize(text:, href: nil, **options)
|
31
|
+
super(**options)
|
32
|
+
|
33
|
+
@text = text
|
34
|
+
@href = href
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates the HTML for the GOV.UK Error Summary Item
|
38
|
+
#
|
39
|
+
# @return [ActiveSupport::SafeBuffer]
|
40
|
+
|
41
|
+
def render
|
42
|
+
tag.li do
|
43
|
+
if href
|
44
|
+
link_to(text, href, **options[:attributes])
|
45
|
+
else
|
46
|
+
text
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -1,68 +1,70 @@
|
|
1
1
|
require_relative '../base'
|
2
2
|
require_relative 'error_summary/item'
|
3
3
|
|
4
|
-
module CCS
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK Error Summary
|
8
|
+
#
|
9
|
+
# This is used to generate the error summary component from the
|
10
|
+
# {https://design-system.service.gov.uk/components/error-summary GDS - Components - Error summary}
|
11
|
+
#
|
12
|
+
# @!attribute [r] title
|
13
|
+
# @return [String] Heading for the error summary
|
14
|
+
# @!attribute [r] error_summary_items
|
15
|
+
# @return [Array<Item>] An array of the initialised error summary items
|
16
|
+
# @!attribute [r] description
|
17
|
+
# @return [String] Text to use for the description of the errors
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
class ErrorSummary < Base
|
20
|
+
private
|
20
21
|
|
21
|
-
|
22
|
+
attr_reader :title, :error_summary_items, :description
|
22
23
|
|
23
|
-
|
24
|
+
public
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
# @param title [String] text to use for the heading of the error summary block
|
27
|
+
# @param error_summary_items [Array<Hash>] the list of errors to include in the summary. See {Components::GovUK::ErrorSummary::Item#initialize Item#initialize}
|
28
|
+
# @param description [String] optional text to use for the description of the errors
|
29
|
+
# @param options [Hash] options that will be used in customising the HTML
|
30
|
+
#
|
31
|
+
# @option options [String] :classes additional CSS classes for the error summary HTML
|
32
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
def initialize(title:, error_summary_items:, description: nil, **options)
|
35
|
+
super(**options)
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
@title = title
|
38
|
+
@error_summary_items = error_summary_items.map { |error_summary_item| Item.new(context: @context, **error_summary_item) }
|
39
|
+
@description = description
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
+
# rubocop:disable Metrics/AbcSize
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
# Generates the HTML for the GOV.UK Error summary component
|
45
|
+
#
|
46
|
+
# @return [ActiveSupport::SafeBuffer]
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
def render
|
49
|
+
tag.div(**options[:attributes]) do
|
50
|
+
tag.div(role: 'alert') do
|
51
|
+
concat(tag.h2(title, class: 'govuk-error-summary__title'))
|
52
|
+
concat(tag.div(class: 'govuk-error-summary__body') do
|
53
|
+
concat(tag.p(description)) if description
|
54
|
+
concat(tag.ul(class: 'govuk-list govuk-error-summary__list') do
|
55
|
+
error_summary_items.each { |error_summary_item| concat(error_summary_item.render) }
|
56
|
+
end)
|
55
57
|
end)
|
56
|
-
end
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
59
|
-
end
|
60
61
|
|
61
|
-
|
62
|
+
# rubocop:enable Metrics/AbcSize
|
62
63
|
|
63
|
-
|
64
|
+
# The default attributes for the error summary
|
64
65
|
|
65
|
-
|
66
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-error-summary', data: { module: 'govuk-error-summary' } }.freeze
|
67
|
+
end
|
66
68
|
end
|
67
69
|
end
|
68
70
|
end
|
@@ -1,124 +1,126 @@
|
|
1
1
|
require_relative 'textarea'
|
2
2
|
require_relative '../../hint'
|
3
3
|
|
4
|
-
module CCS
|
5
|
-
module
|
6
|
-
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
# This is used for generating the character count component from the
|
11
|
-
# {https://design-system.service.gov.uk/components/character-count GDS - Components - Character count}
|
12
|
-
#
|
13
|
-
# This is a wrapper around a Textarea module and so makes use of the methods in {Textarea}
|
14
|
-
#
|
15
|
-
# @!attribute [r] textarea
|
16
|
-
# @return [Textarea] The initialised textarea
|
17
|
-
# @!attribute [r] fallback_hint
|
18
|
-
# @return [Hint] The initialised character count fallback hint
|
19
|
-
# @!attribute [r] character_count_html_options
|
20
|
-
# @return [Hash] HTML options for the character count
|
21
|
-
|
22
|
-
class CharacterCount
|
23
|
-
include ActionView::Context
|
24
|
-
include ActionView::Helpers
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
attr_reader :textarea, :fallback_hint, :character_count_html_options
|
29
|
-
|
30
|
-
public
|
31
|
-
|
32
|
-
# @param (see CCS::Components::GovUK::Field::Input::Textarea#initialize)
|
33
|
-
# @param character_count_options [Hash] options for the character count
|
34
|
-
# @param context [ActionView::Base] the view context
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
class Field < Base
|
8
|
+
class Input < Field
|
9
|
+
# = GOV.UK Character count
|
35
10
|
#
|
36
|
-
#
|
11
|
+
# This is used for generating the character count component from the
|
12
|
+
# {https://design-system.service.gov.uk/components/character-count GDS - Components - Character count}
|
37
13
|
#
|
38
|
-
#
|
14
|
+
# This is a wrapper around a Textarea module and so makes use of the methods in {Textarea}
|
15
|
+
#
|
16
|
+
# @!attribute [r] textarea
|
17
|
+
# @return [Textarea] The initialised textarea
|
18
|
+
# @!attribute [r] fallback_hint
|
19
|
+
# @return [Hint] The initialised character count fallback hint
|
20
|
+
# @!attribute [r] character_count_html_options
|
21
|
+
# @return [Hash] HTML options for the character count
|
39
22
|
|
40
|
-
|
41
|
-
|
23
|
+
class CharacterCount
|
24
|
+
include ActionView::Context
|
25
|
+
include ActionView::Helpers
|
42
26
|
|
43
|
-
|
44
|
-
initialise_character_count_html_options(character_count_options)
|
45
|
-
initialise_fallback_hint(character_count_attribute, context, character_count_options)
|
46
|
-
end
|
27
|
+
private
|
47
28
|
|
48
|
-
|
49
|
-
|
50
|
-
|
29
|
+
attr_reader :textarea, :fallback_hint, :character_count_html_options
|
30
|
+
|
31
|
+
public
|
32
|
+
|
33
|
+
# @param (see CCS::Components::GovUK::Field::Input::Textarea#initialize)
|
34
|
+
# @param character_count_options [Hash] options for the character count
|
35
|
+
# @param context [ActionView::Base] the view context
|
36
|
+
#
|
37
|
+
# @option (see CCS::Components::GovUK::Field::Input::Textarea#initialize)
|
38
|
+
#
|
39
|
+
# @option (see initialise_character_count_html_options)
|
51
40
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
41
|
+
def initialize(attribute:, character_count_options:, context:, **options)
|
42
|
+
character_count_attribute = options[:form] ? "#{options[:form].object_name}_#{attribute}" : attribute
|
43
|
+
|
44
|
+
initialise_textarea(attribute, character_count_attribute, context, options)
|
45
|
+
initialise_character_count_html_options(character_count_options)
|
46
|
+
initialise_fallback_hint(character_count_attribute, context, character_count_options)
|
56
47
|
end
|
57
|
-
end
|
58
48
|
|
59
|
-
|
49
|
+
# Generates the HTML for the GOV.UK Character count component
|
50
|
+
#
|
51
|
+
# @return [ActiveSupport::SafeBuffer]
|
60
52
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
#
|
68
|
-
# @option (see CCS::Components::GovUK::Field::Input::Textarea#initialize)
|
53
|
+
def render
|
54
|
+
tag.div(**character_count_html_options) do
|
55
|
+
concat(textarea.render)
|
56
|
+
concat(fallback_hint.render)
|
57
|
+
end
|
58
|
+
end
|
69
59
|
|
70
|
-
|
71
|
-
((options[:attributes] ||= {})[:aria] ||= {})[:describedby] = [options.dig(:attributes, :aria, :describedby), "#{character_count_attribute}-info"].compact.join(' ')
|
72
|
-
options[:classes] = "#{options[:classes]} govuk-js-character-count".lstrip
|
60
|
+
private
|
73
61
|
|
74
|
-
|
75
|
-
|
62
|
+
# Initialises the Textarea for the character count
|
63
|
+
#
|
64
|
+
# @param attribute [Symbol] the attribute of the field
|
65
|
+
# @param character_count_attribute [String] the name of the field as it will appear in the textarea
|
66
|
+
# @param context [ActionView::Base] the view context
|
67
|
+
# @param options [Hash] options that will be used for the textarea
|
68
|
+
#
|
69
|
+
# @option (see CCS::Components::GovUK::Field::Input::Textarea#initialize)
|
76
70
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
# If +maxwords+ is set, this is not required.
|
83
|
-
# If +maxwords+ is provided, the +maxlength+ option will be ignored.
|
84
|
-
# @option character_count_options [String] :maxwords the maximum number of words.
|
85
|
-
# If maxlength is set, this is not required.
|
86
|
-
# If +maxwords+ is provided, the +maxlength+ option will be ignored.
|
87
|
-
# @option character_count_options [String] :threshold the percentage value of the limit at which point the count message is displayed.
|
88
|
-
# If this attribute is set, the count message will be hidden by default.
|
89
|
-
# @option character_count_options [Hash] :fallback_hint ({}) additional parameters that will be used to create the hint containing the character count text:
|
90
|
-
# - +:count_message+ replaced the default text for the count message.
|
91
|
-
# If you want the count number to appear, put %<count>s in the string and it will be replaced with the number
|
92
|
-
# - +classes+ additional CSS classes for the fallback hint HTML
|
93
|
-
|
94
|
-
def initialise_character_count_html_options(character_count_options)
|
95
|
-
character_count_html_options = { class: 'govuk-character-count', data: { module: 'govuk-character-count' } }
|
96
|
-
|
97
|
-
%i[maxlength threshold maxwords].each do |data_attribute|
|
98
|
-
character_count_html_options[:data][data_attribute] = character_count_options[data_attribute].to_s if character_count_options[data_attribute]
|
71
|
+
def initialise_textarea(attribute, character_count_attribute, context, options)
|
72
|
+
((options[:attributes] ||= {})[:aria] ||= {})[:describedby] = [options.dig(:attributes, :aria, :describedby), "#{character_count_attribute}-info"].compact.join(' ')
|
73
|
+
options[:classes] = "#{options[:classes]} govuk-js-character-count".lstrip
|
74
|
+
|
75
|
+
@textarea = Textarea.new(attribute: attribute, context: context, **options)
|
99
76
|
end
|
100
77
|
|
101
|
-
|
102
|
-
|
78
|
+
# Initialises the charcter count options
|
79
|
+
#
|
80
|
+
# @param character_count_options [Hash] options for the charcter count
|
81
|
+
#
|
82
|
+
# @option character_count_options [String] :maxlength the maximum number of characters.
|
83
|
+
# If +maxwords+ is set, this is not required.
|
84
|
+
# If +maxwords+ is provided, the +maxlength+ option will be ignored.
|
85
|
+
# @option character_count_options [String] :maxwords the maximum number of words.
|
86
|
+
# If maxlength is set, this is not required.
|
87
|
+
# If +maxwords+ is provided, the +maxlength+ option will be ignored.
|
88
|
+
# @option character_count_options [String] :threshold the percentage value of the limit at which point the count message is displayed.
|
89
|
+
# If this attribute is set, the count message will be hidden by default.
|
90
|
+
# @option character_count_options [Hash] :fallback_hint ({}) additional parameters that will be used to create the hint containing the character count text:
|
91
|
+
# - +:count_message+ replaced the default text for the count message.
|
92
|
+
# If you want the count number to appear, put %<count>s in the string and it will be replaced with the number
|
93
|
+
# - +classes+ additional CSS classes for the fallback hint HTML
|
94
|
+
|
95
|
+
def initialise_character_count_html_options(character_count_options)
|
96
|
+
character_count_html_options = { class: 'govuk-character-count', data: { module: 'govuk-character-count' } }
|
97
|
+
|
98
|
+
%i[maxlength threshold maxwords].each do |data_attribute|
|
99
|
+
character_count_html_options[:data][data_attribute] = character_count_options[data_attribute].to_s if character_count_options[data_attribute]
|
100
|
+
end
|
101
|
+
|
102
|
+
@character_count_html_options = character_count_html_options
|
103
|
+
end
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
105
|
+
# Initialises the charcter count fall back hint
|
106
|
+
#
|
107
|
+
# @param character_count_attribute [String] the name of the field as it will appear in the textarea
|
108
|
+
# @param context [ActionView::Base] the view context
|
109
|
+
# @param (see initialise_character_count_html_options)
|
110
|
+
#
|
111
|
+
# @option (see initialise_character_count_html_options)
|
111
112
|
|
112
|
-
|
113
|
-
|
113
|
+
def initialise_fallback_hint(character_count_attribute, context, character_count_options)
|
114
|
+
fallback_hint = character_count_options[:fallback_hint] || {}
|
114
115
|
|
115
|
-
|
116
|
-
|
116
|
+
fallback_hint_length = character_count_options[:maxwords] || character_count_options[:maxlength]
|
117
|
+
fallback_hint_default = "You can enter up to %<count>s #{character_count_options[:maxwords] ? 'words' : 'characters'}"
|
117
118
|
|
118
|
-
|
119
|
-
|
119
|
+
text = format(fallback_hint[:count_message] || fallback_hint_default, count: fallback_hint_length)
|
120
|
+
classes = "#{fallback_hint[:classes]} govuk-character-count__message".lstrip
|
120
121
|
|
121
|
-
|
122
|
+
@fallback_hint = Hint.new(text: text, classes: classes, attributes: { id: "#{character_count_attribute}-info" }, context: context)
|
123
|
+
end
|
122
124
|
end
|
123
125
|
end
|
124
126
|
end
|
@@ -1,40 +1,42 @@
|
|
1
1
|
require_relative '../input'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
|
8
|
-
|
9
|
-
# This is used for generating the file upload component from the
|
10
|
-
# {https://design-system.service.gov.uk/components/file-upload GDS - Components - File Upload}
|
11
|
-
|
12
|
-
class FileUpload < Input
|
13
|
-
# @param (see CCS::Components::GovUK::Field::Input#initialize)
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Field < Base
|
7
|
+
class Input < Field
|
8
|
+
# = GOV.UK File Upload
|
14
9
|
#
|
15
|
-
#
|
10
|
+
# This is used for generating the file upload component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/file-upload GDS - Components - File Upload}
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
class FileUpload < Input
|
14
|
+
# @param (see CCS::Components::GovUK::Field::Input#initialize)
|
15
|
+
#
|
16
|
+
# @option (see CCS::Components::GovUK::Field::Input#initialize)
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
def initialize(attribute:, **options)
|
19
|
+
super(attribute: attribute, **options)
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
# Generates the HTML for the GOV.UK File Upload component
|
23
|
+
#
|
24
|
+
# @return [ActiveSupport::SafeBuffer]
|
25
|
+
|
26
|
+
def render
|
27
|
+
super() do
|
28
|
+
if options[:form]
|
29
|
+
options[:form].file_field(attribute, **options[:attributes])
|
30
|
+
else
|
31
|
+
context.file_field_tag(attribute, **options[:attributes])
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
35
|
-
|
36
|
+
# The default attributes for the file upload
|
36
37
|
|
37
|
-
|
38
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-file-upload' }.freeze
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|