@justeattakeaway/pie-cookie-banner 0.26.11 → 1.0.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.
- package/custom-elements.json +103 -17
- package/dist/index.d.ts +49 -5
- package/dist/index.js +210 -146
- package/dist/react.d.ts +49 -5
- package/dist/react.js +12 -9
- package/locales/it-it.json +1 -1
- package/package.json +1 -1
- package/src/defs.ts +58 -7
- package/src/index.ts +42 -6
package/custom-elements.json
CHANGED
|
@@ -12,6 +12,22 @@
|
|
|
12
12
|
"kind": "javascript-module",
|
|
13
13
|
"path": "src/defs.js",
|
|
14
14
|
"declarations": [
|
|
15
|
+
{
|
|
16
|
+
"kind": "variable",
|
|
17
|
+
"name": "Language",
|
|
18
|
+
"type": {
|
|
19
|
+
"text": "{\n BULGARIAN: 'bg',\n CATALAN: 'ca',\n DANISH: 'da',\n DUTCH: 'nl',\n ENGLISH: 'en',\n FRENCH: 'fr',\n GERMAN: 'de',\n HEBREW: 'he',\n ITALIAN: 'it',\n POLISH: 'pl',\n SLOVAK: 'sk',\n SPANISH: 'es',\n}"
|
|
20
|
+
},
|
|
21
|
+
"default": "{\n BULGARIAN: 'bg',\n CATALAN: 'ca',\n DANISH: 'da',\n DUTCH: 'nl',\n ENGLISH: 'en',\n FRENCH: 'fr',\n GERMAN: 'de',\n HEBREW: 'he',\n ITALIAN: 'it',\n POLISH: 'pl',\n SLOVAK: 'sk',\n SPANISH: 'es',\n}"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"kind": "variable",
|
|
25
|
+
"name": "Country",
|
|
26
|
+
"type": {
|
|
27
|
+
"text": "{\n BULGARIA: 'bg',\n DENMARK: 'dk',\n FRANCE: 'fr',\n GERMANY: 'de',\n GREAT_BRITAIN: 'gb',\n ISRAEL: 'il',\n ITALY: 'it',\n NETHERLANDS: 'nl',\n POLAND: 'pl',\n SLOVAKIA: 'sk',\n SPAIN: 'es',\n}"
|
|
28
|
+
},
|
|
29
|
+
"default": "{\n BULGARIA: 'bg',\n DENMARK: 'dk',\n FRANCE: 'fr',\n GERMANY: 'de',\n GREAT_BRITAIN: 'gb',\n ISRAEL: 'il',\n ITALY: 'it',\n NETHERLANDS: 'nl',\n POLAND: 'pl',\n SLOVAKIA: 'sk',\n SPAIN: 'es',\n}"
|
|
30
|
+
},
|
|
15
31
|
{
|
|
16
32
|
"kind": "variable",
|
|
17
33
|
"name": "ON_COOKIE_BANNER_ACCEPT_ALL",
|
|
@@ -62,10 +78,31 @@
|
|
|
62
78
|
"type": {
|
|
63
79
|
"text": "DefaultProps"
|
|
64
80
|
},
|
|
65
|
-
"default": "{\n hasPrimaryActionsOnly: false,\n defaultPreferences: {},\n
|
|
81
|
+
"default": "{\n hasPrimaryActionsOnly: false,\n defaultPreferences: {},\n country: Country.GREAT_BRITAIN,\n language: Language.ENGLISH,\n cookieStatementLink: '',\n cookieTechnologiesLink: '',\n}"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"kind": "variable",
|
|
85
|
+
"name": "defaultLanguage",
|
|
86
|
+
"default": "new Map<CountryCode, LanguageCode>([\n [Country.GREAT_BRITAIN, Language.ENGLISH],\n [Country.FRANCE, Language.FRENCH],\n [Country.DENMARK, Language.DANISH],\n [Country.SPAIN, Language.SPANISH],\n [Country.ITALY, Language.ITALIAN],\n [Country.NETHERLANDS, Language.DUTCH],\n [Country.POLAND, Language.POLISH],\n [Country.SLOVAKIA, Language.SLOVAK],\n [Country.BULGARIA, Language.BULGARIAN],\n [Country.GERMANY, Language.GERMAN],\n [Country.ISRAEL, Language.HEBREW],\n])"
|
|
66
87
|
}
|
|
67
88
|
],
|
|
68
89
|
"exports": [
|
|
90
|
+
{
|
|
91
|
+
"kind": "js",
|
|
92
|
+
"name": "Language",
|
|
93
|
+
"declaration": {
|
|
94
|
+
"name": "Language",
|
|
95
|
+
"module": "src/defs.js"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"kind": "js",
|
|
100
|
+
"name": "Country",
|
|
101
|
+
"declaration": {
|
|
102
|
+
"name": "Country",
|
|
103
|
+
"module": "src/defs.js"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
69
106
|
{
|
|
70
107
|
"kind": "js",
|
|
71
108
|
"name": "ON_COOKIE_BANNER_ACCEPT_ALL",
|
|
@@ -113,6 +150,14 @@
|
|
|
113
150
|
"name": "defaultProps",
|
|
114
151
|
"module": "src/defs.js"
|
|
115
152
|
}
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"kind": "js",
|
|
156
|
+
"name": "defaultLanguage",
|
|
157
|
+
"declaration": {
|
|
158
|
+
"name": "defaultLanguage",
|
|
159
|
+
"module": "src/defs.js"
|
|
160
|
+
}
|
|
116
161
|
}
|
|
117
162
|
]
|
|
118
163
|
},
|
|
@@ -143,6 +188,15 @@
|
|
|
143
188
|
"privacy": "private",
|
|
144
189
|
"default": "false"
|
|
145
190
|
},
|
|
191
|
+
{
|
|
192
|
+
"kind": "field",
|
|
193
|
+
"name": "_locale",
|
|
194
|
+
"type": {
|
|
195
|
+
"text": "CookieBannerLocale"
|
|
196
|
+
},
|
|
197
|
+
"privacy": "private",
|
|
198
|
+
"default": "defaultLocale"
|
|
199
|
+
},
|
|
146
200
|
{
|
|
147
201
|
"kind": "field",
|
|
148
202
|
"name": "hasPrimaryActionsOnly",
|
|
@@ -155,15 +209,6 @@
|
|
|
155
209
|
"privacy": "public",
|
|
156
210
|
"attribute": "defaultPreferences"
|
|
157
211
|
},
|
|
158
|
-
{
|
|
159
|
-
"kind": "field",
|
|
160
|
-
"name": "locale",
|
|
161
|
-
"type": {
|
|
162
|
-
"text": "CookieBannerLocale"
|
|
163
|
-
},
|
|
164
|
-
"privacy": "public",
|
|
165
|
-
"attribute": "locale"
|
|
166
|
-
},
|
|
167
212
|
{
|
|
168
213
|
"kind": "field",
|
|
169
214
|
"name": "cookieStatementLink",
|
|
@@ -176,6 +221,18 @@
|
|
|
176
221
|
"privacy": "public",
|
|
177
222
|
"attribute": "cookieTechnologiesLink"
|
|
178
223
|
},
|
|
224
|
+
{
|
|
225
|
+
"kind": "field",
|
|
226
|
+
"name": "country",
|
|
227
|
+
"privacy": "public",
|
|
228
|
+
"attribute": "country"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"kind": "field",
|
|
232
|
+
"name": "language",
|
|
233
|
+
"privacy": "public",
|
|
234
|
+
"attribute": "language"
|
|
235
|
+
},
|
|
179
236
|
{
|
|
180
237
|
"kind": "field",
|
|
181
238
|
"name": "_preferencesNodes",
|
|
@@ -183,6 +240,34 @@
|
|
|
183
240
|
"text": "NodeListOf<PieSwitch>"
|
|
184
241
|
}
|
|
185
242
|
},
|
|
243
|
+
{
|
|
244
|
+
"kind": "method",
|
|
245
|
+
"name": "_setLocaleBasedOnCountryAndLanguage",
|
|
246
|
+
"privacy": "private",
|
|
247
|
+
"return": {
|
|
248
|
+
"type": {
|
|
249
|
+
"text": "Promise<void>"
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
"parameters": [
|
|
253
|
+
{
|
|
254
|
+
"name": "country",
|
|
255
|
+
"type": {
|
|
256
|
+
"text": "CountryCode"
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
"name": "language",
|
|
261
|
+
"type": {
|
|
262
|
+
"text": "LanguageCode"
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
"name": "fallback",
|
|
267
|
+
"default": "false"
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
},
|
|
186
271
|
{
|
|
187
272
|
"kind": "field",
|
|
188
273
|
"name": "_customTagEnhancers",
|
|
@@ -324,13 +409,6 @@
|
|
|
324
409
|
"name": "defaultPreferences",
|
|
325
410
|
"fieldName": "defaultPreferences"
|
|
326
411
|
},
|
|
327
|
-
{
|
|
328
|
-
"name": "locale",
|
|
329
|
-
"type": {
|
|
330
|
-
"text": "CookieBannerLocale"
|
|
331
|
-
},
|
|
332
|
-
"fieldName": "locale"
|
|
333
|
-
},
|
|
334
412
|
{
|
|
335
413
|
"name": "cookieStatementLink",
|
|
336
414
|
"fieldName": "cookieStatementLink"
|
|
@@ -338,6 +416,14 @@
|
|
|
338
416
|
{
|
|
339
417
|
"name": "cookieTechnologiesLink",
|
|
340
418
|
"fieldName": "cookieTechnologiesLink"
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
"name": "country",
|
|
422
|
+
"fieldName": "country"
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
"name": "language",
|
|
426
|
+
"fieldName": "language"
|
|
341
427
|
}
|
|
342
428
|
],
|
|
343
429
|
"superclass": {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
|
2
2
|
import type { CSSResult } from 'lit';
|
|
3
3
|
import type { LitElement } from 'lit';
|
|
4
4
|
import { PieSwitch } from '@justeattakeaway/pie-switch';
|
|
5
|
+
import type { PropertyValues } from 'lit';
|
|
5
6
|
import type { TemplateResult } from 'lit-html';
|
|
6
7
|
import { TemplateResult as TemplateResult_2 } from 'lit';
|
|
7
8
|
|
|
@@ -51,10 +52,6 @@ export declare interface CookieBannerProps {
|
|
|
51
52
|
* When true, sets the variant to "primary" for the button which accepts necessary cookies only.
|
|
52
53
|
*/
|
|
53
54
|
hasPrimaryActionsOnly: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Assigns the data for localising the component strings
|
|
56
|
-
*/
|
|
57
|
-
locale: CookieBannerLocale;
|
|
58
55
|
/**
|
|
59
56
|
* The URL of the cookie statement page the banner should link to.
|
|
60
57
|
*/
|
|
@@ -63,6 +60,14 @@ export declare interface CookieBannerProps {
|
|
|
63
60
|
* The URL for the cookie technology link.
|
|
64
61
|
*/
|
|
65
62
|
cookieTechnologiesLink: string;
|
|
63
|
+
/**
|
|
64
|
+
* Assigns the country used for dynamically localising the component strings
|
|
65
|
+
*/
|
|
66
|
+
country: CountryCode;
|
|
67
|
+
/**
|
|
68
|
+
* Assigns the language used for dynamically localising the component strings
|
|
69
|
+
*/
|
|
70
|
+
language: LanguageCode;
|
|
66
71
|
/**
|
|
67
72
|
* Allows consumers to pass in specific preference(s) to the component which will toggle
|
|
68
73
|
* the switch to be on by default (if set to `true`).
|
|
@@ -73,14 +78,49 @@ export declare interface CookieBannerProps {
|
|
|
73
78
|
defaultPreferences?: Partial<Record<PreferenceIds, boolean>>;
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
export declare const Country: {
|
|
82
|
+
readonly BULGARIA: "bg";
|
|
83
|
+
readonly DENMARK: "dk";
|
|
84
|
+
readonly FRANCE: "fr";
|
|
85
|
+
readonly GERMANY: "de";
|
|
86
|
+
readonly GREAT_BRITAIN: "gb";
|
|
87
|
+
readonly ISRAEL: "il";
|
|
88
|
+
readonly ITALY: "it";
|
|
89
|
+
readonly NETHERLANDS: "nl";
|
|
90
|
+
readonly POLAND: "pl";
|
|
91
|
+
readonly SLOVAKIA: "sk";
|
|
92
|
+
readonly SPAIN: "es";
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export declare type CountryCode = typeof Country[keyof typeof Country];
|
|
96
|
+
|
|
76
97
|
export declare interface CustomTagEnhancers {
|
|
77
98
|
[key: string]: (tagContent: string) => TemplateResult_2;
|
|
78
99
|
}
|
|
79
100
|
|
|
101
|
+
export declare const defaultLanguage: Map<CountryCode, LanguageCode>;
|
|
102
|
+
|
|
80
103
|
export declare type DefaultProps = ComponentDefaultProps<CookieBannerProps>;
|
|
81
104
|
|
|
82
105
|
export declare const defaultProps: DefaultProps;
|
|
83
106
|
|
|
107
|
+
export declare const Language: {
|
|
108
|
+
readonly BULGARIAN: "bg";
|
|
109
|
+
readonly CATALAN: "ca";
|
|
110
|
+
readonly DANISH: "da";
|
|
111
|
+
readonly DUTCH: "nl";
|
|
112
|
+
readonly ENGLISH: "en";
|
|
113
|
+
readonly FRENCH: "fr";
|
|
114
|
+
readonly GERMAN: "de";
|
|
115
|
+
readonly HEBREW: "he";
|
|
116
|
+
readonly ITALIAN: "it";
|
|
117
|
+
readonly POLISH: "pl";
|
|
118
|
+
readonly SLOVAK: "sk";
|
|
119
|
+
readonly SPANISH: "es";
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export declare type LanguageCode = typeof Language[keyof typeof Language];
|
|
123
|
+
|
|
84
124
|
/**
|
|
85
125
|
* Event name for when all cookies are accepted.
|
|
86
126
|
*
|
|
@@ -119,12 +159,16 @@ export declare const ON_COOKIE_BANNER_PREFS_SAVED = "pie-cookie-banner-prefs-sav
|
|
|
119
159
|
export declare class PieCookieBanner extends LitElement implements CookieBannerProps {
|
|
120
160
|
private _isCookieBannerHidden;
|
|
121
161
|
private _isModalOpen;
|
|
162
|
+
private _locale;
|
|
122
163
|
hasPrimaryActionsOnly: boolean;
|
|
123
164
|
defaultPreferences: Partial<Record<PreferenceIds, boolean>>;
|
|
124
|
-
locale: CookieBannerLocale;
|
|
125
165
|
cookieStatementLink: string;
|
|
126
166
|
cookieTechnologiesLink: string;
|
|
167
|
+
country: CountryCode;
|
|
168
|
+
language: LanguageCode;
|
|
127
169
|
_preferencesNodes: NodeListOf<PieSwitch>;
|
|
170
|
+
updated(changedProperties: PropertyValues<this>): Promise<void>;
|
|
171
|
+
private _setLocaleBasedOnCountryAndLanguage;
|
|
128
172
|
private _customTagEnhancers;
|
|
129
173
|
private _localiseText;
|
|
130
174
|
private _localiseRichText;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { state as
|
|
1
|
+
import { LitElement as L, html as d, nothing as A, unsafeCSS as T } from "lit";
|
|
2
|
+
import { state as b, property as u, queryAll as E } from "lit/decorators.js";
|
|
3
3
|
import { repeat as C } from "lit/directives/repeat.js";
|
|
4
4
|
import "@justeattakeaway/pie-button";
|
|
5
5
|
import "@justeattakeaway/pie-divider";
|
|
@@ -7,47 +7,33 @@ import "@justeattakeaway/pie-icon-button";
|
|
|
7
7
|
import "@justeattakeaway/pie-link";
|
|
8
8
|
import "@justeattakeaway/pie-modal";
|
|
9
9
|
import "@justeattakeaway/pie-switch";
|
|
10
|
-
import { dispatchCustomEvent as
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
personalized: {
|
|
38
|
-
title: "Personalised (targeting and advertising)",
|
|
39
|
-
description: "These marketing cookies are used to tailor the delivery of information to you based upon your interest and to measure the effectiveness of such advertisements, both on our website and our advertising partners' websites."
|
|
40
|
-
},
|
|
41
|
-
cta: {
|
|
42
|
-
save: {
|
|
43
|
-
label: "Save",
|
|
44
|
-
ariaLabel: ""
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}, P = {
|
|
48
|
-
banner: M,
|
|
49
|
-
preferencesManagement: N
|
|
50
|
-
}, z = "pie-cookie-banner-accept-all", E = "pie-cookie-banner-necessary-only", L = "pie-cookie-banner-manage-prefs", R = "pie-cookie-banner-prefs-saved", H = [
|
|
10
|
+
import { dispatchCustomEvent as k, defineCustomElement as O } from "@justeattakeaway/pie-webc-core";
|
|
11
|
+
const $ = "*,*:after,*:before{box-sizing:inherit}*{margin:0}.c-cookieBanner{--cb-font-family: var(--dt-font-interactive-l-family);--cb-font-size: calc(var(--dt-font-body-l-size) * 1px);--cb-line-height: calc(var(--dt-font-body-l-line-height) * 1px);--cb-font-weight: var(--dt-font-body-l-weight);--cb-padding-inline: var(--dt-spacing-d);--cb-padding-block: var(--dt-spacing-d);--cb-offset: 0;color-scheme:only dark;background-color:var(--dt-color-background-dark);color:var(--dt-color-content-inverse);font-family:var(--cb-font-family);font-size:var(--cb-font-size);line-height:var(--cb-line-height);font-weight:var(--cb-font-weight);padding-block-start:var(--cb-padding-block);padding-block-end:var(--cb-padding-block);max-height:432px;position:fixed;bottom:var(--cb-offset);left:var(--cb-offset);right:var(--cb-offset);border-top-left-radius:var(--dt-radius-rounded-c);border-top-right-radius:var(--dt-radius-rounded-c);z-index:var(--dt-z-index-cookie-banner)}@media (min-width: 700px) and (orientation: landscape){.c-cookieBanner{--cb-padding-inline: var(--dt-spacing-f);--cb-offset: var(--dt-spacing-d);max-height:90%;border-bottom-left-radius:var(--dt-radius-rounded-c);border-bottom-right-radius:var(--dt-radius-rounded-c)}}.c-cookieBanner[isCookieBannerHidden]{display:none}@media (prefers-reduced-motion: no-preference){.c-cookieBanner{animation:.5s animate-enter ease-out}@keyframes animate-enter{0%{transform:translate3d(0,75%,0)}to{transform:translateZ(0)}}}.c-cookieBanner-title,.c-cookieBanner-body,.c-cookieBanner-actions{padding-inline-start:var(--cb-padding-inline);padding-inline-end:var(--cb-padding-inline)}.c-cookieBanner-title{--cb-title-font-size: var(--dt-font-heading-s-size--narrow);--cb-title-line-height: var(--dt-font-heading-s-line-height--narrow);font-size:calc(var(--cb-title-font-size) * 1px);font-weight:var(--dt-font-heading-s-weight);line-height:calc(var(--cb-title-line-height) * 1px)}@media (min-width: 700px) and (orientation: landscape){.c-cookieBanner-title{--cb-title-font-size: var(--dt-font-heading-s-size--wide);--cb-title-line-height: var(--dt-font-heading-s-line-height--wide)}}.c-cookieBanner-body{--cb-scroll-shadow-color: var(--dt-color-black);margin-block-start:var(--dt-spacing-a);max-height:200px;overflow-y:auto;background:linear-gradient(to bottom,transparent,var(--dt-color-background-dark) 75%) center bottom,linear-gradient(transparent,var(--cb-scroll-shadow-color)) center bottom;background-repeat:no-repeat;background-size:100% 48px,100% 8px;background-attachment:local,scroll}@media (min-width: 700px) and (orientation: landscape){.c-cookieBanner-body{max-height:150px}}.c-cookieBanner-actions{--cb-actions-flex-dir: column;margin-block-start:var(--dt-spacing-d);display:flex;gap:var(--dt-spacing-d);flex-direction:var(--cb-actions-flex-dir)}.c-cookieBanner-actions>pie-link{text-align:center;align-self:center}@media (min-width: 700px) and (orientation: landscape){.c-cookieBanner-actions{--cb-actions-flex-dir: row-reverse;justify-content:flex-start;align-items:center}}.c-cookieBanner-subheading{--cb-subheading-font-size: var(--dt-font-heading-s-size--narrow);--cb-subheading-line-height: var(--dt-font-heading-s-line-height--narrow);font-size:calc(var(--cb-subheading-font-size) * 1px);font-weight:var(--dt-font-heading-s-weight);line-height:calc(var(--cb-subheading-line-height) * 1px)}@media (min-width: 700px) and (orientation: landscape){.c-cookieBanner-subheading{--cb-subheading-font-size: var(--dt-font-heading-s-size--wide);--cb-subheading-line-height: var(--dt-font-heading-s-line-height--wide)}}.c-cookieBanner-description{font-size:calc(var(--dt-font-body-s-size) * 1px);line-height:calc(var(--dt-font-body-s-line-height) * 1px)}.c-cookieBanner-preference{display:flex;gap:var(--dt-spacing-d);justify-content:space-between;margin-block-start:var(--dt-spacing-e);margin-block-end:var(--dt-spacing-e)}.c-cookieBanner-preference p{margin-block-start:var(--dt-spacing-b)}.c-cookieBanner-preference:last-child{margin-block-end:0}", c = {
|
|
12
|
+
BULGARIAN: "bg",
|
|
13
|
+
CATALAN: "ca",
|
|
14
|
+
DANISH: "da",
|
|
15
|
+
DUTCH: "nl",
|
|
16
|
+
ENGLISH: "en",
|
|
17
|
+
FRENCH: "fr",
|
|
18
|
+
GERMAN: "de",
|
|
19
|
+
HEBREW: "he",
|
|
20
|
+
ITALIAN: "it",
|
|
21
|
+
POLISH: "pl",
|
|
22
|
+
SLOVAK: "sk",
|
|
23
|
+
SPANISH: "es"
|
|
24
|
+
}, l = {
|
|
25
|
+
BULGARIA: "bg",
|
|
26
|
+
DENMARK: "dk",
|
|
27
|
+
FRANCE: "fr",
|
|
28
|
+
GERMANY: "de",
|
|
29
|
+
GREAT_BRITAIN: "gb",
|
|
30
|
+
ISRAEL: "il",
|
|
31
|
+
ITALY: "it",
|
|
32
|
+
NETHERLANDS: "nl",
|
|
33
|
+
POLAND: "pl",
|
|
34
|
+
SLOVAKIA: "sk",
|
|
35
|
+
SPAIN: "es"
|
|
36
|
+
}, R = "pie-cookie-banner-accept-all", M = "pie-cookie-banner-necessary-only", P = "pie-cookie-banner-manage-prefs", I = "pie-cookie-banner-prefs-saved", z = [
|
|
51
37
|
{
|
|
52
38
|
id: "all",
|
|
53
39
|
hasDivider: !0,
|
|
@@ -71,89 +57,158 @@ const S = "*,*:after,*:before{box-sizing:inherit}*{margin:0}.c-cookieBanner{--cb
|
|
|
71
57
|
id: "personalized",
|
|
72
58
|
hasDescription: !0
|
|
73
59
|
}
|
|
74
|
-
],
|
|
60
|
+
], g = {
|
|
75
61
|
hasPrimaryActionsOnly: !1,
|
|
76
62
|
defaultPreferences: {},
|
|
77
|
-
|
|
63
|
+
country: l.GREAT_BRITAIN,
|
|
64
|
+
language: c.ENGLISH,
|
|
78
65
|
cookieStatementLink: "",
|
|
79
66
|
cookieTechnologiesLink: ""
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
}, H = /* @__PURE__ */ new Map([
|
|
68
|
+
[l.GREAT_BRITAIN, c.ENGLISH],
|
|
69
|
+
[l.FRANCE, c.FRENCH],
|
|
70
|
+
[l.DENMARK, c.DANISH],
|
|
71
|
+
[l.SPAIN, c.SPANISH],
|
|
72
|
+
[l.ITALY, c.ITALIAN],
|
|
73
|
+
[l.NETHERLANDS, c.DUTCH],
|
|
74
|
+
[l.POLAND, c.POLISH],
|
|
75
|
+
[l.SLOVAKIA, c.SLOVAK],
|
|
76
|
+
[l.BULGARIA, c.BULGARIAN],
|
|
77
|
+
[l.GERMANY, c.GERMAN],
|
|
78
|
+
[l.ISRAEL, c.HEBREW]
|
|
79
|
+
]);
|
|
80
|
+
function w(a) {
|
|
81
|
+
console.error(`[localisation-utils]: ${a}`);
|
|
83
82
|
}
|
|
84
|
-
function
|
|
85
|
-
const n = (t) => String.prototype.split.call(e, t).filter(Boolean).reduce((
|
|
86
|
-
return typeof
|
|
83
|
+
function D(a, e) {
|
|
84
|
+
const n = (t) => String.prototype.split.call(e, t).filter(Boolean).reduce((o, s) => o != null && typeof o == "object" ? o[s] : o, a), i = n(/[,[\]]+?/) || n(/[,[\].]+?/);
|
|
85
|
+
return typeof i != "string" ? "" : i;
|
|
87
86
|
}
|
|
88
|
-
function
|
|
89
|
-
if (!
|
|
87
|
+
function N(a, e) {
|
|
88
|
+
if (!a) throw new Error('"locale" parameter cannot be empty');
|
|
90
89
|
if (!e) throw new Error('"key" parameter cannot be empty');
|
|
91
|
-
const n =
|
|
92
|
-
return n || (
|
|
90
|
+
const n = D(a, e);
|
|
91
|
+
return n || (w(`Couldn't find a value for the key "${e}", it will be used as fallback.`), e);
|
|
93
92
|
}
|
|
94
|
-
function
|
|
95
|
-
const n =
|
|
93
|
+
function G(a) {
|
|
94
|
+
const n = a.map((t) => `(<${t}.*>.*</${t}>)`).join("|");
|
|
96
95
|
return new RegExp(n, "igm");
|
|
97
96
|
}
|
|
98
|
-
function
|
|
97
|
+
function K(a, e) {
|
|
99
98
|
const n = Object.keys(e);
|
|
100
|
-
if (n.length === 0) return [
|
|
101
|
-
const
|
|
102
|
-
return
|
|
103
|
-
if (!t.match(
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
106
|
-
const [,
|
|
107
|
-
return [
|
|
99
|
+
if (n.length === 0) return [a];
|
|
100
|
+
const i = G(n);
|
|
101
|
+
return a.split(i).filter((t) => !!t).map((t) => {
|
|
102
|
+
if (!t.match(i)) return t;
|
|
103
|
+
const s = t.match(/<(.*)>(.*)<\/.*>/);
|
|
104
|
+
if (!s) return t;
|
|
105
|
+
const [, f, p] = s;
|
|
106
|
+
return [f, p];
|
|
108
107
|
}).map((t) => {
|
|
109
108
|
if (!Array.isArray(t)) return t;
|
|
110
|
-
const [
|
|
111
|
-
return
|
|
109
|
+
const [s, f] = t, p = e[s];
|
|
110
|
+
return p || typeof p == "function" ? p(f) : (w(`Custom tag "${s}" does not have a matching enhancer function`), f);
|
|
112
111
|
});
|
|
113
112
|
}
|
|
114
|
-
function F(
|
|
115
|
-
if (!
|
|
113
|
+
function F(a, e, n) {
|
|
114
|
+
if (!a) throw new Error('"locale" parameter cannot be empty');
|
|
116
115
|
if (!e) throw new Error('"key" parameter cannot be empty');
|
|
117
116
|
if (!n) throw new Error('"customTagEnhancers" parameter cannot be empty');
|
|
118
|
-
const
|
|
119
|
-
return
|
|
117
|
+
const i = N(a, e);
|
|
118
|
+
return K(i, n);
|
|
120
119
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
const j = {
|
|
121
|
+
title: "Cookies",
|
|
122
|
+
description: "We use our own and third party cookies and other tech to enhance and personalise your user experience, optimize analytics, and show ads with third parties (read our <linkStatement>Statement</linkStatement>). Necessary cookies are always set. Click <linkNecessaryOnly>Necessary only</linkNecessaryOnly> to continue without accepting more. Click <linkManagePreferences>Manage preferences</linkManagePreferences> to share your preferences or <linkAcceptAll>Accept all</linkAcceptAll>.",
|
|
123
|
+
cta: {
|
|
124
|
+
managePreferences: "Manage preferences",
|
|
125
|
+
necessaryOnly: "Necessary only",
|
|
126
|
+
acceptAll: "Accept all"
|
|
127
|
+
}
|
|
128
|
+
}, V = {
|
|
129
|
+
title: "Manage your preferences",
|
|
130
|
+
description: "You can find all the information in the <linkCookieStatement>Cookie Statement</linkCookieStatement> and <linkCookieTechList>Cookie technology list</linkCookieTechList>.",
|
|
131
|
+
all: {
|
|
132
|
+
title: "Turn all on"
|
|
133
|
+
},
|
|
134
|
+
necessary: {
|
|
135
|
+
title: "Necessary",
|
|
136
|
+
description: "These cookies are necessary to ensure that the website and its features function properly. Services you have asked for cannot be provided without these cookies."
|
|
137
|
+
},
|
|
138
|
+
functional: {
|
|
139
|
+
title: "Functional",
|
|
140
|
+
description: "These cookies allow the website to remember the choices you make to give you better functionality and personal features."
|
|
141
|
+
},
|
|
142
|
+
analytical: {
|
|
143
|
+
title: "Analytical",
|
|
144
|
+
description: "These analytical cookies, including statistics, are used to understand how visitors interact with the website and we can measure and improve the performance of our website."
|
|
145
|
+
},
|
|
146
|
+
personalized: {
|
|
147
|
+
title: "Personalised (targeting and advertising)",
|
|
148
|
+
description: "These marketing cookies are used to tailor the delivery of information to you based upon your interest and to measure the effectiveness of such advertisements, both on our website and our advertising partners' websites."
|
|
149
|
+
},
|
|
150
|
+
cta: {
|
|
151
|
+
save: {
|
|
152
|
+
label: "Save",
|
|
153
|
+
ariaLabel: ""
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, _ = {
|
|
157
|
+
banner: j,
|
|
158
|
+
preferencesManagement: V
|
|
125
159
|
};
|
|
126
|
-
|
|
160
|
+
var Y = Object.defineProperty, h = (a, e, n, i) => {
|
|
161
|
+
for (var t = void 0, o = a.length - 1, s; o >= 0; o--)
|
|
162
|
+
(s = a[o]) && (t = s(e, n, t) || t);
|
|
163
|
+
return t && Y(e, n, t), t;
|
|
164
|
+
};
|
|
165
|
+
const U = "pie-cookie-banner", m = class m extends L {
|
|
127
166
|
constructor() {
|
|
128
|
-
super(...arguments), this._isCookieBannerHidden = !1, this._isModalOpen = !1, this.hasPrimaryActionsOnly =
|
|
129
|
-
linkStatement: (e) =>
|
|
130
|
-
linkNecessaryOnly: (e) =>
|
|
131
|
-
linkManagePreferences: (e) =>
|
|
132
|
-
linkAcceptAll: (e) =>
|
|
133
|
-
linkCookieStatement: (e) =>
|
|
134
|
-
linkCookieTechList: (e) =>
|
|
167
|
+
super(...arguments), this._isCookieBannerHidden = !1, this._isModalOpen = !1, this._locale = _, this.hasPrimaryActionsOnly = g.hasPrimaryActionsOnly, this.defaultPreferences = g.defaultPreferences, this.cookieStatementLink = g.cookieStatementLink, this.cookieTechnologiesLink = g.cookieTechnologiesLink, this.country = g.country, this.language = g.language, this._customTagEnhancers = {
|
|
168
|
+
linkStatement: (e) => d`<pie-link href="${this.cookieStatementLink}" variant="inverse" target="_blank" data-test-id="cookie-statement-link">${e}</pie-link>`,
|
|
169
|
+
linkNecessaryOnly: (e) => d`<pie-link data-test-id="body-necessary-only" tag="button" variant="inverse" @click="${this._onNecessaryOnly}">${e}</pie-link>`,
|
|
170
|
+
linkManagePreferences: (e) => d`<pie-link data-test-id="body-manage-prefs" tag="button" variant="inverse" @click="${this._openManagePreferencesModal}">${e}</pie-link>`,
|
|
171
|
+
linkAcceptAll: (e) => d`<pie-link data-test-id="body-accept-all" tag="button" variant="inverse" @click="${this._onAcceptAll}">${e}</pie-link>`,
|
|
172
|
+
linkCookieStatement: (e) => d`<pie-link href="${this.cookieStatementLink}" size="small" target="_blank" data-test-id="cookie-statement-link">${e}</pie-link>`,
|
|
173
|
+
linkCookieTechList: (e) => d`<pie-link href="${this.cookieTechnologiesLink}" size="small" target="_blank" data-test-id="cookie-technology-link">${e}</pie-link>`
|
|
135
174
|
}, this._onNecessaryOnly = () => {
|
|
136
|
-
|
|
175
|
+
k(this, M), this._isCookieBannerHidden = !0;
|
|
137
176
|
}, this._onAcceptAll = () => {
|
|
138
|
-
|
|
177
|
+
k(this, R), this._isCookieBannerHidden = !0;
|
|
139
178
|
}, this._openManagePreferencesModal = () => {
|
|
140
|
-
this._isCookieBannerHidden = !0,
|
|
179
|
+
this._isCookieBannerHidden = !0, k(this, P), this._isModalOpen = !0;
|
|
141
180
|
}, this._handleSwitchStates = (e) => {
|
|
142
|
-
const { id: n } = e == null ? void 0 : e.currentTarget,
|
|
143
|
-
if (n ===
|
|
181
|
+
const { id: n } = e == null ? void 0 : e.currentTarget, i = [...this._preferencesNodes].find(({ id: t }) => t === "all");
|
|
182
|
+
if (n === i.id) {
|
|
144
183
|
const { checked: t } = e.target;
|
|
145
|
-
this._preferencesNodes.forEach((
|
|
146
|
-
|
|
184
|
+
this._preferencesNodes.forEach((o) => {
|
|
185
|
+
o.checked = o.disabled ? o.checked : t;
|
|
147
186
|
});
|
|
148
187
|
} else
|
|
149
|
-
|
|
188
|
+
i.checked = [...this._preferencesNodes].filter(({ id: t }) => t !== "all").every(({ checked: t }) => t);
|
|
150
189
|
};
|
|
151
190
|
}
|
|
191
|
+
async updated(e) {
|
|
192
|
+
(e.has("country") || e.has("language")) && await this._setLocaleBasedOnCountryAndLanguage(this.country, this.language);
|
|
193
|
+
}
|
|
194
|
+
// Dynamically import locale JSON based on country and language
|
|
195
|
+
async _setLocaleBasedOnCountryAndLanguage(e, n, i = !1) {
|
|
196
|
+
try {
|
|
197
|
+
this._locale = (await import(`../locales/${n.toLowerCase()}-${e.toLowerCase()}.json`)).default;
|
|
198
|
+
} catch {
|
|
199
|
+
if (i)
|
|
200
|
+
this._locale = _;
|
|
201
|
+
else {
|
|
202
|
+
const t = H.get(e) || g.language;
|
|
203
|
+
await this._setLocaleBasedOnCountryAndLanguage(e, t, !0);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
152
207
|
_localiseText(e) {
|
|
153
|
-
return
|
|
208
|
+
return N(this._locale, e);
|
|
154
209
|
}
|
|
155
210
|
_localiseRichText(e) {
|
|
156
|
-
return F(this.
|
|
211
|
+
return F(this._locale, e, this._customTagEnhancers);
|
|
157
212
|
}
|
|
158
213
|
/**
|
|
159
214
|
* Handles closing the modal and re-displaying the cookie banner
|
|
@@ -173,9 +228,9 @@ const I = "pie-cookie-banner", k = class k extends $ {
|
|
|
173
228
|
*/
|
|
174
229
|
_handlePreferencesSaved() {
|
|
175
230
|
let e = {};
|
|
176
|
-
[...this._preferencesNodes].filter(({ id: n }) => n !== "all").forEach(({ id: n, checked:
|
|
177
|
-
e = { ...e, [n]:
|
|
178
|
-
}),
|
|
231
|
+
[...this._preferencesNodes].filter(({ id: n }) => n !== "all").forEach(({ id: n, checked: i }) => {
|
|
232
|
+
e = { ...e, [n]: i };
|
|
233
|
+
}), k(this, I, e), this._isModalOpen = !1, this._isCookieBannerHidden = !0;
|
|
179
234
|
}
|
|
180
235
|
/**
|
|
181
236
|
* Renders the content of the preference item.
|
|
@@ -184,41 +239,41 @@ const I = "pie-cookie-banner", k = class k extends $ {
|
|
|
184
239
|
renderPreference({
|
|
185
240
|
id: e,
|
|
186
241
|
checked: n,
|
|
187
|
-
disabled:
|
|
242
|
+
disabled: i,
|
|
188
243
|
hasDivider: t,
|
|
189
|
-
hasDescription:
|
|
244
|
+
hasDescription: o
|
|
190
245
|
}) {
|
|
191
|
-
var
|
|
192
|
-
const
|
|
193
|
-
var
|
|
194
|
-
return ((
|
|
246
|
+
var y;
|
|
247
|
+
const s = this._localiseText(`preferencesManagement.${e}.title`), f = `preferencesManagement.${e}.description`, p = o && this._localiseText(f), B = ["functional", "personalized", "analytical"].every((S) => {
|
|
248
|
+
var v;
|
|
249
|
+
return ((v = this.defaultPreferences) == null ? void 0 : v[S]) === !0;
|
|
195
250
|
});
|
|
196
|
-
return
|
|
251
|
+
return d`
|
|
197
252
|
<div class="c-cookieBanner-preference">
|
|
198
253
|
<div>
|
|
199
|
-
<h3 class="c-cookieBanner-subheading">${
|
|
200
|
-
${
|
|
254
|
+
<h3 class="c-cookieBanner-subheading">${s}</h3>
|
|
255
|
+
${p ? d`<p class="c-cookieBanner-description">${p}</p>` : A}
|
|
201
256
|
</div>
|
|
202
257
|
<pie-switch
|
|
203
258
|
id="${e}"
|
|
204
|
-
?checked="${((
|
|
205
|
-
?disabled="${
|
|
259
|
+
?checked="${((y = this.defaultPreferences) == null ? void 0 : y[e]) || B || n}"
|
|
260
|
+
?disabled="${i}"
|
|
206
261
|
@change="${this._handleSwitchStates}">
|
|
207
262
|
</pie-switch>
|
|
208
263
|
</div>
|
|
209
|
-
${t ?
|
|
264
|
+
${t ? d`<pie-divider></pie-divider>` : A}`;
|
|
210
265
|
}
|
|
211
266
|
/**
|
|
212
267
|
* Renders the modal content.
|
|
213
268
|
* @private
|
|
214
269
|
*/
|
|
215
270
|
renderModalContent() {
|
|
216
|
-
return
|
|
271
|
+
return d`
|
|
217
272
|
<p class="c-cookieBanner-description" data-test-id="modal-description">
|
|
218
273
|
${this._localiseRichText("preferencesManagement.description")}
|
|
219
274
|
</p>
|
|
220
275
|
${C(
|
|
221
|
-
|
|
276
|
+
z,
|
|
222
277
|
({ id: e }) => e,
|
|
223
278
|
(e) => this.renderPreference(e)
|
|
224
279
|
)}`;
|
|
@@ -228,7 +283,7 @@ const I = "pie-cookie-banner", k = class k extends $ {
|
|
|
228
283
|
text: this._localiseText("preferencesManagement.cta.save.label"),
|
|
229
284
|
ariaLabel: this._localiseText("preferencesManagement.cta.save.label")
|
|
230
285
|
};
|
|
231
|
-
return
|
|
286
|
+
return d`
|
|
232
287
|
<pie-modal
|
|
233
288
|
.isOpen="${this._isModalOpen}"
|
|
234
289
|
hasBackButton
|
|
@@ -275,39 +330,48 @@ const I = "pie-cookie-banner", k = class k extends $ {
|
|
|
275
330
|
</aside>`;
|
|
276
331
|
}
|
|
277
332
|
};
|
|
278
|
-
|
|
279
|
-
let
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
],
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
],
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
],
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
],
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
],
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
],
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
],
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
],
|
|
304
|
-
|
|
333
|
+
m.styles = T($);
|
|
334
|
+
let r = m;
|
|
335
|
+
h([
|
|
336
|
+
b()
|
|
337
|
+
], r.prototype, "_isCookieBannerHidden");
|
|
338
|
+
h([
|
|
339
|
+
b()
|
|
340
|
+
], r.prototype, "_isModalOpen");
|
|
341
|
+
h([
|
|
342
|
+
b()
|
|
343
|
+
], r.prototype, "_locale");
|
|
344
|
+
h([
|
|
345
|
+
u({ type: Boolean })
|
|
346
|
+
], r.prototype, "hasPrimaryActionsOnly");
|
|
347
|
+
h([
|
|
348
|
+
u({ type: Object })
|
|
349
|
+
], r.prototype, "defaultPreferences");
|
|
350
|
+
h([
|
|
351
|
+
u({ type: String })
|
|
352
|
+
], r.prototype, "cookieStatementLink");
|
|
353
|
+
h([
|
|
354
|
+
u({ type: String })
|
|
355
|
+
], r.prototype, "cookieTechnologiesLink");
|
|
356
|
+
h([
|
|
357
|
+
u({ type: String })
|
|
358
|
+
], r.prototype, "country");
|
|
359
|
+
h([
|
|
360
|
+
u({ type: String })
|
|
361
|
+
], r.prototype, "language");
|
|
362
|
+
h([
|
|
363
|
+
E("pie-switch")
|
|
364
|
+
], r.prototype, "_preferencesNodes");
|
|
365
|
+
O(U, r);
|
|
305
366
|
export {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
367
|
+
l as Country,
|
|
368
|
+
c as Language,
|
|
369
|
+
R as ON_COOKIE_BANNER_ACCEPT_ALL,
|
|
370
|
+
P as ON_COOKIE_BANNER_MANAGE_PREFS,
|
|
371
|
+
M as ON_COOKIE_BANNER_NECESSARY_ONLY,
|
|
372
|
+
I as ON_COOKIE_BANNER_PREFS_SAVED,
|
|
373
|
+
r as PieCookieBanner,
|
|
374
|
+
H as defaultLanguage,
|
|
375
|
+
g as defaultProps,
|
|
376
|
+
z as preferences
|
|
313
377
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
|
2
2
|
import type { CSSResult } from 'lit';
|
|
3
3
|
import type { LitElement } from 'lit';
|
|
4
4
|
import { PieSwitch } from '@justeattakeaway/pie-switch';
|
|
5
|
+
import type { PropertyValues } from 'lit';
|
|
5
6
|
import * as React_2 from 'react';
|
|
6
7
|
import type { TemplateResult } from 'lit-html';
|
|
7
8
|
import { TemplateResult as TemplateResult_2 } from 'lit';
|
|
@@ -52,10 +53,6 @@ export declare interface CookieBannerProps {
|
|
|
52
53
|
* When true, sets the variant to "primary" for the button which accepts necessary cookies only.
|
|
53
54
|
*/
|
|
54
55
|
hasPrimaryActionsOnly: boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Assigns the data for localising the component strings
|
|
57
|
-
*/
|
|
58
|
-
locale: CookieBannerLocale;
|
|
59
56
|
/**
|
|
60
57
|
* The URL of the cookie statement page the banner should link to.
|
|
61
58
|
*/
|
|
@@ -64,6 +61,14 @@ export declare interface CookieBannerProps {
|
|
|
64
61
|
* The URL for the cookie technology link.
|
|
65
62
|
*/
|
|
66
63
|
cookieTechnologiesLink: string;
|
|
64
|
+
/**
|
|
65
|
+
* Assigns the country used for dynamically localising the component strings
|
|
66
|
+
*/
|
|
67
|
+
country: CountryCode;
|
|
68
|
+
/**
|
|
69
|
+
* Assigns the language used for dynamically localising the component strings
|
|
70
|
+
*/
|
|
71
|
+
language: LanguageCode;
|
|
67
72
|
/**
|
|
68
73
|
* Allows consumers to pass in specific preference(s) to the component which will toggle
|
|
69
74
|
* the switch to be on by default (if set to `true`).
|
|
@@ -74,14 +79,49 @@ export declare interface CookieBannerProps {
|
|
|
74
79
|
defaultPreferences?: Partial<Record<PreferenceIds, boolean>>;
|
|
75
80
|
}
|
|
76
81
|
|
|
82
|
+
export declare const Country: {
|
|
83
|
+
readonly BULGARIA: "bg";
|
|
84
|
+
readonly DENMARK: "dk";
|
|
85
|
+
readonly FRANCE: "fr";
|
|
86
|
+
readonly GERMANY: "de";
|
|
87
|
+
readonly GREAT_BRITAIN: "gb";
|
|
88
|
+
readonly ISRAEL: "il";
|
|
89
|
+
readonly ITALY: "it";
|
|
90
|
+
readonly NETHERLANDS: "nl";
|
|
91
|
+
readonly POLAND: "pl";
|
|
92
|
+
readonly SLOVAKIA: "sk";
|
|
93
|
+
readonly SPAIN: "es";
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export declare type CountryCode = typeof Country[keyof typeof Country];
|
|
97
|
+
|
|
77
98
|
export declare interface CustomTagEnhancers {
|
|
78
99
|
[key: string]: (tagContent: string) => TemplateResult_2;
|
|
79
100
|
}
|
|
80
101
|
|
|
102
|
+
export declare const defaultLanguage: Map<CountryCode, LanguageCode>;
|
|
103
|
+
|
|
81
104
|
export declare type DefaultProps = ComponentDefaultProps<CookieBannerProps>;
|
|
82
105
|
|
|
83
106
|
export declare const defaultProps: DefaultProps;
|
|
84
107
|
|
|
108
|
+
export declare const Language: {
|
|
109
|
+
readonly BULGARIAN: "bg";
|
|
110
|
+
readonly CATALAN: "ca";
|
|
111
|
+
readonly DANISH: "da";
|
|
112
|
+
readonly DUTCH: "nl";
|
|
113
|
+
readonly ENGLISH: "en";
|
|
114
|
+
readonly FRENCH: "fr";
|
|
115
|
+
readonly GERMAN: "de";
|
|
116
|
+
readonly HEBREW: "he";
|
|
117
|
+
readonly ITALIAN: "it";
|
|
118
|
+
readonly POLISH: "pl";
|
|
119
|
+
readonly SLOVAK: "sk";
|
|
120
|
+
readonly SPANISH: "es";
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export declare type LanguageCode = typeof Language[keyof typeof Language];
|
|
124
|
+
|
|
85
125
|
/**
|
|
86
126
|
* Event name for when all cookies are accepted.
|
|
87
127
|
*
|
|
@@ -122,12 +162,16 @@ export declare const PieCookieBanner: React_2.ForwardRefExoticComponent<CookieBa
|
|
|
122
162
|
declare class PieCookieBanner_2 extends LitElement implements CookieBannerProps {
|
|
123
163
|
private _isCookieBannerHidden;
|
|
124
164
|
private _isModalOpen;
|
|
165
|
+
private _locale;
|
|
125
166
|
hasPrimaryActionsOnly: boolean;
|
|
126
167
|
defaultPreferences: Partial<Record<PreferenceIds, boolean>>;
|
|
127
|
-
locale: CookieBannerLocale;
|
|
128
168
|
cookieStatementLink: string;
|
|
129
169
|
cookieTechnologiesLink: string;
|
|
170
|
+
country: CountryCode;
|
|
171
|
+
language: LanguageCode;
|
|
130
172
|
_preferencesNodes: NodeListOf<PieSwitch>;
|
|
173
|
+
updated(changedProperties: PropertyValues<this>): Promise<void>;
|
|
174
|
+
private _setLocaleBasedOnCountryAndLanguage;
|
|
131
175
|
private _customTagEnhancers;
|
|
132
176
|
private _localiseText;
|
|
133
177
|
private _localiseRichText;
|
package/dist/react.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as e from "react";
|
|
2
2
|
import { createComponent as o } from "@lit/react";
|
|
3
3
|
import { PieCookieBanner as n } from "./index.js";
|
|
4
|
-
import { ON_COOKIE_BANNER_ACCEPT_ALL as
|
|
4
|
+
import { Country as c, Language as p, ON_COOKIE_BANNER_ACCEPT_ALL as N, ON_COOKIE_BANNER_MANAGE_PREFS as _, ON_COOKIE_BANNER_NECESSARY_ONLY as E, ON_COOKIE_BANNER_PREFS_SAVED as P, defaultLanguage as k, defaultProps as O, preferences as B } from "./index.js";
|
|
5
5
|
const a = o({
|
|
6
6
|
displayName: "PieCookieBanner",
|
|
7
7
|
elementClass: n,
|
|
@@ -17,13 +17,16 @@ const a = o({
|
|
|
17
17
|
onPieCookieBannerPrefsSaved: "pie-cookie-banner-prefs-saved"
|
|
18
18
|
// when a user clicks save preferences.
|
|
19
19
|
}
|
|
20
|
-
}),
|
|
20
|
+
}), t = a;
|
|
21
21
|
export {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
N as
|
|
25
|
-
_ as
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
c as Country,
|
|
23
|
+
p as Language,
|
|
24
|
+
N as ON_COOKIE_BANNER_ACCEPT_ALL,
|
|
25
|
+
_ as ON_COOKIE_BANNER_MANAGE_PREFS,
|
|
26
|
+
E as ON_COOKIE_BANNER_NECESSARY_ONLY,
|
|
27
|
+
P as ON_COOKIE_BANNER_PREFS_SAVED,
|
|
28
|
+
t as PieCookieBanner,
|
|
29
|
+
k as defaultLanguage,
|
|
30
|
+
O as defaultProps,
|
|
31
|
+
B as preferences
|
|
29
32
|
};
|
package/locales/it-it.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "Usiamo cookie nostri e di terze parti e altre tecnologie per migliorare e personalizzare la tua esperienza utente, ottimizzare l’analisi dei dati e mostrare annunci pubblicitari in collaborazione con terze parti (leggi la nostra <linkStatement>Informativa</linkStatement>). I cookie necessari sono sempre attivi. Premi Solo <linkNecessaryOnly>necessari</linkNecessaryOnly> per proseguire senza accettare altri cookie. Apri <linkManagePreferences>Gestisci preferenze</linkManagePreferences> per scegliere quali cookie attivare, oppure premi <linkAcceptAll>Accetta tutti</linkAcceptAll> per attivare tutti i cookie.",
|
|
5
5
|
"cta": {
|
|
6
6
|
"managePreferences": "Gestisci preferenze",
|
|
7
|
-
"necessaryOnly": "
|
|
7
|
+
"necessaryOnly": "Solo necessari",
|
|
8
8
|
"acceptAll": "Accetta tutti"
|
|
9
9
|
}
|
|
10
10
|
},
|
package/package.json
CHANGED
package/src/defs.ts
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
import { type TemplateResult } from 'lit';
|
|
2
2
|
import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export const Language = {
|
|
5
|
+
BULGARIAN: 'bg',
|
|
6
|
+
CATALAN: 'ca',
|
|
7
|
+
DANISH: 'da',
|
|
8
|
+
DUTCH: 'nl',
|
|
9
|
+
ENGLISH: 'en',
|
|
10
|
+
FRENCH: 'fr',
|
|
11
|
+
GERMAN: 'de',
|
|
12
|
+
HEBREW: 'he',
|
|
13
|
+
ITALIAN: 'it',
|
|
14
|
+
POLISH: 'pl',
|
|
15
|
+
SLOVAK: 'sk',
|
|
16
|
+
SPANISH: 'es',
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
export const Country = {
|
|
20
|
+
BULGARIA: 'bg',
|
|
21
|
+
DENMARK: 'dk',
|
|
22
|
+
FRANCE: 'fr',
|
|
23
|
+
GERMANY: 'de',
|
|
24
|
+
GREAT_BRITAIN: 'gb',
|
|
25
|
+
ISRAEL: 'il',
|
|
26
|
+
ITALY: 'it',
|
|
27
|
+
NETHERLANDS: 'nl',
|
|
28
|
+
POLAND: 'pl',
|
|
29
|
+
SLOVAKIA: 'sk',
|
|
30
|
+
SPAIN: 'es',
|
|
31
|
+
} as const;
|
|
32
|
+
|
|
33
|
+
export type LanguageCode = typeof Language[keyof typeof Language];
|
|
34
|
+
|
|
35
|
+
export type CountryCode = typeof Country[keyof typeof Country];
|
|
5
36
|
|
|
6
37
|
export interface CookieBannerLocale {
|
|
7
38
|
banner: {
|
|
@@ -50,11 +81,6 @@ export interface CookieBannerProps {
|
|
|
50
81
|
*/
|
|
51
82
|
hasPrimaryActionsOnly: boolean;
|
|
52
83
|
|
|
53
|
-
/**
|
|
54
|
-
* Assigns the data for localising the component strings
|
|
55
|
-
*/
|
|
56
|
-
locale: CookieBannerLocale;
|
|
57
|
-
|
|
58
84
|
/**
|
|
59
85
|
* The URL of the cookie statement page the banner should link to.
|
|
60
86
|
*/
|
|
@@ -65,6 +91,16 @@ export interface CookieBannerProps {
|
|
|
65
91
|
*/
|
|
66
92
|
cookieTechnologiesLink: string;
|
|
67
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Assigns the country used for dynamically localising the component strings
|
|
96
|
+
*/
|
|
97
|
+
country: CountryCode;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Assigns the language used for dynamically localising the component strings
|
|
101
|
+
*/
|
|
102
|
+
language: LanguageCode;
|
|
103
|
+
|
|
68
104
|
/**
|
|
69
105
|
* Allows consumers to pass in specific preference(s) to the component which will toggle
|
|
70
106
|
* the switch to be on by default (if set to `true`).
|
|
@@ -148,7 +184,22 @@ export type DefaultProps = ComponentDefaultProps<CookieBannerProps>;
|
|
|
148
184
|
export const defaultProps: DefaultProps = {
|
|
149
185
|
hasPrimaryActionsOnly: false,
|
|
150
186
|
defaultPreferences: {},
|
|
151
|
-
|
|
187
|
+
country: Country.GREAT_BRITAIN,
|
|
188
|
+
language: Language.ENGLISH,
|
|
152
189
|
cookieStatementLink: '',
|
|
153
190
|
cookieTechnologiesLink: '',
|
|
154
191
|
};
|
|
192
|
+
|
|
193
|
+
export const defaultLanguage = new Map<CountryCode, LanguageCode>([
|
|
194
|
+
[Country.GREAT_BRITAIN, Language.ENGLISH],
|
|
195
|
+
[Country.FRANCE, Language.FRENCH],
|
|
196
|
+
[Country.DENMARK, Language.DANISH],
|
|
197
|
+
[Country.SPAIN, Language.SPANISH],
|
|
198
|
+
[Country.ITALY, Language.ITALIAN],
|
|
199
|
+
[Country.NETHERLANDS, Language.DUTCH],
|
|
200
|
+
[Country.POLAND, Language.POLISH],
|
|
201
|
+
[Country.SLOVAKIA, Language.SLOVAK],
|
|
202
|
+
[Country.BULGARIA, Language.BULGARIAN],
|
|
203
|
+
[Country.GERMANY, Language.GERMAN],
|
|
204
|
+
[Country.ISRAEL, Language.HEBREW],
|
|
205
|
+
]);
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LitElement,
|
|
2
|
+
LitElement,
|
|
3
|
+
html,
|
|
4
|
+
unsafeCSS,
|
|
5
|
+
nothing,
|
|
6
|
+
type PropertyValues,
|
|
3
7
|
} from 'lit';
|
|
4
8
|
import { property, state, queryAll } from 'lit/decorators.js';
|
|
5
9
|
import { repeat } from 'lit/directives/repeat.js';
|
|
@@ -26,9 +30,13 @@ import {
|
|
|
26
30
|
type PreferenceIds,
|
|
27
31
|
type CookieBannerLocale,
|
|
28
32
|
type CustomTagEnhancers,
|
|
33
|
+
defaultLanguage,
|
|
34
|
+
type CountryCode,
|
|
35
|
+
type LanguageCode,
|
|
29
36
|
} from './defs';
|
|
30
37
|
|
|
31
38
|
import { localiseText, localiseRichText } from './localisation-utils';
|
|
39
|
+
import defaultLocale from '../locales/en-gb.json' assert { type: 'json' };
|
|
32
40
|
|
|
33
41
|
// Valid values available to consumers
|
|
34
42
|
export * from './defs';
|
|
@@ -49,24 +57,52 @@ export class PieCookieBanner extends LitElement implements CookieBannerProps {
|
|
|
49
57
|
@state()
|
|
50
58
|
private _isModalOpen = false;
|
|
51
59
|
|
|
60
|
+
@state()
|
|
61
|
+
private _locale: CookieBannerLocale = defaultLocale;
|
|
62
|
+
|
|
52
63
|
@property({ type: Boolean })
|
|
53
64
|
public hasPrimaryActionsOnly = defaultProps.hasPrimaryActionsOnly;
|
|
54
65
|
|
|
55
66
|
@property({ type: Object })
|
|
56
67
|
public defaultPreferences = defaultProps.defaultPreferences;
|
|
57
68
|
|
|
58
|
-
@property({ type: Object })
|
|
59
|
-
public locale:CookieBannerLocale = defaultProps.locale;
|
|
60
|
-
|
|
61
69
|
@property({ type: String })
|
|
62
70
|
public cookieStatementLink = defaultProps.cookieStatementLink;
|
|
63
71
|
|
|
64
72
|
@property({ type: String })
|
|
65
73
|
public cookieTechnologiesLink = defaultProps.cookieTechnologiesLink;
|
|
66
74
|
|
|
75
|
+
@property({ type: String })
|
|
76
|
+
public country = defaultProps.country;
|
|
77
|
+
|
|
78
|
+
@property({ type: String })
|
|
79
|
+
public language = defaultProps.language;
|
|
80
|
+
|
|
67
81
|
@queryAll('pie-switch')
|
|
68
82
|
_preferencesNodes!: NodeListOf<PieSwitch>;
|
|
69
83
|
|
|
84
|
+
async updated (changedProperties: PropertyValues<this>) {
|
|
85
|
+
// Re-fetch locale when country or language changes
|
|
86
|
+
if (changedProperties.has('country') || changedProperties.has('language')) {
|
|
87
|
+
await this._setLocaleBasedOnCountryAndLanguage(this.country, this.language);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Dynamically import locale JSON based on country and language
|
|
92
|
+
private async _setLocaleBasedOnCountryAndLanguage (country: CountryCode, language: LanguageCode, fallback = false): Promise<void> {
|
|
93
|
+
try {
|
|
94
|
+
this._locale = (await import(`../locales/${language.toLowerCase()}-${country.toLowerCase()}.json`, { assert: { type: 'json' } })).default;
|
|
95
|
+
} catch {
|
|
96
|
+
// If loading fails, try using the default language, if that fails fall back to the global default locale
|
|
97
|
+
if (!fallback) {
|
|
98
|
+
const fallbackLang = defaultLanguage.get(country) || defaultProps.language;
|
|
99
|
+
await this._setLocaleBasedOnCountryAndLanguage(country, fallbackLang, true);
|
|
100
|
+
} else {
|
|
101
|
+
this._locale = defaultLocale;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
70
106
|
private _customTagEnhancers: CustomTagEnhancers = {
|
|
71
107
|
linkStatement: (tagContent: string) => html`<pie-link href="${this.cookieStatementLink}" variant="inverse" target="_blank" data-test-id="cookie-statement-link">${tagContent}</pie-link>`,
|
|
72
108
|
linkNecessaryOnly: (tagContent: string) => html`<pie-link data-test-id="body-necessary-only" tag="button" variant="inverse" @click="${this._onNecessaryOnly}">${tagContent}</pie-link>`,
|
|
@@ -77,11 +113,11 @@ export class PieCookieBanner extends LitElement implements CookieBannerProps {
|
|
|
77
113
|
};
|
|
78
114
|
|
|
79
115
|
private _localiseText (key: string) {
|
|
80
|
-
return localiseText(this.
|
|
116
|
+
return localiseText(this._locale, key);
|
|
81
117
|
}
|
|
82
118
|
|
|
83
119
|
private _localiseRichText (key: string) {
|
|
84
|
-
return localiseRichText(this.
|
|
120
|
+
return localiseRichText(this._locale, key, this._customTagEnhancers);
|
|
85
121
|
}
|
|
86
122
|
|
|
87
123
|
/**
|