@onsvisual/svelte-components 0.0.7 → 0.0.9

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 (63) hide show
  1. package/dist/@types/datavis/Table/Table.svelte.d.ts +4 -4
  2. package/dist/@types/datavis/shared/data.d.ts +6 -0
  3. package/dist/@types/index.d.ts +1 -0
  4. package/dist/@types/inputs/Button/Button.svelte.d.ts +2 -2
  5. package/dist/@types/inputs/Checkbox/Checkbox.svelte.d.ts +41 -0
  6. package/dist/@types/inputs/Checkboxes/Checkboxes.svelte.d.ts +37 -0
  7. package/dist/@types/inputs/Dropdown/Dropdown.svelte.d.ts +2 -2
  8. package/dist/@types/inputs/ErrorPanel/ErrorPanel.svelte.d.ts +27 -0
  9. package/dist/@types/inputs/ErrorSummary/ErrorSummary.svelte.d.ts +29 -0
  10. package/dist/@types/inputs/Input/Input.svelte.d.ts +2 -2
  11. package/dist/@types/inputs/Radios/Radio.svelte.d.ts +37 -0
  12. package/dist/@types/inputs/Radios/Radios.svelte.d.ts +39 -0
  13. package/dist/@types/inputs/Select/Select.svelte.d.ts +2 -2
  14. package/dist/@types/inputs/Textarea/Textarea.svelte.d.ts +2 -2
  15. package/dist/@types/layout/Accordion/AccordionItem.svelte.d.ts +2 -2
  16. package/dist/@types/layout/AnalyticsBanner/AnalyticsBanner.svelte.d.ts +30 -0
  17. package/dist/@types/layout/BackLink/Backlink.svelte.d.ts +23 -0
  18. package/dist/@types/layout/Breadcrumb/Breadcrumb.svelte.d.ts +23 -0
  19. package/dist/@types/layout/Contents/Contents.svelte.d.ts +29 -0
  20. package/dist/@types/layout/ErrorPage/ErrorPage.svelte.d.ts +25 -0
  21. package/dist/@types/layout/Grid/Grid.svelte.d.ts +2 -2
  22. package/dist/@types/layout/Header/Header.svelte.d.ts +2 -2
  23. package/dist/@types/layout/Hero/Hero.svelte.d.ts +2 -2
  24. package/dist/@types/layout/NavSections/NavSection.svelte.d.ts +2 -2
  25. package/dist/@types/layout/Notice/Notice.svelte.d.ts +31 -0
  26. package/dist/@types/layout/PhaseBanner/PhaseBanner.svelte.d.ts +25 -0
  27. package/dist/@types/layout/Scroller/Scroller.svelte.d.ts +2 -2
  28. package/dist/@types/layout/Scroller/ScrollerSection.svelte.d.ts +2 -2
  29. package/dist/@types/layout/Section/Section.svelte.d.ts +2 -2
  30. package/dist/@types/layout/ShareButtons/ShareButtons.svelte.d.ts +33 -0
  31. package/dist/@types/layout/Summary/Summary.svelte.d.ts +25 -0
  32. package/dist/@types/layout/Survey/Survey.svelte.d.ts +23 -0
  33. package/dist/@types/layout/Survey/init-survey.d.ts +1 -0
  34. package/dist/@types/layout/Tabs/Tab.svelte.d.ts +31 -0
  35. package/dist/@types/layout/Tabs/Tabs.svelte.d.ts +27 -0
  36. package/dist/@types/layout/TitleBlock/TitleBlock.svelte.d.ts +2 -2
  37. package/dist/css/main.css +2 -2
  38. package/dist/datavis/shared/data.js +18 -0
  39. package/dist/index.js +2 -0
  40. package/dist/inputs/Checkbox/Checkbox.svelte +133 -0
  41. package/dist/inputs/Checkboxes/Checkboxes.svelte +33 -0
  42. package/dist/inputs/ErrorPanel/ErrorPanel.svelte +35 -0
  43. package/dist/inputs/ErrorSummary/ErrorSummary.svelte +40 -0
  44. package/dist/inputs/Radios/Radio.svelte +108 -0
  45. package/dist/inputs/Radios/Radios.svelte +46 -0
  46. package/dist/layout/AnalyticsBanner/AnalyticsBanner.svelte +256 -0
  47. package/dist/layout/BackLink/Backlink.svelte +32 -0
  48. package/dist/layout/Breadcrumb/Breadcrumb.svelte +39 -0
  49. package/dist/layout/Contents/Contents.svelte +44 -0
  50. package/dist/layout/ErrorPage/ErrorPage.svelte +39 -0
  51. package/dist/layout/Header/Header.svelte +1 -1
  52. package/dist/layout/NavSections/NavSection.svelte +2 -2
  53. package/dist/layout/Notice/Notice.svelte +54 -0
  54. package/dist/layout/PhaseBanner/PhaseBanner.svelte +40 -0
  55. package/dist/layout/Scroller/ScrollerSection.svelte +2 -2
  56. package/dist/layout/Section/Section.svelte +2 -2
  57. package/dist/layout/ShareButtons/ShareButtons.svelte +177 -0
  58. package/dist/layout/Summary/Summary.svelte +51 -0
  59. package/dist/layout/Survey/Survey.svelte +96 -0
  60. package/dist/layout/Survey/init-survey.js +230 -0
  61. package/dist/layout/Tabs/Tab.svelte +48 -0
  62. package/dist/layout/Tabs/Tabs.svelte +85 -0
  63. package/package.json +22 -1
@@ -0,0 +1,18 @@
1
+ export default [
2
+ { year: 2017, value: 320, group: "apples" },
3
+ { year: 2017, value: 480, group: "bananas" },
4
+ { year: 2017, value: 640, group: "cherries" },
5
+ { year: 2017, value: 400, group: "dates" },
6
+ { year: 2018, value: 640, group: "apples" },
7
+ { year: 2018, value: 960, group: "bananas" },
8
+ { year: 2018, value: 640, group: "cherries" },
9
+ { year: 2018, value: 400, group: "dates" },
10
+ { year: 2019, value: 1600, group: "apples" },
11
+ { year: 2019, value: 1440, group: "bananas" },
12
+ { year: 2019, value: 960, group: "cherries" },
13
+ { year: 2019, value: 400, group: "dates" },
14
+ { year: 2020, value: 3840, group: "apples" },
15
+ { year: 2020, value: 1920, group: "bananas" },
16
+ { year: 2020, value: 960, group: "cherries" },
17
+ { year: 2020, value: 400, group: "dates" },
18
+ ];
package/dist/index.js CHANGED
@@ -6,6 +6,8 @@ export { default as Theme } from "./wrappers/Theme/Theme.svelte";
6
6
 
7
7
  // Layout
8
8
  export { default as Accordion } from "./layout/Accordion/Accordion.svelte";
9
+ export { default as AnalyticsBanner } from "./layout/AnalyticsBanner/AnalyticsBanner.svelte";
10
+ export { AnalyticsEvent } from "./layout/AnalyticsBanner/AnalyticsBanner.svelte";
9
11
  export { default as Filler } from "./layout/Filler/Filler.svelte";
10
12
  export { default as Footer } from "./layout/Footer/Footer.svelte";
11
13
  export { default as Grid } from "./layout/Grid/Grid.svelte";
@@ -0,0 +1,133 @@
1
+ <script>
2
+ import { createEventDispatcher } from "svelte";
3
+
4
+ const dispatch = createEventDispatcher();
5
+
6
+ /**
7
+ * ID for input element
8
+ * @type {string}
9
+ */
10
+ export let id;
11
+ /**
12
+ * Label for input
13
+ * @type {string}
14
+ */
15
+ export let label;
16
+ /**
17
+ * Binding for checked state of input
18
+ * @type {boolean}
19
+ */
20
+ export let checked = false;
21
+ /**
22
+ * Binding for checked state of input
23
+ * @type {boolean}
24
+ */
25
+ export let group = null;
26
+ /**
27
+ * (Optional) Extended description for element
28
+ * @type {string}
29
+ */
30
+ export let description = null;
31
+ /**
32
+ * Set display mode of checkbox
33
+ * @type {"default"|"ghost"}
34
+ */
35
+ export let variant = "default";
36
+ /**
37
+ * Option to disable input
38
+ * @type {boolean}
39
+ */
40
+ export let disabled = false;
41
+ /**
42
+ * Compact mode (no border)
43
+ * @type {boolean}
44
+ */
45
+ export let compact = false;
46
+ </script>
47
+
48
+ <span
49
+ class="ons-checkboxes__item"
50
+ class:ons-checkboxes__item--ghost="{variant === 'ghost'}"
51
+ class:ons-checkboxes__item--no-border="{compact}"
52
+ >
53
+ <span class="ons-checkbox" class:ons-checkbox--no-border="{compact}">
54
+ {#if Array.isArray(group)}
55
+ <input
56
+ type="checkbox"
57
+ id="{id}"
58
+ value="{id}"
59
+ bind:group="{group}"
60
+ class="ons-checkbox__input ons-js-checkbox"
61
+ disabled="{disabled}"
62
+ aria-disabled="{disabled}"
63
+ on:change="{(e) => dispatch('change', e)}"
64
+ />
65
+ {:else}
66
+ <input
67
+ type="checkbox"
68
+ id="{id}"
69
+ value="{id}"
70
+ bind:checked="{checked}"
71
+ class="ons-checkbox__input ons-js-checkbox"
72
+ disabled="{disabled}"
73
+ aria-disabled="{disabled}"
74
+ on:change="{(e) => dispatch('change', e)}"
75
+ />
76
+ {/if}
77
+ <label
78
+ class="ons-checkbox__label"
79
+ class:ons-label--with-description="{description}"
80
+ for="{id}"
81
+ id="{id}-label"
82
+ aria-describedby="{description ? `${id}-label-description-hint` : null}"
83
+ >
84
+ {label}
85
+ {#if description}
86
+ <span class="ons-label__aria-hidden-description" aria-hidden="true"
87
+ ><span class="ons-label__description ons-radio__label--with-description">
88
+ {description}
89
+ </span></span
90
+ >
91
+ {/if}
92
+ </label>
93
+ {#if description}
94
+ <span
95
+ class="ons-label__visually-hidden-description ons-u-vh"
96
+ id="{id}-label-description-hint"
97
+ >
98
+ {description}
99
+ </span>
100
+ {/if}
101
+ </span>
102
+ </span>
103
+
104
+ <style>
105
+ .ons-checkboxes__item {
106
+ display: table;
107
+ }
108
+ .ons-checkbox__input:disabled {
109
+ border: 2px solid var(--ons-color-border-disabled);
110
+ }
111
+ .ons-checkboxes__item label::before {
112
+ background: none;
113
+ border-color: currentColor;
114
+ box-shadow: 0 0 0 1px currentColor;
115
+ }
116
+ .ons-checkboxes__item--ghost label::before {
117
+ opacity: 60%;
118
+ }
119
+ .ons-checkboxes__item .ons-checkbox__input:focus + .ons-checkbox__label::before {
120
+ box-shadow: 0 0 0 1px currentColor, 0 0 0 4px #fbc900;
121
+ opacity: 100%;
122
+ }
123
+ .ons-checkboxes__item input {
124
+ background: none;
125
+ border-color: currentColor;
126
+ }
127
+ .ons-checkboxes__item input::after {
128
+ border-color: currentColor;
129
+ }
130
+
131
+ .ons-checkboxes__item--no-border .ons-checkbox__input:focus {
132
+ box-shadow: 0 0 0 1px currentColor, 0 0 0 4px #fbc900;
133
+ }</style>
@@ -0,0 +1,33 @@
1
+ <script>
2
+ import Checkbox from "../Checkbox/Checkbox.svelte";
3
+
4
+ /**
5
+ * Label for grouped inputs
6
+ * @type {string}
7
+ */
8
+ export let label = "";
9
+ /** (Optional) Define the checkboxes as an array of {id, label, checked, description?}
10
+ * @type {array}
11
+ */
12
+ export let items = null;
13
+ /** Compact mode (no borders)
14
+ * @type {boolean}
15
+ */
16
+ export let compact = false;
17
+ /** Binding for selected checkboxes (if checkboxes are defined as "items")
18
+ * @type {array}
19
+ */
20
+ export let value = [];
21
+ </script>
22
+
23
+ {#if label}
24
+ <p class="ons-checkboxes__label">{label}</p>
25
+ {/if}
26
+ <div class="ons-checkboxes__items">
27
+ <slot />
28
+ {#if items}
29
+ {#each items as item, i}
30
+ <Checkbox {...item} group="{value}" compact="{compact}" on:change />
31
+ {/each}
32
+ {/if}
33
+ </div>
@@ -0,0 +1,35 @@
1
+ <script>
2
+ /**
3
+ * Set an error message
4
+ * @type {string}
5
+ */
6
+ export let message = "";
7
+ </script>
8
+
9
+ <div class="ons-panel ons-panel--error ons-panel--no-title" id="number-of-employees-error">
10
+ <span class="ons-panel__assistive-text ons-u-vh">Error: </span>
11
+ <div class="ons-panel__body">
12
+ {#if message}
13
+ <p class="ons-panel__error">
14
+ <strong>{message}</strong>
15
+ </p>
16
+ {/if}
17
+ <slot />
18
+ </div>
19
+ </div>
20
+
21
+ <style>
22
+ .ons-panel {
23
+ color: rgb(34, 34, 34);
24
+ }
25
+ :global(.ons-panel__body a) {
26
+ color: #206095 !important;
27
+ }
28
+ :global(.ons-panel__body a:hover) {
29
+ color: rgb(0, 60, 87) !important;
30
+ -webkit-text-decoration: underline solid rgb(0, 60, 87) 2px !important;
31
+ text-decoration: underline solid rgb(0, 60, 87) 2px !important;
32
+ }
33
+ :global(.ons-panel__body .ons-input) {
34
+ background: white !important;
35
+ }</style>
@@ -0,0 +1,40 @@
1
+ <script>
2
+ import List from "../../layout/List/List.svelte";
3
+
4
+ /**
5
+ * Defines the title of the error
6
+ * @type {string}
7
+ */
8
+ export let title = "";
9
+ /**
10
+ * Define an array of errors/issues in the format {label, href?}
11
+ */
12
+ export let items = [];
13
+ </script>
14
+
15
+ <div aria-labelledby="alert" role="alert" tabindex="-1" class="ons-panel ons-panel--error">
16
+ <div class="ons-panel__header">
17
+ <h2 id="alert" data-qa="error-header" class="ons-panel__title ons-u-fs-r--b">{title}</h2>
18
+ </div>
19
+ <div class="ons-panel__body">
20
+ {#if Array.isArray(items)}
21
+ <List mode="number">
22
+ {#each items as item}
23
+ <li>
24
+ {#if item.href}
25
+ <a href="{item.href}">{item.label}</a>
26
+ {:else}
27
+ {item.label}
28
+ {/if}
29
+ </li>
30
+ {/each}
31
+ </List>
32
+ {/if}
33
+ <slot />
34
+ </div>
35
+ </div>
36
+
37
+ <style>
38
+ .ons-panel {
39
+ color: rgb(34, 34, 34);
40
+ }</style>
@@ -0,0 +1,108 @@
1
+ <script>
2
+ import { createEventDispatcher } from "svelte";
3
+
4
+ const dispatch = createEventDispatcher();
5
+
6
+ /**
7
+ * Unique ID input
8
+ * @type {string}
9
+ */
10
+ export let id;
11
+ /**
12
+ * ID for radio group (required)
13
+ * @type {string}
14
+ */
15
+ export let groupId;
16
+ /**
17
+ * Label for input
18
+ * @type {string}
19
+ */
20
+ export let label;
21
+ /**
22
+ * Binding for ID of selected option
23
+ * @type {string}
24
+ */
25
+ export let value = null;
26
+ /**
27
+ * (Optional) Extended description for element
28
+ * @type {string}
29
+ */
30
+ export let description = null;
31
+ /**
32
+ * Compact mode (no border)
33
+ * @type {boolean}
34
+ */
35
+ export let compact = false;
36
+ </script>
37
+
38
+ <span class="ons-radios__item" class:ons-radios__item--no-border="{compact}">
39
+ <span class="ons-radio" class:ons-radio--no-border="{compact}">
40
+ <input
41
+ type="radio"
42
+ id="{id}"
43
+ bind:group="{value}"
44
+ value="{id}"
45
+ name="{groupId}"
46
+ class="ons-radio__input ons-js-radio"
47
+ on:change="{(e) => dispatch('change', e)}"
48
+ />
49
+ <label
50
+ class="ons-radio__label"
51
+ class:ons-label--with-description="{description}"
52
+ for="{id}"
53
+ id="{id}-label"
54
+ aria-describedby="{description ? `${id}-label-description-hint` : null}"
55
+ >
56
+ {label}
57
+ {#if description}
58
+ <span class="ons-label__aria-hidden-description" aria-hidden="true"
59
+ ><span class="ons-label__description ons-radio__label--with-description">
60
+ {description}
61
+ </span></span
62
+ >
63
+ {/if}
64
+ </label>
65
+ {#if description}
66
+ <span
67
+ class="ons-label__visually-hidden-description ons-u-vh"
68
+ id="{id}-label-description-hint"
69
+ >
70
+ {description}
71
+ </span>
72
+ {/if}
73
+ </span>
74
+ </span>
75
+
76
+ <style>
77
+ .ons-radios__item {
78
+ display: table;
79
+ }
80
+ .ons-radio__input {
81
+ border-color: currentColor !important;
82
+ background: none !important;
83
+ box-shadow: none !important;
84
+ }
85
+ .ons-radio--no-border .ons-radio__input:focus {
86
+ box-shadow: 0 0 0 1px currentColor, 0 0 0 4px #fbc900 !important;
87
+ }
88
+ .ons-radio__input:checked::after {
89
+ border-color: currentColor;
90
+ }
91
+ .ons-radio__input::after {
92
+ left: 50% !important;
93
+ top: 50% !important;
94
+ margin-left: -6px !important;
95
+ margin-top: -6px !important;
96
+ /* background-color: currentColor !important;
97
+ border-color: currentColor !important; */
98
+ }
99
+ .ons-radio__label::before {
100
+ background: none;
101
+ border-color: currentColor;
102
+ }
103
+ .ons-radio__input:checked + .ons-radio__label::before {
104
+ background: var(--pale, #f5f5f6);
105
+ }
106
+ .ons-radio__input:focus + .ons-radio__label::before {
107
+ box-shadow: 0 0 0 1px currentColor, 0 0 0 4px #fbc900;
108
+ }</style>
@@ -0,0 +1,46 @@
1
+ <script>
2
+ import Radio from "./Radio.svelte";
3
+
4
+ /**
5
+ * Unique ID for radio group (required)
6
+ * @type {string}
7
+ */
8
+ export let id = "name";
9
+ /**
10
+ * Label for grouped inputs
11
+ * @type {string}
12
+ */
13
+ export let label = "";
14
+ /**
15
+ * Binding for ID of selected option
16
+ * @type {string}
17
+ */
18
+ export let value = null;
19
+ /** (Optional) Define the radios as an array of {id, label, description?}
20
+ * @type {array}
21
+ */
22
+ export let items = [];
23
+ /**
24
+ * Compact mode (no border)
25
+ * @type {boolean}
26
+ */
27
+ export let compact = false;
28
+ </script>
29
+
30
+ {#if label}
31
+ <p class="ons-radios__label">{label}</p>
32
+ {/if}
33
+ <div class="ons-radios__items">
34
+ <slot />
35
+ {#each items as item, i}
36
+ <Radio
37
+ id="{item.id}"
38
+ label="{item.label}"
39
+ description="{item.description}"
40
+ groupId="{id}"
41
+ compact="{compact}"
42
+ bind:value="{value}"
43
+ on:change
44
+ />
45
+ {/each}
46
+ </div>
@@ -0,0 +1,256 @@
1
+ <script context="module">
2
+ export function analyticsEvent(props) {
3
+ if (window?.dataLayer) window.dataLayer.push(props);
4
+ }
5
+ </script>
6
+
7
+ <script>
8
+ import { onMount, getContext } from "svelte";
9
+
10
+ const page = getContext("page"); // Optional: Set Svelte Kit's page store to the context to track navigation in multi-page apps
11
+
12
+ /**
13
+ * Google analytics/tags manager ID
14
+ * @type {string}
15
+ */
16
+ export let analyticsId = "GTM-MBCBVQS";
17
+ /**
18
+ * Optional props to describe the content
19
+ * @type {object}
20
+ */
21
+ export let analyticsProps = {};
22
+ /**
23
+ * Bind to this value if you need to know if cookies have been accepted
24
+ * @type {boolean}
25
+ */
26
+ export let usageCookies = false;
27
+ /**
28
+ * Set the width of the banner
29
+ * @type {"medium"|"wide"}
30
+ */
31
+ export let width = "medium";
32
+
33
+ let live; // Don't run analytics unless page is live on ONS site (re-set in the onMount function)
34
+ let showBanner = false;
35
+ let showConfirm = false;
36
+ let message = "";
37
+ let lang = $page && $page.url.host.startsWith("cy") ? "cy" : "en";
38
+ let location = null; // For keeping track of navigation multi-page apps
39
+
40
+ function hasCookiesPreferencesSet() {
41
+ return -1 < document.cookie.indexOf("cookies_preferences_set=true");
42
+ }
43
+
44
+ // Check if usage cookies are allowed (for Google Analytics + Hotjar)
45
+ function getUsageCookieValue() {
46
+ var cookiesPolicyCookie = document.cookie.match(
47
+ new RegExp("(^|;) ?cookies_policy=([^;]*)(;|$)")
48
+ );
49
+ if (cookiesPolicyCookie) {
50
+ var decodedCookie = decodeURIComponent(cookiesPolicyCookie[2]);
51
+ var cookieValue = JSON.parse(decodedCookie);
52
+ return cookieValue.usage;
53
+ }
54
+ return false;
55
+ }
56
+
57
+ // Set site cookie with 'all' or 'essential' cookies
58
+ function setCookie(option) {
59
+ let oneYearInSeconds = 60 * 60 * 24 * 365;
60
+ let cookiesDomain = window.location.hostname;
61
+ let cookiesPreference = !0;
62
+ let encodedCookiesPolicy = `%7B%22essential%22%3Atrue%2C%22usage%22%3A${
63
+ option == "all" ? "true" : "false"
64
+ }%7D`;
65
+ let cookiesPath = "/";
66
+
67
+ document.cookie = `cookies_preferences_set=${cookiesPreference};max-age=${oneYearInSeconds};domain=${cookiesDomain};path=${cookiesPath};`;
68
+ document.cookie = `cookies_policy=${encodedCookiesPolicy};max-age=${oneYearInSeconds};domain=${cookiesDomain};path=${cookiesPath};`;
69
+
70
+ message = `You have ${option == "all" ? "accepted" : "rejected"} all additional cookies.`;
71
+ if (option == "all") usageCookies = true;
72
+ showConfirm = true;
73
+
74
+ if (option == "all") initAnalytics();
75
+ }
76
+
77
+ // Initialise analytics and 'window.dataLayer' (which can be used throughout the app)
78
+ function initAnalytics() {
79
+ console.log("initialising analytics");
80
+ window.dataLayer = [
81
+ {
82
+ analyticsOptOut: false,
83
+ "gtm.whitelist": ["google", "hjtc", "lcl"],
84
+ "gtm.blacklist": ["customScripts", "sp", "adm", "awct", "k", "d", "j"],
85
+ ...analyticsProps,
86
+ },
87
+ ];
88
+
89
+ (function (w, d, s, l, i) {
90
+ w[l] = w[l] || [];
91
+ w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" });
92
+ var f = d.head,
93
+ j = d.createElement(s),
94
+ dl = l != "dataLayer" ? "&l=" + l : "";
95
+ j.async = true;
96
+ j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl;
97
+ f.appendChild(j);
98
+ })(window, document, "script", "dataLayer", analyticsId);
99
+
100
+ if ($page) location = `${$page.url.href}`.replace($page.url.hash, "");
101
+ }
102
+
103
+ // This code is only relevant for multi-page Svelte Kit apps. It sends an analytics event when the URL changes
104
+ function onPageChange(page) {
105
+ if (page && location) {
106
+ const newlocation = `${page.url.href}`.replace(page.url.hash, "");
107
+ if (newlocation !== location) {
108
+ location = newlocation;
109
+ analyticsEvent({
110
+ event: "pageView",
111
+ pageURL: location,
112
+ ...analyticsProps,
113
+ });
114
+ }
115
+ }
116
+ }
117
+ $: onPageChange($page);
118
+
119
+ onMount(() => {
120
+ live = true;
121
+ //live = document.location.hostname == "www.ons.gov.uk" || document.location.hostname == "cy.ons.gov.uk";
122
+ if (!page) lang = document.location.host.startsWith("cy") ? "cy" : "en";
123
+ showBanner = !hasCookiesPreferencesSet();
124
+ usageCookies = getUsageCookieValue();
125
+ if (usageCookies && live) initAnalytics();
126
+ });
127
+
128
+ const texts = {
129
+ "Cookies on ons.gov.uk": "Cwcis ar ons.gov.uk",
130
+ "Cookies are small files stored on your device when you visit a website. We use some essential cookies to make this website work.":
131
+ "Ffeiliau bach a gaiff eu storio ar eich dyfais pan fyddwch yn mynd ar wefan yw cwcis. Rydym ni’n defnyddio rhai cwcis hanfodol i wneud i’r wefan hon weithio.",
132
+ "We would like to set": "Hoffem osod",
133
+ "additional cookies": "cwcis ychwanegol",
134
+ "to remember your settings and understand how you use the site. This helps us to improve our services.":
135
+ "er mwyn cofio eich gosodiadau a deall sut rydych chi’n defnyddio’r wefan. Mae hyn yn ein helpu ni i wella ein gwasanaethau.",
136
+ "Accept additional cookies": "Derbyn cwcis ychwanegol",
137
+ "Reject additional cookies": "Gwrthod cwcis ychwanegol",
138
+ "View cookies": "Gweld cwcis",
139
+ "You have accepted all additional cookies.": "Rydych chi wedi derbyn yr holl gwcis ychwanegol.",
140
+ "You have rejected all additional cookies.":
141
+ "Rydych chi wedi gwrthod yr holl gwcis ychwanegol.",
142
+ "You can": "Gallwch chi",
143
+ "change your cookie preferences": "newid eich dewisiadau o ran cwcis",
144
+ "at any time.": "ar unrhyw adeg.",
145
+ Hide: "Cuddio",
146
+ };
147
+ const i18n = (text) => (lang == "cy" && texts[text] ? texts[text] : text);
148
+ </script>
149
+
150
+ {#if showBanner}
151
+ <div
152
+ class="ons-cookies-banner"
153
+ role="region"
154
+ aria-label="Cookies banner"
155
+ style:display="{showBanner ? "block" : null}"
156
+ >
157
+ {#if !showConfirm}
158
+ <form
159
+ action="/cookies/accept-all"
160
+ method="GET"
161
+ id="global-cookie-message"
162
+ aria-label="cookie banner"
163
+ >
164
+ <div
165
+ class="ons-container ons-cookies-banner__primary"
166
+ class:ons-page__container--wide="{width === 'wide'}"
167
+ >
168
+ <div class="ons-grid">
169
+ <div class="ons-grid__col ons-col-8@m">
170
+ <h2 class="ons-cookies-banner__title ons-u-mb-xs">{i18n("Cookies on ons.gov.uk")}</h2>
171
+ <div class="ons-cookies-banner__statement">
172
+ <p>
173
+ {i18n(
174
+ "Cookies are small files stored on your device when you visit a website. We use some essential cookies to make this website work."
175
+ )}
176
+ </p>
177
+ <p>
178
+ {i18n("We would like to set")} <a href="/cookies">{i18n("additional cookies")}</a>
179
+ {i18n(
180
+ "to remember your settings and understand how you use the site. This helps us to improve our services."
181
+ )}
182
+ </p>
183
+ </div>
184
+ </div>
185
+ </div>
186
+ <div class="ons-grid ons-grid--flex ons-u-mt-s">
187
+ <div class="ons-grid__col">
188
+ <button
189
+ type="submit"
190
+ class="ons-btn ons-btn--small ons-js-accept-cookies ons-cookies-banner__btn"
191
+ data-button="accept"
192
+ on:click|preventDefault="{() => setCookie('all')}"
193
+ >
194
+ <span class="ons-btn__inner"
195
+ ><span class="ons-btn__text">{i18n("Accept additional cookies")}</span>
196
+ </span>
197
+ </button>
198
+ </div>
199
+ <div class="ons-grid__col">
200
+ <button
201
+ type="button"
202
+ class="ons-btn ons-btn--small ons-js-reject-cookies ons-cookies-banner__btn"
203
+ data-button="reject"
204
+ on:click|preventDefault="{() => setCookie('reject')}"
205
+ >
206
+ <span class="ons-btn__inner"
207
+ ><span class="ons-btn__text">{i18n("Reject additional cookies")}</span>
208
+ </span>
209
+ </button>
210
+ </div>
211
+ <div class="ons-grid__col">
212
+ <a class="ons-cookies-banner__link" href="/cookies">{i18n("View cookies")}</a>
213
+ </div>
214
+ </div>
215
+ </div>
216
+ </form>
217
+ {:else}
218
+ <div
219
+ class="ons-container ons-cookies-banner__confirmation"
220
+ class:ons-page__container--wide="{width === 'wide'}"
221
+ >
222
+ <div
223
+ class="ons-grid ons-grid--flex ons-grid--between ons-grid--gutterless ons-grid--no-wrap@s ons-grid--vertical-center"
224
+ >
225
+ <div class="ons-grid__col ons-grid__col--flex ons-col-auto ons-u-flex-shrink@s">
226
+ <p class="ons-cookies-banner__desc ons-u-mb-no@s ons-u-mr-s@s">
227
+ <span>{i18n(message)}</span>
228
+ <span class="ons-cookies-banner__preferences-text"
229
+ >{i18n("You can")} <a href="/cookies">{i18n("change your cookie preferences")}</a>
230
+ {i18n("at any time")}.</span
231
+ >
232
+ </p>
233
+ </div>
234
+ <div class="ons-grid__col">
235
+ <button
236
+ type="button"
237
+ class="ons-btn ons-btn--secondary ons-btn--small ons-js-hide-button"
238
+ on:click="{() => (showBanner = false)}"
239
+ >
240
+ <span class="ons-btn__inner"><span class="ons-btn__text">{i18n("Hide")}</span> </span>
241
+ </button>
242
+ </div>
243
+ </div>
244
+ </div>
245
+ {/if}
246
+ </div>
247
+ {/if}
248
+
249
+ <style>
250
+ .ons-cookies-banner {
251
+ /* padding: 0; */
252
+ background: none !important;
253
+ }
254
+ .ons-page__container--wide {
255
+ max-width: 1240px;
256
+ }</style>