@uncinc/uncinc-react-kitchen-sink 2.16.13 → 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 useCookieStore from '../../hooks/useCookieStore';
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;
@@ -39,6 +45,8 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
39
45
  acceptAllText = _props$acceptAllText === void 0 ? t('cookies.acceptAll') : _props$acceptAllText,
40
46
  _props$acceptSelectio = props.acceptSelectionText,
41
47
  acceptSelectionText = _props$acceptSelectio === void 0 ? t('cookies.acceptSelection') : _props$acceptSelectio,
48
+ _props$acceptAllSelec = props.acceptAllSelectionsText,
49
+ acceptAllSelectionsText = _props$acceptAllSelec === void 0 ? t(['cookies.acceptAllSelections', 'cookies.acceptAll']) : _props$acceptAllSelec,
42
50
  _props$onlyNecessaryT = props.onlyNecessaryText,
43
51
  onlyNecessaryText = _props$onlyNecessaryT === void 0 ? t('cookies.acceptOnlyNecessary') : _props$onlyNecessaryT,
44
52
  _props$cookieContents = props.cookieContentsShowMore,
@@ -47,6 +55,8 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
47
55
  cookieContentsShowLess = _props$cookieContents2 === void 0 ? /*#__PURE__*/React.createElement("div", null, t('cookies.hideDetails')) : _props$cookieContents2,
48
56
  _props$showAcceptOnly = props.showAcceptOnlyNeeded,
49
57
  showAcceptOnlyNeeded = _props$showAcceptOnly === void 0 ? true : _props$showAcceptOnly,
58
+ _props$showAcceptOnly2 = props.showAcceptOnlyNeededSelections,
59
+ showAcceptOnlyNeededSelections = _props$showAcceptOnly2 === void 0 ? false : _props$showAcceptOnly2,
50
60
  _props$onAgree = props.onAgree,
51
61
  onAgree = _props$onAgree === void 0 ? function () {} : _props$onAgree,
52
62
  _props$cookieLevels = props.cookieLevels,
@@ -86,12 +96,7 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
86
96
  _props$cookieDomain = props.cookieDomain,
87
97
  cookieDomain = _props$cookieDomain === void 0 ? null : _props$cookieDomain,
88
98
  _props$defaultValues = props.defaultValues,
89
- defaultValues = _props$defaultValues === void 0 ? {
90
- necessary: true,
91
- preferences: false,
92
- statistics: false,
93
- marketing: false
94
- } : _props$defaultValues,
99
+ defaultValues = _props$defaultValues === void 0 ? categoryDefaultValues : _props$defaultValues,
95
100
  _props$manualHeader = props.manualHeader,
96
101
  manualHeader = _props$manualHeader === void 0 ? '' : _props$manualHeader,
97
102
  _props$manualButtonCl = props.manualButtonClassname,
@@ -183,34 +188,33 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
183
188
  setManualChoiceVisible(true);
184
189
  };
185
190
 
186
- // Build an object of passed consent, send that to google via "update"
187
- // Set the cookie containing the consent categories and version
188
- var handleGoogleConsent = function handleGoogleConsent() {
189
- var selectedConsent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
190
- var selectedCategories = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
191
- var consentEventObject = {};
192
- Object.values(AvailableConsentPermissions).forEach(function (consentOption) {
193
- consentEventObject[consentOption] = selectedConsent.indexOf(consentOption) > -1 ? 'granted' : 'denied';
194
- });
195
- window.gtag('consent', 'update', consentEventObject);
196
- window.gtag('event', CONSENT_UPDATE_EVENT);
197
- Cookies.set(COOKIE_CONSENT_CATEGORIES, JSON.stringify({
198
- categories: selectedCategories,
199
- consent: consentEventObject
200
- }), {
201
- expires: cookieOptions.days,
202
- domain: cookieDomain
203
- });
204
- setDidConsent(JSON.stringify({
205
- status: LocalConsentStatus.STATUS_ACCEPTED,
206
- version: version
207
- }), cookieOptions);
208
- setAnsweredInCurrentSession(true);
209
- };
210
-
211
191
  // On agree clicked, send consent for categories to Google
212
192
  // Update cookie and fire agree callback
213
- var onInternalAgree = function onInternalAgree(choices) {
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
+ };
214
218
  var selectedCategories = Object.keys(choices).filter(function (key) {
215
219
  return choices[key];
216
220
  });
@@ -225,10 +229,10 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
225
229
  selectedCategories: selectedCategories,
226
230
  consent: selectedConsent
227
231
  });
228
- };
232
+ }, [cookieDomain, cookieLevels, cookieOptions, onAgree, setDidConsent, version]);
229
233
 
230
234
  // Function for accepting al categories at once.
231
- var onConsentAll = function onConsentAll() {
235
+ var onConsentAll = useCallback(function () {
232
236
  var allCategoriesSelected = categories.reduce(function (prev, category) {
233
237
  var newPartialState = prev;
234
238
  newPartialState[category] = true;
@@ -236,19 +240,17 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
236
240
  }, {});
237
241
  setChoicesSelected(allCategoriesSelected);
238
242
  onInternalAgree(allCategoriesSelected);
239
- };
243
+ }, [categories, onInternalAgree]);
244
+ var onConsentOnlyNecessary = useCallback(function () {
245
+ setChoicesSelected(defaultValues);
246
+ onInternalAgree(defaultValues);
247
+ }, [defaultValues, onInternalAgree]);
240
248
 
241
249
  // This function is fired when the accept button is pressed.
242
250
  // Also has eventual support for a false case.
243
- var onConsent = function onConsent(onlyNecessary) {
244
- return function () {
245
- if (onlyNecessary === true) {
246
- onInternalAgree(defaultValues);
247
- } else {
248
- onInternalAgree(choicesSelected);
249
- }
250
- };
251
- };
251
+ var onConsent = useCallback(function () {
252
+ onInternalAgree(choicesSelected);
253
+ }, [choicesSelected, onInternalAgree]);
252
254
 
253
255
  // This function sets the value of the checkmark in the form state.
254
256
  var handleChoiceState = function handleChoiceState(event) {
@@ -322,7 +324,7 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
322
324
  id: "only-necessary-agree",
323
325
  className: "Button--cta",
324
326
  inverted: necessaryButtonInverted,
325
- onClick: onConsent(true)
327
+ onClick: onConsentOnlyNecessary
326
328
  }, onlyNecessaryText), /*#__PURE__*/React.createElement("button", {
327
329
  type: "button",
328
330
  className: "GoogleConsentCookieBanner__content__buttons__manual GoogleConsentCookieBanner__content__buttons__manual-agree ".concat(manualButtonClassname),
@@ -340,12 +342,17 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
340
342
  }, /*#__PURE__*/React.createElement(Button, {
341
343
  className: "Button--cta",
342
344
  primary: true,
343
- onClick: onConsent(false)
344
- }, acceptSelectionText), /*#__PURE__*/React.createElement(Button, {
345
+ onClick: onConsent
346
+ }, acceptSelectionText), showAcceptOnlyNeededSelections && /*#__PURE__*/React.createElement(Button, {
347
+ id: "only-necessary-agree-selections",
348
+ className: "Button--cta",
349
+ inverted: necessaryButtonInverted,
350
+ onClick: onConsentOnlyNecessary
351
+ }, onlyNecessaryText), /*#__PURE__*/React.createElement(Button, {
345
352
  className: "Button--cta",
346
353
  inverted: necessaryButtonInverted,
347
354
  onClick: onConsentAll
348
- }, acceptAllText))))));
355
+ }, acceptAllSelectionsText))))));
349
356
  };
350
357
 
351
358
  /**
@@ -51,6 +51,7 @@ export interface CookieCompliancePopupProps {
51
51
  children?: any;
52
52
  acceptAllText?: string;
53
53
  acceptSelectionText?: string;
54
+ acceptAllSelectionsText?: string;
54
55
  onlyNecessaryText?: string;
55
56
  title?: string;
56
57
  cookieContentsShowMore?: string;
@@ -59,6 +60,7 @@ export interface CookieCompliancePopupProps {
59
60
  manualHeader?: string;
60
61
  onAgree?: Function;
61
62
  showAcceptOnlyNeeded?: boolean;
63
+ showAcceptOnlyNeededSelections?: boolean;
62
64
  manualButtonClassname?: string;
63
65
  necessaryButtonInverted?: boolean;
64
66
  cookieLevels?: Array<CookieLevel>;
@@ -15,7 +15,7 @@ export default function useDialogHelpers<T extends HTMLElement>(options: UseDial
15
15
  readonly id: string;
16
16
  readonly labelId: string;
17
17
  readonly dialogHelpersProps: {
18
- 'aria-role': string;
18
+ role: string;
19
19
  'aria-labelledby': string;
20
20
  };
21
21
  };
@@ -73,7 +73,7 @@ export default function useDialogHelpers(options) {
73
73
  */
74
74
  var labelId = "".concat(id, "-label");
75
75
  var dialogHelpersProps = {
76
- 'aria-role': 'dialog',
76
+ role: 'dialog',
77
77
  'aria-labelledby': labelId
78
78
  };
79
79
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uncinc/uncinc-react-kitchen-sink",
3
- "version": "2.16.13",
3
+ "version": "2.16.15",
4
4
  "description": "Default React components that are easily extended.",
5
5
  "author": "uncinc",
6
6
  "license": "MIT",