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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/Gemfile.lock +1 -1
  4. data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
  5. data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
  6. data/lib/ccs/components/ccs/footer/link.rb +41 -39
  7. data/lib/ccs/components/ccs/footer/meta.rb +49 -48
  8. data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
  9. data/lib/ccs/components/ccs/footer.rb +69 -67
  10. data/lib/ccs/components/ccs/header/link.rb +47 -45
  11. data/lib/ccs/components/ccs/header/navigation.rb +85 -84
  12. data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
  13. data/lib/ccs/components/ccs/header.rb +87 -85
  14. data/lib/ccs/components/ccs/logo.rb +36 -34
  15. data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
  16. data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
  17. data/lib/ccs/components/govuk/accordion/section.rb +49 -48
  18. data/lib/ccs/components/govuk/accordion.rb +43 -41
  19. data/lib/ccs/components/govuk/back_link.rb +39 -37
  20. data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
  21. data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
  22. data/lib/ccs/components/govuk/button.rb +83 -81
  23. data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
  24. data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
  25. data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
  26. data/lib/ccs/components/govuk/details.rb +38 -36
  27. data/lib/ccs/components/govuk/error_message.rb +46 -44
  28. data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
  29. data/lib/ccs/components/govuk/error_summary.rb +49 -47
  30. data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
  31. data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
  32. data/lib/ccs/components/govuk/field/input/select.rb +61 -59
  33. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
  34. data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
  35. data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
  36. data/lib/ccs/components/govuk/field/input.rb +46 -44
  37. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
  38. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
  39. data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
  40. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
  41. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
  42. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
  43. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
  44. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
  45. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
  46. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
  47. data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
  48. data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
  49. data/lib/ccs/components/govuk/field/inputs.rb +42 -40
  50. data/lib/ccs/components/govuk/field.rb +90 -88
  51. data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
  52. data/lib/ccs/components/govuk/fieldset.rb +40 -38
  53. data/lib/ccs/components/govuk/footer/link.rb +41 -39
  54. data/lib/ccs/components/govuk/footer/meta.rb +49 -48
  55. data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
  56. data/lib/ccs/components/govuk/footer.rb +105 -103
  57. data/lib/ccs/components/govuk/form_group.rb +45 -43
  58. data/lib/ccs/components/govuk/header/link.rb +41 -39
  59. data/lib/ccs/components/govuk/header/navigation.rb +54 -53
  60. data/lib/ccs/components/govuk/header.rb +84 -82
  61. data/lib/ccs/components/govuk/hint.rb +33 -31
  62. data/lib/ccs/components/govuk/inset_text.rb +39 -37
  63. data/lib/ccs/components/govuk/label.rb +61 -59
  64. data/lib/ccs/components/govuk/notification_banner.rb +83 -81
  65. data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
  66. data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
  67. data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
  68. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
  69. data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
  70. data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
  71. data/lib/ccs/components/govuk/pagination/item.rb +47 -45
  72. data/lib/ccs/components/govuk/pagination.rb +69 -67
  73. data/lib/ccs/components/govuk/panel.rb +49 -47
  74. data/lib/ccs/components/govuk/phase_banner.rb +50 -48
  75. data/lib/ccs/components/govuk/skip_link.rb +39 -37
  76. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
  77. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
  78. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
  82. data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
  83. data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
  84. data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
  85. data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
  86. data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
  87. data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
  88. data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
  89. data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
  90. data/lib/ccs/components/govuk/summary_list/row.rb +47 -45
  91. data/lib/ccs/components/govuk/summary_list.rb +48 -46
  92. data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
  93. data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
  94. data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
  95. data/lib/ccs/components/govuk/table.rb +83 -81
  96. data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
  97. data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
  98. data/lib/ccs/components/govuk/tabs.rb +48 -46
  99. data/lib/ccs/components/govuk/tag.rb +39 -37
  100. data/lib/ccs/components/govuk/warning_text.rb +49 -47
  101. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
  102. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
  103. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
  104. data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
  105. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
  106. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
  107. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
  108. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
  109. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
  110. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
  111. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
  112. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
  113. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
  114. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
  115. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
  116. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
  117. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
  118. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
  119. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
  120. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
  121. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
  122. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
  123. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
  124. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
  125. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
  126. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
  127. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
  128. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
  129. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
  130. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
  131. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
  132. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
  133. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
  134. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
  135. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
  136. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
  137. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
  138. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
  139. data/lib/ccs/frontend_helpers/version.rb +1 -1
  140. metadata +2 -2
@@ -1,78 +1,80 @@
1
1
  require_relative '../input'
2
2
 
3
- module CCS::Components
4
- module GovUK
5
- class Field < Base
6
- class Input < Field
7
- # = GOV.UK Select
8
- #
9
- # This is used for generating the select component from the
10
- # {https://design-system.service.gov.uk/components/select GDS - Components - Select}
11
- #
12
- # @!attribute [r] items
13
- # @return [Array<Hash>] The select items
14
- # @!attribute [r] selected
15
- # @return [String] The selected option
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
- class Select < Input
18
- private
18
+ class Select < Input
19
+ private
19
20
 
20
- attr_reader :items, :selected
21
+ attr_reader :items, :selected
21
22
 
22
- public
23
+ public
23
24
 
24
- # @param (see CCS::Components::GovUK::Field::Input#initialize)
25
- # @param items [Array<Hash>] array of options for select.
26
- # The options are:
27
- # - +:text+ the text of the option item. If this is blank the value is used
28
- # - +:value+ the value of the option item
29
- # - +:attributes+ any additional attributes that will added as part of the option HTML
30
- # @param selected [String] the selected option
31
- #
32
- # @option (see CCS::Components::GovUK::Field::Input#initialize)
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
- def initialize(attribute:, items:, selected: nil, **options)
35
- super(attribute: attribute, **options)
35
+ def initialize(attribute:, items:, selected: nil, **options)
36
+ super(attribute: attribute, **options)
36
37
 
37
- @items = items.map do |item|
38
- [
39
- item[:text] || item[:value],
40
- item[:value],
41
- (item[:attributes] || {})
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
- # Generates the HTML for the GOV.UK Select component
48
- #
49
- # @return [ActiveSupport::SafeBuffer]
48
+ # Generates the HTML for the GOV.UK Select component
49
+ #
50
+ # @return [ActiveSupport::SafeBuffer]
50
51
 
51
- def render
52
- super() do
53
- if options[:form]
54
- options[:form].select(
55
- attribute,
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
- selected
66
- ),
67
- **options[:attributes]
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
- # The default attributes for the select
74
+ # The default attributes for the select
74
75
 
75
- DEFAULT_ATTRIBUTES = { class: 'govuk-select' }.freeze
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::Components
4
- module GovUK
5
- class Field < Base
6
- class Input < Field
7
- class TextInput < Input
8
- # = GOV.UK Text Input prefix/suffix
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
- # @param options [Hash] options that will be used in customising the HTML
11
+ # This is used to generate the prefix/suffix HTML for a text input
26
12
  #
27
- # @option options [String] :classes additional CSS classes for the prefix/suffix HTML
28
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
13
+ # @!attribute [r] text
14
+ # @return [String] Text for the prefix/suffix
29
15
 
30
- def initialize(text:, fix:, **options)
31
- super(**options)
16
+ class Fix < Base
17
+ private
32
18
 
33
- @options[:attributes][:class] = "govuk-input__#{fix}fix #{@options[:attributes][:class]}".rstrip
34
- (@options[:attributes][:aria] ||= {})[:hidden] = true
19
+ attr_reader :text
35
20
 
36
- @text = text
37
- end
21
+ public
38
22
 
39
- # Generates the HTML for the GOV.UK Text Input prefix/suffix
40
- #
41
- # @yield (see CCS::Components::GovUK::Field#render)
42
- #
43
- # @return [ActiveSupport::SafeBuffer]
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
- def render
46
- tag.div(text, **options[:attributes])
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::Components
5
- module GovUK
6
- class Field < Base
7
- class Input < Field
8
- # = GOV.UK Input
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
- # @option (see CCS::Components::GovUK::Field::Input#initialize)
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
- def initialize(attribute:, field_type: :text, value: nil, prefix: nil, suffix: nil, **options)
42
- super(attribute: attribute, **options)
51
+ # rubocop:enable Metrics/ParameterLists
43
52
 
44
- @field_type = :"#{field_type}_field"
45
- @value = @options[:model] ? @options[:model].send(attribute) : value
46
- @prefix = Fix.new(fix: 'pre', context: @context, **prefix) if prefix
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
- # rubocop:enable Metrics/ParameterLists
51
-
52
- # Generates the HTML for the GOV.UK Text Input component
53
- #
54
- # @return [ActiveSupport::SafeBuffer]
55
-
56
- def render
57
- super() do
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
- # The default attributes for the text input
69
+ # The default attributes for the text input
69
70
 
70
- DEFAULT_ATTRIBUTES = { class: 'govuk-input' }.freeze
71
+ DEFAULT_ATTRIBUTES = { class: 'govuk-input' }.freeze
71
72
 
72
- private
73
+ private
73
74
 
74
- # Wrapper method used by {render} to wrap the text input with a prefix or suffix if they exist
75
- #
76
- # @yield the text input HTML
77
- #
78
- # @return [ActiveSupport::SafeBuffer]
79
-
80
- def text_input_wrapper
81
- if prefix || suffix
82
- tag.div(class: 'govuk-input__wrapper') do
83
- concat(prefix.render) if prefix
84
- concat(yield)
85
- concat(suffix.render) if suffix
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::Components
4
- module GovUK
5
- class Field < Base
6
- class Input < Field
7
- # = GOV.UK Textarea
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
- # @option (see CCS::Components::GovUK::Field::Input#initialize)
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
- def initialize(attribute:, content: nil, rows: 5, **options)
29
- super(attribute: attribute, **options)
16
+ class Textarea < Input
17
+ private
30
18
 
31
- @options[:attributes][:rows] ||= rows
19
+ attr_reader :content
32
20
 
33
- @content = @options[:model] ? @options[:model].send(attribute) : content
34
- end
21
+ public
35
22
 
36
- # Generates the HTML for the GOV.UK Textarea component
37
- #
38
- # @return [ActiveSupport::SafeBuffer]
39
-
40
- def render
41
- super() do
42
- if options[:form]
43
- options[:form].text_area(attribute, **options[:attributes])
44
- else
45
- context.text_area_tag(attribute, content, **options[:attributes])
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
- # The default attributes for the textarea
51
+ # The default attributes for the textarea
51
52
 
52
- DEFAULT_ATTRIBUTES = { class: 'govuk-textarea' }.freeze
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::Components
5
- module GovUK
6
- class Field < Base
7
- # = GOV.UK Field Input
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
- # @option (see CCS::Components::GovUK::Field#initialize)
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
- def initialize(attribute:, label:, **options)
31
- super(attribute: attribute, **options)
19
+ class Input < Field
20
+ private
32
21
 
33
- set_described_by(@options, @attribute, @error_message, options[:hint])
22
+ attr_reader :label
34
23
 
35
- @options[:attributes][:class] << " #{self.class::DEFAULT_ATTRIBUTES[:class]}--error" if @error_message
24
+ public
36
25
 
37
- field_id = @options.dig(:attributes, :id)
38
- (label[:attributes] ||= {})[:for] = field_id if field_id
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
- @label = Label.new(attribute: attribute, form: @options[:form], context: @context, **label)
41
- end
31
+ def initialize(attribute:, label:, **options)
32
+ super(attribute: attribute, **options)
42
33
 
43
- # Generates the HTML to wrap arround a GDS form component
44
- #
45
- # @yield (see CCS::Components::GovUK::Field#render)
46
- #
47
- # @return [ActiveSupport::SafeBuffer]
48
-
49
- def render
50
- super() do |display_error_message|
51
- concat(label.render)
52
- concat(hint.render) if hint
53
- concat(display_error_message)
54
- concat(yield)
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