govuk-design-system-rails 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/app/helpers/govuk_design_system/accordion_helper.rb +7 -0
  3. data/app/helpers/govuk_design_system/back_link_helper.rb +13 -0
  4. data/app/helpers/govuk_design_system/breadcrumbs_helper.rb +7 -0
  5. data/app/helpers/govuk_design_system/button_helper.rb +71 -0
  6. data/app/helpers/govuk_design_system/checkboxes_helper.rb +8 -0
  7. data/app/helpers/govuk_design_system/components_helper.rb +13 -0
  8. data/app/helpers/govuk_design_system/cookie_banner_helper.rb +7 -0
  9. data/app/helpers/govuk_design_system/date_input_helper.rb +8 -0
  10. data/app/helpers/govuk_design_system/details_helper.rb +32 -0
  11. data/app/helpers/govuk_design_system/error_message_helper.rb +7 -0
  12. data/app/helpers/govuk_design_system/error_summary_helper.rb +20 -0
  13. data/app/helpers/govuk_design_system/fieldset_helper.rb +9 -0
  14. data/app/helpers/govuk_design_system/file_upload_helper.rb +59 -0
  15. data/app/helpers/govuk_design_system/header_helper.rb +7 -0
  16. data/app/helpers/govuk_design_system/hint_helper.rb +7 -0
  17. data/app/helpers/govuk_design_system/hmcts_badge_helper.rb +7 -0
  18. data/app/helpers/govuk_design_system/hmcts_banner_helper.rb +7 -0
  19. data/app/helpers/govuk_design_system/input_helper.rb +8 -0
  20. data/app/helpers/govuk_design_system/inset_text_helper.rb +9 -0
  21. data/app/helpers/govuk_design_system/label_helper.rb +7 -0
  22. data/app/helpers/govuk_design_system/notification_banner_helper.rb +8 -0
  23. data/app/helpers/govuk_design_system/phase_banner_helper.rb +21 -0
  24. data/app/helpers/govuk_design_system/radios_helper.rb +8 -0
  25. data/app/helpers/govuk_design_system/select_helper.rb +8 -0
  26. data/app/helpers/govuk_design_system/skip_link_helper.rb +13 -0
  27. data/app/helpers/govuk_design_system/summary_list_helper.rb +7 -0
  28. data/app/helpers/govuk_design_system/tabs_helper.rb +7 -0
  29. data/app/helpers/govuk_design_system/tag_helper.rb +8 -0
  30. data/app/helpers/govuk_design_system/textarea_helper.rb +8 -0
  31. data/app/helpers/govuk_design_system/warning_text_helper.rb +20 -0
  32. data/app/views/components/_govuk_accordion.html.erb +44 -0
  33. data/app/views/components/_govuk_action_link.html.erb +12 -0
  34. data/app/views/components/_govuk_breadcrumbs.html.erb +25 -0
  35. data/app/views/components/_govuk_checkboxes.html.erb +125 -0
  36. data/app/views/components/_govuk_cookie_banner.html.erb +75 -0
  37. data/app/views/components/_govuk_date_input.html.erb +94 -0
  38. data/app/views/components/_govuk_error_message.html.erb +13 -0
  39. data/app/views/components/_govuk_error_summary.html.erb +32 -0
  40. data/app/views/components/_govuk_fieldset.html.erb +21 -0
  41. data/app/views/components/_govuk_header.html.erb +64 -0
  42. data/app/views/components/_govuk_hint.html.erb +7 -0
  43. data/app/views/components/_govuk_hr.html.erb +1 -0
  44. data/app/views/components/_govuk_input.html.erb +97 -0
  45. data/app/views/components/_govuk_inset_text.html.erb +10 -0
  46. data/app/views/components/_govuk_label.html.erb +18 -0
  47. data/app/views/components/_govuk_notification_banner.html.erb +68 -0
  48. data/app/views/components/_govuk_radios.html.erb +141 -0
  49. data/app/views/components/_govuk_select.html.erb +105 -0
  50. data/app/views/components/_govuk_summary_list.html.erb +39 -0
  51. data/app/views/components/_govuk_tabs.html.erb +46 -0
  52. data/app/views/components/_govuk_textarea.html.erb +70 -0
  53. data/app/views/components/_hmcts_banner.html.erb +33 -0
  54. data/app/views/form_components/_govuk_checkboxes.html.erb +21 -0
  55. data/app/views/form_components/_govuk_date_input.html.erb +32 -0
  56. data/app/views/form_components/_govuk_input.html.erb +11 -0
  57. data/app/views/form_components/_govuk_radios.html.erb +24 -0
  58. data/app/views/form_components/_govuk_select.html.erb +25 -0
  59. data/app/views/form_components/_govuk_textarea.html.erb +11 -0
  60. data/lib/govuk-design-system-rails.rb +1 -0
  61. data/lib/govuk_design_system/engine.rb +50 -0
  62. data/lib/govuk_design_system.rb +4 -0
  63. data/spec/dummy/Rakefile +6 -0
  64. data/spec/dummy/app/assets/config/manifest.js +2 -0
  65. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  66. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  67. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  68. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  69. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  70. data/spec/dummy/app/javascript/packs/application.js +15 -0
  71. data/spec/dummy/app/jobs/application_job.rb +7 -0
  72. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  73. data/spec/dummy/app/models/application_record.rb +3 -0
  74. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  75. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  76. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  77. data/spec/dummy/bin/rails +4 -0
  78. data/spec/dummy/bin/rake +4 -0
  79. data/spec/dummy/bin/setup +33 -0
  80. data/spec/dummy/config/application.rb +38 -0
  81. data/spec/dummy/config/boot.rb +5 -0
  82. data/spec/dummy/config/cable.yml +10 -0
  83. data/spec/dummy/config/database.yml +25 -0
  84. data/spec/dummy/config/environment.rb +5 -0
  85. data/spec/dummy/config/environments/development.rb +76 -0
  86. data/spec/dummy/config/environments/production.rb +120 -0
  87. data/spec/dummy/config/environments/test.rb +59 -0
  88. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  89. data/spec/dummy/config/initializers/assets.rb +12 -0
  90. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  91. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  92. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  93. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  94. data/spec/dummy/config/initializers/inflections.rb +16 -0
  95. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  96. data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
  97. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  98. data/spec/dummy/config/locales/en.yml +33 -0
  99. data/spec/dummy/config/puma.rb +43 -0
  100. data/spec/dummy/config/routes.rb +3 -0
  101. data/spec/dummy/config/storage.yml +34 -0
  102. data/spec/dummy/config.ru +6 -0
  103. data/spec/dummy/db/development.sqlite3 +0 -0
  104. data/spec/dummy/db/test.sqlite3 +0 -0
  105. data/spec/dummy/public/404.html +67 -0
  106. data/spec/dummy/public/422.html +67 -0
  107. data/spec/dummy/public/500.html +66 -0
  108. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  109. data/spec/dummy/public/apple-touch-icon.png +0 -0
  110. data/spec/dummy/public/favicon.ico +0 -0
  111. data/spec/dummy/tmp/development_secret.txt +1 -0
  112. data/spec/helpers/govuk_design_system/accordion_helper_spec.rb +353 -0
  113. data/spec/helpers/govuk_design_system/breadcrumbs_helper_spec.rb +90 -0
  114. data/spec/helpers/govuk_design_system/button_helper_spec.rb +34 -0
  115. data/spec/helpers/govuk_design_system/checkboxes_helper_spec.rb +146 -0
  116. data/spec/helpers/govuk_design_system/cookie_banner_helper_spec.rb +65 -0
  117. data/spec/helpers/govuk_design_system/date_input_helper_spec.rb +63 -0
  118. data/spec/helpers/govuk_design_system/details_helper_spec.rb +42 -0
  119. data/spec/helpers/govuk_design_system/error_message_helper_spec.rb +18 -0
  120. data/spec/helpers/govuk_design_system/error_summary_helper_spec.rb +39 -0
  121. data/spec/helpers/govuk_design_system/header_helper_spec.rb +138 -0
  122. data/spec/helpers/govuk_design_system/hint_helper_spec.rb +20 -0
  123. data/spec/helpers/govuk_design_system/hmcts_badge_helper_spec.rb +16 -0
  124. data/spec/helpers/govuk_design_system/hmcts_banner_helper_spec.rb +59 -0
  125. data/spec/helpers/govuk_design_system/input_helper_spec.rb +157 -0
  126. data/spec/helpers/govuk_design_system/inset_text_helper_spec.rb +58 -0
  127. data/spec/helpers/govuk_design_system/label_helper_spec.rb +21 -0
  128. data/spec/helpers/govuk_design_system/notification_banner_helper_spec.rb +98 -0
  129. data/spec/helpers/govuk_design_system/radios_helper_spec.rb +270 -0
  130. data/spec/helpers/govuk_design_system/select_helper_spec.rb +85 -0
  131. data/spec/helpers/govuk_design_system/summary_list_helper_spec.rb +138 -0
  132. data/spec/helpers/govuk_design_system/tabs_helper_spec.rb +129 -0
  133. data/spec/helpers/govuk_design_system/tag_helper_spec.rb +17 -0
  134. data/spec/helpers/govuk_design_system/textarea_helper_spec.rb +67 -0
  135. data/spec/rails_helper.rb +64 -0
  136. data/spec/spec_helper.rb +116 -0
  137. metadata +401 -0
@@ -0,0 +1,141 @@
1
+ <%
2
+ id_prefix = local_assigns[:idPrefix] || local_assigns[:name]
3
+ described_by = ""
4
+ is_conditional = items.any? { |item| item[:conditional] }
5
+ %>
6
+
7
+ <% radios_html = capture do %>
8
+ <% if local_assigns[:hint] %>
9
+ <%
10
+ hint_id = id_prefix + '-hint'
11
+ described_by = described_by.present? ? described_by + ' ' + hint_id : hint_id
12
+ hint_classes = class_names(
13
+ "govuk-hint",
14
+ local_assigns[:hint][:classes]
15
+ )
16
+ %>
17
+ <%= govukHint({
18
+ id: hint_id,
19
+ classes: hint_classes,
20
+ attributes: local_assigns[:hint][:attributes],
21
+ html: local_assigns[:hint][:html],
22
+ text: local_assigns[:hint][:text]
23
+ }) %>
24
+ <% end %>
25
+
26
+ <% radio_classes = class_names(
27
+ "govuk-radios",
28
+ { "govuk-radios--conditional" => is_conditional },
29
+ local_assigns[:classes]
30
+ )
31
+ %>
32
+ <% if local_assigns[:errorMessage] %>
33
+ <%
34
+ error_id = id_prefix + '-error'
35
+ described_by = described_by.blank? ? error_id : "#{described_by} #{error_id}"
36
+ error_attributes = (local_assigns[:errorMessage][:attributes] || {}).merge(id: error_id)
37
+ %>
38
+ <%=
39
+ govukErrorMessage({
40
+ id: error_id,
41
+ classes: local_assigns[:errorMessage][:classes],
42
+ attributes: error_attributes,
43
+ html: local_assigns[:errorMessage][:html],
44
+ text: local_assigns[:errorMessage][:text],
45
+ visuallyHiddenText: local_assigns[:errorMessage][:visuallyHiddenText]
46
+ })
47
+ %>
48
+ <% end %>
49
+ <%
50
+ radio_attributes = {class: radio_classes}.merge!(local_assigns[:attributes] || {})
51
+ .merge!({"data-module" => "govuk-radios"})
52
+ %>
53
+
54
+ <%= tag.div(**radio_attributes) do %>
55
+ <% local_assigns[:items].each_with_index do |item, index| %>
56
+ <%
57
+ id = item[:id] || "#{id_prefix}-#{index + 1}"
58
+ conditional_id = 'conditional-' + id
59
+ %>
60
+ <% if item[:divider] %>
61
+ <div class="govuk-radios__divider">
62
+ <%= item[:divider] %>
63
+ <% else %>
64
+ <%
65
+ has_hint = item[:hint] && (item[:hint][:text] || item[:hint][:html])
66
+ item_hint_id = id + '-item-hint'
67
+ disabled = item
68
+ is_checked = item[:checked] || (!item[:value].nil? && item[:value] == local_assigns[:value])
69
+ input_attributes = {
70
+ id: id,
71
+ name: local_assigns[:name],
72
+ type: "radio",
73
+ value: item[:value],
74
+ class: "govuk-radios__input"
75
+ }
76
+
77
+ input_attributes.merge!({disabled: "disabled"}) if item[:disabled]
78
+ input_attributes.merge!({checked: "checked"}) if is_checked
79
+ input_attributes.merge!({"data-aria-controls" => conditional_id}) if item[:conditional]
80
+ input_attributes.merge!({"aria-describedby" => item_hint_id}) if has_hint
81
+ %>
82
+ <%
83
+ label_classes = class_names(
84
+ 'govuk-radios__label',
85
+ { item[:label].try(:[], :classes) => item[:label] }
86
+ )
87
+ %>
88
+ <div class="govuk-radios__item">
89
+ <%= tag.input(**input_attributes) %>
90
+ <%=
91
+ govukLabel({
92
+ html: item[:html],
93
+ text: item[:text],
94
+ classes: label_classes,
95
+ attributes: item[:label].try(:[], :attributes),
96
+ for: id
97
+ })
98
+ %>
99
+
100
+ <% if has_hint %>
101
+ <% item_hint_classes = class_names('govuk-radios__hint', item.dig(:hint, :classes)) %>
102
+ <%=
103
+ govukHint({
104
+ id: item_hint_id,
105
+ classes: item_hint_classes,
106
+ attributes: item.dig(:hint, :attributes),
107
+ html: item.dig(:hint, :html),
108
+ text: item.dig(:hint, :text)
109
+ })
110
+ %>
111
+ <% end %>
112
+ <% end %>
113
+ </div>
114
+
115
+ <% if item[:conditional] %>
116
+ <% conditional_classes = class_names(
117
+ "govuk-radios__conditional",
118
+ "govuk-radios__conditional--hidden" => !is_checked
119
+ ) %>
120
+
121
+ <%= tag.div(class: conditional_classes, id: conditional_id) do %>
122
+ <%= item[:conditional][:html] %>
123
+ <% end %>
124
+ <% end %>
125
+ <% end %>
126
+ <% end %>
127
+ <% end %>
128
+
129
+ <% form_group_classes = class_names(
130
+ "govuk-form-group",
131
+ local_assigns.dig(:formGroup, :classes),
132
+ "govuk-form-group--error" => local_assigns[:errorMessage]
133
+ ) %>
134
+
135
+ <%= tag.div(class: form_group_classes) do %>
136
+ <% if local_assigns[:fieldset].present? %>
137
+ <%= govukFieldset(classes: local_assigns[:fieldset][:classes], describedBy: described_by, legend: local_assigns[:fieldset][:legend], attributes: local_assigns[:fieldset]) { radios_html } %>
138
+ <% else %>
139
+ <%= radios_html %>
140
+ <% end %>
141
+ <% end %>
@@ -0,0 +1,105 @@
1
+ <%
2
+ described_by = local_assigns[:described_by] || ""
3
+ form_group_classes = class_names(
4
+ "govuk-form-group",
5
+ local_assigns[:formGroup].try(:[], :classes),
6
+ "govuk-form-group--error" => local_assigns[:errorMessage].present?
7
+ )
8
+ select_classes = class_names(
9
+ "govuk-select",
10
+ local_assigns[:classes],
11
+ "govuk-select--error" => local_assigns[:errorMessage].present?
12
+ )
13
+
14
+ select_attributes = {
15
+ class: select_classes,
16
+ id: local_assigns[:id],
17
+ name: local_assigns[:name],
18
+ "aria-describedby": described_by.presence
19
+ }
20
+
21
+ select_attributes.merge!(local_assigns[:attributes]) if local_assigns[:attributes]
22
+ %>
23
+
24
+ <%= tag.div(class: form_group_classes) do %>
25
+ <%=
26
+ govukLabel(
27
+ html: local_assigns[:label].try(:[], :html),
28
+ text: local_assigns[:label].try(:[], :text),
29
+ classes: local_assigns[:label].try(:[], :classes),
30
+ attributes: local_assigns[:label].try(:[], :attributes),
31
+ for: local_assigns[:id])
32
+ %>
33
+
34
+ <% if local_assigns[:hint] %>
35
+ <%
36
+ hint_id = local_assigns.try(:[], :name) + '-hint'
37
+ described_by = described_by.present? ? described_by + ' ' + hint_id : hint_id
38
+ hint_classes = class_names(
39
+ "govuk-hint",
40
+ local_assigns[:hint][:classes]
41
+ )
42
+ %>
43
+ <%= govukHint({
44
+ id: hint_id,
45
+ classes: hint_classes,
46
+ attributes: local_assigns[:hint][:attributes],
47
+ html: local_assigns[:hint][:html],
48
+ text: local_assigns[:hint][:text]
49
+ }) %>
50
+ <% end %>
51
+
52
+ <% if local_assigns[:errorMessage] %>
53
+ <%
54
+ error_id = local_assigns.try(:[], :name) + '-error'
55
+ described_by = described_by.blank? ? error_id : "#{described_by} #{error_id}"
56
+ error_attributes = (local_assigns[:errorMessage][:attributes] || {}).merge(id: error_id)
57
+ %>
58
+ <%=
59
+ govukErrorMessage({
60
+ id: error_id,
61
+ classes: local_assigns[:errorMessage][:classes],
62
+ attributes: error_attributes,
63
+ html: local_assigns[:errorMessage][:html],
64
+ text: local_assigns[:errorMessage][:text],
65
+ visuallyHiddenText: local_assigns[:errorMessage][:visuallyHiddenText]
66
+ })
67
+ %>
68
+ <% end %>
69
+
70
+ <% select = capture do %>
71
+ <%= tag.select(**select_attributes) do %>
72
+ <% local_assigns[:items].each do |item| %>
73
+ <%
74
+ option_attributes = {
75
+ selected: item[:selected] || (!local_assigns[:value].nil? && item[:value] == local_assigns[:value]),
76
+ disabled: item[:disabled],
77
+ value: item[:value]
78
+ }
79
+ item_attributes = (item[:attributes] || {}).merge(option_attributes || {})
80
+ %>
81
+ <%= tag.option(item[:text], **item_attributes) %>
82
+ <% end %>
83
+ <% end %>
84
+ <% end %>
85
+
86
+ <% if local_assigns[:is_autocomplete] %>
87
+ <%= tag.div(class: class_names("autocomplete-select-with-clear" => local_assigns[:show_all_values])) do %>
88
+ <%= select %>
89
+ <% end %>
90
+ <% if local_assigns[:show_all_values] %>
91
+ <button class="autocomplete__clear-button" id="clear-<%= local_assigns[:id] %>" style="display: none;" type="button">
92
+ <span class="govuk-visually-hidden">Clear autocomplete</span>
93
+ <svg class="autocomplete__clear-viewbox" viewbox="0 0 40 40">
94
+ <path class="autocomplete__clear-icon" d="M 10,10 L 30,30 M 30,10 L 10,30"></path>
95
+ </svg>
96
+ </button>
97
+ <% end %>
98
+ <%= javascript_tag nonce: true do -%>
99
+ window.callAutocompleteWhenReady("<%= local_assigns[:id] %>", {showAllValues: "<%= local_assigns[:show_all_values] %>"});
100
+ <% end -%>
101
+ <% else %>
102
+ <%= select %>
103
+ <% end %>
104
+
105
+ <% end %>
@@ -0,0 +1,39 @@
1
+ <%
2
+ any_row_has_actions = local_assigns[:rows].any? { |row| row.dig(:actions, :items)&.any? }
3
+ dl_attributes = {
4
+ class: class_names("govuk-summary-list", local_assigns[:classes]),
5
+ }.merge!(local_assigns[:attributes] || {})
6
+ %>
7
+ <%= tag.dl **dl_attributes do %>
8
+ <% local_assigns[:rows].each do |row| %>
9
+ <% if row %>
10
+ <%
11
+ this_row_has_actions = row.dig(:actions, :items)&.any?
12
+ row_classes = class_names("govuk-summary-list__row", { "govuk-summary-list__row--no-actions" => (any_row_has_actions && !this_row_has_actions) }, row[:classes])
13
+ %>
14
+ <div class="<%= row_classes %>">
15
+ <dt class="<%= class_names("govuk-summary-list__key", row.dig(:key, :classes)) %>">
16
+ <%= row.dig(:key, :html).presence || row.dig(:key, :text) %>
17
+ </dt>
18
+ <dd class="<%= class_names("govuk-summary-list__value", row.dig(:value, :classes)) %>">
19
+ <%= row.dig(:value, :html).presence || row.dig(:value, :text) %>
20
+ </dd>
21
+ <% if row.dig(:actions, :items)&.any? %>
22
+ <dd class="<%= class_names("govuk-summary-list__actions", row.dig(:actions, :classes)) %>">
23
+ <% if row.dig(:actions, :items).size == 1 %>
24
+ <%= render "components/govuk_action_link", **row.dig(:actions, :items).first %>
25
+ <% else %>
26
+ <ul class="govuk-summary-list__actions-list">
27
+ <% row.dig(:actions, :items).each do |action| %>
28
+ <li class="govuk-summary-list__actions-list-item">
29
+ <%= render "components/govuk_action_link", **action %>
30
+ </li>
31
+ <% end %>
32
+ </ul>
33
+ <% end %>
34
+ </dd>
35
+ <% end %>
36
+ </div>
37
+ <% end %>
38
+ <% end %>
39
+ <% end %>
@@ -0,0 +1,46 @@
1
+ <%
2
+ id_prefix = local_assigns[:idPrefix]
3
+ attributes = {
4
+ class: class_names("govuk-tabs", local_assigns[:classes]),
5
+ data: { module: "govuk-tabs" }
6
+ }.merge!(local_assigns[:attributes] || {})
7
+ %>
8
+ <%= tag.div **attributes do %>
9
+ <h2 class="govuk-tabs__title">
10
+ <%= local_assigns[:title] || "Contents" %>
11
+ </h2>
12
+ <% if (items = local_assigns[:items] || []).any? %>
13
+ <ul class="govuk-tabs__list">
14
+ <% items.each_with_index do |item, i| %>
15
+ <% if item %>
16
+ <%
17
+ item_id = item[:id].presence || ([id_prefix, i].join("-"))
18
+ item_classes = class_names("govuk-tabs__list-item", { "govuk-tabs__list-item--selected" => i.zero? })
19
+ link_attributes = item[:attributes] || {}
20
+ link_attributes[:class] = class_names("govuk-tabs__tab", link_attributes[:class])
21
+ %>
22
+ <li class="<%= item_classes %>">
23
+ <%= tag.a item[:label], href: "##{item_id}", **link_attributes %>
24
+ </li>
25
+ <% end %>
26
+ <% end %>
27
+ </ul>
28
+ <% items.each_with_index do |item, i| %>
29
+ <% if item %>
30
+ <%
31
+ item_id = item[:id].presence || ([id_prefix, i].join("-"))
32
+ panel_attributes = {
33
+ class: class_names("govuk-tabs__panel", { "govuk-tabs__panel--hidden" => i.positive? })
34
+ }.merge!(item.dig(:panel, :attributes) || {})
35
+ %>
36
+ <%= tag.div(id: item_id, **panel_attributes) do %>
37
+ <% if (html_content = item.dig(:panel, :html).presence) %>
38
+ <%= html_content %>
39
+ <% else %>
40
+ <p class="govuk-body"><%= item.dig(:panel, :text) %></p>
41
+ <% end %>
42
+ <% end %>
43
+ <% end %>
44
+ <% end %>
45
+ <% end %>
46
+ <% end %>
@@ -0,0 +1,70 @@
1
+ <% described_by = "" %>
2
+
3
+ <%
4
+ form_classes = class_names(
5
+ "govuk-form-group",
6
+ { "govuk-form-group--error" => local_assigns[:errorMessage] },
7
+ local_assigns[:formGroup].try(:[], :classes)
8
+ )
9
+ %>
10
+
11
+ <% text_area_class = class_names(
12
+ "govuk-textarea",
13
+ { "govuk-textarea--error" => local_assigns[:errorMessage] },
14
+ local_assigns[:classes]
15
+ )
16
+ %>
17
+
18
+ <%= tag.div(class: form_classes) do %>
19
+ <%=
20
+ govukLabel({
21
+ html: local_assigns[:label][:html],
22
+ text: local_assigns[:label][:text],
23
+ classes: local_assigns[:label][:classes],
24
+ isPageHeading: local_assigns[:label][:isPageHeading],
25
+ attributes: local_assigns[:label][:attributes],
26
+ for: local_assigns[:id]
27
+ })
28
+ %>
29
+
30
+ <% if local_assigns[:hint] %>
31
+ <% hintId = local_assigns[:id].to_s + '-hint' %>
32
+ <% described_by = described_by.blank? ? hintId : described_by + ' ' + hintId %>
33
+ <%= govukHint({
34
+ id: hintId,
35
+ classes: local_assigns[:hint][:classes],
36
+ attributes: local_assigns[:hint][:attributes],
37
+ html: local_assigns[:hint][:html],
38
+ text: local_assigns[:hint][:text]
39
+ }) %>
40
+ <% end %>
41
+
42
+ <% if local_assigns[:errorMessage] %>
43
+ <% errorId = local_assigns[:id].to_s + '-error' %>
44
+ <% described_by = described_by.blank? ? errorId : described_by + ' ' + errorId %>
45
+ <% attributes = local_assigns[:errorMessage][:attributes] || {} %>
46
+ <%= govukErrorMessage({
47
+ id: errorId,
48
+ classes: local_assigns[:errorMessage][:classes],
49
+ attributes: attributes.merge({id: errorId}),
50
+ html: local_assigns[:errorMessage][:html],
51
+ text: local_assigns[:errorMessage][:text],
52
+ visuallyHiddenText: local_assigns[:errorMessage][:visuallyHiddenText]
53
+ }) %>
54
+ <% end %>
55
+
56
+ <%
57
+ rows = local_assigns[:rows] || 5
58
+ text_area_attributes = {
59
+ class: text_area_class,
60
+ id: local_assigns[:id],
61
+ name: local_assigns[:name],
62
+ key: local_assigns[:key],
63
+ rows: rows,
64
+ "aria-describedby" => described_by,
65
+ }.merge!(local_assigns[:attributes] || {})
66
+ text_area_attributes[:autocomplete] = local_assigns[:autocomplete] if local_assigns[:autocomplete].present?
67
+ %>
68
+
69
+ <%= tag.textarea(local_assigns[:value], **text_area_attributes) %>
70
+ <% end %>
@@ -0,0 +1,33 @@
1
+ <%
2
+ banner_type = local_assigns[:type]&.to_s
3
+ banner_classes = class_names(
4
+ "hmcts-banner",
5
+ local_assigns[:classes],
6
+ { "hmcts-banner--#{banner_type}" => banner_type != "information" }
7
+ )
8
+ %>
9
+ <%= tag.div(class: banner_classes) do %>
10
+ <div class="hmcts-banner__message">
11
+ <% if local_assigns[:iconFallbackText] %>
12
+ <span class="hmcts-banner__assistive">
13
+ <%= local_assigns[:iconFallbackText] %>
14
+ </span>
15
+ <% end %>
16
+ <%= local_assigns[:html] || local_assigns[:text] %>
17
+ <% if banner_type == "success" %>
18
+ <svg class="hmcts-banner__icon" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 25 25" height="25" width="25">
19
+ <path d="M25,6.2L8.7,23.2L0,14.1l4-4.2l4.7,4.9L21,2L25,6.2z"></path>
20
+ </svg>
21
+ <% end %>
22
+ <% if banner_type == "warning" %>
23
+ <svg class="hmcts-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25">
24
+ <path d="M25,6.2L8.7,23.2L0,14.1l4-4.2l4.7,4.9L21,2L25,6.2z"></path>
25
+ </svg>
26
+ <% end %>
27
+ <% if banner_type == "information" %>
28
+ <svg class="hmcts-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25">
29
+ <path d="M13.7,18.5h-2.4v-2.4h2.4V18.5z M12.5,13.7c-0.7,0-1.2-0.5-1.2-1.2V7.7c0-0.7,0.5-1.2,1.2-1.2s1.2,0.5,1.2,1.2v4.8 C13.7,13.2,13.2,13.7,12.5,13.7z M12.5,0.5c-6.6,0-12,5.4-12,12s5.4,12,12,12s12-5.4,12-12S19.1,0.5,12.5,0.5z"></path>
30
+ </svg>
31
+ <% end %>
32
+ </div>
33
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <%
2
+ # NOTE: Give items ids based on rails' convention
3
+ local_assigns[:idPrefix] ||= get_attribute_id_prefix(form, key) if local_assigns[:key]
4
+ local_assigns[:items].each do |item|
5
+ item[:id] ||= get_attribute_id_prefix(form, item[:key] || local_assigns[:name])
6
+ item[:value] ||= "1"
7
+ item[:name] ||= get_attribute_name(form, item[:key] || local_assigns[:name])
8
+ end
9
+ if form.object
10
+ local_assigns[:items].each do |item|
11
+ if form.object.respond_to?(item[:key])
12
+ item[:checked] = form.object.send(item[:key]) == item[:value]
13
+ end
14
+ end
15
+ if form.object.errors
16
+ error_text = form.object.errors.full_messages_for(key).first.presence
17
+ local_assigns[:errorMessage] ||= { text: error_text } if error_text
18
+ end
19
+ end
20
+ %>
21
+ <%= render "components/govuk_checkboxes", **local_assigns %>
@@ -0,0 +1,32 @@
1
+ <%
2
+ # Infer name and id_prefix from attribute key
3
+ local_assigns[:id] ||= get_attribute_id_prefix(form, key)
4
+ errors = form.object.errors
5
+ date_errors = errors.full_messages_for(key.to_sym)
6
+ day_errors = errors.full_messages_for("#{key}_day".to_sym)
7
+ month_errors = errors.full_messages_for("#{key}_month".to_sym)
8
+ year_errors = errors.full_messages_for("#{key}_year".to_sym)
9
+ local_assigns[:items] = [
10
+ {
11
+ label: "day",
12
+ classes: "govuk-input--width-2 #{'govuk-input--error' if day_errors.any? || date_errors.any?}",
13
+ value: form.object.send(:get_day, key),
14
+ name: "#{get_attribute_name(form, key)}[day]"
15
+ },
16
+ {
17
+ label: "month",
18
+ classes: "govuk-input--width-2 #{'govuk-input--error' if month_errors.any? || date_errors.any?}",
19
+ value: form.object.send(:get_month, key),
20
+ name: "#{get_attribute_name(form, key)}[month]"
21
+ },
22
+ {
23
+ label: "year",
24
+ classes: "govuk-input--width-4 #{'govuk-input--error' if year_errors.any? || date_errors.any?}",
25
+ value: form.object.send(:get_year, key),
26
+ name: "#{get_attribute_name(form, key)}[year]"
27
+ }
28
+ ]
29
+ error_text = errors.full_messages_for(key).first.presence
30
+ local_assigns[:errorMessage] ||= { text: error_text } if error_text
31
+ %>
32
+ <%= render "components/govuk_date_input", **local_assigns %>
@@ -0,0 +1,11 @@
1
+ <%
2
+ # Infer name and id_prefix from attribute key
3
+ local_assigns[:name] ||= get_attribute_name(form, key)
4
+ local_assigns[:id] ||= get_attribute_id_prefix(form, key)
5
+ local_assigns[:value] ||= form.object.send(key) if form.object.respond_to?(key)
6
+ unless form.object.nil?
7
+ error_text = form.object.errors.full_messages_for(key).first.presence
8
+ local_assigns[:errorMessage] ||= { text: error_text } if error_text
9
+ end
10
+ %>
11
+ <%= render "components/govuk_input", **local_assigns %>
@@ -0,0 +1,24 @@
1
+ <%
2
+ # Infer name and id_prefix from attribute key
3
+ local_assigns[:name] ||= get_attribute_name(form, key)
4
+ local_assigns[:idPrefix] ||= get_attribute_id_prefix(form, key)
5
+ #Give items ids based on rails' convention
6
+ local_assigns[:items].each do |item|
7
+ #sanitization taken from https://github.com/rails/rails/
8
+ # blob/7caea98e189c02721b2e944a074c405b033852eb/actionview/lib/action_view/helpers/tags/base.rb#L140
9
+ value = item[:value].to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase.to_s
10
+ item[:id] ||= "#{local_assigns[:idPrefix]}_#{value}"
11
+ end
12
+ if form.object.respond_to?(key)
13
+ # Make item checked based on attribute value
14
+ item_matching_state = items.find do |item|
15
+ !item[:divider] && item[:value].to_s == form.object.public_send(key).to_s
16
+ end
17
+ item_matching_state[:checked] = true if item_matching_state
18
+ end
19
+ unless form.object.nil?
20
+ error_text = form.object.errors.full_messages_for(key).first.presence
21
+ local_assigns[:errorMessage] ||= { text: error_text } if error_text
22
+ end
23
+ %>
24
+ <%= render "components/govuk_radios", **local_assigns %>
@@ -0,0 +1,25 @@
1
+ <%
2
+ local_assigns[:name] ||= get_attribute_name(form, key)
3
+ local_assigns[:id] ||= get_attribute_id_prefix(form, key)
4
+ local_assigns[:items] ||= local_assigns[:choices].map { |choice| { value: choice, text: choice } }
5
+
6
+ if local_assigns[:include_blank] || local_assigns[:is_autocomplete]
7
+ local_assigns[:items].unshift(value: nil, text: "")
8
+ end
9
+
10
+ if local_assigns[:selected]
11
+ item_matching_selected = local_assigns[:items].find { |item| item[:value].to_s == local_assigns[:selected] }
12
+ item_matching_selected[:selected] = true if item_matching_selected
13
+ elsif form.object&.respond_to?(key)
14
+ # Make item selected based on attribute value
15
+ item_matching_state = local_assigns[:items].find { |item| item[:value].to_s == form.object.send(key).to_s }
16
+ item_matching_state[:selected] = true if item_matching_state
17
+ end
18
+
19
+ if form.object&.errors
20
+ error_text = form.object.errors.full_messages_for(key).first.presence
21
+ local_assigns[:errorMessage] ||= { text: error_text } if error_text
22
+ end
23
+ %>
24
+
25
+ <%= render "components/govuk_select", **local_assigns %>
@@ -0,0 +1,11 @@
1
+ <%
2
+ # Infer name and id_prefix from attribute key
3
+ local_assigns[:name] ||= get_attribute_name(form, key)
4
+ local_assigns[:id] ||= get_attribute_id_prefix(form, key)
5
+ local_assigns[:value] ||= form.object.send(key) if form.object.respond_to?(key)
6
+ unless form.object.nil?
7
+ error_text = form.object.errors.full_messages_for(key).first.presence
8
+ local_assigns[:errorMessage] ||= { text: error_text } if error_text
9
+ end
10
+ %>
11
+ <%= render "components/govuk_textarea", **local_assigns %>
@@ -0,0 +1 @@
1
+ require "govuk_design_system"
@@ -0,0 +1,50 @@
1
+ module GovukDesignSystem
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace GovukDesignSystem
4
+
5
+ initializer "govuk_design_system.action_view" do |_app|
6
+ ActiveSupport.on_load(:action_view) do
7
+ # NOTE: These includes make the helpers available in every view of the
8
+ # consuming application. If a helper is not listed here, it will be
9
+ # isolated, and unavailable to apps which use this gem.
10
+ ActionView::Base.include GovukDesignSystem::AccordionHelper
11
+ ActionView::Base.include GovukDesignSystem::BackLinkHelper
12
+ ActionView::Base.include GovukDesignSystem::BreadcrumbsHelper
13
+ ActionView::Base.include GovukDesignSystem::ButtonHelper
14
+ ActionView::Base.include GovukDesignSystem::CheckboxesHelper
15
+ ActionView::Base.include GovukDesignSystem::ComponentsHelper
16
+ ActionView::Base.include GovukDesignSystem::CookieBannerHelper
17
+ ActionView::Base.include GovukDesignSystem::DateInputHelper
18
+ ActionView::Base.include GovukDesignSystem::DetailsHelper
19
+ ActionView::Base.include GovukDesignSystem::ErrorMessageHelper
20
+ ActionView::Base.include GovukDesignSystem::ErrorSummaryHelper
21
+ ActionView::Base.include GovukDesignSystem::FieldsetHelper
22
+ ActionView::Base.include GovukDesignSystem::FieldsetHelper
23
+ ActionView::Base.include GovukDesignSystem::FileUploadHelper
24
+ ActionView::Base.include GovukDesignSystem::HeaderHelper
25
+ ActionView::Base.include GovukDesignSystem::HintHelper
26
+ ActionView::Base.include GovukDesignSystem::HmctsBadgeHelper
27
+ ActionView::Base.include GovukDesignSystem::HmctsBannerHelper
28
+ ActionView::Base.include GovukDesignSystem::InputHelper
29
+ ActionView::Base.include GovukDesignSystem::InsetTextHelper
30
+ ActionView::Base.include GovukDesignSystem::LabelHelper
31
+ ActionView::Base.include GovukDesignSystem::NotificationBannerHelper
32
+ ActionView::Base.include GovukDesignSystem::PhaseBannerHelper
33
+ ActionView::Base.include GovukDesignSystem::RadiosHelper
34
+ ActionView::Base.include GovukDesignSystem::SelectHelper
35
+ ActionView::Base.include GovukDesignSystem::SkipLinkHelper
36
+ ActionView::Base.include GovukDesignSystem::SummaryListHelper
37
+ ActionView::Base.include GovukDesignSystem::TabsHelper
38
+ ActionView::Base.include GovukDesignSystem::TagHelper
39
+ ActionView::Base.include GovukDesignSystem::TextareaHelper
40
+ ActionView::Base.include GovukDesignSystem::WarningTextHelper
41
+ end
42
+ end
43
+
44
+ config.generators do |g|
45
+ g.test_framework :rspec
46
+ g.assets false
47
+ g.helper false
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,4 @@
1
+ require "govuk_design_system/engine"
2
+
3
+ module GovukDesignSystem
4
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative "config/application"
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end