@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.
@@ -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 locale: defaultLocale,\n cookieStatementLink: '',\n cookieTechnologiesLink: '',\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 $, html as s, nothing as m, unsafeCSS as A } from "lit";
2
- import { state as y, property as f, queryAll as T } from "lit/decorators.js";
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 g, defineCustomElement as O } from "@justeattakeaway/pie-webc-core";
11
- const S = "*,*: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}", M = {
12
- title: "Cookies",
13
- 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>.",
14
- cta: {
15
- managePreferences: "Manage preferences",
16
- necessaryOnly: "Necessary only",
17
- acceptAll: "Accept all"
18
- }
19
- }, N = {
20
- title: "Manage your preferences",
21
- description: "You can find all the information in the <linkCookieStatement>Cookie Statement</linkCookieStatement> and <linkCookieTechList>Cookie technology list</linkCookieTechList>.",
22
- all: {
23
- title: "Turn all on"
24
- },
25
- necessary: {
26
- title: "Necessary",
27
- 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."
28
- },
29
- functional: {
30
- title: "Functional",
31
- description: "These cookies allow the website to remember the choices you make to give you better functionality and personal features."
32
- },
33
- analytical: {
34
- title: "Analytical",
35
- 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."
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
- ], h = {
60
+ ], g = {
75
61
  hasPrimaryActionsOnly: !1,
76
62
  defaultPreferences: {},
77
- locale: P,
63
+ country: l.GREAT_BRITAIN,
64
+ language: c.ENGLISH,
78
65
  cookieStatementLink: "",
79
66
  cookieTechnologiesLink: ""
80
- };
81
- function v(i) {
82
- console.error(`[localisation-utils]: ${i}`);
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 j(i, e) {
85
- const n = (t) => String.prototype.split.call(e, t).filter(Boolean).reduce((a, r) => a != null && typeof a == "object" ? a[r] : a, i), o = n(/[,[\]]+?/) || n(/[,[\].]+?/);
86
- return typeof o != "string" ? "" : o;
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 _(i, e) {
89
- if (!i) throw new Error('"locale" parameter cannot be empty');
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 = j(i, e);
92
- return n || (v(`Couldn't find a value for the key "${e}", it will be used as fallback.`), e);
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 K(i) {
95
- const n = i.map((t) => `(<${t}.*>.*</${t}>)`).join("|");
93
+ function G(a) {
94
+ const n = a.map((t) => `(<${t}.*>.*</${t}>)`).join("|");
96
95
  return new RegExp(n, "igm");
97
96
  }
98
- function D(i, e) {
97
+ function K(a, e) {
99
98
  const n = Object.keys(e);
100
- if (n.length === 0) return [i];
101
- const o = K(n);
102
- return i.split(o).filter((t) => !!t).map((t) => {
103
- if (!t.match(o)) return t;
104
- const r = t.match(/<(.*)>(.*)<\/.*>/);
105
- if (!r) return t;
106
- const [, p, l] = r;
107
- return [p, l];
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 [r, p] = t, l = e[r];
111
- return l || typeof l == "function" ? l(p) : (v(`Custom tag "${r}" does not have a matching enhancer function`), p);
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(i, e, n) {
115
- if (!i) throw new Error('"locale" parameter cannot be empty');
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 o = _(i, e);
119
- return D(o, n);
117
+ const i = N(a, e);
118
+ return K(i, n);
120
119
  }
121
- var V = Object.defineProperty, d = (i, e, n, o) => {
122
- for (var t = void 0, a = i.length - 1, r; a >= 0; a--)
123
- (r = i[a]) && (t = r(e, n, t) || t);
124
- return t && V(e, n, t), t;
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
- const I = "pie-cookie-banner", k = class k extends $ {
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 = h.hasPrimaryActionsOnly, this.defaultPreferences = h.defaultPreferences, this.locale = h.locale, this.cookieStatementLink = h.cookieStatementLink, this.cookieTechnologiesLink = h.cookieTechnologiesLink, this._customTagEnhancers = {
129
- linkStatement: (e) => s`<pie-link href="${this.cookieStatementLink}" variant="inverse" target="_blank" data-test-id="cookie-statement-link">${e}</pie-link>`,
130
- linkNecessaryOnly: (e) => s`<pie-link data-test-id="body-necessary-only" tag="button" variant="inverse" @click="${this._onNecessaryOnly}">${e}</pie-link>`,
131
- linkManagePreferences: (e) => s`<pie-link data-test-id="body-manage-prefs" tag="button" variant="inverse" @click="${this._openManagePreferencesModal}">${e}</pie-link>`,
132
- linkAcceptAll: (e) => s`<pie-link data-test-id="body-accept-all" tag="button" variant="inverse" @click="${this._onAcceptAll}">${e}</pie-link>`,
133
- linkCookieStatement: (e) => s`<pie-link href="${this.cookieStatementLink}" size="small" target="_blank" data-test-id="cookie-statement-link">${e}</pie-link>`,
134
- linkCookieTechList: (e) => s`<pie-link href="${this.cookieTechnologiesLink}" size="small" target="_blank" data-test-id="cookie-technology-link">${e}</pie-link>`
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
- g(this, E), this._isCookieBannerHidden = !0;
175
+ k(this, M), this._isCookieBannerHidden = !0;
137
176
  }, this._onAcceptAll = () => {
138
- g(this, z), this._isCookieBannerHidden = !0;
177
+ k(this, R), this._isCookieBannerHidden = !0;
139
178
  }, this._openManagePreferencesModal = () => {
140
- this._isCookieBannerHidden = !0, g(this, L), this._isModalOpen = !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, o = [...this._preferencesNodes].find(({ id: t }) => t === "all");
143
- if (n === o.id) {
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((a) => {
146
- a.checked = a.disabled ? a.checked : t;
184
+ this._preferencesNodes.forEach((o) => {
185
+ o.checked = o.disabled ? o.checked : t;
147
186
  });
148
187
  } else
149
- o.checked = [...this._preferencesNodes].filter(({ id: t }) => t !== "all").every(({ checked: t }) => t);
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 _(this.locale, e);
208
+ return N(this._locale, e);
154
209
  }
155
210
  _localiseRichText(e) {
156
- return F(this.locale, e, this._customTagEnhancers);
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: o }) => {
177
- e = { ...e, [n]: o };
178
- }), g(this, R, e), this._isModalOpen = !1, this._isCookieBannerHidden = !0;
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: o,
242
+ disabled: i,
188
243
  hasDivider: t,
189
- hasDescription: a
244
+ hasDescription: o
190
245
  }) {
191
- var u;
192
- const r = this._localiseText(`preferencesManagement.${e}.title`), p = `preferencesManagement.${e}.description`, l = a && this._localiseText(p), w = ["functional", "personalized", "analytical"].every((B) => {
193
- var b;
194
- return ((b = this.defaultPreferences) == null ? void 0 : b[B]) === !0;
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 s`
251
+ return d`
197
252
  <div class="c-cookieBanner-preference">
198
253
  <div>
199
- <h3 class="c-cookieBanner-subheading">${r}</h3>
200
- ${l ? s`<p class="c-cookieBanner-description">${l}</p>` : m}
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="${((u = this.defaultPreferences) == null ? void 0 : u[e]) || w || n}"
205
- ?disabled="${o}"
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 ? s`<pie-divider></pie-divider>` : m}`;
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 s`
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
- H,
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 s`
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
- k.styles = A(S);
279
- let c = k;
280
- d([
281
- y()
282
- ], c.prototype, "_isCookieBannerHidden");
283
- d([
284
- y()
285
- ], c.prototype, "_isModalOpen");
286
- d([
287
- f({ type: Boolean })
288
- ], c.prototype, "hasPrimaryActionsOnly");
289
- d([
290
- f({ type: Object })
291
- ], c.prototype, "defaultPreferences");
292
- d([
293
- f({ type: Object })
294
- ], c.prototype, "locale");
295
- d([
296
- f({ type: String })
297
- ], c.prototype, "cookieStatementLink");
298
- d([
299
- f({ type: String })
300
- ], c.prototype, "cookieTechnologiesLink");
301
- d([
302
- T("pie-switch")
303
- ], c.prototype, "_preferencesNodes");
304
- O(I, c);
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
- z as ON_COOKIE_BANNER_ACCEPT_ALL,
307
- L as ON_COOKIE_BANNER_MANAGE_PREFS,
308
- E as ON_COOKIE_BANNER_NECESSARY_ONLY,
309
- R as ON_COOKIE_BANNER_PREFS_SAVED,
310
- c as PieCookieBanner,
311
- h as defaultProps,
312
- H as preferences
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 t, ON_COOKIE_BANNER_MANAGE_PREFS as C, ON_COOKIE_BANNER_NECESSARY_ONLY as N, ON_COOKIE_BANNER_PREFS_SAVED as _, defaultProps as E, preferences as P } from "./index.js";
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
- }), s = a;
20
+ }), t = a;
21
21
  export {
22
- t as ON_COOKIE_BANNER_ACCEPT_ALL,
23
- C as ON_COOKIE_BANNER_MANAGE_PREFS,
24
- N as ON_COOKIE_BANNER_NECESSARY_ONLY,
25
- _ as ON_COOKIE_BANNER_PREFS_SAVED,
26
- s as PieCookieBanner,
27
- E as defaultProps,
28
- P as preferences
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
  };
@@ -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": " Solo necessari",
7
+ "necessaryOnly": "Solo necessari",
8
8
  "acceptAll": "Accetta tutti"
9
9
  }
10
10
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-cookie-banner",
3
3
  "description": "PIE Design System Cookie Banner built using Web Components",
4
- "version": "0.26.11",
4
+ "version": "1.0.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
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
- import defaultLocale from '../locales/en-gb.json' assert { type: 'json' };
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
- locale: defaultLocale,
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, html, unsafeCSS, nothing,
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.locale, key);
116
+ return localiseText(this._locale, key);
81
117
  }
82
118
 
83
119
  private _localiseRichText (key: string) {
84
- return localiseRichText(this.locale, key, this._customTagEnhancers);
120
+ return localiseRichText(this._locale, key, this._customTagEnhancers);
85
121
  }
86
122
 
87
123
  /**