@uncinc/uncinc-react-kitchen-sink 2.15.2 → 2.16.1
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/dist/components/GoogleConsentCookieBanner/index.js +56 -11
- package/dist/components/GoogleConsentCookieBanner/style.scss +2 -1
- package/dist/components/GoogleConsentCookieBanner/types.d.ts +2 -1
- package/dist/components/GoogleConsentCookieBanner/types.js +1 -0
- package/dist/components/MediaPlayer/types.d.ts +11 -10
- package/dist/hooks/useCookieStore.d.ts +16 -0
- package/dist/hooks/useCookieStore.js +38 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +3 -2
|
@@ -11,7 +11,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
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
13
|
import React, { useEffect, useState } from 'react';
|
|
14
|
-
import useCookie from 'react-use-cookie';
|
|
15
14
|
import Cookies from 'js-cookie';
|
|
16
15
|
import classNames from 'classnames';
|
|
17
16
|
import { useTranslation } from 'react-i18next';
|
|
@@ -22,6 +21,7 @@ import Container from '../Layout/Container';
|
|
|
22
21
|
import Checkbox from './Checkbox';
|
|
23
22
|
import './style.scss';
|
|
24
23
|
import { LocalConsentStatus, AvailableConsentPermissions } from './types';
|
|
24
|
+
import useCookieStore from '../../hooks/useCookieStore';
|
|
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;
|
|
@@ -125,15 +125,21 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
125
125
|
// STATUS DECLINED (0 as cookie value)
|
|
126
126
|
// STATUS NOT YET ANSWERED (1 as cookie value)
|
|
127
127
|
// STATUS ACCEPTED_ALL (2 as cookie value)
|
|
128
|
-
var
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
var _useCookieStore = useCookieStore(COOKIE_CONSENT_STATE, JSON.stringify({
|
|
129
|
+
status: LocalConsentStatus.STATUS_DEFAULT,
|
|
130
|
+
version: version
|
|
131
|
+
})),
|
|
132
|
+
_useCookieStore2 = _slicedToArray(_useCookieStore, 2),
|
|
133
|
+
didConsent = _useCookieStore2[0],
|
|
134
|
+
setDidConsent = _useCookieStore2[1];
|
|
132
135
|
var categories = cookieLevels.map(function (item) {
|
|
133
136
|
return item.value;
|
|
134
137
|
});
|
|
135
138
|
var defaultState = categories.reduce(function (prev, category) {
|
|
136
|
-
|
|
139
|
+
var existingConsent = getPreviouslyAcceptedCookieLevels(defaultValues);
|
|
140
|
+
if (existingConsent) {
|
|
141
|
+
return existingConsent;
|
|
142
|
+
}
|
|
137
143
|
var newPartialState = prev;
|
|
138
144
|
if (defaultValues[category] !== undefined) {
|
|
139
145
|
newPartialState[category] = defaultValues[category];
|
|
@@ -148,20 +154,28 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
148
154
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
149
155
|
choicesSelected = _useState6[0],
|
|
150
156
|
setChoicesSelected = _useState6[1];
|
|
157
|
+
var isLoading = didConsent === undefined;
|
|
158
|
+
var didConsentContent = typeof didConsent === 'string' && didConsent.length > 0 ? JSON.parse(didConsent) : null;
|
|
151
159
|
useEffect(function () {
|
|
152
160
|
// We now know the value of the cookie. If there is no cookie set,
|
|
153
161
|
// immediately set the didConsent state to STATUS_NOT_YET_ANSWERED.
|
|
154
|
-
if (
|
|
162
|
+
if ((didConsentContent === null || didConsentContent === void 0 ? void 0 : didConsentContent.status) === LocalConsentStatus.STATUS_DEFAULT
|
|
163
|
+
// For backwards compatibility
|
|
164
|
+
|| didConsent === LocalConsentStatus.STATUS_DEFAULT) {
|
|
155
165
|
setDidConsent(JSON.stringify({
|
|
156
166
|
status: LocalConsentStatus.STATUS_NOT_YET_ANSWERED,
|
|
157
167
|
version: version
|
|
158
168
|
}), cookieOptions);
|
|
159
169
|
}
|
|
160
|
-
}, [
|
|
161
|
-
var isLoading = didConsent === undefined;
|
|
162
|
-
var didConsentContent = typeof didConsent === 'string' && didConsent.length > 0 ? JSON.parse(didConsent) : null;
|
|
170
|
+
}, [didConsentContent, cookieOptions, setDidConsent, version]);
|
|
163
171
|
var isPrompting = (didConsentContent === null || didConsentContent === void 0 ? void 0 : didConsentContent.status) === LocalConsentStatus.STATUS_NOT_YET_ANSWERED;
|
|
164
172
|
var isAnswered = (didConsentContent === null || didConsentContent === void 0 ? void 0 : didConsentContent.status) === LocalConsentStatus.STATUS_ACCEPTED || (didConsentContent === null || didConsentContent === void 0 ? void 0 : didConsentContent.status) === LocalConsentStatus.STATUS_ONLY_NECESSARY;
|
|
173
|
+
var isEditing = (didConsentContent === null || didConsentContent === void 0 ? void 0 : didConsentContent.status) === LocalConsentStatus.STATUS_EDITING;
|
|
174
|
+
useEffect(function () {
|
|
175
|
+
if (isEditing) {
|
|
176
|
+
setManualChoiceVisible(true);
|
|
177
|
+
}
|
|
178
|
+
}, [didConsent, setManualChoiceVisible, isEditing]);
|
|
165
179
|
|
|
166
180
|
// This function expands the notification to show the options.
|
|
167
181
|
var displayConsentChoices = function displayConsentChoices(e) {
|
|
@@ -220,6 +234,7 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
220
234
|
newPartialState[category] = true;
|
|
221
235
|
return newPartialState;
|
|
222
236
|
}, {});
|
|
237
|
+
setChoicesSelected(allCategoriesSelected);
|
|
223
238
|
onInternalAgree(allCategoriesSelected);
|
|
224
239
|
};
|
|
225
240
|
|
|
@@ -248,7 +263,8 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
248
263
|
'GoogleConsentCookieBanner--answered': isAnswered,
|
|
249
264
|
// answering refers to the fact that the user has answered in the current session.
|
|
250
265
|
'GoogleConsentCookieBanner--answering': answeredInCurrentSession,
|
|
251
|
-
'GoogleConsentCookieBanner--hidden': isAnswered
|
|
266
|
+
'GoogleConsentCookieBanner--hidden': isAnswered,
|
|
267
|
+
'GoogleConsentCookieBanner--editing': isEditing
|
|
252
268
|
});
|
|
253
269
|
|
|
254
270
|
// if it is answered in the current session
|
|
@@ -340,4 +356,33 @@ var CookieCompliancePopup = function CookieCompliancePopup(props) {
|
|
|
340
356
|
onClick: onConsentAll
|
|
341
357
|
}, acceptAllText))))));
|
|
342
358
|
};
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Get the previously accepted cookie levels from the cookie if the user has previously
|
|
362
|
+
* given consent to the use of cookies.
|
|
363
|
+
*
|
|
364
|
+
* @param defaultValues The default values for the cookie categories. Keys that are
|
|
365
|
+
* retrieved from the cookie that are not present in defaultValues will be omitted.
|
|
366
|
+
*/
|
|
367
|
+
function getPreviouslyAcceptedCookieLevels(defaultValues) {
|
|
368
|
+
var cookies = Cookies.get(COOKIE_CONSENT_CATEGORIES);
|
|
369
|
+
if (!cookies) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
var parsedCookies = JSON.parse(cookies);
|
|
374
|
+
if (!('categories' in parsedCookies)) {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
var result = _objectSpread({}, defaultValues);
|
|
378
|
+
parsedCookies.categories.forEach(function (category) {
|
|
379
|
+
if (defaultValues[category] !== undefined) {
|
|
380
|
+
result[category] = true;
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
return result;
|
|
384
|
+
} catch (error) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
343
388
|
export default CookieCompliancePopup;
|
|
@@ -2,7 +2,8 @@ export declare enum LocalConsentStatus {
|
|
|
2
2
|
STATUS_DEFAULT = "-1",
|
|
3
3
|
STATUS_ONLY_NECESSARY = "0",
|
|
4
4
|
STATUS_NOT_YET_ANSWERED = "1",
|
|
5
|
-
STATUS_ACCEPTED = "2"
|
|
5
|
+
STATUS_ACCEPTED = "2",
|
|
6
|
+
STATUS_EDITING = "3"
|
|
6
7
|
}
|
|
7
8
|
export declare enum AvailableConsentPermissions {
|
|
8
9
|
SECURITY_STORAGE = "security_storage",
|
|
@@ -3,6 +3,7 @@ export var LocalConsentStatus = /*#__PURE__*/function (LocalConsentStatus) {
|
|
|
3
3
|
LocalConsentStatus["STATUS_ONLY_NECESSARY"] = "0";
|
|
4
4
|
LocalConsentStatus["STATUS_NOT_YET_ANSWERED"] = "1";
|
|
5
5
|
LocalConsentStatus["STATUS_ACCEPTED"] = "2";
|
|
6
|
+
LocalConsentStatus["STATUS_EDITING"] = "3";
|
|
6
7
|
return LocalConsentStatus;
|
|
7
8
|
}({});
|
|
8
9
|
export var AvailableConsentPermissions = /*#__PURE__*/function (AvailableConsentPermissions) {
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { VideoJsPlayer as NativeVideoJsPlayer, VideoJsPlayerOptions } from 'video.js';
|
|
2
2
|
export type MimeType = 'audio/3gpp' | 'audio/aac' | 'audio/flac' | 'audio/mpeg' | 'audio/mp3' | 'audio/mp4' | 'audio/ogg' | 'audio/wav' | 'audio/webm' | 'video/3gpp' | 'video/mpeg' | 'video/mpeg' | 'video/mp4' | 'video/ogg' | 'video/quicktime' | 'video/webm' | 'video/youtube' | 'video/vimeo';
|
|
3
3
|
export type Control = 'play' | 'currentTime' | 'timeDivider' | 'duration' | 'seekbar' | 'captions' | 'volume' | 'fullscreen';
|
|
4
4
|
export type VideoJSControls = {
|
|
5
5
|
[K in Control]: string;
|
|
6
6
|
};
|
|
7
|
+
export type VideoJsPlayer = NativeVideoJsPlayer;
|
|
7
8
|
export type MediaPlayerProps = {
|
|
8
9
|
src: string;
|
|
9
10
|
type: MimeType;
|
|
10
11
|
controls?: Control[] | false;
|
|
11
12
|
posterUrl?: string;
|
|
12
|
-
options?:
|
|
13
|
-
captions?:
|
|
13
|
+
options?: VideoJsPlayerOptions;
|
|
14
|
+
captions?: VideoJsPlayerOptions['tracks'];
|
|
14
15
|
audioOnly?: boolean;
|
|
15
16
|
notSupportedMessage?: string;
|
|
16
17
|
className?: string;
|
|
17
|
-
onPlay?: (player:
|
|
18
|
-
onPause?: (player:
|
|
19
|
-
onEnded?: (player:
|
|
20
|
-
onSeeking?: (player:
|
|
21
|
-
onVolumeChange?: (player:
|
|
22
|
-
onFullscreenChange?: (player:
|
|
23
|
-
onError?: (player:
|
|
18
|
+
onPlay?: (player: NativeVideoJsPlayer, event: EventTarget) => void;
|
|
19
|
+
onPause?: (player: NativeVideoJsPlayer, event: EventTarget) => void;
|
|
20
|
+
onEnded?: (player: NativeVideoJsPlayer, event: EventTarget) => void;
|
|
21
|
+
onSeeking?: (player: NativeVideoJsPlayer, event: EventTarget) => void;
|
|
22
|
+
onVolumeChange?: (player: NativeVideoJsPlayer, event: EventTarget) => void;
|
|
23
|
+
onFullscreenChange?: (player: NativeVideoJsPlayer, event: EventTarget) => void;
|
|
24
|
+
onError?: (player: NativeVideoJsPlayer, event: EventTarget) => void;
|
|
24
25
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react-use-cookie" />
|
|
2
|
+
interface UseCookieStoreOptions {
|
|
3
|
+
polling?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A wrapper around 'react-use-cookie', but optionally uses a polling mechanism to
|
|
7
|
+
* keep the cookie (as read from the browser) in sync with the state.
|
|
8
|
+
*
|
|
9
|
+
* This is necessary when the same cookie key is used in multiple places -- react-use-cookie
|
|
10
|
+
* makes use of an in-memory React state to store the cookie value, which is not
|
|
11
|
+
* synchronized with the actual cookie value in the browser.
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/tylerwolff/useCookie/blob/master/index.js#L60
|
|
14
|
+
*/
|
|
15
|
+
export default function useCookieStore(key: string, initialValue?: string, options?: UseCookieStoreOptions): readonly [string, import("react-use-cookie").updateItem, import("react-use-cookie").removeItem];
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
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; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import useCookie, { getCookie } from 'react-use-cookie';
|
|
8
|
+
import { useEffect } from 'react';
|
|
9
|
+
var POLLING_INTERVAL = 500;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A wrapper around 'react-use-cookie', but optionally uses a polling mechanism to
|
|
13
|
+
* keep the cookie (as read from the browser) in sync with the state.
|
|
14
|
+
*
|
|
15
|
+
* This is necessary when the same cookie key is used in multiple places -- react-use-cookie
|
|
16
|
+
* makes use of an in-memory React state to store the cookie value, which is not
|
|
17
|
+
* synchronized with the actual cookie value in the browser.
|
|
18
|
+
*
|
|
19
|
+
* @see https://github.com/tylerwolff/useCookie/blob/master/index.js#L60
|
|
20
|
+
*/
|
|
21
|
+
export default function useCookieStore(key, initialValue) {
|
|
22
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
23
|
+
polling: true
|
|
24
|
+
};
|
|
25
|
+
var _useCookie = useCookie(key, initialValue),
|
|
26
|
+
_useCookie2 = _slicedToArray(_useCookie, 3),
|
|
27
|
+
item = _useCookie2[0],
|
|
28
|
+
setItem = _useCookie2[1],
|
|
29
|
+
removeItem = _useCookie2[2];
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
if (options.polling) {
|
|
32
|
+
setInterval(function () {
|
|
33
|
+
setItem(getCookie(key, item));
|
|
34
|
+
}, POLLING_INTERVAL);
|
|
35
|
+
}
|
|
36
|
+
}, [key, setItem, item, options.polling]);
|
|
37
|
+
return [item, setItem, removeItem];
|
|
38
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,7 @@ export { default as useOnScreen } from "./hooks/useOnScreen";
|
|
|
77
77
|
export { default as usePrevious } from "./hooks/usePrevious";
|
|
78
78
|
export { default as useScrollPosition } from "./hooks/useScrollPosition";
|
|
79
79
|
export { default as useWindowDimensions } from "./hooks/useWindowDimensions";
|
|
80
|
+
export { default as useCookieStore } from "./hooks/useCookieStore";
|
|
80
81
|
export { default as gtm } from "./helpers/gtm";
|
|
81
82
|
export { default as useValueForCurrentViewPort } from "./helpers/useValueForCurrentViewPort";
|
|
82
83
|
export { default as getApiAutoCompleteSuggestions } from "./helpers/apiAutoComplete";
|
package/dist/index.js
CHANGED
|
@@ -90,6 +90,7 @@ export { default as useOnScreen } from './hooks/useOnScreen';
|
|
|
90
90
|
export { default as usePrevious } from './hooks/usePrevious';
|
|
91
91
|
export { default as useScrollPosition } from './hooks/useScrollPosition';
|
|
92
92
|
export { default as useWindowDimensions } from './hooks/useWindowDimensions';
|
|
93
|
+
export { default as useCookieStore } from './hooks/useCookieStore';
|
|
93
94
|
|
|
94
95
|
// Helpers
|
|
95
96
|
export { default as gtm } from './helpers/gtm';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uncinc/uncinc-react-kitchen-sink",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.1",
|
|
4
4
|
"description": "Default React components that are easily extended.",
|
|
5
5
|
"author": "uncinc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"react-select": "^3.1.0",
|
|
90
90
|
"react-share": "^4.3.1",
|
|
91
91
|
"react-slick": "^0.27.14",
|
|
92
|
-
"react-use-cookie": "^1.
|
|
92
|
+
"react-use-cookie": "^1.6.1",
|
|
93
93
|
"redux": "^4.0.5",
|
|
94
94
|
"sass": "^1.55.0",
|
|
95
95
|
"sass-loader": "^8.0.2",
|
|
@@ -124,6 +124,7 @@
|
|
|
124
124
|
"@storybook/theming": "^7.0.18",
|
|
125
125
|
"@testing-library/jest-dom": "^5.11.2",
|
|
126
126
|
"@testing-library/react": "^14.0.0",
|
|
127
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
127
128
|
"@testing-library/user-event": "^7.1.2",
|
|
128
129
|
"@types/jest": "^29.5.1",
|
|
129
130
|
"@types/js-cookie": "^3.0.6",
|