@justeattakeaway/pie-cookie-banner 0.19.6 → 0.19.8

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/README.md CHANGED
@@ -8,17 +8,6 @@
8
8
  </a>
9
9
  </p>
10
10
 
11
- # Table of Contents
12
-
13
- 1. [Introduction](#pie-cookie-banner)
14
- 2. [Installation](#installation)
15
- 3. [Importing the component](#importing-the-component)
16
- 4. [Peer Dependencies](#peer-dependencies)
17
- 5. [Props](#props)
18
- 6. [Events](#events)
19
- 7. [Contributing](#contributing)
20
-
21
-
22
11
  ## pie-cookie-banner
23
12
 
24
13
  `pie-cookie-banner` is a Web Component built using the Lit library.
@@ -43,84 +32,13 @@ $ yarn add @justeattakeaway/pie-cookie-banner
43
32
 
44
33
  For full information on using PIE components as part of an application, check out the [Getting Started Guide](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components).
45
34
 
35
+ ## Documentation
46
36
 
47
- ### Importing the component
48
-
49
- #### JavaScript
50
- ```js
51
- // Default – for Native JS Applications, Vue, Angular, Svelte, etc.
52
- import { PieCookieBanner } from '@justeattakeaway/pie-cookie-banner';
53
-
54
- // If you don't need to reference the imported object, you can simply
55
- // import the module which registers the component as a custom element.
56
- import '@justeattakeaway/pie-cookie-banner';
57
- ```
58
-
59
- #### React
60
- ```js
61
- // React
62
- // For React, you will need to import our React-specific component build
63
- // which wraps the web component using ​@lit/react
64
- import { PieCookieBanner } from '@justeattakeaway/pie-cookie-banner/dist/react';
65
- ```
66
-
67
- > [!NOTE]
68
- > When using the React version of the component, please make sure to also
69
- > include React as a [peer dependency](#peer-dependencies) in your project.
70
-
71
-
72
- ## Peer Dependencies
73
-
74
- > [!IMPORTANT]
75
- > When using `pie-cookie-banner`, you will also need to include a couple of dependencies to ensure the component renders as expected. See [the PIE Wiki](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components#expected-dependencies) for more information and how to include these in your application.
76
-
77
- ## Props
78
-
79
- | Property | Type | Default | Description |
80
- |---|---|---|---|
81
- | hasPrimaryActionsOnly | `Boolean` | `false` | When true, sets the variant to "primary" for the button which accepts necessary cookies only. |
82
- | locale | `Object` | {English language locale} | Assigns the localisation data for the component strings. |
83
- | cookieStatementLink | `String` | `''` | Allows a url to be passed for the cookie statement link. |
84
- | cookieTechnologiesLink | `String` | `''` | Allows a url to be passed for the cookie technology link. |
85
- | defaultPreferences | `Object` | `{}` | Allows default preferences to be passed in by the consumer`{ 'functional': true, 'personalized': true, 'analytical': true }` or `{ 'functional': true }`. |
37
+ Visit [Cookie Banner | PIE Design System](https://pie.design/patterns/cookie-banner/code/) to view more information on this component.
86
38
 
87
- ## Events
39
+ ## Questions
88
40
 
89
- The pie cookie banner does not directly establish cookies within the application or component. Instead, it offers events that application developers (consumers of this component) can subscribe to. This, in turn, enables applications to manage the process of setting their own cookies. The table below provides a list of events you can listen to:
90
-
91
- | Event | Type | Description |
92
- |-------|------|-------------|
93
- | `pie-cookie-banner-accept-all` | `CustomEvent` | Triggered when `accept all` is clicked. |
94
- | `pie-cookie-banner-necessary-only` | `CustomEvent` | Triggered when `necessary` is clicked. |
95
- | `pie-cookie-banner-manage-prefs` | `CustomEvent` | Triggered when `manage prefs` is clicked. |
96
- | `pie-cookie-banner-prefs-saved` | `CustomEvent` | Triggered when `manage prefs saved` is clicked. |
97
-
98
- In your markup or JSX, you can then use these to set the properties for the `pie-cookie-banner` component:
99
-
100
- ```html
101
- <!-- Native HTML -->
102
- <pie-cookie-banner></pie-cookie-banner>
103
-
104
- <!-- JSX -->
105
- <PieCookieBanner></PieCookieBanner>
106
- ```
107
-
108
- ### Localisation
109
-
110
- By default the component displays its content in English language. To display the content in another language, you need to import the locale data for that language and pass it in the `locale` prop. For example, to display the content in Dutch, you need to import the Dutch locale data:
111
-
112
- ```js
113
- import locale from '@justeattakeaway/pie-cookie-banner/locales/nl-nl.json';
114
-
115
- <!-- JSX -->
116
- <PieCookieBanner locale={locale}></PieCookieBanner>
117
- ```
118
-
119
- It's possible to import all locales at once, if necessary:
120
-
121
- ```js
122
- import allLocales from '@justeattakeaway/pie-cookie-banner/locales';
123
- ```
41
+ Please head to [FAQs | PIE Design System](https://pie.design/support/contact-us/) to see our FAQs and get in touch.
124
42
 
125
43
  ## Contributing
126
44
 
@@ -104,6 +104,14 @@
104
104
  "kind": "javascript-module",
105
105
  "path": "src/index.js",
106
106
  "declarations": [
107
+ {
108
+ "kind": "variable",
109
+ "name": "defaultProps",
110
+ "type": {
111
+ "text": "DefaultProps"
112
+ },
113
+ "default": "{\n hasPrimaryActionsOnly: false,\n defaultPreferences: {},\n locale: defaultLocale,\n cookieStatementLink: '',\n cookieTechnologiesLink: '',\n}"
114
+ },
107
115
  {
108
116
  "kind": "class",
109
117
  "description": "",
@@ -130,11 +138,7 @@
130
138
  {
131
139
  "kind": "field",
132
140
  "name": "hasPrimaryActionsOnly",
133
- "type": {
134
- "text": "boolean"
135
- },
136
141
  "privacy": "public",
137
- "default": "false",
138
142
  "attribute": "hasPrimaryActionsOnly"
139
143
  },
140
144
  {
@@ -144,7 +148,6 @@
144
148
  "text": "CookieBannerProps['defaultPreferences']"
145
149
  },
146
150
  "privacy": "public",
147
- "default": "{}",
148
151
  "attribute": "defaultPreferences"
149
152
  },
150
153
  {
@@ -154,27 +157,18 @@
154
157
  "text": "CookieBannerLocale"
155
158
  },
156
159
  "privacy": "public",
157
- "default": "defaultLocale",
158
160
  "attribute": "locale"
159
161
  },
160
162
  {
161
163
  "kind": "field",
162
164
  "name": "cookieStatementLink",
163
- "type": {
164
- "text": "string"
165
- },
166
165
  "privacy": "public",
167
- "default": "''",
168
166
  "attribute": "cookieStatementLink"
169
167
  },
170
168
  {
171
169
  "kind": "field",
172
170
  "name": "cookieTechnologiesLink",
173
- "type": {
174
- "text": "string"
175
- },
176
171
  "privacy": "public",
177
- "default": "''",
178
172
  "attribute": "cookieTechnologiesLink"
179
173
  },
180
174
  {
@@ -339,10 +333,6 @@
339
333
  "attributes": [
340
334
  {
341
335
  "name": "hasPrimaryActionsOnly",
342
- "type": {
343
- "text": "boolean"
344
- },
345
- "default": "false",
346
336
  "fieldName": "hasPrimaryActionsOnly"
347
337
  },
348
338
  {
@@ -350,7 +340,6 @@
350
340
  "type": {
351
341
  "text": "CookieBannerProps['defaultPreferences']"
352
342
  },
353
- "default": "{}",
354
343
  "fieldName": "defaultPreferences"
355
344
  },
356
345
  {
@@ -358,26 +347,14 @@
358
347
  "type": {
359
348
  "text": "CookieBannerLocale"
360
349
  },
361
- "default": "defaultLocale",
362
- "resolveInitializer": {
363
- "module": "/locales/en-gb.json"
364
- },
365
350
  "fieldName": "locale"
366
351
  },
367
352
  {
368
353
  "name": "cookieStatementLink",
369
- "type": {
370
- "text": "string"
371
- },
372
- "default": "''",
373
354
  "fieldName": "cookieStatementLink"
374
355
  },
375
356
  {
376
357
  "name": "cookieTechnologiesLink",
377
- "type": {
378
- "text": "string"
379
- },
380
- "default": "''",
381
358
  "fieldName": "cookieTechnologiesLink"
382
359
  }
383
360
  ],
@@ -398,6 +375,14 @@
398
375
  "package": "./defs"
399
376
  }
400
377
  },
378
+ {
379
+ "kind": "js",
380
+ "name": "defaultProps",
381
+ "declaration": {
382
+ "name": "defaultProps",
383
+ "module": "src/index.js"
384
+ }
385
+ },
401
386
  {
402
387
  "kind": "js",
403
388
  "name": "PieCookieBanner",
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ComponentDefaultPropsGeneric } from '@justeattakeaway/pie-webc-core';
1
2
  import type { CSSResult } from 'lit';
2
3
  import type { LitElement } from 'lit';
3
4
  import { PieSwitch } from '@justeattakeaway/pie-switch';
@@ -54,11 +55,11 @@ export declare interface CookieBannerProps {
54
55
  */
55
56
  locale: CookieBannerLocale;
56
57
  /**
57
- * Allows consumers to pass in a specific cookie statement link.
58
+ * The URL of the cookie statement page the banner should link to.
58
59
  */
59
60
  cookieStatementLink: string;
60
61
  /**
61
- * Allows consumers to pass in a specific cookie technology link.
62
+ * The URL for the cookie technology link.
62
63
  */
63
64
  cookieTechnologiesLink: string;
64
65
  /**
@@ -66,6 +67,7 @@ export declare interface CookieBannerProps {
66
67
  * the switch to be on by default (if set to `true`).
67
68
  *
68
69
  * e.g. { 'functional': true }
70
+ * or { 'functional': true, 'personalized': true, 'analytical': true }
69
71
  */
70
72
  defaultPreferences?: Partial<Record<PreferenceIds, boolean>>;
71
73
  }
@@ -74,6 +76,10 @@ export declare interface CustomTagEnhancers {
74
76
  [key: string]: (tagContent: string) => TemplateResult;
75
77
  }
76
78
 
79
+ export declare type DefaultProps = ComponentDefaultPropsGeneric<CookieBannerProps, 'hasPrimaryActionsOnly' | 'defaultPreferences' | 'locale' | 'cookieStatementLink' | 'cookieTechnologiesLink'>;
80
+
81
+ export declare const defaultProps: DefaultProps;
82
+
77
83
  /**
78
84
  * Event name for when all cookies are accepted.
79
85
  *
package/dist/index.js CHANGED
@@ -1,15 +1,54 @@
1
- import { unsafeCSS as w, LitElement as B, html as s, nothing as k } from "lit";
2
- import { state as b, property as h, queryAll as $ } from "lit/decorators.js";
3
- import { repeat as A } from "lit/directives/repeat.js";
1
+ import { unsafeCSS as B, LitElement as $, html as s, nothing as b } from "lit";
2
+ import { state as m, property as f, queryAll as A } from "lit/decorators.js";
3
+ import { repeat as C } from "lit/directives/repeat.js";
4
4
  import "@justeattakeaway/pie-button";
5
5
  import "@justeattakeaway/pie-divider";
6
6
  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 { defineCustomElement as C, dispatchCustomEvent as f } from "@justeattakeaway/pie-webc-core";
11
- const T = `*,*: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}.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}
12
- `, O = "pie-cookie-banner-accept-all", S = "pie-cookie-banner-necessary-only", M = "pie-cookie-banner-manage-prefs", N = "pie-cookie-banner-prefs-saved", P = [
10
+ import { defineCustomElement as T, dispatchCustomEvent as g } from "@justeattakeaway/pie-webc-core";
11
+ const O = {
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
+ }, S = {
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: O,
49
+ preferencesManagement: S
50
+ }, M = `*,*: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}.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}
51
+ `, N = "pie-cookie-banner-accept-all", z = "pie-cookie-banner-necessary-only", E = "pie-cookie-banner-manage-prefs", L = "pie-cookie-banner-prefs-saved", R = [
13
52
  {
14
53
  id: "all",
15
54
  hasDivider: !0,
@@ -34,30 +73,30 @@ const T = `*,*:after,*:before{box-sizing:inherit}*{margin:0}.c-cookieBanner{--cb
34
73
  hasDescription: !0
35
74
  }
36
75
  ];
37
- function m(a) {
76
+ function y(a) {
38
77
  console.error(`[localisation-utils]: ${a}`);
39
78
  }
40
- function z(a, e) {
79
+ function j(a, e) {
41
80
  const n = (t) => String.prototype.split.call(e, t).filter(Boolean).reduce((o, r) => o != null && typeof o == "object" ? o[r] : o, a), i = n(/[,[\]]+?/) || n(/[,[\].]+?/);
42
81
  return typeof i != "string" ? "" : i;
43
82
  }
44
- function y(a, e) {
83
+ function v(a, e) {
45
84
  if (!a)
46
85
  throw new Error('"locale" parameter cannot be empty');
47
86
  if (!e)
48
87
  throw new Error('"key" parameter cannot be empty');
49
- const n = z(a, e);
50
- return n || (m(`Couldn't find a value for the key "${e}", it will be used as fallback.`), e);
88
+ const n = j(a, e);
89
+ return n || (y(`Couldn't find a value for the key "${e}", it will be used as fallback.`), e);
51
90
  }
52
- function E(a) {
91
+ function H(a) {
53
92
  const n = a.map((t) => `(<${t}.*>.*</${t}>)`).join("|");
54
93
  return new RegExp(n, "igm");
55
94
  }
56
- function L(a, e) {
95
+ function D(a, e) {
57
96
  const n = Object.keys(e);
58
97
  if (n.length === 0)
59
98
  return [a];
60
- const i = E(n);
99
+ const i = H(n);
61
100
  return a.split(i).filter((t) => !!t).map((t) => {
62
101
  if (!t.match(i))
63
102
  return t;
@@ -70,68 +109,34 @@ function L(a, e) {
70
109
  if (!Array.isArray(t))
71
110
  return t;
72
111
  const [r, p] = t, l = e[r];
73
- return l || typeof l == "function" ? l(p) : (m(`Custom tag "${r}" does not have a matching enhancer function`), p);
112
+ return l || typeof l == "function" ? l(p) : (y(`Custom tag "${r}" does not have a matching enhancer function`), p);
74
113
  });
75
114
  }
76
- function R(a, e, n) {
115
+ function K(a, e, n) {
77
116
  if (!a)
78
117
  throw new Error('"locale" parameter cannot be empty');
79
118
  if (!e)
80
119
  throw new Error('"key" parameter cannot be empty');
81
120
  if (!n)
82
121
  throw new Error('"customTagEnhancers" parameter cannot be empty');
83
- const i = y(a, e);
84
- return L(i, n);
122
+ const i = v(a, e);
123
+ return D(i, n);
85
124
  }
86
- const j = {
87
- title: "Cookies",
88
- 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>.",
89
- cta: {
90
- managePreferences: "Manage preferences",
91
- necessaryOnly: "Necessary only",
92
- acceptAll: "Accept all"
93
- }
94
- }, H = {
95
- title: "Manage your preferences",
96
- description: "You can find all the information in the <linkCookieStatement>Cookie Statement</linkCookieStatement> and <linkCookieTechList>Cookie technology list</linkCookieTechList>.",
97
- all: {
98
- title: "Turn all on"
99
- },
100
- necessary: {
101
- title: "Necessary",
102
- 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."
103
- },
104
- functional: {
105
- title: "Functional",
106
- description: "These cookies allow the website to remember the choices you make to give you better functionality and personal features."
107
- },
108
- analytical: {
109
- title: "Analytical",
110
- 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."
111
- },
112
- personalized: {
113
- title: "Personalised (targeting and advertising)",
114
- 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."
115
- },
116
- cta: {
117
- save: {
118
- label: "Save",
119
- ariaLabel: ""
120
- }
121
- }
122
- }, D = {
123
- banner: j,
124
- preferencesManagement: H
125
- };
126
- var K = Object.defineProperty, F = Object.getOwnPropertyDescriptor, d = (a, e, n, i) => {
127
- for (var t = i > 1 ? void 0 : i ? F(e, n) : e, o = a.length - 1, r; o >= 0; o--)
125
+ var F = Object.defineProperty, V = Object.getOwnPropertyDescriptor, d = (a, e, n, i) => {
126
+ for (var t = i > 1 ? void 0 : i ? V(e, n) : e, o = a.length - 1, r; o >= 0; o--)
128
127
  (r = a[o]) && (t = (i ? r(e, n, t) : r(t)) || t);
129
- return i && t && K(e, n, t), t;
128
+ return i && t && F(e, n, t), t;
130
129
  };
131
- const V = "pie-cookie-banner";
132
- class c extends B {
130
+ const h = {
131
+ hasPrimaryActionsOnly: !1,
132
+ defaultPreferences: {},
133
+ locale: P,
134
+ cookieStatementLink: "",
135
+ cookieTechnologiesLink: ""
136
+ }, I = "pie-cookie-banner";
137
+ class c extends $ {
133
138
  constructor() {
134
- super(...arguments), this._isCookieBannerHidden = !1, this._isModalOpen = !1, this.hasPrimaryActionsOnly = !1, this.defaultPreferences = {}, this.locale = D, this.cookieStatementLink = "", this.cookieTechnologiesLink = "", this._customTagEnhancers = {
139
+ 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 = {
135
140
  linkStatement: (e) => s`<pie-link href="${this.cookieStatementLink}" variant="inverse" target="_blank" data-test-id="cookie-statement-link">${e}</pie-link>`,
136
141
  linkNecessaryOnly: (e) => s`<pie-link data-test-id="body-necessary-only" tag="button" variant="inverse" @click="${this._onNecessaryOnly}">${e}</pie-link>`,
137
142
  linkManagePreferences: (e) => s`<pie-link data-test-id="body-manage-prefs" tag="button" variant="inverse" @click="${this._openManagePreferencesModal}">${e}</pie-link>`,
@@ -139,11 +144,11 @@ class c extends B {
139
144
  linkCookieStatement: (e) => s`<pie-link href="${this.cookieStatementLink}" size="small" target="_blank" data-test-id="cookie-statement-link">${e}</pie-link>`,
140
145
  linkCookieTechList: (e) => s`<pie-link href="${this.cookieTechnologiesLink}" size="small" target="_blank" data-test-id="cookie-technology-link">${e}</pie-link>`
141
146
  }, this._onNecessaryOnly = () => {
142
- f(this, S), this._isCookieBannerHidden = !0;
147
+ g(this, z), this._isCookieBannerHidden = !0;
143
148
  }, this._onAcceptAll = () => {
144
- f(this, O), this._isCookieBannerHidden = !0;
149
+ g(this, N), this._isCookieBannerHidden = !0;
145
150
  }, this._openManagePreferencesModal = () => {
146
- this._isCookieBannerHidden = !0, f(this, M), this._isModalOpen = !0;
151
+ this._isCookieBannerHidden = !0, g(this, E), this._isModalOpen = !0;
147
152
  }, this._handleSwitchStates = (e) => {
148
153
  const { id: n } = e == null ? void 0 : e.currentTarget, i = [...this._preferencesNodes].find(({ id: t }) => t === "all");
149
154
  if (n === i.id) {
@@ -156,10 +161,10 @@ class c extends B {
156
161
  };
157
162
  }
158
163
  _localiseText(e) {
159
- return y(this.locale, e);
164
+ return v(this.locale, e);
160
165
  }
161
166
  _localiseRichText(e) {
162
- return R(this.locale, e, this._customTagEnhancers);
167
+ return K(this.locale, e, this._customTagEnhancers);
163
168
  }
164
169
  /**
165
170
  * Handles closing the modal and re-displaying the cookie banner
@@ -181,7 +186,7 @@ class c extends B {
181
186
  let e = {};
182
187
  [...this._preferencesNodes].filter(({ id: n }) => n !== "all").forEach(({ id: n, checked: i }) => {
183
188
  e = { ...e, [n]: i };
184
- }), f(this, N, e), this._isModalOpen = !1, this._isCookieBannerHidden = !0;
189
+ }), g(this, L, e), this._isModalOpen = !1, this._isCookieBannerHidden = !0;
185
190
  }
186
191
  /**
187
192
  * Renders the content of the preference item.
@@ -194,25 +199,25 @@ class c extends B {
194
199
  hasDivider: t,
195
200
  hasDescription: o
196
201
  }) {
197
- var g;
198
- const r = this._localiseText(`preferencesManagement.${e}.title`), p = `preferencesManagement.${e}.description`, l = o && this._localiseText(p), _ = ["functional", "personalized", "analytical"].every((x) => {
202
+ var k;
203
+ const r = this._localiseText(`preferencesManagement.${e}.title`), p = `preferencesManagement.${e}.description`, l = o && this._localiseText(p), x = ["functional", "personalized", "analytical"].every((w) => {
199
204
  var u;
200
- return ((u = this.defaultPreferences) == null ? void 0 : u[x]) === !0;
205
+ return ((u = this.defaultPreferences) == null ? void 0 : u[w]) === !0;
201
206
  });
202
207
  return s`
203
208
  <div class="c-cookieBanner-preference">
204
209
  <div>
205
210
  <h3 class="c-cookieBanner-subheading">${r}</h3>
206
- ${l ? s`<p class="c-cookieBanner-description">${l}</p>` : k}
211
+ ${l ? s`<p class="c-cookieBanner-description">${l}</p>` : b}
207
212
  </div>
208
213
  <pie-switch
209
214
  id="${e}"
210
- ?checked="${((g = this.defaultPreferences) == null ? void 0 : g[e]) || _ || n}"
215
+ ?checked="${((k = this.defaultPreferences) == null ? void 0 : k[e]) || x || n}"
211
216
  ?disabled="${i}"
212
217
  @change="${this._handleSwitchStates}">
213
218
  </pie-switch>
214
219
  </div>
215
- ${t ? s`<pie-divider></pie-divider>` : k}`;
220
+ ${t ? s`<pie-divider></pie-divider>` : b}`;
216
221
  }
217
222
  /**
218
223
  * Renders the modal content.
@@ -223,8 +228,8 @@ class c extends B {
223
228
  <p class="c-cookieBanner-description" data-test-id="modal-description">
224
229
  ${this._localiseRichText("preferencesManagement.description")}
225
230
  </p>
226
- ${A(
227
- P,
231
+ ${C(
232
+ R,
228
233
  ({ id: e }) => e,
229
234
  (e) => this.renderPreference(e)
230
235
  )}`;
@@ -283,37 +288,38 @@ class c extends B {
283
288
  </aside>`;
284
289
  }
285
290
  }
286
- c.styles = w(T);
291
+ c.styles = B(M);
287
292
  d([
288
- b()
293
+ m()
289
294
  ], c.prototype, "_isCookieBannerHidden", 2);
290
295
  d([
291
- b()
296
+ m()
292
297
  ], c.prototype, "_isModalOpen", 2);
293
298
  d([
294
- h({ type: Boolean })
299
+ f({ type: Boolean })
295
300
  ], c.prototype, "hasPrimaryActionsOnly", 2);
296
301
  d([
297
- h({ type: Object })
302
+ f({ type: Object })
298
303
  ], c.prototype, "defaultPreferences", 2);
299
304
  d([
300
- h({ type: Object })
305
+ f({ type: Object })
301
306
  ], c.prototype, "locale", 2);
302
307
  d([
303
- h({ type: String })
308
+ f({ type: String })
304
309
  ], c.prototype, "cookieStatementLink", 2);
305
310
  d([
306
- h({ type: String })
311
+ f({ type: String })
307
312
  ], c.prototype, "cookieTechnologiesLink", 2);
308
313
  d([
309
- $("pie-switch")
314
+ A("pie-switch")
310
315
  ], c.prototype, "_preferencesNodes", 2);
311
- C(V, c);
316
+ T(I, c);
312
317
  export {
313
- O as ON_COOKIE_BANNER_ACCEPT_ALL,
314
- M as ON_COOKIE_BANNER_MANAGE_PREFS,
315
- S as ON_COOKIE_BANNER_NECESSARY_ONLY,
316
- N as ON_COOKIE_BANNER_PREFS_SAVED,
318
+ N as ON_COOKIE_BANNER_ACCEPT_ALL,
319
+ E as ON_COOKIE_BANNER_MANAGE_PREFS,
320
+ z as ON_COOKIE_BANNER_NECESSARY_ONLY,
321
+ L as ON_COOKIE_BANNER_PREFS_SAVED,
317
322
  c as PieCookieBanner,
318
- P as preferences
323
+ h as defaultProps,
324
+ R as preferences
319
325
  };
package/dist/react.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ComponentDefaultPropsGeneric } from '@justeattakeaway/pie-webc-core';
1
2
  import type { CSSResult } from 'lit';
2
3
  import type { LitElement } from 'lit';
3
4
  import { PieSwitch } from '@justeattakeaway/pie-switch';
@@ -55,11 +56,11 @@ export declare interface CookieBannerProps {
55
56
  */
56
57
  locale: CookieBannerLocale;
57
58
  /**
58
- * Allows consumers to pass in a specific cookie statement link.
59
+ * The URL of the cookie statement page the banner should link to.
59
60
  */
60
61
  cookieStatementLink: string;
61
62
  /**
62
- * Allows consumers to pass in a specific cookie technology link.
63
+ * The URL for the cookie technology link.
63
64
  */
64
65
  cookieTechnologiesLink: string;
65
66
  /**
@@ -67,6 +68,7 @@ export declare interface CookieBannerProps {
67
68
  * the switch to be on by default (if set to `true`).
68
69
  *
69
70
  * e.g. { 'functional': true }
71
+ * or { 'functional': true, 'personalized': true, 'analytical': true }
70
72
  */
71
73
  defaultPreferences?: Partial<Record<PreferenceIds, boolean>>;
72
74
  }
@@ -75,6 +77,8 @@ export declare interface CustomTagEnhancers {
75
77
  [key: string]: (tagContent: string) => TemplateResult;
76
78
  }
77
79
 
80
+ export declare type DefaultProps = ComponentDefaultPropsGeneric<CookieBannerProps, 'hasPrimaryActionsOnly' | 'defaultPreferences' | 'locale' | 'cookieStatementLink' | 'cookieTechnologiesLink'>;
81
+
78
82
  /**
79
83
  * Event name for when all cookies are accepted.
80
84
  *
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.19.6",
4
+ "version": "0.19.8",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -43,13 +43,13 @@
43
43
  "cem-plugin-module-file-extensions": "0.0.5"
44
44
  },
45
45
  "dependencies": {
46
- "@justeattakeaway/pie-button": "0.47.4",
47
- "@justeattakeaway/pie-divider": "0.13.4",
48
- "@justeattakeaway/pie-icon-button": "0.28.5",
49
- "@justeattakeaway/pie-link": "0.17.4",
50
- "@justeattakeaway/pie-modal": "0.42.5",
51
- "@justeattakeaway/pie-switch": "0.29.4",
52
- "@justeattakeaway/pie-webc-core": "0.22.0"
46
+ "@justeattakeaway/pie-button": "0.47.6",
47
+ "@justeattakeaway/pie-divider": "0.13.5",
48
+ "@justeattakeaway/pie-icon-button": "0.28.6",
49
+ "@justeattakeaway/pie-link": "0.17.5",
50
+ "@justeattakeaway/pie-modal": "0.42.7",
51
+ "@justeattakeaway/pie-switch": "0.29.6",
52
+ "@justeattakeaway/pie-webc-core": "0.23.0"
53
53
  },
54
54
  "volta": {
55
55
  "extends": "../../../package.json"
package/src/defs.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { type ComponentDefaultPropsGeneric } from '@justeattakeaway/pie-webc-core';
2
+
1
3
  import {
2
4
  TemplateResult,
3
5
  } from 'lit';
@@ -54,12 +56,12 @@ export interface CookieBannerProps {
54
56
  locale: CookieBannerLocale;
55
57
 
56
58
  /**
57
- * Allows consumers to pass in a specific cookie statement link.
59
+ * The URL of the cookie statement page the banner should link to.
58
60
  */
59
61
  cookieStatementLink: string;
60
62
 
61
63
  /**
62
- * Allows consumers to pass in a specific cookie technology link.
64
+ * The URL for the cookie technology link.
63
65
  */
64
66
  cookieTechnologiesLink: string;
65
67
 
@@ -68,6 +70,7 @@ export interface CookieBannerProps {
68
70
  * the switch to be on by default (if set to `true`).
69
71
  *
70
72
  * e.g. { 'functional': true }
73
+ * or { 'functional': true, 'personalized': true, 'analytical': true }
71
74
  */
72
75
  defaultPreferences?: Partial<Record<PreferenceIds, boolean>>;
73
76
  }
@@ -139,3 +142,6 @@ export const preferences: Preference[] = [
139
142
  export interface CustomTagEnhancers {
140
143
  [key: string]: (tagContent: string) => TemplateResult;
141
144
  }
145
+
146
+ export type DefaultProps = ComponentDefaultPropsGeneric<CookieBannerProps, 'hasPrimaryActionsOnly' | 'defaultPreferences' | 'locale' | 'cookieStatementLink' | 'cookieTechnologiesLink'>;
147
+
package/src/index.ts CHANGED
@@ -15,6 +15,8 @@ import { PieSwitch } from '@justeattakeaway/pie-switch';
15
15
  import { defineCustomElement, dispatchCustomEvent } from '@justeattakeaway/pie-webc-core';
16
16
  /* eslint-enable import/no-duplicates */
17
17
 
18
+ import defaultLocale from '../locales/en-gb.json';
19
+
18
20
  import styles from './cookie-banner.scss?inline';
19
21
  import {
20
22
  CookieBannerProps,
@@ -27,14 +29,25 @@ import {
27
29
  type PreferenceIds,
28
30
  type CookieBannerLocale,
29
31
  type CustomTagEnhancers,
32
+ DefaultProps,
30
33
  } from './defs';
31
34
 
32
35
  import { localiseText, localiseRichText } from './localisation-utils';
33
- import defaultLocale from '../locales/en-gb.json';
34
36
 
35
37
  // Valid values available to consumers
36
38
  export * from './defs';
37
39
 
40
+ // TODO: Move this object to defs.ts
41
+ // It can be moved as soon as we manage to figure a safe way to avoid the error TS2821
42
+ // Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'
43
+ export const defaultProps: DefaultProps = {
44
+ hasPrimaryActionsOnly: false,
45
+ defaultPreferences: {},
46
+ locale: defaultLocale,
47
+ cookieStatementLink: '',
48
+ cookieTechnologiesLink: '',
49
+ };
50
+
38
51
  const componentSelector = 'pie-cookie-banner';
39
52
 
40
53
  /**
@@ -52,19 +65,19 @@ export class PieCookieBanner extends LitElement implements CookieBannerProps {
52
65
  private _isModalOpen = false;
53
66
 
54
67
  @property({ type: Boolean })
55
- public hasPrimaryActionsOnly = false;
68
+ public hasPrimaryActionsOnly = defaultProps.hasPrimaryActionsOnly;
56
69
 
57
70
  @property({ type: Object })
58
- public defaultPreferences: CookieBannerProps['defaultPreferences'] = {};
71
+ public defaultPreferences: CookieBannerProps['defaultPreferences'] = defaultProps.defaultPreferences;
59
72
 
60
73
  @property({ type: Object })
61
- public locale:CookieBannerLocale = defaultLocale;
74
+ public locale:CookieBannerLocale = defaultProps.locale;
62
75
 
63
76
  @property({ type: String })
64
- public cookieStatementLink = '';
77
+ public cookieStatementLink = defaultProps.cookieStatementLink;
65
78
 
66
79
  @property({ type: String })
67
- public cookieTechnologiesLink = '';
80
+ public cookieTechnologiesLink = defaultProps.cookieTechnologiesLink;
68
81
 
69
82
  @queryAll('pie-switch')
70
83
  _preferencesNodes!: NodeListOf<PieSwitch>;