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,153 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../field'
4
-
5
- module CCS
6
- module FrontendHelpers
7
- module GovUKFrontend
8
- module Field
9
- # = GOV.UK Input
10
- #
11
- # This helper 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
- # This is considered a Field module and so makes use of the methods in {CCS::FrontendHelpers::GovUKFrontend::Field}
15
-
16
- module Input
17
- include Field
18
-
19
- # Generates the HTML for the GOV.UK input component
20
- #
21
- # @param attribute [String, Symbol] the attribute of the input
22
- # @param govuk_input_options [Hash] options that will be used for the parts of the form group, label, hint and input
23
- #
24
- # @option govuk_input_options [String] :error_message (nil) the error message to be displayed
25
- # @option govuk_input_options [ActiveModel] :model (nil) optional model that can be used to find an error message
26
- # @option govuk_label_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
27
- # the input tag and find the error message
28
- # @option govuk_input_options [Hash] :form_group see {govuk_field}
29
- # @option govuk_input_options [Hash] :label see {govuk_field}
30
- # @option govuk_input_options [Hash] :hint see {govuk_field}
31
- # @option govuk_input_options [Hash] :input ({}) the options that will be used when rendering the input.
32
- # See {_govuk_input_field} for more details.
33
- #
34
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Input
35
- # which can then be rendered on the page
36
-
37
- def govuk_input(attribute, **govuk_input_options)
38
- govuk_field(:input, attribute, **govuk_input_options) do |govuk_field_options, error_message|
39
- concat(_govuk_input_field(error_message, **govuk_field_options) do
40
- field_type = get_field_type(govuk_field_options[:field_type])
41
- govuk_field_options[:value] = govuk_input_options[:model].send(attribute) if govuk_input_options[:model]
42
-
43
- if govuk_input_options[:form]
44
- govuk_input_form(govuk_input_options[:form], field_type, attribute, **govuk_field_options)
45
- else
46
- govuk_input_tag(field_type, attribute, **govuk_field_options)
47
- end
48
- end)
49
- end
50
- end
51
-
52
- private
53
-
54
- # Generates the input HTML for {govuk_input}
55
- #
56
- # @param field_type [String] the inout field type
57
- # @param attribute [String, Symbol] the attribute of the input
58
- # @param govuk_text_input_options [Hash] options that will be used in customising the HTML
59
- #
60
- # @option (see _govuk_input_field)
61
- #
62
- # @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {govuk_input}
63
-
64
- def govuk_input_tag(field_type, attribute, **govuk_text_input_options)
65
- send("#{field_type}_tag", attribute, govuk_text_input_options[:value], **govuk_text_input_options[:attributes])
66
- end
67
-
68
- # Generates the input HTML for {govuk_input} when there is a ActionView::Helpers::FormBuilder
69
- #
70
- # @param form [ActionView::Helpers::FormBuilder] the form builder used to create the input tag
71
- # @param (see govuk_input_tag)
72
- #
73
- # @option (see _govuk_input_field)
74
- #
75
- # @return (see govuk_input_tag)
76
-
77
- def govuk_input_form(form, field_type, attribute, **govuk_text_input_options)
78
- form.send(field_type, attribute, **govuk_text_input_options[:attributes])
79
- end
80
-
81
- # Wrapper method used by {govuk_input} to generate the Input HTML
82
- #
83
- # @param error_message [String] used to indicate if there is an error which will add extra classes
84
- # @param govuk_text_input_options [Hash] options that will be used in customising the HTML
85
- #
86
- # @option govuk_text_input_options [String] :classes additional CSS classes for the input HTML
87
- # @option govuk_text_input_options [String] :value (nil) the value of the input
88
- # @option govuk_text_input_options [Symbol] :field_type the type of the input field, see {get_field_type} for options
89
- # @option govuk_text_input_options [Hash] :prefix (nil) optional prefix for the input field. See {govuk_fix} for more details.
90
- # @option govuk_text_input_options [Hash] :suffix (nil) optional suffix for the input field. See {govuk_fix} for more details.
91
- # @option govuk_text_input_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
92
- #
93
- # @yield the input HTML generated by {govuk_input_tag} or {govuk_input_form}
94
- #
95
- # @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used by {govuk_input}
96
-
97
- def _govuk_input_field(error_message, **govuk_text_input_options)
98
- initialise_attributes_and_set_classes(govuk_text_input_options, "govuk-input #{'govuk-input--error' if error_message}".rstrip)
99
-
100
- input_html = yield
101
-
102
- prefix = govuk_text_input_options[:prefix]
103
- suffix = govuk_text_input_options[:suffix]
104
-
105
- if prefix || suffix
106
- tag.div(class: 'govuk-input__wrapper') do
107
- concat(govuk_fix('pre', prefix)) if prefix
108
- concat(input_html)
109
- concat(govuk_fix('suf', suffix)) if suffix
110
- end
111
- else
112
- input_html
113
- end
114
- end
115
-
116
- # Generates the prefix and suffix HTML for {_govuk_input_field}
117
- #
118
- # @param fix [String] either +"pre"+ or +"suf"+
119
- # @param govuk_fix_options [Hash] options that will be used in customising the HTML
120
- #
121
- # @option govuk_fix_options [String] :classes additional CSS classes for the input HTML
122
- # @option govuk_text_input_options [Hash] :attributes ({ aria: { hidden: true } }) any additional attributes that will added as part of the HTML
123
- #
124
- # @return [ActiveSupport::SafeBuffer] the HTML for the input field which is used in {_govuk_input_field}
125
-
126
- def govuk_fix(fix, govuk_fix_options)
127
- initialise_attributes_and_set_classes(govuk_fix_options, "govuk-input__#{fix}fix")
128
-
129
- (govuk_fix_options[:attributes][:aria] ||= {})[:hidden] = true
130
-
131
- tag.div(govuk_fix_options[:text], **govuk_fix_options[:attributes])
132
- end
133
-
134
- # Returns the field type used to create the rails input tag
135
- #
136
- # @param field_type [Symbol] the type of the field, defaults to text
137
- # Allowed values are:
138
- # - +:email+
139
- # - +:password+
140
-
141
- def get_field_type(field_type)
142
- case field_type
143
- when :email, :password
144
- :"#{field_type}_field"
145
- else
146
- :text_field
147
- end
148
- end
149
- end
150
- end
151
- end
152
- end
153
- end
@@ -1,201 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../field'
4
-
5
- module CCS
6
- module FrontendHelpers
7
- module GovUKFrontend
8
- module Field
9
- # = GOV.UK Radios
10
- #
11
- # This helper is used for generating the radios component from the
12
- # {https://design-system.service.gov.uk/components/radios GDS - Components - Radios}
13
- #
14
- # This is considered a Field module and so makes use of the methods in {CCS::FrontendHelpers::GovUKFrontend::Field}
15
-
16
- module Radios
17
- include Field
18
-
19
- # Generates the HTML for the GOV.UK Radios component
20
- #
21
- # @param attribute [String, Symbol] the attribute of the raido buttons
22
- # @param items [Array] array of radio items, see {_govuk_radios_fields}
23
- # @param govuk_radios_options [Hash] options that will be used for the parts of the fieldset, form group, hint and radio buttons
24
- #
25
- # @option govuk_radios_options [String] :error_message (nil) the error message to be displayed
26
- # @option govuk_radios_options [ActiveModel] :model (nil) optional model that can be used to find an error message
27
- # @option govuk_radios_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
28
- # the radio tags and find the error message
29
- # @option govuk_radios_options [Hash] :form_group see {govuk_fields}
30
- # @option govuk_radios_options [Hash] :fieldset see {govuk_fields}
31
- # @option govuk_radios_options [Hash] :hint see {govuk_field}
32
- # @option govuk_radios_options [Hash] :radios ({}) the options that will be used when rendering the radio buttons.
33
- # See {govuk_radio_fields_tag} for more details.
34
- #
35
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Radios
36
- # which can then be rendered on the page
37
-
38
- def govuk_radios(attribute, items, **govuk_radios_options)
39
- govuk_fields(:radios, attribute, **govuk_radios_options) do |govuk_field_options|
40
- if govuk_radios_options[:model] || govuk_radios_options[:form]
41
- value = (govuk_radios_options[:model] || govuk_radios_options[:form].object).send(attribute)
42
- items.each { |item| item[:checked] = item[:value] == value }
43
- end
44
-
45
- concat(
46
- if govuk_radios_options[:form]
47
- govuk_radio_fields_form(govuk_radios_options[:form], attribute, items, **govuk_field_options)
48
- else
49
- govuk_radio_fields_tag(attribute, items, **govuk_field_options)
50
- end
51
- )
52
- end
53
- end
54
-
55
- private
56
-
57
- # Generates the radios HTML for {govuk_radios}
58
- #
59
- # @param attribute [String, Symbol] the attribute of the raido buttons
60
- # @param items [Array] array of radio items, see {_govuk_radios_fields}
61
- # @param govuk_radios_options [Hash] options that will be used in customising the HTML
62
- #
63
- # @option (see _govuk_radios_fields)
64
- #
65
- # @return [ActiveSupport::SafeBuffer] the HTML for the radio buttons which is used in {govuk_radios}
66
-
67
- def govuk_radio_fields_tag(attribute, items, **govuk_radios_options)
68
- _govuk_radios_fields(items, **govuk_radios_options) do |radio_item|
69
- govuk_radio_item_tag(attribute, radio_item)
70
- end
71
- end
72
-
73
- # Generates the radios HTML for {govuk_radios} when there is a ActionView::Helpers::FormBuilder
74
- #
75
- # @param form [ActionView::Helpers::FormBuilder] the form builder used to create the radio buttons
76
- # @param (see govuk_radio_fields_tag)
77
- #
78
- # @option (see _govuk_radios_fields)
79
- #
80
- # @return (see govuk_radio_fields_tag)
81
-
82
- def govuk_radio_fields_form(form, attribute, items, **govuk_radios_options)
83
- _govuk_radios_fields(items, **govuk_radios_options) do |radio_item|
84
- govuk_radio_item_form(form, attribute, radio_item)
85
- end
86
- end
87
-
88
- # Wrapper method used by {govuk_radio_fields_tag} and {govuk_radio_fields_form} to generate the radios HTML
89
- #
90
- # @param items [Array] array of radio items.
91
- # Each item is a hash which can be:
92
- # - +:divider+ text to separate radio items
93
- # - radio item, see {_govuk_radio_item}
94
- # @param govuk_radios_options [Hash] options that will be used in customising the HTML
95
- #
96
- # @option govuk_radios_options [String] :classes additional CSS classes for the radios HTML
97
- # @option govuk_radios_options [Hash] :attributes ({ module: 'govuk-radios' }) any additional attributes that will added as part of the HTML
98
- #
99
- # @yield the radio item HTML generated by {govuk_radio_fields_tag} or {govuk_radio_fields_form}
100
- #
101
- # @yieldparam radio_item [Hash] the current radio item to be rendered
102
- #
103
- # @return [ActiveSupport::SafeBuffer] the HTML for the radio buttons which is used in {govuk_radio_fields_tag} or {govuk_radio_fields_form}
104
-
105
- def _govuk_radios_fields(items, **govuk_radios_options)
106
- initialise_attributes_and_set_classes(govuk_radios_options, 'govuk-radios')
107
- set_data_module(govuk_radios_options, 'govuk-radios')
108
-
109
- tag.div(**govuk_radios_options[:attributes]) do
110
- items.each do |radio_item|
111
- concat(
112
- if radio_item[:divider]
113
- tag.div(radio_item[:divider], class: 'govuk-radios__divider')
114
- else
115
- tag.div(class: 'govuk-radios__item') do
116
- yield(radio_item)
117
- end
118
- end
119
- )
120
- end
121
- end
122
- end
123
-
124
- # Generates the HTML for a radio button for {govuk_radio_fields_form}
125
- #
126
- # @param (see _govuk_radio_item)
127
- #
128
- # @option (see _govuk_radio_item)
129
- #
130
- # @return (see _govuk_radio_item)
131
-
132
- def govuk_radio_item_tag(attribute, radio_item)
133
- _govuk_radio_item(attribute, radio_item) do
134
- label_attribute = radio_item[:attributes][:id] || "#{attribute}[#{radio_item[:value]}]"
135
-
136
- concat(radio_button_tag(attribute, radio_item[:value], radio_item[:checked], **radio_item[:attributes]))
137
- concat(govuk_label(label_attribute, radio_item[:label][:text], **radio_item[:label]))
138
- end
139
- end
140
-
141
- # Generates the HTML for a radio button for {govuk_radio_fields_tag}
142
- #
143
- # @param (see _govuk_radio_item)
144
- # @param form [ActionView::Helpers::FormBuilder] the form builder used to create the radio buttons
145
- #
146
- # @option (see _govuk_radio_item)
147
- #
148
- # @return (see _govuk_radio_item)
149
-
150
- def govuk_radio_item_form(form, attribute, radio_item)
151
- _govuk_radio_item(attribute, radio_item) do
152
- (radio_item[:label][:attributes] ||= {})[:value] = radio_item[:value]
153
- radio_item[:label][:attributes][:for] = radio_item[:attributes][:id] if radio_item[:attributes][:id]
154
-
155
- concat(form.radio_button(attribute, radio_item[:value], **radio_item[:attributes]))
156
- concat(govuk_label(attribute, radio_item[:label][:text], form: form, **radio_item[:label]))
157
- end
158
- end
159
-
160
- # rubocop:disable Metrics/AbcSize
161
-
162
- # Wrapper method used by {govuk_radio_item_tag} and {govuk_radio_item_form} to generate the radios HTML
163
- # including the label and hint, if there is one.
164
- #
165
- # @param attribute [String, Symbol] the attribute of the raido buttons
166
- # @param radio_item [Hash] the options for the radio item
167
- #
168
- # @option radio_item [String] :classes additional CSS classes for the radio button HTML
169
- # @option radio_item [Hash] :label the parameters that will be used to create the label for the radio button, see {govuk_label}
170
- # @option radio_item [Hash] :hint (nil) the parameters that will be used to create the hint for the radio button, see {govuk_hint}.
171
- # If no hint is given then no hint will be rendered
172
- # @option radio_item [Hash] :conditional (nil) content that will appear when the radio button is checked.
173
- # It can have the following options:
174
- # - +[:content]+ the content that will be shown
175
- # - +[:attributes][:id]+ the id of the conditional section
176
- # If no conditional is given then no conditional content will be rendered
177
- # @option radio_item [Hash] :attributes ({}) any additional attributes that will be added as part of the radio button HTML
178
- #
179
- # @return [ActiveSupport::SafeBuffer] the HTML for the radio buttons, label and hint
180
- # which is used in {govuk_radio_item_tag} and {govuk_radio_item_form}
181
-
182
- def _govuk_radio_item(attribute, radio_item)
183
- (radio_item[:attributes] ||= {})[:class] = 'govuk-radios__input'
184
-
185
- radio_item[:label] ||= {}
186
- radio_item[:label][:classes] = "govuk-radios__label #{radio_item[:label][:classes]}".rstrip
187
-
188
- set_item_options_for_hint('radios', attribute, radio_item)
189
- set_conditional_item_options('radios', attribute, radio_item)
190
-
191
- yield
192
- concat(govuk_hint(radio_item[:hint][:text], **radio_item[:hint])) if radio_item[:hint]
193
- concat(tag.div(radio_item[:conditional][:content], class: radio_item[:conditional][:attributes][:class], id: radio_item[:conditional][:attributes][:id])) if radio_item[:conditional]
194
- end
195
-
196
- # rubocop:enable Metrics/AbcSize
197
- end
198
- end
199
- end
200
- end
201
- end
@@ -1,124 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'action_view'
4
- require_relative '../field'
5
-
6
- module CCS
7
- module FrontendHelpers
8
- module GovUKFrontend
9
- module Field
10
- # = GOV.UK Select
11
- #
12
- # This helper is used for generating the select component from the
13
- # {https://design-system.service.gov.uk/components/select GDS - Components - Select}
14
- #
15
- # This is considered a Field module and so makes use of the methods in {CCS::FrontendHelpers::GovUKFrontend::Field}
16
-
17
- module Select
18
- include ActionView::Helpers::FormOptionsHelper
19
- include Field
20
-
21
- # Generates the HTML for the GOV.UK Select component
22
- #
23
- # @param attribute [String, Symbol] the attribute of the select field
24
- # @param items [Array] array of option items for the select, see {govuk_map_select_items}
25
- # @param govuk_select_options [Hash] options that will be used for the parts of the form group, label, hint and select
26
- #
27
- # @option govuk_select_options [String] :error_message (nil) the error message to be displayed
28
- # @option govuk_select_options [ActiveModel] :model (nil) optional model that can be used to find an error message
29
- # @option govuk_select_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
30
- # the select tag and find the error message
31
- # @option govuk_select_options [Hash] :form_group see {govuk_field}
32
- # @option govuk_select_options [Hash] :label see {govuk_field}
33
- # @option govuk_select_options [Hash] :hint see {govuk_field}
34
- # @option govuk_select_options [Hash] :select ({}) the options that will be used when rendering the select field.
35
- # See {govuk_select_tag} for more details.
36
- #
37
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Select
38
- # which can then be rendered on the page
39
-
40
- def govuk_select(attribute, items, **govuk_select_options)
41
- govuk_field(:select, attribute, **govuk_select_options) do |govuk_field_options, error_message|
42
- initialise_attributes_and_set_classes(govuk_field_options, "govuk-select #{'govuk-select--error' if error_message}".rstrip)
43
-
44
- (govuk_select_options[:select] ||= {})[:selected] = govuk_select_options[:model].send(attribute) if govuk_select_options[:model]
45
-
46
- concat(
47
- if govuk_select_options[:form]
48
- govuk_select_form(govuk_select_options[:form], attribute, items, **govuk_field_options)
49
- else
50
- govuk_select_tag(attribute, items, **govuk_field_options)
51
- end
52
- )
53
- end
54
- end
55
-
56
- private
57
-
58
- # Generates the select HTML for {govuk_select}
59
- #
60
- # @param attribute [String, Symbol] the attribute of the select field
61
- # @param items [Array] array of option items for the select, see {govuk_map_select_items}
62
- # @param govuk_select_options [Hash] options that will be used in customising the HTML
63
- #
64
- # @option govuk_select_options [String] :classes additional CSS classes for the select HTML
65
- # @option govuk_select_options [String] :selected (nil) the selected option
66
- # @option govuk_select_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
67
- #
68
- # @return [ActiveSupport::SafeBuffer] the HTML for the select field which is used in {govuk_select}
69
-
70
- def govuk_select_tag(attribute, items, **govuk_select_options)
71
- select_tag(
72
- attribute,
73
- options_for_select(
74
- govuk_map_select_items(items),
75
- govuk_select_options[:selected]
76
- ),
77
- **govuk_select_options[:attributes]
78
- )
79
- end
80
-
81
- # Generates the select HTML for {govuk_select} when there is a ActionView::Helpers::FormBuilder
82
- #
83
- # @param form [ActionView::Helpers::FormBuilder] the form builder used to create the select field
84
- # @param (see govuk_select_tag)
85
- #
86
- # @option (see govuk_select_tag)
87
- #
88
- # @return (see govuk_select_tag)
89
-
90
- def govuk_select_form(form, attribute, items, **govuk_select_options)
91
- form.select(
92
- attribute,
93
- govuk_map_select_items(items),
94
- govuk_select_options[:select_options] || {},
95
- **govuk_select_options[:attributes]
96
- )
97
- end
98
-
99
- # Maps the items into an array that can be used to generate the options for
100
- # {govuk_select_tag} and {govuk_select_form}
101
- #
102
- # @param items [Array] array of option items for the select
103
- #
104
- # @option items [String] :text the text of the option item.
105
- # If this is blank the value is used
106
- # @option items [String] :value the value of the option item
107
- # @option items [Hash] :attributes ({}) any additional attributes that will added as part of the option HTML
108
- #
109
- # @return [Array] array of option params that are used in {govuk_select_tag} and {govuk_select_form}
110
-
111
- def govuk_map_select_items(items)
112
- items.map do |item|
113
- [
114
- item[:text] || item[:value],
115
- item[:value],
116
- (item[:attributes] || {})
117
- ]
118
- end
119
- end
120
- end
121
- end
122
- end
123
- end
124
- end
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../field'
4
-
5
- module CCS
6
- module FrontendHelpers
7
- module GovUKFrontend
8
- module Field
9
- # = GOV.UK Textarea
10
- #
11
- # This helper is used for generating the textarea component from the
12
- # {https://design-system.service.gov.uk/components/textarea GDS - Components - Textarea}
13
- #
14
- # This is considered a Field module and so makes use of the methods in {CCS::FrontendHelpers::GovUKFrontend::Field}
15
-
16
- module Textarea
17
- include Field
18
-
19
- # Generates the HTML for the GOV.UK textarea component
20
- #
21
- # @param attribute [String, Symbol] the attribute of the textarea
22
- # @param govuk_textarea_options [Hash] options that will be used for the parts of the form group, label, hint and textarea
23
- #
24
- # @option govuk_textarea_options [String] :error_message (nil) the error message to be displayed
25
- # @option govuk_textarea_options [ActiveModel] :model (nil) optional model that can be used to find an error message
26
- # @option govuk_textarea_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
27
- # the textarea tag and find the error message
28
- # @option govuk_textarea_options [Hash] :form_group see {govuk_field}
29
- # @option govuk_textarea_options [Hash] :label see {govuk_field}
30
- # @option govuk_textarea_options [Hash] :hint see {govuk_field}
31
- # @option govuk_textarea_options [Hash] :textarea ({}) the options that will be used when rendering the textarea.
32
- # See {set_govuk_textarea_field_options} for more details.
33
- #
34
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK textarea
35
- # which can then be rendered on the page
36
-
37
- def govuk_textarea(attribute, **govuk_textarea_options)
38
- govuk_field(:textarea, attribute, **govuk_textarea_options) do |govuk_field_options, error_message|
39
- set_govuk_textarea_field_options(error_message, govuk_field_options)
40
- (govuk_textarea_options[:textarea] ||= {})[:content] = govuk_textarea_options[:model].send(attribute) if govuk_textarea_options[:model]
41
-
42
- concat(
43
- if govuk_textarea_options[:form]
44
- govuk_textarea_form(govuk_textarea_options[:form], attribute, **govuk_field_options)
45
- else
46
- govuk_textarea_tag(attribute, **govuk_field_options)
47
- end
48
- )
49
- end
50
- end
51
-
52
- private
53
-
54
- # Generates the textarea HTML for {govuk_textarea}
55
- #
56
- # @param attribute [String, Symbol] the attribute of the textarea
57
- # @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
58
- #
59
- # @option (see set_govuk_textarea_field_options)
60
- #
61
- # @return [ActiveSupport::SafeBuffer] the HTML for the textarea field which is used in {govuk_textarea}
62
-
63
- def govuk_textarea_tag(attribute, **govuk_text_textarea_options)
64
- text_area_tag(
65
- attribute,
66
- govuk_text_textarea_options[:content],
67
- **govuk_text_textarea_options[:attributes]
68
- )
69
- end
70
-
71
- # Generates the textarea HTML for {govuk_textarea} when there is a ActionView::Helpers::FormBuilder
72
- #
73
- # @param form [ActionView::Helpers::FormBuilder] the form builder used to create the textarea
74
- # @param (see govuk_textarea_tag)
75
- #
76
- # @option (see set_govuk_textarea_field_options)
77
- #
78
- # @return (see govuk_textarea_tag)
79
-
80
- def govuk_textarea_form(form, attribute, **govuk_text_textarea_options)
81
- form.text_area(
82
- attribute,
83
- **govuk_text_textarea_options[:attributes]
84
- )
85
- end
86
-
87
- # Initialises the attributes for the textarea input
88
- #
89
- # @param error_message [String] used to indicate if there is an error which will add extra classes
90
- # @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
91
- #
92
- # @option govuk_text_textarea_options [String] :classes additional CSS classes for the textarea HTML
93
- # @option govuk_text_textarea_options [String] :content (nil) the content of the textarea
94
- # @option govuk_text_textarea_options [String] :rows (5) the number of rows for the text area
95
- # @option govuk_text_textarea_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
96
-
97
- def set_govuk_textarea_field_options(error_message, govuk_text_textarea_options)
98
- initialise_attributes_and_set_classes(govuk_text_textarea_options, "govuk-textarea #{'govuk-textarea--error' if error_message}".rstrip)
99
-
100
- govuk_text_textarea_options[:attributes][:rows] ||= govuk_text_textarea_options[:rows] || 5
101
- end
102
- end
103
- end
104
- end
105
- end
106
- end