@ons/design-system 72.5.0 → 72.6.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.
Files changed (37) hide show
  1. package/components/chart/_chart.scss +51 -0
  2. package/components/chart/_macro.njk +27 -3
  3. package/components/chart/_macro.spec.js +388 -0
  4. package/components/chart/annotations-options.js +78 -0
  5. package/components/chart/bar-chart.js +6 -2
  6. package/components/chart/chart.js +111 -26
  7. package/components/chart/column-chart.js +2 -2
  8. package/components/chart/common-chart-options.js +97 -50
  9. package/components/chart/example-bar-chart-with-annotations.njk +62 -0
  10. package/components/chart/example-bar-chart.njk +1 -0
  11. package/components/chart/example-bar-with-line-chart.njk +64 -0
  12. package/components/chart/example-clustered-column-chart.njk +3 -1
  13. package/components/chart/example-column-chart-with-annotations.njk +62 -0
  14. package/components/chart/example-column-chart.njk +3 -1
  15. package/components/chart/example-column-with-line-chart.njk +62 -0
  16. package/components/chart/example-line-chart-with-annotations.njk +235 -0
  17. package/components/chart/example-line-chart.njk +4 -2
  18. package/components/chart/example-stacked-column-chart.njk +3 -1
  19. package/components/chart/line-chart.js +2 -7
  20. package/components/hero/_hero.scss +31 -0
  21. package/components/hero/_macro.njk +20 -9
  22. package/components/hero/_macro.spec.js +94 -0
  23. package/components/hero/example-hero-grey.njk +8 -0
  24. package/components/icon/_macro.njk +1 -1
  25. package/components/pagination/_pagination.scss +7 -1
  26. package/components/summary/_macro.njk +1 -1
  27. package/components/summary/_macro.spec.js +6 -0
  28. package/components/table-of-contents/_macro.njk +40 -0
  29. package/components/table-of-contents/_macro.spec.js +72 -0
  30. package/components/table-of-contents/_table-of-contents.scss +11 -0
  31. package/components/table-of-contents/example-table-of-contents-related-links-with-button.njk +60 -0
  32. package/css/main.css +1 -1
  33. package/js/cookies-functions.js +11 -6
  34. package/js/cookies-functions.spec.js +44 -0
  35. package/package.json +1 -1
  36. package/scripts/main.es5.js +1 -1
  37. package/scripts/main.js +1 -1
@@ -75,7 +75,6 @@ export function getConsentCookie() {
75
75
 
76
76
  export function setConsentCookie(options) {
77
77
  const domain = getDomain(document.domain);
78
-
79
78
  let cookieConsent = getConsentCookie();
80
79
  if (!cookieConsent) {
81
80
  cookieConsent = JSON.parse(JSON.stringify(DEFAULT_COOKIE_CONSENT).replace(/'/g, '"'));
@@ -168,15 +167,21 @@ export function getCookie(name) {
168
167
  return null;
169
168
  }
170
169
 
171
- export function getDomain(domain) {
170
+ export function getDomain(domain, cookieHandler = document) {
171
+ if (domain.startsWith('www.')) {
172
+ domain = domain.substring(4);
173
+ }
172
174
  let i = 0,
173
175
  domainName = domain,
174
176
  p = domainName.split('.'),
175
177
  s = '_gd' + new Date().getTime();
176
- while (i < p.length - 1 && document.cookie.indexOf(s + '=' + s) == -1) {
177
- domainName = p.slice(-1 - ++i).join('.');
178
- document.cookie = s + '=' + s + ';domain=' + domainName + ';';
178
+ while (i < p.length - 1 && cookieHandler.cookie.indexOf(s + '=' + s) == -1) {
179
+ // Loop until we find a valid cookie set at the domain or until we've checked all possible domains
180
+ domainName = p.slice(i, p.length).join('.');
181
+ cookieHandler.cookie = s + '=' + s + ';domain=' + domainName + ';';
182
+
183
+ i++;
179
184
  }
180
- document.cookie = s + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=' + domainName + ';';
185
+ cookieHandler.cookie = s + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=' + domainName + ';';
181
186
  return domainName;
182
187
  }
@@ -0,0 +1,44 @@
1
+ /** @jest-environment jsdom */
2
+
3
+ import { getDomain } from './cookies-functions';
4
+ let mockCookieStore = {};
5
+
6
+ // Mocking document.cookie which is used for setting domain name in `getDomain()`
7
+ export const setMockcookie = {
8
+ get cookie() {
9
+ return Object.entries(mockCookieStore)
10
+ .map(([key, value]) => `${key}=${value}`)
11
+ .join('; ');
12
+ },
13
+ set cookie(value) {
14
+ const domainMatch = value.match(/domain=([^;]+)/i);
15
+ const domain = domainMatch?.[1]?.trim();
16
+
17
+ // Simulate failure to set cookie on this domain
18
+ if (domain === 'new-website.ons.gov.uk') return;
19
+
20
+ const [key, val] = value.split('=');
21
+ mockCookieStore[key] = val.split(';')[0];
22
+ },
23
+ };
24
+
25
+ describe('script: getDomain()', () => {
26
+ beforeEach(() => {
27
+ mockCookieStore = {}; // clear the cookie between tests
28
+ });
29
+
30
+ test('should return service-manual.ons.gov.uk as the domain name when cookies can be set at the full subdomain', () => {
31
+ const result = getDomain('service-manual.ons.gov.uk', setMockcookie);
32
+ expect(result).toBe('service-manual.ons.gov.uk');
33
+ });
34
+
35
+ test('should remove `www` from the domain name www.ons.gov.uk', () => {
36
+ const result = getDomain('www.ons.gov.uk', setMockcookie);
37
+ expect(result).toBe('ons.gov.uk');
38
+ });
39
+
40
+ test('returns `ons.gov.uk` as the domain name when cookies can not be set at subdomain `new-website.ons.gov.uk`', () => {
41
+ const result = getDomain('new-website.ons.gov.uk', setMockcookie);
42
+ expect(result).toBe('ons.gov.uk');
43
+ });
44
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ons/design-system",
3
3
  "description": "ONS Design System built CSS, JS, and Nunjucks templates",
4
- "version": "72.5.0",
4
+ "version": "72.6.0",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "author": {