govuk_publishing_components 24.1.1 → 24.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 664f19b71a4b1ec65f49a7a14fa21d4a2a64465b2f593a3c75e2de132474417a
4
- data.tar.gz: 8e734701d0d66817548de5855938a6cdad1f9b2ce2fa96437075e9058331785a
3
+ metadata.gz: 9ce32a486835dfd2796501f4cf80d3403ad4074fa1a832678a221fb9b607f3d3
4
+ data.tar.gz: 3b67448789550b585b08a3aa96666ac4fdc7a18cd5c6c8621668aa8e5ed91506
5
5
  SHA512:
6
- metadata.gz: 9073c4b0254a544f3a0f6da89889550786a3f0e7cc5611b6c89768be9c8d66ff27b8364d54525e677013c439e73acb7dd618289f2d72787d56b6f833d89df910
7
- data.tar.gz: 2ed858269eee93ae2212110fd2aa4b4cee21106e5028a36508d3242982a8e60be387b1f31e8b7694f1b66b401707049865f4fda1338639d3b9ce5e702db99b05
6
+ metadata.gz: c3a19281a025aa4f0a0c51a14c06844d4ad67b2de6217fe57cf87bef328ed42a0bc7b959d0c07672d58e68b7e7995d7b2e02a47744723854ad7e3444ee3b748f
7
+ data.tar.gz: f866b24a0aa8c7cce2dfe1f3c4bab39aa977d1e40ded6abc218563c365fba0f743efe2a4d1ce47091beb5610b98f2c0acc367b18b11a533cfbe92f9eadb5ece9
@@ -9,10 +9,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
9
9
  this.$module.hideCookieMessage = this.hideCookieMessage.bind(this)
10
10
  this.$module.showConfirmationMessage = this.showConfirmationMessage.bind(this)
11
11
  this.$module.setCookieConsent = this.setCookieConsent.bind(this)
12
+ this.$module.rejectCookieConsent = this.rejectCookieConsent.bind(this)
12
13
 
13
14
  this.$module.cookieBanner = document.querySelector('.gem-c-cookie-banner')
14
15
  this.$module.cookieBannerConfirmationMessage = this.$module.querySelector('.gem-c-cookie-banner__confirmation')
15
-
16
+ this.$module.cookieBannerConfirmationMessageText = this.$module.querySelector('.gem-c-cookie-banner__confirmation-message')
16
17
  this.setupCookieMessage()
17
18
  }
18
19
 
@@ -24,9 +25,16 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
24
25
  }
25
26
  }
26
27
 
27
- this.$acceptCookiesLink = this.$module.querySelector('button[data-accept-cookies]')
28
- if (this.$acceptCookiesLink) {
29
- this.$acceptCookiesLink.addEventListener('click', this.$module.setCookieConsent)
28
+ this.$acceptCookiesButton = this.$module.querySelector('button[data-accept-cookies]')
29
+ if (this.$acceptCookiesButton) {
30
+ this.$acceptCookiesButton.style.display = 'block'
31
+ this.$acceptCookiesButton.addEventListener('click', this.$module.setCookieConsent)
32
+ }
33
+
34
+ this.$rejectCookiesButton = this.$module.querySelector('button[data-reject-cookies]')
35
+ if (this.$rejectCookiesButton) {
36
+ this.$rejectCookiesButton.style.display = 'block'
37
+ this.$rejectCookiesButton.addEventListener('click', this.$module.rejectCookieConsent)
30
38
  }
31
39
 
32
40
  this.showCookieMessage()
@@ -56,6 +64,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
56
64
 
57
65
  CookieBanner.prototype.hideCookieMessage = function (event) {
58
66
  if (this.$module) {
67
+ this.$module.hidden = true
59
68
  this.$module.style.display = 'none'
60
69
  window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
61
70
  }
@@ -66,6 +75,9 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
66
75
  }
67
76
 
68
77
  CookieBanner.prototype.setCookieConsent = function () {
78
+ if (this.$acceptCookiesButton.getAttribute('data-cookie-types') === 'all') {
79
+ this.$module.cookieBannerConfirmationMessageText.insertAdjacentHTML('afterbegin', 'You have accepted additional cookies. ')
80
+ }
69
81
  window.GOVUK.approveAllCookieTypes()
70
82
  this.$module.showConfirmationMessage()
71
83
  this.$module.cookieBannerConfirmationMessage.focus()
@@ -78,11 +90,19 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
78
90
  }
79
91
  }
80
92
 
93
+ CookieBanner.prototype.rejectCookieConsent = function () {
94
+ this.$module.cookieBannerConfirmationMessageText.insertAdjacentHTML('afterbegin', 'You have rejected additional cookies. ')
95
+ this.$module.showConfirmationMessage()
96
+ this.$module.cookieBannerConfirmationMessage.focus()
97
+ window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
98
+ }
99
+
81
100
  CookieBanner.prototype.showConfirmationMessage = function () {
82
- this.$cookieBannerMainContent = document.querySelector('.gem-c-cookie-banner__wrapper')
101
+ this.$cookieBannerMainContent = document.querySelector('.js-banner-wrapper')
83
102
 
84
- this.$cookieBannerMainContent.style.display = 'none'
103
+ this.$cookieBannerMainContent.hidden = true
85
104
  this.$module.cookieBannerConfirmationMessage.style.display = 'block'
105
+ this.$module.cookieBannerConfirmationMessage.hidden = false
86
106
  }
87
107
 
88
108
  CookieBanner.prototype.isInCookiesPage = function () {
@@ -1,3 +1,4 @@
1
+ @import "govuk/components/cookie-banner/cookie-banner";
1
2
  $govuk-cookie-banner-background: govuk-colour("light-grey", "grey-4");
2
3
 
3
4
  .js-enabled {
@@ -7,50 +8,14 @@ $govuk-cookie-banner-background: govuk-colour("light-grey", "grey-4");
7
8
  }
8
9
 
9
10
  .gem-c-cookie-banner {
10
- @include govuk-font($size: 16);
11
- padding: govuk-spacing(2) 0;
12
11
  background-color: $govuk-cookie-banner-background;
13
12
  }
14
13
 
15
- .gem-c-cookie-banner--services {
14
+ // can't be used without js so implement there
15
+ .gem-c-cookie-banner .gem-c-button {
16
16
  display: none;
17
17
  }
18
18
 
19
- .gem-c-cookie-banner__message {
20
- display: inline-block;
21
- padding-bottom: govuk-spacing(2);
22
-
23
- @include govuk-font($size: 16);
24
- @include govuk-media-query($from: desktop) {
25
- padding-right: govuk-spacing(4);
26
- }
27
- }
28
-
29
- .gem-c-cookie-banner__button {
30
- &.govuk-grid-column-one-half-from-desktop {
31
- padding: 0;
32
- }
33
-
34
- .govuk-button {
35
- @include govuk-media-query($from: desktop) {
36
- width: 90%;
37
- }
38
-
39
- @include govuk-media-query($until: desktop) {
40
- margin-bottom: govuk-spacing(4);
41
- }
42
- }
43
- }
44
-
45
- // Only show accept button if users have js and can accept
46
- .gem-c-cookie-banner__button-accept {
47
- display: none;
48
- }
49
-
50
- .js-enabled .gem-c-cookie-banner__button-accept {
51
- display: inline-block;
52
- }
53
-
54
19
  .gem-c-cookie-banner__confirmation {
55
20
  display: none;
56
21
  position: relative;
@@ -81,51 +46,11 @@ $govuk-cookie-banner-background: govuk-colour("light-grey", "grey-4");
81
46
  }
82
47
  }
83
48
 
84
- .gem-c-cookie-banner__hide-button {
85
- @include govuk-font($size: 19);
86
- outline: 0;
87
- border: 0;
88
- background: none;
89
- text-decoration: underline;
90
- color: $govuk-link-colour;
91
- padding: govuk-spacing(0);
92
- margin-top: govuk-spacing(2);
93
-
94
- &:hover {
95
- color: $govuk-link-hover-colour;
96
- cursor: pointer;
97
- }
98
-
99
- &:focus {
100
- @include govuk-focused-text;
101
- }
102
-
103
- @include govuk-media-query($from: desktop) {
104
- margin-top: govuk-spacing(0);
105
- position: absolute;
106
- right: govuk-spacing(1);
107
- }
108
- }
109
-
110
- .gem-c-cookie-banner__buttons--flex {
111
- display: flex;
112
- flex-wrap: wrap;
113
- align-items: baseline;
114
-
115
- .govuk-button,
116
- .gem-c-cookie-banner__link {
117
- flex-grow: 1;
118
- flex-basis: 10rem;
119
- margin-right: govuk-spacing(3);
120
- margin-bottom: govuk-spacing(3);
121
- }
122
- }
123
-
124
49
  // Override the styles from govuk_template
125
50
  // stylelint-disable selector-max-id
126
51
  .gem-c-cookie-banner#global-cookie-message {
127
52
  background-color: $govuk-cookie-banner-background;
128
- padding: govuk-spacing(4) 0;
53
+ padding: 0;
129
54
  box-sizing: border-box;
130
55
 
131
56
  .gem-c-cookie-banner__message,
@@ -135,18 +60,13 @@ $govuk-cookie-banner-background: govuk-colour("light-grey", "grey-4");
135
60
  @include govuk-font($size: 19);
136
61
  }
137
62
 
138
- .gem-c-cookie-banner__message {
139
- margin-bottom: 0;
140
- }
141
-
142
63
  p {
143
64
  @include govuk-font($size: 19);
144
65
  margin: 0 0 govuk-spacing(2) 0;
145
66
  }
146
67
 
147
- .gem-c-cookie-banner__confirmation-message {
148
- @include govuk-media-query($from: desktop) {
149
- margin-bottom: 0;
150
- }
68
+ .gem-c-cookie-banner__message,
69
+ .gem-c-cookie-banner__confirmation {
70
+ margin-bottom: - govuk-spacing(2);
151
71
  }
152
72
  }
@@ -1,72 +1,83 @@
1
1
  <%
2
2
  id ||= 'global-cookie-message'
3
- title ||= "Tell us whether you accept cookies"
4
- text ||= raw("We use <a class='govuk-link' href='/help/cookies'>cookies to collect information</a> about how you use GOV.UK. We use this information to make the website work as well as possible and improve government services.")
3
+ title ||= "Cookies on GOV.UK"
4
+ text ||= ["We use some essential cookies to make this website work.", "We’d like to set additional cookies to understand how you use GOV.UK, remember your settings and improve government services.", "We also use cookies set by other sites to help us deliver content from their services."]
5
+ if text.kind_of?(Array)
6
+ newtext = ""
7
+ text.each do |t|
8
+ newtext += "<p class='govuk-body'>#{t}</p>"
9
+ end
10
+ text = newtext
11
+ else
12
+ text = "<p class='govuk-body'>#{text}</p>"
13
+ end
14
+ text = raw(text)
15
+
5
16
  cookie_preferences_href ||= "/help/cookies"
6
- confirmation_message ||= raw("You’ve accepted all cookies. You can <a class='govuk-link' href='#{cookie_preferences_href}' data-module='track-click' data-track-category='cookieBanner' data-track-action='Cookie banner settings clicked from confirmation'>change your cookie settings</a> at any time.")
17
+ confirmation_message ||= raw("You can <a class='govuk-link' href='#{cookie_preferences_href}' data-module='track-click' data-track-category='cookieBanner' data-track-action='Cookie banner settings clicked from confirmation'>change your cookie settings</a> at any time.")
7
18
  services_cookies ||= nil
8
19
  css_classes = %w(gem-c-cookie-banner govuk-clearfix)
9
20
  css_classes << "gem-c-cookie-banner--services" if services_cookies
10
21
  %>
11
-
12
22
  <div id="<%= id %>" class="<%= css_classes.join(' ') %>" data-module="cookie-banner" role="region" aria-label="cookie banner" data-nosnippet>
13
- <div class="gem-c-cookie-banner__wrapper govuk-width-container">
14
- <div class="govuk-grid-row">
15
- <div class="govuk-grid-column-two-thirds">
16
- <div class="gem-c-cookie-banner__message">
17
- <h2 class="govuk-heading-m"><%= title %></h2>
18
- <p class="govuk-body"><%= text %></p>
23
+ <div class="govuk-cookie-banner js-banner-wrapper" role="region" aria-label="<%= title %>">
24
+ <div class="gem-c-cookie-banner__message govuk-cookie-banner__message govuk-width-container">
25
+ <div class="govuk-grid-row">
26
+ <div class="govuk-grid-column-two-thirds">
27
+ <h2 class="govuk-cookie-banner__heading govuk-heading-m"><%= title %></h2>
28
+ <div class="govuk-cookie-banner__content">
29
+ <%= text %>
30
+ </div>
19
31
  </div>
20
- <% if services_cookies %>
21
- <div class="gem-c-cookie-banner__buttons gem-c-cookie-banner__buttons--flex">
32
+ </div>
33
+ <% if services_cookies %>
34
+ <div class="govuk-button-group">
22
35
  <%= render "govuk_publishing_components/components/button", {
36
+ name: "cookies",
23
37
  text: services_cookies.dig(:yes, :text) || "Yes",
24
- inline_layout: true,
25
38
  data_attributes: { module: "track-click", "accept-cookies": "true", }.merge(services_cookies.dig(:yes, :data_attributes) || {})
26
39
  } %>
27
40
  <%= render "govuk_publishing_components/components/button", {
41
+ name: "cookies",
28
42
  text: services_cookies.dig(:no, :text) || "No",
29
- inline_layout: true,
30
- data_attributes: { module: "track-click", "hide-cookie-banner": "true", }.merge(services_cookies.dig(:no, :data_attributes) || {})
43
+ data_attributes: { module: "track-click", "reject-cookies": "true", }.merge(services_cookies.dig(:no, :data_attributes) || {})
31
44
  } %>
32
45
  <% if services_cookies[:cookie_preferences] %>
33
- <%= link_to services_cookies.dig(:cookie_preferences, :text), services_cookies.dig(:cookie_preferences, :href), class: "gem-c-cookie-banner__link govuk-link" %>
46
+ <%= link_to services_cookies.dig(:cookie_preferences, :text), services_cookies.dig(:cookie_preferences, :href), class: "govuk-link" %>
34
47
  <% end %>
35
48
  </div>
36
49
  <% else %>
37
- <div class="gem-c-cookie-banner__buttons">
38
- <div class="gem-c-cookie-banner__button gem-c-cookie-banner__button-accept govuk-grid-column-full govuk-grid-column-one-half-from-desktop">
39
- <%= render "govuk_publishing_components/components/button", {
40
- text: "Accept all cookies",
41
- inline_layout: true,
50
+ <div class="govuk-button-group">
51
+ <%= render "govuk_publishing_components/components/button", {
52
+ name: "cookies",
53
+ text: "Accept additional cookies",
42
54
  data_attributes: {
43
55
  module: "track-click",
44
56
  "accept-cookies": "true",
45
57
  "track-category": "cookieBanner",
46
- "track-action": "Cookie banner accepted"
58
+ "track-action": "Cookie banner accepted",
59
+ "cookie-types": "all",
47
60
  }
48
- } %>
49
- </div>
50
- <div class="gem-c-cookie-banner__button gem-c-cookie-banner__button-settings govuk-grid-column-full govuk-grid-column-one-half-from-desktop">
51
- <%= render "govuk_publishing_components/components/button", {
52
- text: "Set cookie preferences",
53
- href: cookie_preferences_href,
54
- inline_layout: true,
61
+ } %>
62
+ <%= render "govuk_publishing_components/components/button", {
63
+ name: "cookies",
64
+ text: "Reject additional cookies",
55
65
  data_attributes: {
56
66
  module: "track-click",
67
+ "reject-cookies": "true",
57
68
  "track-category": "cookieBanner",
58
- "track-action": "Cookie banner settings clicked"
69
+ "track-action": "Cookie banner rejected",
59
70
  }
60
- } %>
61
- </div>
71
+ } %>
72
+ <a class="govuk-link" href="<%= cookie_preferences_href %>">View cookies</a>
62
73
  </div>
63
74
  <% end %>
64
- </div>
65
75
  </div>
66
76
  </div>
67
-
68
- <div class="gem-c-cookie-banner__confirmation govuk-width-container" tabindex="-1">
77
+ <div class="gem-c-cookie-banner__confirmation govuk-width-container" tabindex="-1" hidden>
69
78
  <p class="gem-c-cookie-banner__confirmation-message" role="alert"><%= confirmation_message %></p>
70
- <button class="gem-c-cookie-banner__hide-button" data-hide-cookie-banner="true" data-module="track-click" data-track-category="cookieBanner" data-track-action="Hide cookie banner">Hide</button>
79
+ <div class="govuk-button-group">
80
+ <button class="gem-c-cookie-banner__hide-button govuk-button" data-hide-cookie-banner="true" data-module="track-click" data-track-category="cookieBanner" data-track-action="Hide cookie banner">Hide this message</button>
81
+ </div>
71
82
  </div>
72
83
  </div>
@@ -1,6 +1,8 @@
1
1
  name: Cookie banner
2
2
  description: Help users manage their personal data by telling them when you store cookies on their device.
3
3
  body: |
4
+ By default the cookie banner is shown to all users with just a link to the settings page. If JS is on this is enhanced to show accept/reject buttons if preferences aren't set, or to hide the banner if they are.
5
+
4
6
  Setting `data-hide-cookie-banner="true"` on any link inside the banner will overwrite the default action and when clicked will dismiss the cookie banner for a period of 365 days (approx. 1 year).
5
7
 
6
8
  If the examples below are not showing the banner, make sure the `cookies_preferences_set` cookie is not present or is set to false.
@@ -18,6 +20,13 @@ examples:
18
20
  title: "Can we store analytics cookies on your device?"
19
21
  text: "This is some custom text in my cookie banner which lets users know what we're using cookies for. I can also include a link to the <a class='govuk-link' href='/cookies'>cookies page</a>"
20
22
  confirmation_message: "You’ve accepted all cookies."
23
+
24
+ with_multi_paragraph_custom_content:
25
+ data:
26
+ title: "Can we store analytics cookies on your device?"
27
+ text: ["This is some custom text in my cookie banner.","There are three paragraphs.","They are passed as an array"]
28
+ confirmation_message: "You’ve accepted all cookies."
29
+
21
30
  with_custom_cookie_preferences_href:
22
31
  data:
23
32
  cookie_preferences_href: "/cookies"
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "24.1.1".freeze
2
+ VERSION = "24.2.0".freeze
3
3
  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: 24.1.1
4
+ version: 24.2.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: 2021-02-15 00:00:00.000000000 Z
11
+ date: 2021-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config