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
@@ -1,213 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'fieldset'
4
- require_relative 'form_group'
5
- require_relative 'hint'
6
- require_relative 'label'
7
-
8
- module CCS
9
- module FrontendHelpers
10
- module GovUKFrontend
11
- # = GOV.UK Field
12
- #
13
- # This module contains methods to wrap the:
14
- # - fieldset
15
- # - form group
16
- # - label
17
- # - hint
18
- # - error message
19
- # around some kind of input.
20
- #
21
- # The wrapper functions in this module are used
22
- # to create the fields using the structure of a GDS input field component.
23
-
24
- module Field
25
- include Fieldset
26
- include FormGroup
27
- include Hint
28
- include Label
29
-
30
- # Generates the HTML to wrap arround a GDS input field component.
31
- #
32
- # @param field [Symbol] the type of the field
33
- # @param attribute [String, Symbol] the attribute of the field
34
- # @param govuk_field_options [Hash] options that will be used for the parts of the form group, label, hint and field
35
- #
36
- # @option govuk_field_options [String] :error_message (nil) the error message to be displayed
37
- # @option govuk_field_options [ActiveModel] :model (nil) optional model that can be used to find an error message
38
- # @option govuk_field_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
39
- # the field and find the error message
40
- # @option govuk_field_options [Hash] :form_group ({}) the options for govuk_form_group {govuk_form_group}
41
- # @option govuk_field_options [Hash] :label the parameters that will be used to create the label for the field, see {govuk_label}
42
- # @option govuk_field_options [Hash] :hint (nil) the parameters that will be used to create the hint for the field, see {govuk_hint}.
43
- # If no hint is given then no hint will be rendered
44
- # @option govuk_field_options [Hash] :field_options ({}) the options that will be used when rendering the field.
45
- # For more details look at the specific module that uses +Field+.
46
- #
47
- # @yield the field HTML
48
- #
49
- # @yieldparam govuk_field_options [Hash] the HTML options used when rendering the field
50
- # @yieldparam error_message [String] flag to indicate if there are any erros
51
- #
52
- # @return [ActiveSupport::SafeBuffer] the HTML that wraps arround the field
53
-
54
- def govuk_field(field, attribute, **govuk_field_options)
55
- set_label_for_if_custom_id(field, govuk_field_options)
56
- set_hint_id(attribute, govuk_field_options)
57
- error_message = find_field_error_message(attribute, govuk_field_options)
58
-
59
- govuk_form_group(attribute, error_message: error_message, **(govuk_field_options[:form_group] || {})) do |display_error_message|
60
- set_field_described_by(field, attribute, error_message, govuk_field_options)
61
-
62
- concat(govuk_label(attribute, govuk_field_options[:label][:text], form: govuk_field_options[:form], **govuk_field_options[:label]))
63
- concat(govuk_hint(govuk_field_options[:hint][:text], **govuk_field_options[:hint])) if govuk_field_options[:hint]
64
- concat(display_error_message)
65
- yield(govuk_field_options[field], error_message)
66
- end
67
- end
68
-
69
- # Generates the HTML to wrap arround a GDS input fields component.
70
- # These are inputs that require being wrapped in a fieldset, for example radio buttons.
71
- #
72
- # @param field [Symbol] the type of the fields
73
- # @param attribute [String, Symbol] the attribute of the fields
74
- # @param govuk_fields_options [Hash] options that will be used for the parts of the fieldset, form group, hint and fields
75
- #
76
- # @option govuk_fields_options [String] :error_message (nil) the error message to be displayed
77
- # @option govuk_fields_options [ActiveModel] :model (nil) optional model that can be used to find an error message
78
- # @option govuk_fields_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
79
- # the field and find the error message
80
- # @option govuk_fields_options [Hash] :form_group ({}) the options for govuk_form_group {govuk_form_group}
81
- # @option govuk_fields_options [Hash] :fieldset ({}) the options for govuk_fieldset {govuk_fieldset}
82
- # @option govuk_fields_options [Hash] :hint (nil) the parameters that will be used to create the hint for the field, see {govuk_hint}.
83
- # If no hint is given then no hint will be rendered
84
- # @option govuk_fields_options [Hash] :field_options ({}) the options that will be used when rendering the fields.
85
- # For more details look at a module that uses +Field+.
86
- #
87
- # @yield the fields HTML
88
- #
89
- # @yieldparam govuk_fields_options [Hash] the HTML options used when rendering the fields
90
- # @yieldparam error_message [String] flag to indicate if there are any erros
91
- #
92
- # @return [ActiveSupport::SafeBuffer] the HTML that wraps arround the fields
93
-
94
- def govuk_fields(field, attribute, **govuk_fields_options)
95
- set_hint_id(attribute, govuk_fields_options)
96
- error_message = find_field_error_message(attribute, govuk_fields_options)
97
-
98
- govuk_form_group(attribute, error_message: error_message, **(govuk_fields_options[:form_group] || {})) do |display_error_message|
99
- set_field_described_by(:fieldset, attribute, error_message, govuk_fields_options)
100
- (govuk_fields_options[field] ||= {})[:attributes] ||= {}
101
-
102
- govuk_fieldset(**govuk_fields_options[:fieldset]) do
103
- concat(govuk_hint(govuk_fields_options[:hint][:text], **govuk_fields_options[:hint])) if govuk_fields_options[:hint]
104
- concat(display_error_message)
105
- yield(govuk_fields_options[field], error_message)
106
- end
107
- end
108
- end
109
-
110
- private
111
-
112
- # If present, will find the error message for the field
113
- #
114
- # @param attribute [String, Symbol] the attribute of the fields
115
- #
116
- # @option govuk_field_options [String] :error_message (nil) the error message to be displayed
117
- # @option govuk_field_options [ActiveModel] :model (nil) optional model that can be used to find an error message
118
- # @option govuk_field_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
119
- # the field and find the error message
120
- #
121
- # @return [String] the error message
122
-
123
- def find_field_error_message(attribute, govuk_field_options)
124
- if govuk_field_options[:model]
125
- govuk_field_options[:model].errors[attribute].first
126
- elsif govuk_field_options[:form]
127
- govuk_field_options[:form].object.errors[attribute].first
128
- else
129
- govuk_field_options[:error_message]
130
- end
131
- end
132
-
133
- # Sets the label +for+ if a custom ID has been given for the field.
134
- #
135
- # @param govuk_field_options [Hash] see {govuk_field} for details
136
-
137
- def set_label_for_if_custom_id(field, govuk_field_options)
138
- field_id = govuk_field_options.dig(field, :attributes, :id)
139
-
140
- govuk_field_options[:label] ||= {}
141
- (govuk_field_options[:label][:attributes] ||= {})[:for] = field_id if field_id
142
- end
143
-
144
- # Sets the hint ID if there is a hint, and the ID for the hint has not been sent
145
- #
146
- # @param attribute [String, Symbol] the attribute of the field
147
- # @param govuk_field_options [Hash] see {govuk_field} for details
148
-
149
- def set_hint_id(attribute, govuk_field_options)
150
- return if !govuk_field_options[:hint] || govuk_field_options.dig(:hint, :attributes, :id)
151
-
152
- govuk_field_options[:hint] ||= {}
153
- (govuk_field_options[:hint][:attributes] ||= {})[:id] = "#{attribute}-hint"
154
- end
155
-
156
- # Adds the aira-describedby attribute for the field
157
- # if there is a hint or an error message
158
- #
159
- # @param attribute [String, Symbol] the attribute of the input
160
- # @param error_message [String] used to indicate if there is an error
161
- # @param govuk_field_options [Hash] see {#govuk_field} for details
162
-
163
- def set_field_described_by(field, attribute, error_message, govuk_field_options)
164
- aria_described_by = []
165
- aria_described_by << govuk_field_options.dig(field, :attributes, :aria, :describedby)
166
- aria_described_by << govuk_field_options[:hint][:attributes][:id] if govuk_field_options[:hint]
167
- aria_described_by << "#{attribute}-error" if error_message
168
- aria_described_by.compact!
169
-
170
- govuk_field_options[field] ||= {}
171
- govuk_field_options[field][:attributes] ||= {}
172
-
173
- return unless aria_described_by.any?
174
-
175
- (govuk_field_options[field][:attributes][:aria] ||= {})[:describedby] = aria_described_by.join(' ')
176
- end
177
-
178
- # Sets the hint attributes and adds the aira-describedby attribute for a fields item
179
- #
180
- # @param type [String] the type of the item
181
- # @param attribute [String, Symbol] the attribute of the item
182
- # @param item [Hash] the options for that item
183
-
184
- def set_item_options_for_hint(type, attribute, item)
185
- return unless item[:hint]
186
-
187
- (item[:hint] ||= {})[:attributes] ||= {}
188
- item[:hint][:classes] = "govuk-#{type}__hint #{item[:hint][:classes]}".rstrip
189
- item[:hint][:attributes][:id] ||= "#{attribute}_#{item[:value]}-item-hint"
190
-
191
- (item[:attributes][:aria] ||= {})[:describedby] = item[:hint][:attributes][:id]
192
- end
193
-
194
- # Sets the conditional attributes and adds the data-aira-controls attribute for a fields item
195
- #
196
- # @param type [String] the type of the item
197
- # @param attribute [String, Symbol] the attribute of the item
198
- # @param item [Hash] the options for that item
199
-
200
- def set_conditional_item_options(type, attribute, item)
201
- return unless item[:conditional]
202
-
203
- item[:conditional][:attributes] ||= {}
204
- item[:conditional][:attributes][:class] = "govuk-#{type}__conditional #{"govuk-#{type}__conditional--hidden" unless item[:checked]}".rstrip
205
- item[:conditional][:attributes][:id] ||= sanitize_to_id("#{attribute}_#{item[:value]}_conditional")
206
- (item[:attributes][:data] ||= {})[:'aria-controls'] = item[:conditional][:attributes][:id]
207
- end
208
- end
209
- end
210
- end
211
-
212
- ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
213
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CCS
4
- module FrontendHelpers
5
- # This module contains methods that are shared between the helpers
6
-
7
- module SharedMethods
8
- # Initialises the attributes and sets the class attribute for a helper
9
- #
10
- # @param options [Hash] the options for a helper
11
- # @param default_class [String] the default class for a helper
12
-
13
- def initialise_attributes_and_set_classes(options, default_class)
14
- (options[:attributes] ||= {})[:class] = "#{default_class} #{options[:classes]}".rstrip
15
- end
16
-
17
- # Initialises the data-module attribute for a helper
18
- #
19
- # @param options [Hash] the options for a helper
20
- # @param data_module [String] the name of the data module
21
-
22
- def set_data_module(options, data_module)
23
- (options[:attributes][:data] ||= {})[:module] = data_module
24
- end
25
- end
26
- end
27
- end