govuk_publishing_components 71.2.0 → 71.3.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/assets/config/govuk_publishing_components_manifest.js +6 -0
- data/app/assets/javascripts/govuk_publishing_components/all_components.js +1 -1
- data/app/assets/javascripts/govuk_publishing_components/components/map/defra-map.js +16 -0
- data/app/assets/javascripts/govuk_publishing_components/components/map/im-maplibre-worker.js +1 -0
- data/app/assets/javascripts/govuk_publishing_components/components/map/map-styles.js +3 -0
- data/app/assets/javascripts/govuk_publishing_components/components/map/map-test.geojson +49 -0
- data/app/assets/javascripts/govuk_publishing_components/components/map.js +215 -0
- data/app/assets/stylesheets/govuk_publishing_components/all-components.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_map.scss +53 -0
- data/app/views/govuk_publishing_components/components/_map.html.erb +82 -0
- data/app/views/govuk_publishing_components/components/docs/map.yml +110 -0
- data/lib/govuk_publishing_components/app_helpers/csp_helper.rb +11 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/lib/govuk_publishing_components.rb +1 -0
- data/node_modules/axe-core/axe.js +481 -345
- data/node_modules/axe-core/axe.min.js +2 -2
- data/node_modules/axe-core/package.json +3 -3
- data/node_modules/axe-core/sri-history.json +4 -0
- metadata +10 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<%
|
|
2
|
+
centre ||= nil
|
|
3
|
+
zoom ||= nil
|
|
4
|
+
heading_text ||= nil
|
|
5
|
+
heading_level ||= 2
|
|
6
|
+
description ||= nil
|
|
7
|
+
height ||= nil
|
|
8
|
+
attribution ||= nil
|
|
9
|
+
geojson ||= nil
|
|
10
|
+
bounds ||= nil
|
|
11
|
+
max_bounds ||= nil
|
|
12
|
+
disable_ga4 ||= false
|
|
13
|
+
|
|
14
|
+
heading_obj = { text: heading_text, heading_level: heading_level, margin_bottom: 4, font_size: "m"}
|
|
15
|
+
heading_obj[:font_size] = "s" if heading_level > 2
|
|
16
|
+
|
|
17
|
+
map_config = {}
|
|
18
|
+
map_config[:center] = centre if centre.kind_of?(Array) && centre.length == 2
|
|
19
|
+
map_config[:zoom] = zoom if zoom
|
|
20
|
+
map_config[:mapLabel] = "Interactive map: #{heading_text}"
|
|
21
|
+
map_config[:containerHeight] = "#{height}px" if height
|
|
22
|
+
map_config[:bounds] = bounds if bounds.kind_of?(Array) && bounds.length == 4
|
|
23
|
+
map_config[:maxBounds] = max_bounds if max_bounds.kind_of?(Array) && max_bounds.length == 4
|
|
24
|
+
|
|
25
|
+
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
|
|
26
|
+
component_helper.set_id("map-#{SecureRandom.hex(4)}")
|
|
27
|
+
component_helper.add_data_attribute({ module: "map" })
|
|
28
|
+
component_helper.add_data_attribute({ config: map_config })
|
|
29
|
+
component_helper.add_data_attribute({ geojson: geojson }) if geojson
|
|
30
|
+
component_helper.add_data_attribute({ csp_worker: ActionController::Base.helpers.asset_path("govuk_publishing_components/components/map/im-maplibre-worker.js") })
|
|
31
|
+
component_helper.add_data_attribute({ tracking_enabled: true }) unless disable_ga4
|
|
32
|
+
component_helper.add_data_attribute({ font_light: ActionController::Base.helpers.asset_path("light-94a07e06a1-v2.woff2") })
|
|
33
|
+
component_helper.add_data_attribute({ font_bold: ActionController::Base.helpers.asset_path("bold-b542beb274-v2.woff2") })
|
|
34
|
+
skip_link_id = "skip-#{SecureRandom.hex(4)}"
|
|
35
|
+
@include_map_script ||= OpenStruct.new(script_included: false)
|
|
36
|
+
%>
|
|
37
|
+
<% if heading_text && ((map_config[:center] && map_config[:zoom]) || !geojson.nil? || bounds) %>
|
|
38
|
+
<%= render "govuk_publishing_components/components/heading", heading_obj %>
|
|
39
|
+
<% if description %>
|
|
40
|
+
<%= render "govuk_publishing_components/components/govspeak", {} do %>
|
|
41
|
+
<%= description %>
|
|
42
|
+
<% end %>
|
|
43
|
+
<% end %>
|
|
44
|
+
|
|
45
|
+
<%= render "govuk_publishing_components/components/skip_link", {
|
|
46
|
+
text: "Skip map",
|
|
47
|
+
href: "##{skip_link_id}",
|
|
48
|
+
} %>
|
|
49
|
+
|
|
50
|
+
<% unless @include_map_script[:script_included] %>
|
|
51
|
+
<%= javascript_include_tag "govuk_publishing_components/components/map/defra-map.js", integrity: false %>
|
|
52
|
+
<%= javascript_include_tag "govuk_publishing_components/components/map.js", integrity: false, type: "module" %>
|
|
53
|
+
<%= javascript_include_tag "govuk_publishing_components/components/map/map-styles.js", integrity: false %>
|
|
54
|
+
<% @include_map_script[:script_included] = true %>
|
|
55
|
+
<% end %>
|
|
56
|
+
|
|
57
|
+
<%= tag.div(**component_helper.all_attributes) do %>
|
|
58
|
+
<%
|
|
59
|
+
panel_link_tracking = {}
|
|
60
|
+
unless disable_ga4
|
|
61
|
+
panel_link_tracking[:module] = "ga4-link-tracker"
|
|
62
|
+
panel_link_tracking[:ga4_link] = { "event_name": "information_click", "type": "map" }.to_json
|
|
63
|
+
end
|
|
64
|
+
%>
|
|
65
|
+
<%= tag.div(data: panel_link_tracking) do %>
|
|
66
|
+
<%= tag.div(class: "gem-c-map") do %>
|
|
67
|
+
<span class="gem-c-map__js-on">Loading map...</span>
|
|
68
|
+
<span class="gem-c-map__no-js">This map uses JavaScript to work. To view the map, turn on JavaScript in your browser's settings.</span>
|
|
69
|
+
<% end %>
|
|
70
|
+
<% end %>
|
|
71
|
+
<div class="gem-c-map__attribution">
|
|
72
|
+
<p class="govuk-body-s gem-c-map__attribution-text">
|
|
73
|
+
<% if attribution %>
|
|
74
|
+
<%= attribution %>
|
|
75
|
+
<% else %>
|
|
76
|
+
<a href="https://openfreemap.org" target="_blank" class="govuk-link" rel="noopener noreferrer external">OpenFreeMap</a> <a href="https://www.openmaptiles.org/" target="_blank" class="govuk-link" rel="noopener noreferrer external">© OpenMapTiles</a> Data from <a href="https://www.openstreetmap.org/copyright" target="_blank" class="govuk-link" rel="noopener noreferrer external">OpenStreetMap</a>
|
|
77
|
+
<% end %>
|
|
78
|
+
</p>
|
|
79
|
+
</div>
|
|
80
|
+
<div id="<%= skip_link_id %>"></div>
|
|
81
|
+
<% end %>
|
|
82
|
+
<% end %>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
name: Map (experimental)
|
|
2
|
+
description: A simple map component.
|
|
3
|
+
body: |
|
|
4
|
+
Displays a map, given a location and a zoom level. Maps can also display markers with popups, if the correct geoJSON is supplied. The map can be scrolled and zoomed.
|
|
5
|
+
|
|
6
|
+
This component uses the [DEFRA map component](https://defra.github.io/interactive-map/).
|
|
7
|
+
|
|
8
|
+
Maps are inaccessible to many users. If you are using this component to display information, you must also display this information in an accessible way separately from the map.
|
|
9
|
+
|
|
10
|
+
The order of positional co-ordinates for this map and its contents is longitude followed by latitude.
|
|
11
|
+
|
|
12
|
+
The JavaScript required for the component is relatively large and should not be included in the main `application.js` - instead the component template includes the required JavaScript files.
|
|
13
|
+
shared_accessibility_criteria:
|
|
14
|
+
- link
|
|
15
|
+
|
|
16
|
+
accessibility_criteria: |
|
|
17
|
+
The map must:
|
|
18
|
+
|
|
19
|
+
- have an accessible alternative, including a list of map markers separate to the map itself
|
|
20
|
+
- be usable with a keyboard
|
|
21
|
+
- provide a skip link to bypass the map for keyboard users
|
|
22
|
+
- have a heading
|
|
23
|
+
uses_component_wrapper_helper: true
|
|
24
|
+
examples:
|
|
25
|
+
default:
|
|
26
|
+
data:
|
|
27
|
+
heading_text: An example map
|
|
28
|
+
zoom: 12
|
|
29
|
+
centre:
|
|
30
|
+
- -3.1883
|
|
31
|
+
- 55.9533
|
|
32
|
+
custom_heading_description_and_attribution:
|
|
33
|
+
description: |
|
|
34
|
+
All maps should have a heading, but the heading level may need to be different depending on the context.
|
|
35
|
+
|
|
36
|
+
Descriptions are rendered inside a govspeak block, so can include govspeak formatting. Descriptions are not required but are recommended, to help users with screen readers understand the purpose of the map.
|
|
37
|
+
data:
|
|
38
|
+
heading_text: Malvern, Worcestershire
|
|
39
|
+
heading_level: 3
|
|
40
|
+
description: |
|
|
41
|
+
<p>The Malvern Hills has been designated an area of outstanding natural beauty.</p>
|
|
42
|
+
attribution: Copyright someone else
|
|
43
|
+
centre:
|
|
44
|
+
- -2.325062
|
|
45
|
+
- 52.107919
|
|
46
|
+
zoom: 12
|
|
47
|
+
with_geojson_url:
|
|
48
|
+
description: |
|
|
49
|
+
Given a URL to a GeoJSON file, the map will draw markers and apply popups as specified in the file.
|
|
50
|
+
data:
|
|
51
|
+
geojson: "/assets/govuk_publishing_components/components/map/map-test.geojson"
|
|
52
|
+
heading_text: Birmingham and surrounding places
|
|
53
|
+
zoom: 9
|
|
54
|
+
centre:
|
|
55
|
+
- -1.89032729180704
|
|
56
|
+
- 52.485470314900795
|
|
57
|
+
with_geojson_string:
|
|
58
|
+
description: |
|
|
59
|
+
GeoJSON can also be passed as a base64 encoded string, as shown.
|
|
60
|
+
data:
|
|
61
|
+
geojson: data:application/geo+json;base64,ewogICJ0eXBlIjogIkZlYXR1cmVDb2xsZWN0aW9uIiwKICAiZmVhdHVyZXMiOiBbCiAgICB7CiAgICAgICJpZCI6IDEsCiAgICAgICJ0eXBlIjogIkZlYXR1cmUiLAogICAgICAicHJvcGVydGllcyI6IHsKICAgICAgICAiZGVzY3JpcHRpb24iOiAiQSBsYXJnZSBjaXR5LiIsCiAgICAgICAgImFkZHJlc3MiOiAiQjEgMUFBIiwKICAgICAgICAibmFtZSI6ICJCaXJtaW5naGFtIgogICAgICB9LAogICAgICAiZ2VvbWV0cnkiOiB7CiAgICAgICAgImNvb3JkaW5hdGVzIjogWwogICAgICAgICAgLTEuODkwMzI3MjkxODA3MDQsCiAgICAgICAgICA1Mi40ODU0NzAzMTQ5MDA3OTUKICAgICAgICBdLAogICAgICAgICJ0eXBlIjogIlBvaW50IgogICAgICB9CiAgICB9LAogICAgewogICAgICAiaWQiOiAyLAogICAgICAidHlwZSI6ICJGZWF0dXJlIiwKICAgICAgInByb3BlcnRpZXMiOiB7CiAgICAgICAgIm5hbWUiOiAiQ292ZW50cnkiLAogICAgICAgICJkZXNjcmlwdGlvbiI6ICJBbm90aGVyIGxhcmdlIGNpdHkiCiAgICAgIH0sCiAgICAgICJnZW9tZXRyeSI6IHsKICAgICAgICAiY29vcmRpbmF0ZXMiOiBbCiAgICAgICAgICAtMS40OTE1NDQyNjYxNTk0NTExLAogICAgICAgICAgNTIuNDAyOTI2ODgzNzk3MjgKICAgICAgICBdLAogICAgICAgICJ0eXBlIjogIlBvaW50IgogICAgICB9CiAgICB9CiAgXQp9Cg==
|
|
62
|
+
heading_text: Birmingham and Coventry
|
|
63
|
+
zoom: 10
|
|
64
|
+
centre:
|
|
65
|
+
- -1.69032729180704
|
|
66
|
+
- 52.445470314900795
|
|
67
|
+
custom_bounds:
|
|
68
|
+
description: This allows the initial position of the map to be set.
|
|
69
|
+
data:
|
|
70
|
+
heading_text: Places with Ham in their name
|
|
71
|
+
description: |
|
|
72
|
+
<p>There's another one over in the east, look.</p>
|
|
73
|
+
bounds:
|
|
74
|
+
- -3.203169743770889
|
|
75
|
+
- 51.643668495828116
|
|
76
|
+
- -0.8983602517140259
|
|
77
|
+
- 50.68105666989489
|
|
78
|
+
geojson: data:application/geo+json;base64,ewogICJ0eXBlIjogIkZlYXR1cmVDb2xsZWN0aW9uIiwKICAiZmVhdHVyZXMiOiBbCiAgICB7CiAgICAgICJpZCI6IDEsCiAgICAgICJ0eXBlIjogIkZlYXR1cmUiLAogICAgICAicHJvcGVydGllcyI6IHsKICAgICAgICAibmFtZSI6ICJIYW1icmlkZ2UsIFNvbWVyc2V0IgogICAgICB9LAogICAgICAiZ2VvbWV0cnkiOiB7CiAgICAgICAgImNvb3JkaW5hdGVzIjogWwogICAgICAgICAgLTIuODcsCiAgICAgICAgICA1MC45OAogICAgICAgIF0sCiAgICAgICAgInR5cGUiOiAiUG9pbnQiCiAgICAgIH0KICAgIH0sCiAgICB7CiAgICAgICJpZCI6IDIsCiAgICAgICJ0eXBlIjogIkZlYXR1cmUiLAogICAgICAicHJvcGVydGllcyI6IHsKICAgICAgICAibmFtZSI6ICJIYW1icm9vaywgU291dGggR2xvdWNlc3RlcnNoaXJlIgogICAgICB9LAogICAgICAiZ2VvbWV0cnkiOiB7CiAgICAgICAgImNvb3JkaW5hdGVzIjogWwogICAgICAgICAgLTIuNTIsCiAgICAgICAgICA1MS40OQogICAgICAgIF0sCiAgICAgICAgInR5cGUiOiAiUG9pbnQiCiAgICAgIH0KICAgIH0sICAgIAogICAgewogICAgICAiaWQiOiAzLAogICAgICAidHlwZSI6ICJGZWF0dXJlIiwKICAgICAgInByb3BlcnRpZXMiOiB7CiAgICAgICAgIm5hbWUiOiAiSGFtYmxlLWxlLVJpY2UsIEhhbXBzaGlyZSIKICAgICAgfSwKICAgICAgImdlb21ldHJ5IjogewogICAgICAgICJjb29yZGluYXRlcyI6IFsKICAgICAgICAgIC0xLjMzLAogICAgICAgICAgNTAuODUKICAgICAgICBdLAogICAgICAgICJ0eXBlIjogIlBvaW50IgogICAgICB9CiAgICB9LCAgICAgICAgCiAgICB7CiAgICAgICJpZCI6IDQsCiAgICAgICJ0eXBlIjogIkZlYXR1cmUiLAogICAgICAicHJvcGVydGllcyI6IHsKICAgICAgICAibmFtZSI6ICJIYW0sIEtlbnQiCiAgICAgIH0sCiAgICAgICJnZW9tZXRyeSI6IHsKICAgICAgICAiY29vcmRpbmF0ZXMiOiBbCiAgICAgICAgICAxLjMyNiwKICAgICAgICAgIDUxLjIzMwogICAgICAgIF0sCiAgICAgICAgInR5cGUiOiAiUG9pbnQiCiAgICAgIH0KICAgIH0gICAgCiAgXQp9Cg==
|
|
79
|
+
max_bounds:
|
|
80
|
+
description: Limits the map to a particular area. Numbers represent West, South, East, and North. Note that if the numbers are wrong or contradict this will have adverse effects on the map.
|
|
81
|
+
data:
|
|
82
|
+
heading_text: A map of only the area around London
|
|
83
|
+
zoom: 9
|
|
84
|
+
centre:
|
|
85
|
+
- -0.12
|
|
86
|
+
- 51.5
|
|
87
|
+
max_bounds:
|
|
88
|
+
- -1
|
|
89
|
+
- 51.1
|
|
90
|
+
- 1
|
|
91
|
+
- 51.9
|
|
92
|
+
custom_height:
|
|
93
|
+
description: The map defaults to a height of 500px on desktop but this can be overridden if required. The height on tablet and mobile is set to be no taller than the window.
|
|
94
|
+
data:
|
|
95
|
+
height: 200
|
|
96
|
+
heading_text: Kings Cross station
|
|
97
|
+
geojson: data:application/geo+json;base64,ewogICJ0eXBlIjogIkZlYXR1cmVDb2xsZWN0aW9uIiwKICAiZmVhdHVyZXMiOiBbCiAgICB7CiAgICAgICJpZCI6IDEsCiAgICAgICJ0eXBlIjogIkZlYXR1cmUiLAogICAgICAicHJvcGVydGllcyI6IHsKICAgICAgICAiZGVzY3JpcHRpb24iOiAiT3BlbmVkIGluIDE4NTIgYW5kIGJ1aWx0IG9uIHRoZSBzaXRlIG9mIGEgc21hbGxwb3ggYW5kIGZldmVyIGhvc3BpdGFsLiIsCiAgICAgICAgIm5hbWUiOiAiS2luZ3MgQ3Jvc3Mgc3RhdGlvbiIKICAgICAgfSwKICAgICAgImdlb21ldHJ5IjogewogICAgICAgICJjb29yZGluYXRlcyI6IFsKICAgICAgICAgIC0wLjEyMzYsCiAgICAgICAgICA1MS41MzE2CiAgICAgICAgXSwKICAgICAgICAidHlwZSI6ICJQb2ludCIKICAgICAgfQogICAgfQogIF0KfQo=
|
|
98
|
+
zoom: 12
|
|
99
|
+
centre:
|
|
100
|
+
- -0.1236
|
|
101
|
+
- 51.5316
|
|
102
|
+
without_ga4_tracking:
|
|
103
|
+
data:
|
|
104
|
+
disable_ga4: true
|
|
105
|
+
heading_text: London stations
|
|
106
|
+
geojson: data:application/geo+json;base64,ewogICJ0eXBlIjogIkZlYXR1cmVDb2xsZWN0aW9uIiwKICAiZmVhdHVyZXMiOiBbCiAgICB7CiAgICAgICJpZCI6IDEsCiAgICAgICJ0eXBlIjogIkZlYXR1cmUiLAogICAgICAicHJvcGVydGllcyI6IHsKICAgICAgICAiZGVzY3JpcHRpb24iOiAiRGVzaWduZWQgYnkgSXNhbWJhcmQgS2luZ2RvbSBCcnVuZWwgYW5kIG9wZW5lZCBpbiAxODM4LiIsCiAgICAgICAgIm5hbWUiOiAiUGFkZGluZ3RvbiBTdGF0aW9uIgogICAgICB9LAogICAgICAiZ2VvbWV0cnkiOiB7CiAgICAgICAgImNvb3JkaW5hdGVzIjogWwogICAgICAgICAgLTAuMTc2NiwKICAgICAgICAgIDUxLjUxNjMKICAgICAgICBdLAogICAgICAgICJ0eXBlIjogIlBvaW50IgogICAgICB9CiAgICB9LAogICAgewogICAgICAiaWQiOiAyLAogICAgICAidHlwZSI6ICJGZWF0dXJlIiwKICAgICAgInByb3BlcnRpZXMiOiB7CiAgICAgICAgIm5hbWUiOiAiTWFyeWxlYm9uZSBTdGF0aW9uIgogICAgICB9LAogICAgICAiZ2VvbWV0cnkiOiB7CiAgICAgICAgImNvb3JkaW5hdGVzIjogWwogICAgICAgICAgLTAuMTYzMiwKICAgICAgICAgIDUxLjUyMjQKICAgICAgICBdLAogICAgICAgICJ0eXBlIjogIlBvaW50IgogICAgICB9CiAgICB9CiAgXQp9Cg==
|
|
107
|
+
zoom: 13
|
|
108
|
+
centre:
|
|
109
|
+
- -0.17
|
|
110
|
+
- 51.52
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module GovukPublishingComponents
|
|
2
|
+
module AppHelpers
|
|
3
|
+
class ContentSecurityPolicy
|
|
4
|
+
def self.configure_policy_for_map(policy)
|
|
5
|
+
# The map component makes use of maplibre
|
|
6
|
+
policy.img_src(*policy.img_src, "https://tiles.openfreemap.org", :data)
|
|
7
|
+
policy.connect_src(*policy.connect_src, "https://tiles.openfreemap.org", :data)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -46,6 +46,7 @@ require "govuk_publishing_components/presenters/pagination_helper"
|
|
|
46
46
|
require "govuk_publishing_components/app_helpers/taxon_breadcrumbs"
|
|
47
47
|
require "govuk_publishing_components/app_helpers/table_helper"
|
|
48
48
|
require "govuk_publishing_components/app_helpers/brand_helper"
|
|
49
|
+
require "govuk_publishing_components/app_helpers/csp_helper"
|
|
49
50
|
require "govuk_publishing_components/app_helpers/environment"
|
|
50
51
|
|
|
51
52
|
# Add i18n paths and views for usage outside of a Rails app
|