ccs-frontend_helpers 0.1.0 → 0.1.1.rc.1

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 +11 -2
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +4 -1
  5. data/Gemfile +15 -1
  6. data/Gemfile.lock +153 -114
  7. data/ccs-frontend_helpers.gemspec +1 -11
  8. data/lib/ccs/components/base.rb +64 -0
  9. data/lib/ccs/components/ccs/dashboard_section/panel.rb +57 -0
  10. data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
  11. data/lib/ccs/components/ccs/footer/link.rb +55 -0
  12. data/lib/ccs/components/ccs/footer/meta.rb +59 -0
  13. data/lib/ccs/components/ccs/footer/navigation.rb +60 -0
  14. data/lib/ccs/components/ccs/footer.rb +95 -0
  15. data/lib/ccs/components/ccs/header/link.rb +60 -0
  16. data/lib/ccs/components/ccs/header/navigation.rb +98 -0
  17. data/lib/ccs/components/ccs/header/service_authentication.rb +53 -0
  18. data/lib/ccs/components/ccs/header.rb +110 -0
  19. data/lib/ccs/{frontend_helpers/ccs_frontend → components/ccs}/logo.rb +10 -12
  20. data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
  21. data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
  22. data/lib/ccs/components/govuk/accordion/section.rb +61 -0
  23. data/lib/ccs/components/govuk/accordion.rb +58 -0
  24. data/lib/ccs/components/govuk/back_link.rb +51 -0
  25. data/lib/ccs/components/govuk/breadcrumbs/link.rb +57 -0
  26. data/lib/ccs/components/govuk/breadcrumbs.rb +55 -0
  27. data/lib/ccs/components/govuk/button.rb +107 -0
  28. data/lib/ccs/components/govuk/cookie_banner/action.rb +60 -0
  29. data/lib/ccs/components/govuk/cookie_banner/message.rb +80 -0
  30. data/lib/ccs/components/govuk/cookie_banner.rb +55 -0
  31. data/lib/ccs/components/govuk/details.rb +53 -0
  32. data/lib/ccs/components/govuk/error_message.rb +60 -0
  33. data/lib/ccs/components/govuk/error_summary/item.rb +54 -0
  34. data/lib/ccs/components/govuk/error_summary.rb +70 -0
  35. data/lib/ccs/components/govuk/field/input/character_count.rb +129 -0
  36. data/lib/ccs/components/govuk/field/input/file_upload.rb +44 -0
  37. data/lib/ccs/components/govuk/field/input/select.rb +82 -0
  38. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +55 -0
  39. data/lib/ccs/components/govuk/field/input/text_input.rb +97 -0
  40. data/lib/ccs/components/govuk/field/input/textarea.rb +59 -0
  41. data/lib/ccs/components/govuk/field/input.rb +62 -0
  42. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +69 -0
  43. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +65 -0
  44. data/lib/ccs/components/govuk/field/inputs/date_input.rb +89 -0
  45. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +47 -0
  46. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +43 -0
  47. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +50 -0
  48. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +50 -0
  49. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +44 -0
  50. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +43 -0
  51. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +50 -0
  52. data/lib/ccs/components/govuk/field/inputs/item.rb +111 -0
  53. data/lib/ccs/components/govuk/field/inputs/radios.rb +69 -0
  54. data/lib/ccs/components/govuk/field/inputs.rb +57 -0
  55. data/lib/ccs/components/govuk/field.rb +108 -0
  56. data/lib/ccs/components/govuk/fieldset/legend.rb +65 -0
  57. data/lib/ccs/components/govuk/fieldset.rb +54 -0
  58. data/lib/ccs/components/govuk/footer/link.rb +55 -0
  59. data/lib/ccs/components/govuk/footer/meta.rb +59 -0
  60. data/lib/ccs/components/govuk/footer/navigation.rb +60 -0
  61. data/lib/ccs/components/govuk/footer.rb +131 -0
  62. data/lib/ccs/components/govuk/form_group.rb +60 -0
  63. data/lib/ccs/components/govuk/header/link.rb +56 -0
  64. data/lib/ccs/components/govuk/header/navigation.rb +71 -0
  65. data/lib/ccs/components/govuk/header.rb +107 -0
  66. data/lib/ccs/components/govuk/hint.rb +49 -0
  67. data/lib/ccs/components/govuk/inset_text.rb +52 -0
  68. data/lib/ccs/components/govuk/label.rb +85 -0
  69. data/lib/ccs/components/govuk/notification_banner.rb +107 -0
  70. data/lib/ccs/components/govuk/pagination/increment/next.rb +44 -0
  71. data/lib/ccs/components/govuk/pagination/increment/previous.rb +43 -0
  72. data/lib/ccs/components/govuk/pagination/increment.rb +98 -0
  73. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +28 -0
  74. data/lib/ccs/components/govuk/pagination/item/form.rb +49 -0
  75. data/lib/ccs/components/govuk/pagination/item/tag.rb +47 -0
  76. data/lib/ccs/components/govuk/pagination/item.rb +64 -0
  77. data/lib/ccs/components/govuk/pagination.rb +96 -0
  78. data/lib/ccs/components/govuk/panel.rb +62 -0
  79. data/lib/ccs/components/govuk/phase_banner.rb +69 -0
  80. data/lib/ccs/components/govuk/skip_link.rb +51 -0
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +53 -0
  82. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +50 -0
  83. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +45 -0
  84. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +63 -0
  85. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +69 -0
  86. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +56 -0
  87. data/lib/ccs/components/govuk/step_by_step_navigation.rb +59 -0
  88. data/lib/ccs/components/govuk/summary_list/action/link.rb +59 -0
  89. data/lib/ccs/components/govuk/summary_list/card/actions.rb +59 -0
  90. data/lib/ccs/components/govuk/summary_list/card/title.rb +51 -0
  91. data/lib/ccs/components/govuk/summary_list/card.rb +63 -0
  92. data/lib/ccs/components/govuk/summary_list/row/actions.rb +59 -0
  93. data/lib/ccs/components/govuk/summary_list/row/key.rb +47 -0
  94. data/lib/ccs/components/govuk/summary_list/row/value.rb +47 -0
  95. data/lib/ccs/components/govuk/summary_list/row.rb +67 -0
  96. data/lib/ccs/components/govuk/summary_list.rb +74 -0
  97. data/lib/ccs/components/govuk/table/body/data_cell.rb +53 -0
  98. data/lib/ccs/components/govuk/table/body/head_cell.rb +52 -0
  99. data/lib/ccs/components/govuk/table/header/head_cell.rb +54 -0
  100. data/lib/ccs/components/govuk/table.rb +111 -0
  101. data/lib/ccs/components/govuk/tabs/panel.rb +58 -0
  102. data/lib/ccs/components/govuk/tabs/tab.rb +56 -0
  103. data/lib/ccs/components/govuk/tabs.rb +66 -0
  104. data/lib/ccs/components/govuk/tag.rb +51 -0
  105. data/lib/ccs/components/govuk/warning_text.rb +61 -0
  106. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +27 -0
  107. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +6 -119
  108. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +6 -183
  109. data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
  110. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +8 -95
  111. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +6 -17
  112. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +6 -54
  113. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +6 -105
  114. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +28 -0
  115. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +28 -0
  116. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +6 -114
  117. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +28 -0
  118. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +7 -23
  119. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +11 -32
  120. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +13 -65
  121. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +7 -48
  122. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +28 -0
  123. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +6 -161
  124. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +13 -24
  125. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +6 -139
  126. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +8 -17
  127. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +28 -0
  128. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +7 -21
  129. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +7 -70
  130. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +7 -113
  131. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +6 -314
  132. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +7 -28
  133. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +8 -27
  134. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +28 -0
  135. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +28 -0
  136. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +6 -18
  137. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +7 -186
  138. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +6 -204
  139. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +11 -100
  140. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +6 -73
  141. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +7 -21
  142. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +28 -0
  143. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +7 -30
  144. data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
  145. data/lib/ccs/frontend_helpers/version.rb +1 -1
  146. metadata +117 -147
  147. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
  148. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
  149. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
  150. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
  151. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
  152. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
  153. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
  154. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
  155. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
  156. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
  157. data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -0,0 +1,97 @@
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
@@ -0,0 +1,59 @@
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
@@ -0,0 +1,62 @@
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
@@ -0,0 +1,69 @@
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
@@ -0,0 +1,65 @@
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
@@ -0,0 +1,89 @@
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
@@ -0,0 +1,47 @@
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
@@ -0,0 +1,43 @@
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
@@ -0,0 +1,50 @@
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
@@ -0,0 +1,50 @@
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
@@ -0,0 +1,44 @@
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