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,78 +1,80 @@
|
|
1
1
|
require_relative '../input'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
class Select < Input
|
19
|
+
private
|
19
20
|
|
20
|
-
|
21
|
+
attr_reader :items, :selected
|
21
22
|
|
22
|
-
|
23
|
+
public
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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)
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
def initialize(attribute:, items:, selected: nil, **options)
|
36
|
+
super(attribute: attribute, **options)
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
43
46
|
end
|
44
|
-
@selected = @options[:model] ? @options[:model].send(attribute) : selected
|
45
|
-
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
# Generates the HTML for the GOV.UK Select component
|
49
|
+
#
|
50
|
+
# @return [ActiveSupport::SafeBuffer]
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
items,
|
57
|
-
{},
|
58
|
-
**options[:attributes]
|
59
|
-
)
|
60
|
-
else
|
61
|
-
context.select_tag(
|
62
|
-
attribute,
|
63
|
-
context.options_for_select(
|
52
|
+
def render
|
53
|
+
super() do
|
54
|
+
if options[:form]
|
55
|
+
options[:form].select(
|
56
|
+
attribute,
|
64
57
|
items,
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
69
71
|
end
|
70
72
|
end
|
71
|
-
end
|
72
73
|
|
73
|
-
|
74
|
+
# The default attributes for the select
|
74
75
|
|
75
|
-
|
76
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-select' }.freeze
|
77
|
+
end
|
76
78
|
end
|
77
79
|
end
|
78
80
|
end
|
@@ -1,49 +1,51 @@
|
|
1
1
|
require_relative '../text_input'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
# This is used to generate the prefix/suffix HTML for a text input
|
11
|
-
#
|
12
|
-
# @!attribute [r] text
|
13
|
-
# @return [String] Text for the prefix/suffix
|
14
|
-
|
15
|
-
class Fix < Base
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :text
|
19
|
-
|
20
|
-
public
|
21
|
-
|
22
|
-
# @param text [String] the text for the prefix/suffix
|
23
|
-
# @param fix [String] either +"pre"+ or +"suf"+
|
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
|
24
10
|
#
|
25
|
-
#
|
11
|
+
# This is used to generate the prefix/suffix HTML for a text input
|
26
12
|
#
|
27
|
-
#
|
28
|
-
#
|
13
|
+
# @!attribute [r] text
|
14
|
+
# @return [String] Text for the prefix/suffix
|
29
15
|
|
30
|
-
|
31
|
-
|
16
|
+
class Fix < Base
|
17
|
+
private
|
32
18
|
|
33
|
-
|
34
|
-
(@options[:attributes][:aria] ||= {})[:hidden] = true
|
19
|
+
attr_reader :text
|
35
20
|
|
36
|
-
|
37
|
-
end
|
21
|
+
public
|
38
22
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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]
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
def render
|
47
|
+
tag.div(text, **options[:attributes])
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -1,91 +1,93 @@
|
|
1
1
|
require_relative '../input'
|
2
2
|
require_relative 'text_input/fix'
|
3
3
|
|
4
|
-
module CCS
|
5
|
-
module
|
6
|
-
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
# This is used for generating the input component from the
|
11
|
-
# {https://design-system.service.gov.uk/components/text-input GDS - Components - Text Input}
|
12
|
-
#
|
13
|
-
# @!attribute [r] field_type
|
14
|
-
# @return [Symbol,String] The input field type
|
15
|
-
# @!attribute [r] value
|
16
|
-
# @return [String] The value of the text input
|
17
|
-
# @!attribute [r] prefix
|
18
|
-
# @return [Fix] The initialised prefix
|
19
|
-
# @!attribute [r] suffix
|
20
|
-
# @return [Fix] The initialised suffix
|
21
|
-
|
22
|
-
class TextInput < Input
|
23
|
-
private
|
24
|
-
|
25
|
-
attr_reader :field_type, :value, :prefix, :suffix
|
26
|
-
|
27
|
-
public
|
28
|
-
|
29
|
-
# rubocop:disable Metrics/ParameterLists
|
30
|
-
|
31
|
-
# @param (see CCS::Components::GovUK::Field::Input#initialize)
|
32
|
-
# @param field_type [Symbol,String] (:text) the input field type
|
33
|
-
# @param value [String] the value if the input
|
34
|
-
# @param prefix [Hash] optional prefix for the input field,
|
35
|
-
# see {CCS::Components::GovUK::Field::Input::TextInput::Fix#initialize Fix#initialize} for more details.
|
36
|
-
# @param suffix [Hash] optional suffix for the input field,
|
37
|
-
# see {CCS::Components::GovUK::Field::Input::TextInput::Fix#initialize Fix#initialize} for more details.
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
class Field < Base
|
8
|
+
class Input < Field
|
9
|
+
# = GOV.UK Input
|
38
10
|
#
|
39
|
-
#
|
11
|
+
# This is used for generating the input component from the
|
12
|
+
# {https://design-system.service.gov.uk/components/text-input GDS - Components - Text Input}
|
13
|
+
#
|
14
|
+
# @!attribute [r] field_type
|
15
|
+
# @return [Symbol,String] The input field type
|
16
|
+
# @!attribute [r] value
|
17
|
+
# @return [String] The value of the text input
|
18
|
+
# @!attribute [r] prefix
|
19
|
+
# @return [Fix] The initialised prefix
|
20
|
+
# @!attribute [r] suffix
|
21
|
+
# @return [Fix] The initialised suffix
|
22
|
+
|
23
|
+
class TextInput < Input
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :field_type, :value, :prefix, :suffix
|
27
|
+
|
28
|
+
public
|
29
|
+
|
30
|
+
# rubocop:disable Metrics/ParameterLists
|
31
|
+
|
32
|
+
# @param (see CCS::Components::GovUK::Field::Input#initialize)
|
33
|
+
# @param field_type [Symbol,String] (:text) the input field type
|
34
|
+
# @param value [String] the value if the input
|
35
|
+
# @param prefix [Hash] optional prefix for the input field,
|
36
|
+
# see {CCS::Components::GovUK::Field::Input::TextInput::Fix#initialize Fix#initialize} for more details.
|
37
|
+
# @param suffix [Hash] optional suffix for the input field,
|
38
|
+
# see {CCS::Components::GovUK::Field::Input::TextInput::Fix#initialize Fix#initialize} for more details.
|
39
|
+
#
|
40
|
+
# @option (see CCS::Components::GovUK::Field::Input#initialize)
|
41
|
+
|
42
|
+
def initialize(attribute:, field_type: :text, value: nil, prefix: nil, suffix: nil, **options)
|
43
|
+
super(attribute: attribute, **options)
|
44
|
+
|
45
|
+
@field_type = :"#{field_type}_field"
|
46
|
+
@value = @options[:model] ? @options[:model].send(attribute) : value
|
47
|
+
@prefix = Fix.new(fix: 'pre', context: @context, **prefix) if prefix
|
48
|
+
@suffix = Fix.new(fix: 'suf', context: @context, **suffix) if suffix
|
49
|
+
end
|
40
50
|
|
41
|
-
|
42
|
-
super(attribute: attribute, **options)
|
51
|
+
# rubocop:enable Metrics/ParameterLists
|
43
52
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
@suffix = Fix.new(fix: 'suf', context: @context, **suffix) if suffix
|
48
|
-
end
|
53
|
+
# Generates the HTML for the GOV.UK Text Input component
|
54
|
+
#
|
55
|
+
# @return [ActiveSupport::SafeBuffer]
|
49
56
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
text_input_wrapper do
|
59
|
-
if options[:form]
|
60
|
-
options[:form].send(field_type, attribute, **options[:attributes])
|
61
|
-
else
|
62
|
-
context.send("#{field_type}_tag", attribute, value, **options[:attributes])
|
57
|
+
def render
|
58
|
+
super() do
|
59
|
+
text_input_wrapper do
|
60
|
+
if options[:form]
|
61
|
+
options[:form].send(field_type, attribute, **options[:attributes])
|
62
|
+
else
|
63
|
+
context.send("#{field_type}_tag", attribute, value, **options[:attributes])
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
66
|
-
end
|
67
68
|
|
68
|
-
|
69
|
+
# The default attributes for the text input
|
69
70
|
|
70
|
-
|
71
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-input' }.freeze
|
71
72
|
|
72
|
-
|
73
|
+
private
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
75
|
+
# Wrapper method used by {render} to wrap the text input with a prefix or suffix if they exist
|
76
|
+
#
|
77
|
+
# @yield the text input HTML
|
78
|
+
#
|
79
|
+
# @return [ActiveSupport::SafeBuffer]
|
80
|
+
|
81
|
+
def text_input_wrapper
|
82
|
+
if prefix || suffix
|
83
|
+
tag.div(class: 'govuk-input__wrapper') do
|
84
|
+
concat(prefix.render) if prefix
|
85
|
+
concat(yield)
|
86
|
+
concat(suffix.render) if suffix
|
87
|
+
end
|
88
|
+
else
|
89
|
+
yield
|
86
90
|
end
|
87
|
-
else
|
88
|
-
yield
|
89
91
|
end
|
90
92
|
end
|
91
93
|
end
|
@@ -1,55 +1,57 @@
|
|
1
1
|
require_relative '../input'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
|
8
|
-
|
9
|
-
# This helper is used for generating the textarea component from the
|
10
|
-
# {https://design-system.service.gov.uk/components/textarea GDS - Components - Textarea}
|
11
|
-
#
|
12
|
-
# @!attribute [r] content
|
13
|
-
# @return [String] The content of the textarea
|
14
|
-
|
15
|
-
class Textarea < Input
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :content
|
19
|
-
|
20
|
-
public
|
21
|
-
|
22
|
-
# @param (see CCS::Components::GovUK::Field::Input#initialize)
|
23
|
-
# @param content [String] the content of the textarea
|
24
|
-
# @param rows [Integer] the number of rows for the text area
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Field < Base
|
7
|
+
class Input < Field
|
8
|
+
# = GOV.UK Textarea
|
25
9
|
#
|
26
|
-
#
|
10
|
+
# This helper is used for generating the textarea component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/textarea GDS - Components - Textarea}
|
12
|
+
#
|
13
|
+
# @!attribute [r] content
|
14
|
+
# @return [String] The content of the textarea
|
27
15
|
|
28
|
-
|
29
|
-
|
16
|
+
class Textarea < Input
|
17
|
+
private
|
30
18
|
|
31
|
-
|
19
|
+
attr_reader :content
|
32
20
|
|
33
|
-
|
34
|
-
end
|
21
|
+
public
|
35
22
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
23
|
+
# @param (see CCS::Components::GovUK::Field::Input#initialize)
|
24
|
+
# @param content [String] the content of the textarea
|
25
|
+
# @param rows [Integer] the number of rows for the text area
|
26
|
+
#
|
27
|
+
# @option (see CCS::Components::GovUK::Field::Input#initialize)
|
28
|
+
|
29
|
+
def initialize(attribute:, content: nil, rows: 5, **options)
|
30
|
+
super(attribute: attribute, **options)
|
31
|
+
|
32
|
+
@options[:attributes][:rows] ||= rows
|
33
|
+
|
34
|
+
@content = @options[:model] ? @options[:model].send(attribute) : content
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates the HTML for the GOV.UK Textarea component
|
38
|
+
#
|
39
|
+
# @return [ActiveSupport::SafeBuffer]
|
40
|
+
|
41
|
+
def render
|
42
|
+
super() do
|
43
|
+
if options[:form]
|
44
|
+
options[:form].text_area(attribute, **options[:attributes])
|
45
|
+
else
|
46
|
+
context.text_area_tag(attribute, content, **options[:attributes])
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
48
|
-
end
|
49
50
|
|
50
|
-
|
51
|
+
# The default attributes for the textarea
|
51
52
|
|
52
|
-
|
53
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-textarea' }.freeze
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -1,57 +1,59 @@
|
|
1
1
|
require_relative '../field'
|
2
2
|
require_relative '../label'
|
3
3
|
|
4
|
-
module CCS
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# This class is used to create a form for an individual field, e.g. text input or select.
|
10
|
-
# It will wrap the input in the form group and:
|
11
|
-
# - display the label
|
12
|
-
# - display the hint (if there is one)
|
13
|
-
# - find and display the error message (if there is one)
|
14
|
-
#
|
15
|
-
# @!attribute [r] label
|
16
|
-
# @return [Label] The initialised label
|
17
|
-
|
18
|
-
class Input < Field
|
19
|
-
private
|
20
|
-
|
21
|
-
attr_reader :label
|
22
|
-
|
23
|
-
public
|
24
|
-
|
25
|
-
# @param (see CCS::Components::GovUK::Field#initialize)
|
26
|
-
# @param label [Hash] attributes for the label, see {CCS::Components::GovUK::Label#initialize Label#initialize} for more details.
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
class Field < Base
|
8
|
+
# = GOV.UK Field Input
|
27
9
|
#
|
28
|
-
#
|
10
|
+
# This class is used to create a form for an individual field, e.g. text input or select.
|
11
|
+
# It will wrap the input in the form group and:
|
12
|
+
# - display the label
|
13
|
+
# - display the hint (if there is one)
|
14
|
+
# - find and display the error message (if there is one)
|
15
|
+
#
|
16
|
+
# @!attribute [r] label
|
17
|
+
# @return [Label] The initialised label
|
29
18
|
|
30
|
-
|
31
|
-
|
19
|
+
class Input < Field
|
20
|
+
private
|
32
21
|
|
33
|
-
|
22
|
+
attr_reader :label
|
34
23
|
|
35
|
-
|
24
|
+
public
|
36
25
|
|
37
|
-
|
38
|
-
|
26
|
+
# @param (see CCS::Components::GovUK::Field#initialize)
|
27
|
+
# @param label [Hash] attributes for the label, see {CCS::Components::GovUK::Label#initialize Label#initialize} for more details.
|
28
|
+
#
|
29
|
+
# @option (see CCS::Components::GovUK::Field#initialize)
|
39
30
|
|
40
|
-
|
41
|
-
|
31
|
+
def initialize(attribute:, label:, **options)
|
32
|
+
super(attribute: attribute, **options)
|
42
33
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
34
|
+
set_described_by(@options, @attribute, @error_message, options[:hint])
|
35
|
+
|
36
|
+
@options[:attributes][:class] << " #{self.class::DEFAULT_ATTRIBUTES[:class]}--error" if @error_message
|
37
|
+
|
38
|
+
field_id = @options.dig(:attributes, :id)
|
39
|
+
(label[:attributes] ||= {})[:for] = field_id if field_id
|
40
|
+
|
41
|
+
@label = Label.new(attribute: attribute, form: @options[:form], context: @context, **label)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Generates the HTML to wrap arround a GDS form component
|
45
|
+
#
|
46
|
+
# @yield (see CCS::Components::GovUK::Field#render)
|
47
|
+
#
|
48
|
+
# @return [ActiveSupport::SafeBuffer]
|
49
|
+
|
50
|
+
def render
|
51
|
+
super() do |display_error_message|
|
52
|
+
concat(label.render)
|
53
|
+
concat(hint.render) if hint
|
54
|
+
concat(display_error_message)
|
55
|
+
concat(yield)
|
56
|
+
end
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|