@uncinc/uncinc-react-kitchen-sink 2.16.14 → 2.16.15
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type CookieCompliancePopupProps } from './types';
|
|
2
3
|
import './style.scss';
|
|
3
|
-
import { CookieCompliancePopupProps } from './types';
|
|
4
4
|
export declare const COOKIE_CONSENT_CATEGORIES = "cookie_consent_categories";
|
|
5
5
|
export declare const COOKIE_CONSENT_STATE = "cookie_consent_state";
|
|
6
6
|
export declare const DEFAULT_COOKIE_EXPIRATION_DAYS = 365;
|
|
@@ -10,22 +10,28 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
10
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
11
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import React, { useEffect, useState } from 'react';
|
|
13
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
14
14
|
import Cookies from 'js-cookie';
|
|
15
15
|
import classNames from 'classnames';
|
|
16
16
|
import { useTranslation } from 'react-i18next';
|
|
17
|
+
import useCookieStore from '../../hooks/useCookieStore';
|
|
17
18
|
import Accordion from '../Accordion';
|
|
18
19
|
import AccordionItemVariant from '../Accordion/AccordionItemVariant';
|
|
19
20
|
import Button from '../Button';
|
|
20
21
|
import Container from '../Layout/Container';
|
|
21
22
|
import Checkbox from './Checkbox';
|
|
22
|
-
import './style.scss';
|
|
23
23
|
import { LocalConsentStatus, AvailableConsentPermissions } from './types';
|
|
24
|
-
import
|
|
24
|
+
import './style.scss';
|
|
25
25
|
export var COOKIE_CONSENT_CATEGORIES = 'cookie_consent_categories';
|
|
26
26
|
export var COOKIE_CONSENT_STATE = 'cookie_consent_state';
|
|
27
27
|
export var DEFAULT_COOKIE_EXPIRATION_DAYS = 365;
|
|
28
28
|
export var CONSENT_UPDATE_EVENT = 'consentUpdate';
|
|
29
|
+
var categoryDefaultValues = {
|
|
30
|
+
necessary: true,
|
|
31
|
+
preferences: false,
|
|
32
|
+
statistics: false,
|
|
33
|
+
marketing: false
|
|
34
|
+
};
|
|
29
35
|
var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
30
36
|
var _useTranslation = useTranslation(),
|
|
31
37
|
t = _useTranslation.t;
|
|
@@ -90,12 +96,7 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
90
96
|
_props$cookieDomain = props.cookieDomain,
|
|
91
97
|
cookieDomain = _props$cookieDomain === void 0 ? null : _props$cookieDomain,
|
|
92
98
|
_props$defaultValues = props.defaultValues,
|
|
93
|
-
defaultValues = _props$defaultValues === void 0 ?
|
|
94
|
-
necessary: true,
|
|
95
|
-
preferences: false,
|
|
96
|
-
statistics: false,
|
|
97
|
-
marketing: false
|
|
98
|
-
} : _props$defaultValues,
|
|
99
|
+
defaultValues = _props$defaultValues === void 0 ? categoryDefaultValues : _props$defaultValues,
|
|
99
100
|
_props$manualHeader = props.manualHeader,
|
|
100
101
|
manualHeader = _props$manualHeader === void 0 ? '' : _props$manualHeader,
|
|
101
102
|
_props$manualButtonCl = props.manualButtonClassname,
|
|
@@ -187,34 +188,33 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
187
188
|
setManualChoiceVisible(true);
|
|
188
189
|
};
|
|
189
190
|
|
|
190
|
-
// Build an object of passed consent, send that to google via "update"
|
|
191
|
-
// Set the cookie containing the consent categories and version
|
|
192
|
-
var handleGoogleConsent = function handleGoogleConsent() {
|
|
193
|
-
var selectedConsent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
194
|
-
var selectedCategories = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
195
|
-
var consentEventObject = {};
|
|
196
|
-
Object.values(AvailableConsentPermissions).forEach(function (consentOption) {
|
|
197
|
-
consentEventObject[consentOption] = selectedConsent.indexOf(consentOption) > -1 ? 'granted' : 'denied';
|
|
198
|
-
});
|
|
199
|
-
window.gtag('consent', 'update', consentEventObject);
|
|
200
|
-
window.gtag('event', CONSENT_UPDATE_EVENT);
|
|
201
|
-
Cookies.set(COOKIE_CONSENT_CATEGORIES, JSON.stringify({
|
|
202
|
-
categories: selectedCategories,
|
|
203
|
-
consent: consentEventObject
|
|
204
|
-
}), {
|
|
205
|
-
expires: cookieOptions.days,
|
|
206
|
-
domain: cookieDomain
|
|
207
|
-
});
|
|
208
|
-
setDidConsent(JSON.stringify({
|
|
209
|
-
status: LocalConsentStatus.STATUS_ACCEPTED,
|
|
210
|
-
version: version
|
|
211
|
-
}), cookieOptions);
|
|
212
|
-
setAnsweredInCurrentSession(true);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
191
|
// On agree clicked, send consent for categories to Google
|
|
216
192
|
// Update cookie and fire agree callback
|
|
217
|
-
var onInternalAgree = function
|
|
193
|
+
var onInternalAgree = useCallback(function (choices) {
|
|
194
|
+
// Build an object of passed consent, send that to google via "update"
|
|
195
|
+
// Set the cookie containing the consent categories and version
|
|
196
|
+
var handleGoogleConsent = function handleGoogleConsent() {
|
|
197
|
+
var selectedConsent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
198
|
+
var selectedCategories = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
199
|
+
var consentEventObject = {};
|
|
200
|
+
Object.values(AvailableConsentPermissions).forEach(function (consentOption) {
|
|
201
|
+
consentEventObject[consentOption] = selectedConsent.indexOf(consentOption) > -1 ? 'granted' : 'denied';
|
|
202
|
+
});
|
|
203
|
+
window.gtag('consent', 'update', consentEventObject);
|
|
204
|
+
window.gtag('event', CONSENT_UPDATE_EVENT);
|
|
205
|
+
Cookies.set(COOKIE_CONSENT_CATEGORIES, JSON.stringify({
|
|
206
|
+
categories: selectedCategories,
|
|
207
|
+
consent: consentEventObject
|
|
208
|
+
}), {
|
|
209
|
+
expires: cookieOptions.days,
|
|
210
|
+
domain: cookieDomain
|
|
211
|
+
});
|
|
212
|
+
setDidConsent(JSON.stringify({
|
|
213
|
+
status: LocalConsentStatus.STATUS_ACCEPTED,
|
|
214
|
+
version: version
|
|
215
|
+
}), cookieOptions);
|
|
216
|
+
setAnsweredInCurrentSession(true);
|
|
217
|
+
};
|
|
218
218
|
var selectedCategories = Object.keys(choices).filter(function (key) {
|
|
219
219
|
return choices[key];
|
|
220
220
|
});
|
|
@@ -229,10 +229,10 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
229
229
|
selectedCategories: selectedCategories,
|
|
230
230
|
consent: selectedConsent
|
|
231
231
|
});
|
|
232
|
-
};
|
|
232
|
+
}, [cookieDomain, cookieLevels, cookieOptions, onAgree, setDidConsent, version]);
|
|
233
233
|
|
|
234
234
|
// Function for accepting al categories at once.
|
|
235
|
-
var onConsentAll = function
|
|
235
|
+
var onConsentAll = useCallback(function () {
|
|
236
236
|
var allCategoriesSelected = categories.reduce(function (prev, category) {
|
|
237
237
|
var newPartialState = prev;
|
|
238
238
|
newPartialState[category] = true;
|
|
@@ -240,19 +240,17 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
240
240
|
}, {});
|
|
241
241
|
setChoicesSelected(allCategoriesSelected);
|
|
242
242
|
onInternalAgree(allCategoriesSelected);
|
|
243
|
-
};
|
|
243
|
+
}, [categories, onInternalAgree]);
|
|
244
|
+
var onConsentOnlyNecessary = useCallback(function () {
|
|
245
|
+
setChoicesSelected(defaultValues);
|
|
246
|
+
onInternalAgree(defaultValues);
|
|
247
|
+
}, [defaultValues, onInternalAgree]);
|
|
244
248
|
|
|
245
249
|
// This function is fired when the accept button is pressed.
|
|
246
250
|
// Also has eventual support for a false case.
|
|
247
|
-
var onConsent = function
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
onInternalAgree(defaultValues);
|
|
251
|
-
} else {
|
|
252
|
-
onInternalAgree(choicesSelected);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
};
|
|
251
|
+
var onConsent = useCallback(function () {
|
|
252
|
+
onInternalAgree(choicesSelected);
|
|
253
|
+
}, [choicesSelected, onInternalAgree]);
|
|
256
254
|
|
|
257
255
|
// This function sets the value of the checkmark in the form state.
|
|
258
256
|
var handleChoiceState = function handleChoiceState(event) {
|
|
@@ -326,7 +324,7 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
326
324
|
id: "only-necessary-agree",
|
|
327
325
|
className: "Button--cta",
|
|
328
326
|
inverted: necessaryButtonInverted,
|
|
329
|
-
onClick:
|
|
327
|
+
onClick: onConsentOnlyNecessary
|
|
330
328
|
}, onlyNecessaryText), /*#__PURE__*/React.createElement("button", {
|
|
331
329
|
type: "button",
|
|
332
330
|
className: "GoogleConsentCookieBanner__content__buttons__manual GoogleConsentCookieBanner__content__buttons__manual-agree ".concat(manualButtonClassname),
|
|
@@ -344,12 +342,12 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
344
342
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
345
343
|
className: "Button--cta",
|
|
346
344
|
primary: true,
|
|
347
|
-
onClick: onConsent
|
|
345
|
+
onClick: onConsent
|
|
348
346
|
}, acceptSelectionText), showAcceptOnlyNeededSelections && /*#__PURE__*/React.createElement(Button, {
|
|
349
347
|
id: "only-necessary-agree-selections",
|
|
350
348
|
className: "Button--cta",
|
|
351
349
|
inverted: necessaryButtonInverted,
|
|
352
|
-
onClick:
|
|
350
|
+
onClick: onConsentOnlyNecessary
|
|
353
351
|
}, onlyNecessaryText), /*#__PURE__*/React.createElement(Button, {
|
|
354
352
|
className: "Button--cta",
|
|
355
353
|
inverted: necessaryButtonInverted,
|