govuk_publishing_components 12.16.0 → 12.17.0
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.
- checksums.yaml +4 -4
- data/app/views/govuk_publishing_components/components/_select.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/docs/select.yml +23 -1
- data/lib/govuk_publishing_components.rb +1 -0
- data/lib/govuk_publishing_components/presenters/select.rb +38 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daf83cc27bbb44657c8193582e9f26cfd1e36301a24ba5ed2ba92ac461577905
|
4
|
+
data.tar.gz: 59ac08cf3f8ead780a03d649fcef1ce65cb4b514af1ea557961764b24968accc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d90669dad89315ddadc53669ea3bb668e56661efb7bb2e3ad048fbc1723b65dab49e1b83d1988cc954c2d7b23058470def9c78a4527226467a1527c7dfa834c
|
7
|
+
data.tar.gz: a248d29a9794f949b176059d65e10b48a78a892f39d1d664d0ede520aaeee34be262e46997ae3924a0ff8817fb85602057e34ac2e428d86e334801dc5aa274c8
|
@@ -2,6 +2,8 @@
|
|
2
2
|
options ||= []
|
3
3
|
id ||= false
|
4
4
|
label ||= false
|
5
|
+
|
6
|
+
select_helper = GovukPublishingComponents::Presenters::SelectHelper.new(options)
|
5
7
|
%>
|
6
8
|
<% if options.any? && id && label %>
|
7
9
|
<div class="govuk-form-group gem-c-select">
|
@@ -9,9 +11,7 @@
|
|
9
11
|
<%= label %>
|
10
12
|
</label>
|
11
13
|
<select class="govuk-select" id="<%= id %>" name="<%= id %>">
|
12
|
-
|
13
|
-
<option value="<%= option[:value] %>" <% if option[:selected] %>selected<% end %>><%= option[:text] %></option>
|
14
|
-
<% end %>
|
14
|
+
<%= options_for_select(select_helper.option_markup, select_helper.selected_option) %>
|
15
15
|
</select>
|
16
16
|
</div>
|
17
17
|
<% end %>
|
@@ -22,7 +22,7 @@ examples:
|
|
22
22
|
with_preselect:
|
23
23
|
data:
|
24
24
|
id: 'dropdown2'
|
25
|
-
label: '
|
25
|
+
label: 'Option 2 preselected'
|
26
26
|
options:
|
27
27
|
- text: 'Option one'
|
28
28
|
value: 'option1'
|
@@ -31,3 +31,25 @@ examples:
|
|
31
31
|
selected: true
|
32
32
|
- text: 'Option three'
|
33
33
|
value: 'option3'
|
34
|
+
with_data_attributes:
|
35
|
+
description: Data attributes can be added to the option elements of the select. Note that the component will not do anything with them - Javascript will have to be added in the application that uses the component, for example to fire tracking events.
|
36
|
+
data:
|
37
|
+
id: 'dropdown3'
|
38
|
+
label: 'With data attributes'
|
39
|
+
options:
|
40
|
+
- text: 'Option one'
|
41
|
+
value: 'option1'
|
42
|
+
data_attributes:
|
43
|
+
track_category: "hello"
|
44
|
+
something_else: "moo"
|
45
|
+
- text: 'Option two'
|
46
|
+
value: 'option2'
|
47
|
+
- text: 'Option three'
|
48
|
+
value: 'option3'
|
49
|
+
data_attributes:
|
50
|
+
track_category: 'navDocumentCollectionLinkClicked'
|
51
|
+
track_action: 1.1
|
52
|
+
track_label: '/government/publications/parental-responsibility-measures-for-behaviour-and-attendance'
|
53
|
+
track_options:
|
54
|
+
dimension28: 2
|
55
|
+
dimension29: 'School behaviour and attendance: parental responsibility measures'
|
@@ -9,6 +9,7 @@ require "govuk_publishing_components/presenters/page_with_step_by_step_navigatio
|
|
9
9
|
require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_parent"
|
10
10
|
require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons"
|
11
11
|
require "govuk_publishing_components/presenters/services"
|
12
|
+
require "govuk_publishing_components/presenters/select"
|
12
13
|
require "govuk_publishing_components/presenters/meta_tags"
|
13
14
|
require "govuk_publishing_components/presenters/taxonomy_navigation"
|
14
15
|
require "govuk_publishing_components/presenters/curated_taxonomy_sidebar_links"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module GovukPublishingComponents
|
2
|
+
module Presenters
|
3
|
+
class SelectHelper
|
4
|
+
attr_reader :options, :option_markup, :selected_option
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@options = options
|
8
|
+
@option_markup = get_options
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def get_options
|
14
|
+
return if options.nil?
|
15
|
+
|
16
|
+
options.map { |option|
|
17
|
+
@selected_option = option[:value] if option[:selected]
|
18
|
+
[
|
19
|
+
option[:text],
|
20
|
+
option[:value],
|
21
|
+
options_data_attribute(option[:data_attributes])
|
22
|
+
]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def options_data_attribute(attributes)
|
27
|
+
return {} if attributes.nil?
|
28
|
+
|
29
|
+
attrs = {}
|
30
|
+
attributes.each do |key, value|
|
31
|
+
key_name = "data-#{key.to_s.split('_').join('-')}"
|
32
|
+
attrs[key_name] = value.is_a?(Hash) ? value.to_json : value
|
33
|
+
end
|
34
|
+
attrs
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_publishing_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 12.
|
4
|
+
version: 12.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govspeak
|
@@ -606,6 +606,7 @@ files:
|
|
606
606
|
- lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb
|
607
607
|
- lib/govuk_publishing_components/presenters/related_navigation_helper.rb
|
608
608
|
- lib/govuk_publishing_components/presenters/schema_org.rb
|
609
|
+
- lib/govuk_publishing_components/presenters/select.rb
|
609
610
|
- lib/govuk_publishing_components/presenters/services.rb
|
610
611
|
- lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb
|
611
612
|
- lib/govuk_publishing_components/presenters/subscription_links_helper.rb
|