ccs-frontend_helpers 0.1.0.rc.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -5
  3. data/CHANGELOG.md +2 -4
  4. data/Gemfile +1 -15
  5. data/Gemfile.lock +80 -81
  6. data/ccs-frontend_helpers.gemspec +10 -0
  7. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
  8. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +119 -6
  9. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +183 -6
  10. data/lib/ccs/{components/ccs → frontend_helpers/ccs_frontend}/logo.rb +12 -10
  11. data/lib/ccs/frontend_helpers/ccs_frontend.rb +4 -2
  12. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +95 -8
  13. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -6
  14. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +54 -6
  15. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +105 -6
  16. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +114 -6
  17. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +23 -7
  18. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -11
  19. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +65 -13
  20. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
  21. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
  22. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
  23. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
  24. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
  25. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
  26. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
  27. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
  28. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
  29. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +48 -7
  30. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +161 -6
  31. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +24 -13
  32. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +139 -6
  33. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -8
  34. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +21 -7
  35. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +70 -7
  36. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +113 -7
  37. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +314 -6
  38. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +28 -7
  39. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +27 -8
  40. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +18 -6
  41. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +186 -7
  42. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +204 -6
  43. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +100 -11
  44. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +73 -6
  45. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +21 -7
  46. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +30 -7
  47. data/lib/ccs/frontend_helpers/govuk_frontend.rb +19 -17
  48. data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
  49. data/lib/ccs/frontend_helpers/version.rb +1 -1
  50. metadata +142 -112
  51. data/.ruby-version +0 -1
  52. data/lib/ccs/components/base.rb +0 -64
  53. data/lib/ccs/components/ccs/dashboard_section/panel.rb +0 -57
  54. data/lib/ccs/components/ccs/dashboard_section.rb +0 -71
  55. data/lib/ccs/components/ccs/footer/link.rb +0 -55
  56. data/lib/ccs/components/ccs/footer/meta.rb +0 -59
  57. data/lib/ccs/components/ccs/footer/navigation.rb +0 -60
  58. data/lib/ccs/components/ccs/footer.rb +0 -95
  59. data/lib/ccs/components/ccs/header/link.rb +0 -60
  60. data/lib/ccs/components/ccs/header/navigation.rb +0 -98
  61. data/lib/ccs/components/ccs/header/service_authentication.rb +0 -53
  62. data/lib/ccs/components/ccs/header.rb +0 -110
  63. data/lib/ccs/components/govuk/accordion/section/content.rb +0 -53
  64. data/lib/ccs/components/govuk/accordion/section/header.rb +0 -57
  65. data/lib/ccs/components/govuk/accordion/section.rb +0 -61
  66. data/lib/ccs/components/govuk/accordion.rb +0 -58
  67. data/lib/ccs/components/govuk/back_link.rb +0 -51
  68. data/lib/ccs/components/govuk/breadcrumbs/link.rb +0 -57
  69. data/lib/ccs/components/govuk/breadcrumbs.rb +0 -55
  70. data/lib/ccs/components/govuk/button.rb +0 -107
  71. data/lib/ccs/components/govuk/cookie_banner/action.rb +0 -60
  72. data/lib/ccs/components/govuk/cookie_banner/message.rb +0 -80
  73. data/lib/ccs/components/govuk/cookie_banner.rb +0 -55
  74. data/lib/ccs/components/govuk/details.rb +0 -53
  75. data/lib/ccs/components/govuk/error_message.rb +0 -60
  76. data/lib/ccs/components/govuk/error_summary/item.rb +0 -54
  77. data/lib/ccs/components/govuk/error_summary.rb +0 -70
  78. data/lib/ccs/components/govuk/field/input/character_count.rb +0 -129
  79. data/lib/ccs/components/govuk/field/input/file_upload.rb +0 -44
  80. data/lib/ccs/components/govuk/field/input/select.rb +0 -82
  81. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +0 -55
  82. data/lib/ccs/components/govuk/field/input/text_input.rb +0 -97
  83. data/lib/ccs/components/govuk/field/input/textarea.rb +0 -59
  84. data/lib/ccs/components/govuk/field/input.rb +0 -62
  85. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +0 -69
  86. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +0 -65
  87. data/lib/ccs/components/govuk/field/inputs/date_input.rb +0 -89
  88. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +0 -47
  89. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +0 -43
  90. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +0 -50
  91. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +0 -50
  92. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +0 -44
  93. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +0 -43
  94. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +0 -50
  95. data/lib/ccs/components/govuk/field/inputs/item.rb +0 -111
  96. data/lib/ccs/components/govuk/field/inputs/radios.rb +0 -69
  97. data/lib/ccs/components/govuk/field/inputs.rb +0 -57
  98. data/lib/ccs/components/govuk/field.rb +0 -108
  99. data/lib/ccs/components/govuk/fieldset/legend.rb +0 -65
  100. data/lib/ccs/components/govuk/fieldset.rb +0 -54
  101. data/lib/ccs/components/govuk/footer/link.rb +0 -55
  102. data/lib/ccs/components/govuk/footer/meta.rb +0 -59
  103. data/lib/ccs/components/govuk/footer/navigation.rb +0 -60
  104. data/lib/ccs/components/govuk/footer.rb +0 -131
  105. data/lib/ccs/components/govuk/form_group.rb +0 -60
  106. data/lib/ccs/components/govuk/header/link.rb +0 -56
  107. data/lib/ccs/components/govuk/header/navigation.rb +0 -71
  108. data/lib/ccs/components/govuk/header.rb +0 -107
  109. data/lib/ccs/components/govuk/hint.rb +0 -49
  110. data/lib/ccs/components/govuk/inset_text.rb +0 -52
  111. data/lib/ccs/components/govuk/label.rb +0 -85
  112. data/lib/ccs/components/govuk/notification_banner.rb +0 -107
  113. data/lib/ccs/components/govuk/pagination/increment/next.rb +0 -44
  114. data/lib/ccs/components/govuk/pagination/increment/previous.rb +0 -43
  115. data/lib/ccs/components/govuk/pagination/increment.rb +0 -98
  116. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +0 -28
  117. data/lib/ccs/components/govuk/pagination/item/form.rb +0 -49
  118. data/lib/ccs/components/govuk/pagination/item/tag.rb +0 -47
  119. data/lib/ccs/components/govuk/pagination/item.rb +0 -64
  120. data/lib/ccs/components/govuk/pagination.rb +0 -96
  121. data/lib/ccs/components/govuk/panel.rb +0 -62
  122. data/lib/ccs/components/govuk/phase_banner.rb +0 -69
  123. data/lib/ccs/components/govuk/skip_link.rb +0 -51
  124. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +0 -53
  125. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +0 -50
  126. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +0 -45
  127. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +0 -63
  128. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +0 -69
  129. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +0 -56
  130. data/lib/ccs/components/govuk/step_by_step_navigation.rb +0 -59
  131. data/lib/ccs/components/govuk/summary_list/action/link.rb +0 -59
  132. data/lib/ccs/components/govuk/summary_list/card/actions.rb +0 -59
  133. data/lib/ccs/components/govuk/summary_list/card/title.rb +0 -51
  134. data/lib/ccs/components/govuk/summary_list/card.rb +0 -63
  135. data/lib/ccs/components/govuk/summary_list/row/actions.rb +0 -59
  136. data/lib/ccs/components/govuk/summary_list/row/key.rb +0 -47
  137. data/lib/ccs/components/govuk/summary_list/row/value.rb +0 -47
  138. data/lib/ccs/components/govuk/summary_list/row.rb +0 -67
  139. data/lib/ccs/components/govuk/summary_list.rb +0 -74
  140. data/lib/ccs/components/govuk/table/body/data_cell.rb +0 -53
  141. data/lib/ccs/components/govuk/table/body/head_cell.rb +0 -52
  142. data/lib/ccs/components/govuk/table/header/head_cell.rb +0 -54
  143. data/lib/ccs/components/govuk/table.rb +0 -111
  144. data/lib/ccs/components/govuk/tabs/panel.rb +0 -58
  145. data/lib/ccs/components/govuk/tabs/tab.rb +0 -56
  146. data/lib/ccs/components/govuk/tabs.rb +0 -66
  147. data/lib/ccs/components/govuk/tag.rb +0 -51
  148. data/lib/ccs/components/govuk/warning_text.rb +0 -61
  149. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +0 -27
  150. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +0 -28
  151. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +0 -28
  152. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +0 -28
  153. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +0 -28
  154. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +0 -28
  155. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +0 -28
  156. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +0 -28
  157. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +0 -28
@@ -1,97 +0,0 @@
1
- require_relative '../input'
2
- require_relative 'text_input/fix'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- class Field < Base
8
- class Input < Field
9
- # = GOV.UK Input
10
- #
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
50
-
51
- # rubocop:enable Metrics/ParameterLists
52
-
53
- # Generates the HTML for the GOV.UK Text Input component
54
- #
55
- # @return [ActiveSupport::SafeBuffer]
56
-
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
65
- end
66
- end
67
- end
68
-
69
- # The default attributes for the text input
70
-
71
- DEFAULT_ATTRIBUTES = { class: 'govuk-input' }.freeze
72
-
73
- private
74
-
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
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end
96
- end
97
- end
@@ -1,59 +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 Textarea
9
- #
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
15
-
16
- class Textarea < Input
17
- private
18
-
19
- attr_reader :content
20
-
21
- public
22
-
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
48
- end
49
- end
50
-
51
- # The default attributes for the textarea
52
-
53
- DEFAULT_ATTRIBUTES = { class: 'govuk-textarea' }.freeze
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,62 +0,0 @@
1
- require_relative '../field'
2
- require_relative '../label'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- class Field < Base
8
- # = GOV.UK Field Input
9
- #
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
18
-
19
- class Input < Field
20
- private
21
-
22
- attr_reader :label
23
-
24
- public
25
-
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)
30
-
31
- def initialize(attribute:, label:, **options)
32
- super(attribute: attribute, **options)
33
-
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
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,69 +0,0 @@
1
- require_relative '../input'
2
- require_relative 'item/divider'
3
- require_relative 'item/checkbox/form'
4
- require_relative 'item/checkbox/tag'
5
-
6
- module CCS
7
- module Components
8
- module GovUK
9
- class Field < Base
10
- class Inputs < Field
11
- # = GOV.UK Checkboxes
12
- #
13
- # This is used for generating the checkboxes component from the
14
- # {https://design-system.service.gov.uk/components/checkboxes GDS - Components - Checkboxes}
15
- #
16
- # @!attribute [r] checkbox_items
17
- # @return [Array<Item::Divider|Item::Checkbox|Item::Checkbox>] An array of the initialised checkbox items
18
-
19
- class Checkboxes < Inputs
20
- private
21
-
22
- attr_reader :checkbox_items
23
-
24
- public
25
-
26
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
27
-
28
- # @param (see CCS::Components::GovUK::Field::Inputs#initialize)
29
- # @param checkbox_items [Array<Hash>] an array of options for the checkboxes.
30
- # See {Components::GovUK::Field::Inputs::Item::Checkbox#initialize Checkbox#initialize} for details of the items in the array.
31
- #
32
- # @option (see CCS::Components::GovUK::Field::Inputs#initialize)
33
-
34
- def initialize(attribute:, checkbox_items:, **options)
35
- super(attribute: attribute, **options)
36
-
37
- if @options[:model] || @options[:form]
38
- values = (@options[:model] || @options[:form].object).send(attribute) || []
39
- checkbox_items.each { |checkbox_item| checkbox_item[:checked] = values.include?(checkbox_item[:value]) }
40
- end
41
-
42
- checkbox_item_class = @options[:form] ? Item::Checkbox::Form : Inputs::Item::Checkbox::Tag
43
-
44
- @checkbox_items = checkbox_items.map { |checkbox_item| checkbox_item[:divider] ? Item::Divider.new(divider: checkbox_item[:divider], type: 'checkboxes') : checkbox_item_class.new(attribute: attribute, form: @options[:form], context: @context, **checkbox_item) }
45
- end
46
-
47
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
48
-
49
- # Generates the HTML for the GOV.UK Checkboxes component
50
- #
51
- # @return [ActiveSupport::SafeBuffer]
52
-
53
- def render
54
- super() do
55
- tag.div(**options[:attributes]) do
56
- checkbox_items.each { |checkbox_item| concat(checkbox_item.render) }
57
- end
58
- end
59
- end
60
-
61
- # The default attributes for the checkboxes
62
-
63
- DEFAULT_ATTRIBUTES = { class: 'govuk-checkboxes', data: { module: 'govuk-checkboxes' } }.freeze
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,65 +0,0 @@
1
- require_relative '../date_input'
2
- require_relative '../../input/text_input'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- class Field < Base
8
- class Inputs < Field
9
- class DateInput < Inputs
10
- # = GOV.UK Date Inputs item
11
- #
12
- # This is used to generate an individual date input item
13
- #
14
- # @!attribute [r] input
15
- # @return [TextInput] The initialised text input for the date item
16
-
17
- class Item
18
- include ActionView::Context
19
- include ActionView::Helpers
20
-
21
- private
22
-
23
- attr_reader :input
24
-
25
- public
26
-
27
- # rubocop:disable Metrics/ParameterLists
28
-
29
- # @param attribute [String,Symbol] the attribute for the date inputs
30
- # @param name [String] the name of the date input item
31
- # @param input [Hash] options for the input of the date input item, see {CCS::Components::GovUK::Field::Input::TextInput#initialize TextInput#initialize} for more details.
32
- # @param label [Hash] options for the label of the date input item, see {CCS::Components::GovUK::Label#initialize Label#initialize} for more details.
33
- # @param context [ActionView::Base] the view context
34
- #
35
- # @option options [Hash] error_message used as a flag to add the error classes to the item
36
- # @option options [ActiveModel] :model (nil) optional model used to create the field
37
- # @option options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create the field
38
-
39
- def initialize(attribute:, name:, context:, input: {}, label: {}, **options)
40
- input[:classes] = "govuk-date-input__input #{input[:classes]}".rstrip
41
- input[:classes] << ' govuk-input--error' if options[:error_message]
42
- (input[:attributes] ||= {})[:inputmode] ||= 'numeric'
43
-
44
- label[:text] ||= name.capitalize
45
- label[:classes] = 'govuk-date-input__label'
46
-
47
- @input = Input::TextInput.new(attribute: "#{attribute}_#{name}", label: label, model: options[:model], form: options[:form], context: context, **input)
48
- end
49
-
50
- # rubocop:enable Metrics/ParameterLists
51
-
52
- # Generates the HTML for the date input item
53
- #
54
- # @return [ActiveSupport::SafeBuffer]
55
-
56
- def render
57
- tag.div(input.render, class: 'govuk-date-input__item')
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end
@@ -1,89 +0,0 @@
1
- require_relative '../input'
2
- require_relative 'date_input/item'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- class Field < Base
8
- class Inputs < Field
9
- # = GOV.UK Date Input
10
- #
11
- # This is used for generating the date input component from the
12
- # {https://design-system.service.gov.uk/components/date-input GDS - Components - Date Input}
13
- #
14
- # @!attribute [r] date_input_items
15
- # @return [Array<DateInput::Item>] An array of the initialised date input items
16
-
17
- class DateInput < Inputs
18
- private
19
-
20
- attr_reader :date_input_items
21
-
22
- public
23
-
24
- # @param (see CCS::Components::GovUK::Field::Inputs#initialize)
25
- # @param date_items [Array<Hash>] an array of options for the date items.
26
- # See {Components::GovUK::Field::Inputs::DateInput::Item#initialize Item#initialize} for details of the items in the array.
27
- #
28
- # @option (see CCS::Components::GovUK::Field::Inputs#initialize)
29
-
30
- def initialize(attribute:, date_items: default_date_items, **options)
31
- (options[:fieldset][:attributes] ||= {})[:role] = 'group'
32
-
33
- super(attribute: attribute, **options)
34
-
35
- # date_items ||= default_date_items
36
-
37
- @date_input_items = date_items.map { |date_input_item| Item.new(attribute: attribute, error_message: @error_message, model: @options[:model], form: @options[:form], context: @context, **date_input_item) }
38
- end
39
-
40
- # Generates the HTML for the GOV.UK date input component
41
- #
42
- # @return [ActiveSupport::SafeBuffer]
43
-
44
- def render
45
- super() do
46
- tag.div(**options[:attributes]) do
47
- date_input_items.each { |date_input_item| concat(date_input_item.render) }
48
- end
49
- end
50
- end
51
-
52
- # The default attributes for the date input
53
-
54
- DEFAULT_ATTRIBUTES = { class: 'govuk-date-input' }.freeze
55
-
56
- private
57
-
58
- # The default date items used if no date items are provided
59
- #
60
- # @return [Array<Hash>]
61
-
62
- def default_date_items
63
- [
64
- {
65
- name: 'day',
66
- input: {
67
- classes: 'govuk-input--width-2'
68
- }
69
- },
70
- {
71
- name: 'month',
72
- input: {
73
- classes: 'govuk-input--width-2'
74
- }
75
- },
76
- {
77
- name: 'year',
78
- input: {
79
- classes: 'govuk-input--width-4'
80
- }
81
- }
82
- ]
83
- end
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end
@@ -1,47 +0,0 @@
1
- require_relative '../checkbox'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Field < Base
7
- class Inputs < Field
8
- class Item < Base
9
- class Checkbox < Item
10
- # = GOV.UK Field Inputs Checkbox form tag
11
- #
12
- # This is used to generate an individual checkbox item using +form.check_box+
13
-
14
- class Form < Checkbox
15
- # @param (see CCS::Components::GovUK::Field::Items::Item::Checkbox#initialize)
16
- #
17
- # @option (see CCS::Components::GovUK::Field::Items::Item::Checkbox#initialize)
18
-
19
- def initialize(attribute:, label:, **options)
20
- super(attribute: attribute, label: label, **options)
21
-
22
- (label[:attributes] ||= {})[:value] = @value
23
- label[:attributes][:for] = @options[:attributes][:id] if @options[:attributes][:id]
24
-
25
- @options[:attributes][:multiple] = true
26
- @options[:attributes][:include_hidden] = false
27
-
28
- @label = Label.new(attribute: attribute, form: @options[:form], context: @context, **label)
29
- end
30
-
31
- # Generates the HTML for the checkbox input
32
- #
33
- # @return [ActiveSupport::SafeBuffer]
34
-
35
- def render
36
- super() do
37
- @options[:form].check_box(@attribute, @options[:attributes], @value)
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,43 +0,0 @@
1
- require_relative '../checkbox'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Field < Base
7
- class Inputs < Field
8
- class Item < Base
9
- class Checkbox < Item
10
- # = GOV.UK Field Inputs Checkbox tag
11
- #
12
- # This is used to generate an individual checkbox item using +check_box_tag+
13
-
14
- class Tag < Checkbox
15
- # @param (see CCS::Components::GovUK::Field::Items::Item::Checkbox#initialize)
16
- #
17
- # @option (see CCS::Components::GovUK::Field::Items::Item::Checkbox#initialize)
18
-
19
- def initialize(attribute:, label:, **options)
20
- super(attribute: attribute, label: label, **options)
21
-
22
- @options[:attributes][:id] ||= "#{sanitize_to_id(@attribute)}_#{sanitize_to_id(@value)}"
23
-
24
- @label = Label.new(attribute: @options[:attributes][:id], context: @context, **label)
25
- end
26
-
27
- # Generates the HTML for the checkbox input
28
- #
29
- # @return [ActiveSupport::SafeBuffer]
30
-
31
- def render
32
- super() do
33
- context.check_box_tag("#{@attribute}[]", @value, @options[:checked], **@options[:attributes])
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,50 +0,0 @@
1
- require_relative '../item'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Field < Base
7
- class Inputs < Field
8
- class Item < Base
9
- # = GOV.UK Field Inputs Checkbox
10
- #
11
- # This is used to generate an individual checkbox item
12
-
13
- class Checkbox < Item
14
- # @param (see CCS::Components::GovUK::Field::Items::Item#initialize)
15
- # label [Hash] attributes for the checkbox label, see {CCS::Components::GovUK::Label#initialize Label#initialize} for more details.
16
- #
17
- # @option (see CCS::Components::GovUK::Field::Items::Item#initialize))
18
-
19
- def initialize(attribute:, label:, **options)
20
- super(attribute: attribute, **options)
21
-
22
- label[:classes] = "govuk-checkboxes__label #{label[:classes]}".rstrip
23
- end
24
-
25
- # Generates the HTML to wrap arround a checkbox input
26
- #
27
- # @yield the checkbox item input HTML
28
- #
29
- # @return [ActiveSupport::SafeBuffer]
30
-
31
- def render(&block)
32
- tag.div(class: 'govuk-checkboxes__item') do
33
- super(&block)
34
- end
35
- end
36
-
37
- # The default attributes for the checkbox
38
-
39
- DEFAULT_ATTRIBUTES = { class: 'govuk-checkboxes__input' }.freeze
40
-
41
- # The type of the input item
42
-
43
- ITEM_TYPE = 'checkboxes'.freeze
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,50 +0,0 @@
1
- require 'action_view'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Field < Base
7
- class Inputs < Field
8
- class Item < Base
9
- # = GOV.UK Field Inputs item divider
10
- #
11
- # The divider for input items e.g. {CCS::Components::GovUK::Field::Inputs::Checkboxes Checkboxes} or {CCS::Components::GovUK::Field::Inputs::Radios Radios}
12
- #
13
- # @!attribute [r] text
14
- # @return [String] Text for the divider
15
- # @!attribute [r] type
16
- # @return [String] The type of the item
17
-
18
- class Divider
19
- include ActionView::Context
20
- include ActionView::Helpers
21
-
22
- private
23
-
24
- attr_reader :text, :type
25
-
26
- public
27
-
28
- # @param divider [String] the text for the divider
29
- # @param type [String] the type of the item divider.
30
- # One of +'checkboxes'+ or +'radios'+
31
-
32
- def initialize(divider:, type:)
33
- @text = divider
34
- @type = type
35
- end
36
-
37
- # Generates the HTML for an item divider
38
- #
39
- # @return [ActiveSupport::SafeBuffer]
40
-
41
- def render
42
- tag.div(text, class: "govuk-#{type}__divider")
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,44 +0,0 @@
1
- require_relative '../radio'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Field < Base
7
- class Inputs < Field
8
- class Item < Base
9
- class Radio < Item
10
- # = GOV.UK Field Inputs Radio form tag
11
- #
12
- # This is used to generate an individual radio item using +form.check_box+
13
-
14
- class Form < Radio
15
- # @param (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
16
- #
17
- # @option (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
18
-
19
- def initialize(attribute:, label:, **options)
20
- super(attribute: attribute, label: label, **options)
21
-
22
- (label[:attributes] ||= {})[:value] = @value
23
- label[:attributes][:for] = @options[:attributes][:id] if @options[:attributes][:id]
24
-
25
- @label = Label.new(attribute: attribute, form: @options[:form], context: @context, **label)
26
- end
27
-
28
- # Generates the HTML for the radio input
29
- #
30
- # @return [ActiveSupport::SafeBuffer]
31
-
32
- def render
33
- super() do
34
- @options[:form].radio_button(@attribute, @value, **@options[:attributes])
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end