govuk_publishing_components 24.3.1 → 24.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +7 -5
  3. data/app/assets/javascripts/govuk_publishing_components/components/details.js +1 -1
  4. data/app/assets/javascripts/govuk_publishing_components/components/reorderable-list.js +108 -0
  5. data/app/assets/javascripts/govuk_publishing_components/components/show-password.js +7 -2
  6. data/app/assets/javascripts/govuk_publishing_components/lib/header-navigation.js +6 -2
  7. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
  8. data/app/assets/stylesheets/govuk_publishing_components/_all_components_print.scss +1 -1
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_breadcrumbs.scss +11 -0
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_reorderable-list.scss +117 -0
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_summary-list.scss +12 -0
  12. data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +8 -5
  13. data/app/views/govuk_publishing_components/components/_list.html.erb +5 -5
  14. data/app/views/govuk_publishing_components/components/_radio.html.erb +2 -1
  15. data/app/views/govuk_publishing_components/components/_reorderable_list.html.erb +45 -0
  16. data/app/views/govuk_publishing_components/components/_search.html.erb +27 -16
  17. data/app/views/govuk_publishing_components/components/_show_password.html.erb +6 -4
  18. data/app/views/govuk_publishing_components/components/_summary_list.html.erb +73 -31
  19. data/app/views/govuk_publishing_components/components/docs/breadcrumbs.yml +22 -0
  20. data/app/views/govuk_publishing_components/components/docs/radio.yml +14 -1
  21. data/app/views/govuk_publishing_components/components/docs/reorderable_list.yml +85 -0
  22. data/app/views/govuk_publishing_components/components/docs/search.yml +10 -0
  23. data/app/views/govuk_publishing_components/components/docs/summary_list.yml +50 -19
  24. data/app/views/govuk_publishing_components/components/layout_header/_search.html.erb +17 -3
  25. data/config/locales/en.yml +25 -15
  26. data/lib/govuk_publishing_components/version.rb +1 -1
  27. data/node_modules/sortablejs/LICENSE +21 -0
  28. data/node_modules/sortablejs/README.md +815 -0
  29. data/node_modules/sortablejs/Sortable.js +3721 -0
  30. data/node_modules/sortablejs/Sortable.min.js +2 -0
  31. data/node_modules/sortablejs/modular/sortable.complete.esm.js +3713 -0
  32. data/node_modules/sortablejs/modular/sortable.core.esm.js +3710 -0
  33. data/node_modules/sortablejs/modular/sortable.esm.js +3711 -0
  34. data/node_modules/sortablejs/package.json +56 -0
  35. metadata +14 -2
@@ -1,4 +1,5 @@
1
1
  <%
2
+ shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
2
3
  id ||= nil
3
4
  id_prefix ||= "radio-#{SecureRandom.hex(4)}"
4
5
  items ||= []
@@ -54,7 +55,7 @@
54
55
  <% end %>
55
56
  <% else %>
56
57
  <%= tag.legend class: legend_classes do %>
57
- <%= tag.h2 heading, class: "govuk-fieldset__heading" %>
58
+ <%= content_tag(shared_helper.get_heading_level, heading, class: "govuk-fieldset__heading") %>
58
59
  <% end %>
59
60
  <% end %>
60
61
  <% end %>
@@ -0,0 +1,45 @@
1
+ <%
2
+ items ||= []
3
+ input_name ||= "ordering"
4
+ data_attributes ||= {}
5
+ data_attributes[:module] = "reorderable-list"
6
+ %>
7
+
8
+ <%= tag.ol class: "gem-c-reorderable-list", data: data_attributes do %>
9
+ <% items.each_with_index do |item, index| %>
10
+ <%= tag.li class: "gem-c-reorderable-list__item" do %>
11
+ <%= tag.div class: "gem-c-reorderable-list__wrapper" do %>
12
+ <%= tag.div class: "gem-c-reorderable-list__content" do %>
13
+ <%= tag.p item[:title], class: "gem-c-reorderable-list__title" %>
14
+ <%= tag.p(item[:description], class: "gem-c-reorderable-list__description") if item[:description].present? %>
15
+ <% end %>
16
+ <%= tag.div class: "gem-c-reorderable-list__actions" do %>
17
+ <% label_text = capture do %>
18
+ Position<span class='govuk-visually-hidden'> for <%= item[:title] %></span>
19
+ <% end %>
20
+ <%= render "govuk_publishing_components/components/input", {
21
+ label: { text: label_text },
22
+ name: "#{input_name}[#{item[:id]}]",
23
+ type: "number",
24
+ value: index + 1,
25
+ width: 2
26
+ } %>
27
+ <%= render "govuk_publishing_components/components/button", {
28
+ text: "Up",
29
+ type: "button",
30
+ aria_label: "Move \"#{item[:title]}\" up",
31
+ classes: "js-reorderable-list-up",
32
+ secondary_solid: true
33
+ } %>
34
+ <%= render "govuk_publishing_components/components/button", {
35
+ text: "Down",
36
+ type: "button",
37
+ aria_label: "Move \"#{item[:title]}\" down",
38
+ classes: "js-reorderable-list-down",
39
+ secondary_solid: true
40
+ } %>
41
+ <% end %>
42
+ <% end %>
43
+ <% end %>
44
+ <% end %>
45
+ <% end %>
@@ -1,11 +1,19 @@
1
1
  <%
2
- size ||= ""
3
- no_border ||= false
4
2
  shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
5
- classes = %w(gem-c-search)
3
+
4
+ aria_controls ||= nil
5
+ button_text ||= t("components.search_box.search_button")
6
+ id ||= "search-main-" + SecureRandom.hex(4)
7
+ label_text ||= t("components.search_box.label")
8
+ name ||= "q"
9
+ no_border ||= false
10
+ size ||= ""
11
+ value ||= ""
12
+
13
+ classes = %w[gem-c-search]
6
14
  classes << (shared_helper.get_margin_top)
7
15
  classes << (shared_helper.get_margin_bottom) if local_assigns[:margin_bottom]
8
- classes << "gem-c-search--large" if size == 'large'
16
+ classes << "gem-c-search--large" if size == "large"
9
17
  classes << "gem-c-search--no-border" if no_border
10
18
  if local_assigns[:on_govuk_blue].eql?(true)
11
19
  classes << "gem-c-search--on-govuk-blue"
@@ -13,25 +21,28 @@
13
21
  classes << "gem-c-search--on-white"
14
22
  end
15
23
  classes << "gem-c-search--separate-label" if local_assigns.include?(:inline_label)
16
-
17
- value ||= ""
18
- id ||= "search-main-" + SecureRandom.hex(4)
19
- label_text ||= "Search on GOV.UK"
20
- name ||= 'q'
21
- aria_controls ||= nil
22
24
  %>
23
25
 
24
- <div class="<%= classes.join(' ') %>" data-module="gem-toggle-input-class-on-focus">
26
+ <div class="<%= classes.join(" ") %>" data-module="gem-toggle-input-class-on-focus">
25
27
  <label for="<%= id %>" class="gem-c-search__label">
26
28
  <%= label_text %>
27
29
  </label>
28
30
  <div class="gem-c-search__item-wrapper">
29
- <input type="search" value="<%= value %>"
30
- id="<%= id %>" name="<%= name %>" title="Search"
31
- aria-controls="<%= aria_controls %>"
32
- class="gem-c-search__item gem-c-search__input js-class-toggle">
31
+ <%= tag.input(
32
+ aria: {
33
+ controls: aria_controls,
34
+ },
35
+ class: "gem-c-search__item gem-c-search__input js-class-toggle",
36
+ id: id,
37
+ name: name,
38
+ title: t("components.search_box.input_title"),
39
+ type: "search",
40
+ value: value,
41
+ ) %>
33
42
  <div class="gem-c-search__item gem-c-search__submit-wrapper">
34
- <button type="submit" class="gem-c-search__submit">Search</button>
43
+ <button class="gem-c-search__submit" type="submit">
44
+ <%= button_text %>
45
+ </button>
35
46
  </div>
36
47
  </div>
37
48
  </div>
@@ -19,10 +19,12 @@
19
19
  data: {
20
20
  module: "show-password",
21
21
  disable_form_submit_check: disable_form_submit_check,
22
- show: t('components.input.show'),
23
- hide: t('components.input.hide'),
24
- announce_show: t('components.input.announce_show'),
25
- announce_hide: t('components.input.announce_hide')
22
+ show_text: t('components.show_password.show'),
23
+ hide_text: t('components.show_password.hide'),
24
+ show_full_text: t('components.show_password.show_password'),
25
+ hide_full_text: t('components.show_password.hide_password'),
26
+ announce_show: t('components.show_password.announce_show'),
27
+ announce_hide: t('components.show_password.announce_hide')
26
28
  } do %>
27
29
  <%= render "govuk_publishing_components/components/input", {
28
30
  label: label,
@@ -10,37 +10,59 @@
10
10
  delete ||= {}
11
11
  items ||= []
12
12
  block ||= yield
13
+ wide_title ||= false
13
14
  %>
14
15
  <% if title || items.any? %>
15
- <%= tag.div class: "gem-c-summary-list #{"govuk-summary-list--no-border" if borderless}", id: id do %>
16
+ <%= tag.div class: "gem-c-summary-list #{"govuk-summary-list--no-border" if borderless} #{"gem-c-summary-list--wide-title" if wide_title}", id: id do %>
16
17
  <% if title %>
17
18
  <%= content_tag(shared_helper.get_heading_level, title, class: "govuk-heading-#{heading_size} gem-c-summary-list__group-title") %>
18
- <% if edit.any? || delete.any? %>
19
+
20
+ <% if edit.any? %>
21
+ <% edit_main_link = capture do %>
22
+ <%
23
+ edit_section_link_text = edit[:link_text] || t("components.summary_list.edit")
24
+ %>
25
+ <%= link_to edit.fetch(:href),
26
+ class: "govuk-link",
27
+ data: edit.fetch(:data_attributes, {}) do %>
28
+ <%= edit_section_link_text %><%= tag.span " #{title}", class: "govuk-visually-hidden" unless edit[:link_text_no_enhance] -%>
29
+ <% end %>
30
+ <% end %>
31
+ <% end %>
32
+
33
+ <% if delete.any? %>
34
+ <% delete_main_link = capture do %>
35
+ <%
36
+ delete_section_link_text = delete[:link_text] || t("components.summary_list.delete")
37
+ %>
38
+ <%= link_to delete.fetch(:href),
39
+ class: "govuk-link gem-link--destructive",
40
+ data: delete.fetch(:data_attributes, {}) do %>
41
+ <%= delete_section_link_text %><%= tag.span " #{title}", class: "govuk-visually-hidden" unless delete[:link_text_no_enhance] -%>
42
+ <% end %>
43
+ <% end %>
44
+ <% end %>
45
+
46
+ <% if edit_main_link && delete_main_link %>
19
47
  <%= tag.ul class: "govuk-summary-list__actions-list gem-c-summary-list__group-actions-list" do %>
20
48
  <%- if edit.any? %>
21
- <% edit_section_link_text = edit[:link_text] || t("components.summary_list.edit") %>
22
49
  <%= tag.li class: "govuk-summary-list__actions-list-item" do -%>
23
- <%= link_to edit.fetch(:href),
24
- class: "govuk-link",
25
- title: "#{edit_section_link_text} #{title}",
26
- data: edit.fetch(:data_attributes, {}) do %>
27
- <%= edit_section_link_text %><%= tag.span " #{title}", class: "govuk-visually-hidden" -%>
28
- <% end %>
50
+ <%= edit_main_link %>
29
51
  <% end %>
30
52
  <% end %>
31
53
  <% if delete.any? %>
32
- <% delete_section_link_text = delete[:link_text] || t("components.summary_list.delete") %>
33
54
  <%= tag.li class: "govuk-summary-list__actions-list-item" do -%>
34
- <%= link_to delete.fetch(:href),
35
- class: "govuk-link gem-link--destructive",
36
- title: "#{delete_section_link_text} #{title}",
37
- data: delete.fetch(:data_attributes, {}) do %>
38
- <%= delete_section_link_text %><%= tag.span " #{title}", class: "govuk-visually-hidden" -%>
39
- <% end %>
55
+ <%= delete_main_link %>
40
56
  <% end %>
41
57
  <% end %>
42
58
  <% end %>
59
+ <% else %>
60
+ <%= tag.div class: "govuk-summary-list__actions-list gem-c-summary-list__group-actions-list" do %>
61
+ <%= edit_main_link %>
62
+ <%= delete_main_link %>
63
+ <% end %>
43
64
  <% end %>
65
+
44
66
  <% end %>
45
67
 
46
68
  <% if items.any? %>
@@ -51,34 +73,54 @@
51
73
  <%= tag.dt item[:field], class: "govuk-summary-list__key" %>
52
74
  <%= tag.dd item[:value], class: "govuk-summary-list__value" %>
53
75
 
54
- <% if item.fetch(:edit, {}).any? || item.fetch(:delete, {}).any? %>
76
+ <% if item.fetch(:edit, {}).any? %>
77
+ <% edit_link = capture do %>
78
+ <%
79
+ edit_link_text = item[:edit][:link_text] || t("components.summary_list.edit")
80
+ %>
81
+ <%= link_to item[:edit].fetch(:href),
82
+ class: "govuk-link",
83
+ data: item[:edit].fetch(:data_attributes, {}) do %>
84
+ <%= edit_link_text %><%= tag.span " #{item[:field]}", class: "govuk-visually-hidden" unless item[:edit][:link_text_no_enhance] -%>
85
+ <% end %>
86
+ <% end %>
87
+ <% end %>
88
+
89
+ <% if item.fetch(:delete, {}).any? %>
90
+ <% delete_link = capture do %>
91
+ <%
92
+ delete_link_text = item[:delete][:link_text] || t("components.summary_list.delete")
93
+ %>
94
+ <%= link_to item[:delete].fetch(:href),
95
+ class: "govuk-link gem-link--destructive",
96
+ data: item[:delete].fetch(:data_attributes, {}) do %>
97
+ <%= delete_link_text %><%= tag.span " #{item[:field]}", class: "govuk-visually-hidden" unless item[:delete][:link_text_no_enhance] -%>
98
+ <% end %>
99
+ <% end %>
100
+ <% end %>
101
+
102
+ <% if edit_link && delete_link %>
55
103
  <%= tag.dd class: "govuk-summary-list__actions" do %>
56
104
  <%= tag.ul class: "govuk-summary-list__actions-list" do %>
57
105
  <% if item.fetch(:edit, {}).any? %>
58
106
  <%= tag.li class: "govuk-summary-list__actions-list-item" do %>
59
- <% edit_link_text = item[:edit][:link_text] || t("components.summary_list.edit") %>
60
- <%= link_to item[:edit].fetch(:href),
61
- class: "govuk-link",
62
- title: "#{edit_link_text} #{item[:field]}",
63
- data: item[:edit].fetch(:data_attributes, {}) do %>
64
- <%= edit_link_text %><%= tag.span " #{item[:field]}", class: "govuk-visually-hidden" -%>
65
- <% end %>
107
+ <%= edit_link %>
66
108
  <% end %>
67
109
  <% end %>
68
110
  <% if item.fetch(:delete, {}).any? %>
69
111
  <%= tag.li class: "govuk-summary-list__actions-list-item" do %>
70
- <% delete_link_text = item[:delete][:link_text] || t("components.summary_list.delete") %>
71
- <%= link_to item[:delete].fetch(:href),
72
- class: "govuk-link gem-link--destructive",
73
- title: "#{delete_link_text} #{item[:field]}",
74
- data: item[:delete].fetch(:data_attributes, {}) do %>
75
- <%= delete_link_text %><%= tag.span " #{item[:field]}", class: "govuk-visually-hidden" -%>
76
- <% end %>
112
+ <%= delete_link %>
77
113
  <% end %>
78
114
  <% end %>
79
115
  <% end %>
80
116
  <% end %>
117
+ <% else %>
118
+ <%= tag.dd class: "govuk-summary-list__actions" do %>
119
+ <%= edit_link %>
120
+ <%= delete_link %>
121
+ <% end %>
81
122
  <% end %>
123
+
82
124
  <% end %>
83
125
  <% end %>
84
126
  <% end %>
@@ -97,3 +97,25 @@ examples:
97
97
  url: '/browse/abroad'
98
98
  - title: 'Travel abroad'
99
99
  url: '/browse/abroad/travel-abroad'
100
+ with_border:
101
+ description: "Set a border below the breadcrumb. Off by default."
102
+ data:
103
+ border: "bottom"
104
+ breadcrumbs:
105
+ - title: "Section"
106
+ url: "/section"
107
+ - title: "Sub-section"
108
+ url: "/section/sub-section"
109
+ - title: "Sub-sub-section"
110
+ url: "/section/sub-section/sub-section"
111
+ with_border_and_collapse_on_mobile:
112
+ data:
113
+ border: "bottom"
114
+ collapse_on_mobile: true
115
+ breadcrumbs:
116
+ - title: "Section"
117
+ url: "/section"
118
+ - title: "Sub-section"
119
+ url: "/section/sub-section"
120
+ - title: "Sub-sub-section"
121
+ url: "/section/sub-section/sub-section"
@@ -184,7 +184,7 @@ examples:
184
184
  text: "Blue"
185
185
  with_custom_heading_size:
186
186
  description: |
187
- This allows the size of the legend to be changed. Valid options are s, m, l, xl, defaulting to m if no option is passed.
187
+ This allows the size of the legend to be changed. Valid options are s, m, l, xl, defaulting to m if no option is passed.
188
188
 
189
189
  If the is_page_heading option is true and heading_size is not set, the text size will be xl.
190
190
  data:
@@ -198,6 +198,19 @@ examples:
198
198
  text: "Green"
199
199
  - value: "blue"
200
200
  text: "Blue"
201
+ with_custom_heading_level:
202
+ description: This allows the heading level to be changed. Heading level will default to `h2` if nothing is passed.
203
+ data:
204
+ name: "radio-group-description"
205
+ heading: "What is your favourite colour?"
206
+ heading_level: 3
207
+ items:
208
+ - value: "red"
209
+ text: "Red"
210
+ - value: "green"
211
+ text: "Green"
212
+ - value: "blue"
213
+ text: "Blue"
201
214
  with_hint_text_on_radios:
202
215
  data:
203
216
  name: "radio-group-hint-text"
@@ -0,0 +1,85 @@
1
+ name: Reorderable list
2
+ description: A list of items that can be reordered
3
+ body: |
4
+ List items can be reordered by drag and drop or by using the up/down buttons.
5
+ On small viewports the drag and drop feature is disabled to prevent being triggered
6
+ when scrolling on touch devices.
7
+
8
+ This component uses SortableJS - a JavaScript library for drag and drop interactions.
9
+ When JavaScript is disabled a set of inputs will be shown allowing users to provide
10
+ an order index for each item.
11
+
12
+ When this component is embedded into a form and that form is submit you will receive a
13
+ parameter of `ordering` (which can be customised with the `input_name` option).
14
+ This will contain item ids and ordering positions in a hash.
15
+
16
+ For example, for two items with id "a" and "b" that are ordered accordingly,
17
+ you'd receive a submission of `ordering[a]=1&ordering[b]=2`, which Rails can
18
+ translate to `"ordering" => { "a" => "1", "b" => "2" }`.
19
+
20
+ accessibility_criteria: |
21
+ Buttons in this component must:
22
+
23
+ * be keyboard focusable
24
+ * inform the user about which item they operate on
25
+ * preserve focus after interacting with them
26
+ examples:
27
+ default:
28
+ data:
29
+ items:
30
+ - id: "ce99dd60-67dc-11eb-ae93-0242ac130002"
31
+ title: "Budget 2018"
32
+ - id: "d321cb86-67dc-11eb-ae93-0242ac130002"
33
+ title: "Budget 2018 (web)"
34
+ - id: "63a6d29e-6b6d-4157-9067-84c1a390e352"
35
+ title: "Impact on households: distributional analysis to accompany Budget 2018"
36
+ - id: "0a4d377d-68f4-472f-b2e3-ef71dc750f85"
37
+ title: "Table 2.1: Budget 2018 policy decisions"
38
+ - id: "5ebd75d7-6c37-4b93-b444-1b7c49757fb9"
39
+ title: "Table 2.2: Measures announced at Autumn Budget 2017 or earlier that will take effect from November 2018 or later (£ million)"
40
+ with_description:
41
+ data:
42
+ items:
43
+ - id: "ce99dd60-67dc-11eb-ae93-0242ac130002"
44
+ title: "Budget 2018"
45
+ description: "PDF, 2.56MB, 48 pages"
46
+ - id: "d321cb86-67dc-11eb-ae93-0242ac130002"
47
+ title: "Budget 2018 (web)"
48
+ description: "HTML attachment"
49
+ - id: "63a6d29e-6b6d-4157-9067-84c1a390e352"
50
+ title: "Impact on households: distributional analysis to accompany Budget 2018"
51
+ description: "PDF, 592KB, 48 pages"
52
+ - id: "0a4d377d-68f4-472f-b2e3-ef71dc750f85"
53
+ title: "Table 2.1: Budget 2018 policy decisions"
54
+ description: "MS Excel Spreadsheet, 248KB"
55
+ - id: "5ebd75d7-6c37-4b93-b444-1b7c49757fb9"
56
+ title: "Table 2.2: Measures announced at Autumn Budget 2017 or earlier that will take effect from November 2018 or later (£ million)"
57
+ description: "MS Excel Spreadsheet, 248KB"
58
+ within_form:
59
+ embed: |
60
+ <form>
61
+ <%= component %>
62
+ <button class="govuk-button" type="submit">Save order</button>
63
+ </form>
64
+ data:
65
+ items:
66
+ - id: "ce99dd60-67dc-11eb-ae93-0242ac130002"
67
+ title: "Budget 2018"
68
+ - id: "d321cb86-67dc-11eb-ae93-0242ac130002"
69
+ title: "Budget 2018 (web)"
70
+ - id: "63a6d29e-6b6d-4157-9067-84c1a390e352"
71
+ title: "Impact on households: distributional analysis to accompany Budget 2018"
72
+ - id: "0a4d377d-68f4-472f-b2e3-ef71dc750f85"
73
+ title: "Table 2.1: Budget 2018 policy decisions"
74
+ - id: "5ebd75d7-6c37-4b93-b444-1b7c49757fb9"
75
+ title: "Table 2.2: Measures announced at Autumn Budget 2017 or earlier that will take effect from November 2018 or later (£ million)"
76
+ with_custom_input_name:
77
+ data:
78
+ input_name: "attachments[ordering]"
79
+ items:
80
+ - id: "5ebd75d7-6c37-4b93-b444-1b7c49757fb9"
81
+ title: "Budget 2018"
82
+ description: "PDF, 2.56MB, 48 pages"
83
+ - id: "0a4d377d-68f4-472f-b2e3-ef71dc750f85"
84
+ title: "Budget 2020"
85
+ description: "PDF, 2.56MB, 48 pages"
@@ -51,6 +51,16 @@ examples:
51
51
  with_aria_controls_attribute:
52
52
  description: |
53
53
  The aria-controls attribute is a 'relationship attribute' which denotes which elements in a page an interactive element or set of elements has control over and affects.
54
+
54
55
  For places like the finders where the page is updated dynamically after value changes to the input.
55
56
  data:
56
57
  aria_controls: "wrapper"
58
+ with_custom_button_text:
59
+ description: |
60
+ The search box component may be used multiple times on a page -- for example, on a [guidance and regulation finder results page](https://www.gov.uk/search/guidance-and-regulation?keywords=bananas&order=relevance) there is both the sitewide search in the header and also for the specific finder.
61
+
62
+ To avoid confusion, the text inside the button should be different for each form. This can be done by setting the `button_text` parameter.
63
+
64
+ This is visually hidden text -- to check for changes use a screen reader or inspect the button element.
65
+ data:
66
+ button_text: "Search absolutely everywhere"