ccs-frontend_helpers 0.1.0.rc.6 → 0.1.0
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 -5
- data/CHANGELOG.md +1 -4
- data/Gemfile.lock +77 -75
- data/ccs-frontend_helpers.gemspec +1 -1
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +119 -6
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +183 -6
- data/lib/ccs/{components/ccs → frontend_helpers/ccs_frontend}/logo.rb +12 -10
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +4 -2
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +95 -8
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +54 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +105 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +114 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +23 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -11
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +65 -13
- data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +48 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +161 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +24 -13
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +139 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -8
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +21 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +70 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +113 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +314 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +28 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +27 -8
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +18 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +186 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +204 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +102 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +73 -6
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +21 -7
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +30 -7
- data/lib/ccs/frontend_helpers/govuk_frontend.rb +19 -17
- data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +18 -114
- data/.ruby-version +0 -1
- data/lib/ccs/components/base.rb +0 -64
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +0 -57
- data/lib/ccs/components/ccs/dashboard_section.rb +0 -71
- data/lib/ccs/components/ccs/footer/link.rb +0 -55
- data/lib/ccs/components/ccs/footer/meta.rb +0 -59
- data/lib/ccs/components/ccs/footer/navigation.rb +0 -60
- data/lib/ccs/components/ccs/footer.rb +0 -95
- data/lib/ccs/components/ccs/header/link.rb +0 -60
- data/lib/ccs/components/ccs/header/navigation.rb +0 -98
- data/lib/ccs/components/ccs/header/service_authentication.rb +0 -53
- data/lib/ccs/components/ccs/header.rb +0 -110
- data/lib/ccs/components/govuk/accordion/section/content.rb +0 -53
- data/lib/ccs/components/govuk/accordion/section/header.rb +0 -57
- data/lib/ccs/components/govuk/accordion/section.rb +0 -61
- data/lib/ccs/components/govuk/accordion.rb +0 -58
- data/lib/ccs/components/govuk/back_link.rb +0 -51
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +0 -57
- data/lib/ccs/components/govuk/breadcrumbs.rb +0 -55
- data/lib/ccs/components/govuk/button.rb +0 -107
- data/lib/ccs/components/govuk/cookie_banner/action.rb +0 -60
- data/lib/ccs/components/govuk/cookie_banner/message.rb +0 -80
- data/lib/ccs/components/govuk/cookie_banner.rb +0 -55
- data/lib/ccs/components/govuk/details.rb +0 -53
- data/lib/ccs/components/govuk/error_message.rb +0 -60
- data/lib/ccs/components/govuk/error_summary/item.rb +0 -54
- data/lib/ccs/components/govuk/error_summary.rb +0 -70
- data/lib/ccs/components/govuk/field/input/character_count.rb +0 -129
- data/lib/ccs/components/govuk/field/input/file_upload.rb +0 -44
- data/lib/ccs/components/govuk/field/input/select.rb +0 -82
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +0 -55
- data/lib/ccs/components/govuk/field/input/text_input.rb +0 -97
- data/lib/ccs/components/govuk/field/input/textarea.rb +0 -59
- data/lib/ccs/components/govuk/field/input.rb +0 -62
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +0 -69
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +0 -65
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +0 -89
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +0 -47
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +0 -43
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +0 -50
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +0 -50
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +0 -44
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +0 -43
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +0 -50
- data/lib/ccs/components/govuk/field/inputs/item.rb +0 -111
- data/lib/ccs/components/govuk/field/inputs/radios.rb +0 -69
- data/lib/ccs/components/govuk/field/inputs.rb +0 -57
- data/lib/ccs/components/govuk/field.rb +0 -108
- data/lib/ccs/components/govuk/fieldset/legend.rb +0 -65
- data/lib/ccs/components/govuk/fieldset.rb +0 -54
- data/lib/ccs/components/govuk/footer/link.rb +0 -55
- data/lib/ccs/components/govuk/footer/meta.rb +0 -59
- data/lib/ccs/components/govuk/footer/navigation.rb +0 -60
- data/lib/ccs/components/govuk/footer.rb +0 -131
- data/lib/ccs/components/govuk/form_group.rb +0 -60
- data/lib/ccs/components/govuk/header/link.rb +0 -56
- data/lib/ccs/components/govuk/header/navigation.rb +0 -71
- data/lib/ccs/components/govuk/header.rb +0 -107
- data/lib/ccs/components/govuk/hint.rb +0 -49
- data/lib/ccs/components/govuk/inset_text.rb +0 -52
- data/lib/ccs/components/govuk/label.rb +0 -85
- data/lib/ccs/components/govuk/notification_banner.rb +0 -107
- data/lib/ccs/components/govuk/pagination/increment/next.rb +0 -44
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +0 -43
- data/lib/ccs/components/govuk/pagination/increment.rb +0 -98
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +0 -28
- data/lib/ccs/components/govuk/pagination/item/form.rb +0 -49
- data/lib/ccs/components/govuk/pagination/item/tag.rb +0 -47
- data/lib/ccs/components/govuk/pagination/item.rb +0 -64
- data/lib/ccs/components/govuk/pagination.rb +0 -96
- data/lib/ccs/components/govuk/panel.rb +0 -62
- data/lib/ccs/components/govuk/phase_banner.rb +0 -69
- data/lib/ccs/components/govuk/skip_link.rb +0 -51
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +0 -53
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +0 -50
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +0 -45
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +0 -63
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +0 -69
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +0 -56
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +0 -59
- data/lib/ccs/components/govuk/summary_list/action/link.rb +0 -59
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +0 -59
- data/lib/ccs/components/govuk/summary_list/card/title.rb +0 -51
- data/lib/ccs/components/govuk/summary_list/card.rb +0 -63
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +0 -59
- data/lib/ccs/components/govuk/summary_list/row/key.rb +0 -47
- data/lib/ccs/components/govuk/summary_list/row/value.rb +0 -47
- data/lib/ccs/components/govuk/summary_list/row.rb +0 -67
- data/lib/ccs/components/govuk/summary_list.rb +0 -74
- data/lib/ccs/components/govuk/table/body/data_cell.rb +0 -53
- data/lib/ccs/components/govuk/table/body/head_cell.rb +0 -52
- data/lib/ccs/components/govuk/table/header/head_cell.rb +0 -54
- data/lib/ccs/components/govuk/table.rb +0 -111
- data/lib/ccs/components/govuk/tabs/panel.rb +0 -58
- data/lib/ccs/components/govuk/tabs/tab.rb +0 -56
- data/lib/ccs/components/govuk/tabs.rb +0 -66
- data/lib/ccs/components/govuk/tag.rb +0 -51
- data/lib/ccs/components/govuk/warning_text.rb +0 -61
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +0 -27
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +0 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +0 -28
@@ -1,55 +0,0 @@
|
|
1
|
-
require_relative '../base'
|
2
|
-
require_relative 'cookie_banner/message'
|
3
|
-
|
4
|
-
module CCS
|
5
|
-
module Components
|
6
|
-
module GovUK
|
7
|
-
# = GOV.UK Cookie Banner
|
8
|
-
#
|
9
|
-
# This is used to generate the cookie banner component from the
|
10
|
-
# {https://design-system.service.gov.uk/components/cookie-banner GDS - Components - Cookie banner}
|
11
|
-
#
|
12
|
-
# @!attribute [r] messages
|
13
|
-
# @return [Array<Message>] An array of the initialised cookie banner messages
|
14
|
-
|
15
|
-
class CookieBanner < Base
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :messages
|
19
|
-
|
20
|
-
public
|
21
|
-
|
22
|
-
# @param messages [Array<Hash>] An array of messages for the cookie banner.
|
23
|
-
# See {Components::GovUK::CookieBanner::Message#initialize Message#initialize} for details of the items in the array.
|
24
|
-
# @param options [Hash] options that will be used in customising the HTML
|
25
|
-
#
|
26
|
-
# @option options [String] :classes additional CSS classes for the cookie banner HTML
|
27
|
-
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
28
|
-
|
29
|
-
def initialize(messages:, **options)
|
30
|
-
super(**options)
|
31
|
-
|
32
|
-
(@options[:attributes][:data] ||= {})[:nosnippet] = 'true'
|
33
|
-
@options[:attributes][:role] = 'region'
|
34
|
-
(@options[:attributes][:aria] ||= {})[:label] ||= 'Cookie banner'
|
35
|
-
|
36
|
-
@messages = messages.map { |message| Message.new(context: @context, **message) }
|
37
|
-
end
|
38
|
-
|
39
|
-
# Generates the HTML for the GOV.UK Cookie banner component
|
40
|
-
#
|
41
|
-
# @return [ActiveSupport::SafeBuffer]
|
42
|
-
|
43
|
-
def render
|
44
|
-
tag.div(**options[:attributes]) do
|
45
|
-
messages.each { |message| concat(message.render) }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# The default attributes for the cookie banner
|
50
|
-
|
51
|
-
DEFAULT_ATTRIBUTES = { class: 'govuk-cookie-banner' }.freeze
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require_relative '../base'
|
2
|
-
|
3
|
-
module CCS
|
4
|
-
module Components
|
5
|
-
module GovUK
|
6
|
-
# = GOV.UK Details
|
7
|
-
#
|
8
|
-
# This is used to generate the details component from the
|
9
|
-
# {https://design-system.service.gov.uk/components/details GDS - Components - Details}
|
10
|
-
#
|
11
|
-
# @!attribute [r] summary_text
|
12
|
-
# @return [String] Summary text for the details element
|
13
|
-
|
14
|
-
class Details < Base
|
15
|
-
private
|
16
|
-
|
17
|
-
attr_reader :summary_text
|
18
|
-
|
19
|
-
public
|
20
|
-
|
21
|
-
# @param summary_text [String] the summary text for the details element
|
22
|
-
# @param options [Hash] options that will be used in customising the HTML
|
23
|
-
#
|
24
|
-
# @option options [String] :classes additional CSS classes for the details HTML
|
25
|
-
# @option options [Hash] :attributes ({ data: { module: 'govuk-details' } }) any additional attributes that will added as part of the HTML
|
26
|
-
|
27
|
-
def initialize(summary_text:, **options)
|
28
|
-
super(**options)
|
29
|
-
|
30
|
-
@summary_text = summary_text
|
31
|
-
end
|
32
|
-
|
33
|
-
# Generates the HTML for the GOV.UK Details component
|
34
|
-
#
|
35
|
-
# @yield HTML that will be contained within the 'govuk-details__text' div
|
36
|
-
#
|
37
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Details
|
38
|
-
# which can then be rendered on the page
|
39
|
-
|
40
|
-
def render(&block)
|
41
|
-
tag.details(**options[:attributes]) do
|
42
|
-
concat(tag.summary(tag.span(summary_text, class: 'govuk-details__summary-text'), class: 'govuk-details__summary'))
|
43
|
-
concat(tag.div(class: 'govuk-details__text', &block))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# The default attributes for the details
|
48
|
-
|
49
|
-
DEFAULT_ATTRIBUTES = { class: 'govuk-details', data: { module: 'govuk-details' } }.freeze
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require_relative '../base'
|
2
|
-
|
3
|
-
module CCS
|
4
|
-
module Components
|
5
|
-
module GovUK
|
6
|
-
# = GOV.UK Error Message
|
7
|
-
#
|
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
|
17
|
-
|
18
|
-
class ErrorMessage < Base
|
19
|
-
private
|
20
|
-
|
21
|
-
attr_reader :message, :attribute, :visually_hidden_text
|
22
|
-
|
23
|
-
public
|
24
|
-
|
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"
|
37
|
-
|
38
|
-
@message = message
|
39
|
-
@attribute = attribute
|
40
|
-
@visually_hidden_text = @options[:visually_hidden_text] || 'Error'
|
41
|
-
end
|
42
|
-
|
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
|
53
|
-
|
54
|
-
# The default attributes for the error message
|
55
|
-
|
56
|
-
DEFAULT_ATTRIBUTES = { class: 'govuk-error-message' }.freeze
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require_relative '../../base'
|
2
|
-
|
3
|
-
module CCS
|
4
|
-
module Components
|
5
|
-
module GovUK
|
6
|
-
class ErrorSummary < Base
|
7
|
-
# = GOV.UK Error Summary Item
|
8
|
-
#
|
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
|
15
|
-
|
16
|
-
class Item < Base
|
17
|
-
private
|
18
|
-
|
19
|
-
attr_reader :text, :href
|
20
|
-
|
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
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require_relative '../base'
|
2
|
-
require_relative 'error_summary/item'
|
3
|
-
|
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
|
18
|
-
|
19
|
-
class ErrorSummary < Base
|
20
|
-
private
|
21
|
-
|
22
|
-
attr_reader :title, :error_summary_items, :description
|
23
|
-
|
24
|
-
public
|
25
|
-
|
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
|
33
|
-
|
34
|
-
def initialize(title:, error_summary_items:, description: nil, **options)
|
35
|
-
super(**options)
|
36
|
-
|
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
|
41
|
-
|
42
|
-
# rubocop:disable Metrics/AbcSize
|
43
|
-
|
44
|
-
# Generates the HTML for the GOV.UK Error summary component
|
45
|
-
#
|
46
|
-
# @return [ActiveSupport::SafeBuffer]
|
47
|
-
|
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)
|
57
|
-
end)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# rubocop:enable Metrics/AbcSize
|
63
|
-
|
64
|
-
# The default attributes for the error summary
|
65
|
-
|
66
|
-
DEFAULT_ATTRIBUTES = { class: 'govuk-error-summary', data: { module: 'govuk-error-summary' } }.freeze
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
require_relative 'textarea'
|
2
|
-
require_relative '../../hint'
|
3
|
-
|
4
|
-
module CCS
|
5
|
-
module Components
|
6
|
-
module GovUK
|
7
|
-
class Field < Base
|
8
|
-
class Input < Field
|
9
|
-
# = GOV.UK Character count
|
10
|
-
#
|
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}
|
13
|
-
#
|
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
|
22
|
-
|
23
|
-
class CharacterCount
|
24
|
-
include ActionView::Context
|
25
|
-
include ActionView::Helpers
|
26
|
-
|
27
|
-
private
|
28
|
-
|
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)
|
40
|
-
|
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)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Generates the HTML for the GOV.UK Character count component
|
50
|
-
#
|
51
|
-
# @return [ActiveSupport::SafeBuffer]
|
52
|
-
|
53
|
-
def render
|
54
|
-
tag.div(**character_count_html_options) do
|
55
|
-
concat(textarea.render)
|
56
|
-
concat(fallback_hint.render)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
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)
|
70
|
-
|
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)
|
76
|
-
end
|
77
|
-
|
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
|
104
|
-
|
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)
|
112
|
-
|
113
|
-
def initialise_fallback_hint(character_count_attribute, context, character_count_options)
|
114
|
-
fallback_hint = character_count_options[:fallback_hint] || {}
|
115
|
-
|
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'}"
|
118
|
-
|
119
|
-
text = format(fallback_hint[:count_message] || fallback_hint_default, count: fallback_hint_length)
|
120
|
-
classes = "#{fallback_hint[:classes]} govuk-character-count__message".lstrip
|
121
|
-
|
122
|
-
@fallback_hint = Hint.new(text: text, classes: classes, attributes: { id: "#{character_count_attribute}-info" }, context: context)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require_relative '../input'
|
2
|
-
|
3
|
-
module CCS
|
4
|
-
module Components
|
5
|
-
module GovUK
|
6
|
-
class Field < Base
|
7
|
-
class Input < Field
|
8
|
-
# = GOV.UK File Upload
|
9
|
-
#
|
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}
|
12
|
-
|
13
|
-
class FileUpload < Input
|
14
|
-
# @param (see CCS::Components::GovUK::Field::Input#initialize)
|
15
|
-
#
|
16
|
-
# @option (see CCS::Components::GovUK::Field::Input#initialize)
|
17
|
-
|
18
|
-
def initialize(attribute:, **options)
|
19
|
-
super(attribute: attribute, **options)
|
20
|
-
end
|
21
|
-
|
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
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# The default attributes for the file upload
|
37
|
-
|
38
|
-
DEFAULT_ATTRIBUTES = { class: 'govuk-file-upload' }.freeze
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require_relative '../input'
|
2
|
-
|
3
|
-
module CCS
|
4
|
-
module Components
|
5
|
-
module GovUK
|
6
|
-
class Field < Base
|
7
|
-
class Input < Field
|
8
|
-
# = GOV.UK Select
|
9
|
-
#
|
10
|
-
# This is used for generating the select component from the
|
11
|
-
# {https://design-system.service.gov.uk/components/select GDS - Components - Select}
|
12
|
-
#
|
13
|
-
# @!attribute [r] items
|
14
|
-
# @return [Array<Hash>] The select items
|
15
|
-
# @!attribute [r] selected
|
16
|
-
# @return [String] The selected option
|
17
|
-
|
18
|
-
class Select < Input
|
19
|
-
private
|
20
|
-
|
21
|
-
attr_reader :items, :selected
|
22
|
-
|
23
|
-
public
|
24
|
-
|
25
|
-
# @param (see CCS::Components::GovUK::Field::Input#initialize)
|
26
|
-
# @param items [Array<Hash>] array of options for select.
|
27
|
-
# The options are:
|
28
|
-
# - +:text+ the text of the option item. If this is blank the value is used
|
29
|
-
# - +:value+ the value of the option item
|
30
|
-
# - +:attributes+ any additional attributes that will added as part of the option HTML
|
31
|
-
# @param selected [String] the selected option
|
32
|
-
#
|
33
|
-
# @option (see CCS::Components::GovUK::Field::Input#initialize)
|
34
|
-
|
35
|
-
def initialize(attribute:, items:, selected: nil, **options)
|
36
|
-
super(attribute: attribute, **options)
|
37
|
-
|
38
|
-
@items = items.map do |item|
|
39
|
-
[
|
40
|
-
item[:text] || item[:value],
|
41
|
-
item[:value],
|
42
|
-
(item[:attributes] || {})
|
43
|
-
]
|
44
|
-
end
|
45
|
-
@selected = @options[:model] ? @options[:model].send(attribute) : selected
|
46
|
-
end
|
47
|
-
|
48
|
-
# Generates the HTML for the GOV.UK Select component
|
49
|
-
#
|
50
|
-
# @return [ActiveSupport::SafeBuffer]
|
51
|
-
|
52
|
-
def render
|
53
|
-
super() do
|
54
|
-
if options[:form]
|
55
|
-
options[:form].select(
|
56
|
-
attribute,
|
57
|
-
items,
|
58
|
-
{},
|
59
|
-
**options[:attributes]
|
60
|
-
)
|
61
|
-
else
|
62
|
-
context.select_tag(
|
63
|
-
attribute,
|
64
|
-
context.options_for_select(
|
65
|
-
items,
|
66
|
-
selected
|
67
|
-
),
|
68
|
-
**options[:attributes]
|
69
|
-
)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# The default attributes for the select
|
75
|
-
|
76
|
-
DEFAULT_ATTRIBUTES = { class: 'govuk-select' }.freeze
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require_relative '../text_input'
|
2
|
-
|
3
|
-
module CCS
|
4
|
-
module Components
|
5
|
-
module GovUK
|
6
|
-
class Field < Base
|
7
|
-
class Input < Field
|
8
|
-
class TextInput < Input
|
9
|
-
# = GOV.UK Text Input prefix/suffix
|
10
|
-
#
|
11
|
-
# This is used to generate the prefix/suffix HTML for a text input
|
12
|
-
#
|
13
|
-
# @!attribute [r] text
|
14
|
-
# @return [String] Text for the prefix/suffix
|
15
|
-
|
16
|
-
class Fix < Base
|
17
|
-
private
|
18
|
-
|
19
|
-
attr_reader :text
|
20
|
-
|
21
|
-
public
|
22
|
-
|
23
|
-
# @param text [String] the text for the prefix/suffix
|
24
|
-
# @param fix [String] either +"pre"+ or +"suf"+
|
25
|
-
#
|
26
|
-
# @param options [Hash] options that will be used in customising the HTML
|
27
|
-
#
|
28
|
-
# @option options [String] :classes additional CSS classes for the prefix/suffix HTML
|
29
|
-
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
30
|
-
|
31
|
-
def initialize(text:, fix:, **options)
|
32
|
-
super(**options)
|
33
|
-
|
34
|
-
@options[:attributes][:class] = "govuk-input__#{fix}fix #{@options[:attributes][:class]}".rstrip
|
35
|
-
(@options[:attributes][:aria] ||= {})[:hidden] = true
|
36
|
-
|
37
|
-
@text = text
|
38
|
-
end
|
39
|
-
|
40
|
-
# Generates the HTML for the GOV.UK Text Input prefix/suffix
|
41
|
-
#
|
42
|
-
# @yield (see CCS::Components::GovUK::Field#render)
|
43
|
-
#
|
44
|
-
# @return [ActiveSupport::SafeBuffer]
|
45
|
-
|
46
|
-
def render
|
47
|
-
tag.div(text, **options[:attributes])
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|