@balena/ui-shared-components 0.6.0 → 0.7.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.
- package/dist/components/CookiesBanner/CoockiesBanner.stories.js +13 -0
- package/dist/components/CookiesBanner/index.d.ts +4 -1
- package/dist/components/CookiesBanner/index.js +36 -22
- package/dist/contexts/AnalyticsContext.js +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +0 -1
- package/dist_esm5/components/CookiesBanner/CoockiesBanner.stories.js +13 -0
- package/dist_esm5/components/CookiesBanner/index.d.ts +4 -1
- package/dist_esm5/components/CookiesBanner/index.js +36 -22
- package/dist_esm5/contexts/AnalyticsContext.js +1 -1
- package/dist_esm5/index.d.ts +1 -2
- package/dist_esm5/index.js +0 -1
- package/package.json +2 -2
- package/dist/contexts/CookiesContext.d.ts +0 -26
- package/dist/contexts/CookiesContext.js +0 -42
- package/dist_esm5/contexts/CookiesContext.d.ts +0 -26
- package/dist_esm5/contexts/CookiesContext.js +0 -32
|
@@ -46,5 +46,18 @@ export var Default = {
|
|
|
46
46
|
args: {
|
|
47
47
|
show: false,
|
|
48
48
|
productName: 'ui-shared-components',
|
|
49
|
+
cookies: {
|
|
50
|
+
marketing: {
|
|
51
|
+
title: 'Marketing',
|
|
52
|
+
description: 'We use cookies to get marketing info from the traffic in our platform',
|
|
53
|
+
value: false,
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
analytics: {
|
|
57
|
+
title: 'Analytics',
|
|
58
|
+
description: 'We use cookies to get analytics from the traffic in our platform',
|
|
59
|
+
value: false,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
49
62
|
},
|
|
50
63
|
};
|
|
@@ -9,9 +9,12 @@ export interface Cookie {
|
|
|
9
9
|
}
|
|
10
10
|
export interface CookiesBannerProps {
|
|
11
11
|
show: boolean;
|
|
12
|
+
cookies: Dictionary<Cookie>;
|
|
12
13
|
productName: string;
|
|
14
|
+
removeCookies?: string[];
|
|
15
|
+
onInit?: (cookies?: Dictionary<Cookie>) => void;
|
|
13
16
|
onChange?: (cookies: Dictionary<Cookie>) => void;
|
|
14
17
|
onClose?: (cookies: Dictionary<Cookie>) => void;
|
|
15
18
|
}
|
|
16
|
-
export declare const CookiesBanner: ({ show, productName, onChange, onClose, }: CookiesBannerProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
19
|
+
export declare const CookiesBanner: ({ show, cookies, productName, removeCookies, onInit, onChange, onClose, }: CookiesBannerProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
17
20
|
export {};
|
|
@@ -11,25 +11,36 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { Box, Button, Drawer, Link, Switch, Typography } from '@mui/material';
|
|
14
|
-
import { useCallback, useState } from 'react';
|
|
14
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
15
15
|
import { getFromLocalStorage, setToLocalStorage } from '../../utils/storage';
|
|
16
|
-
|
|
16
|
+
var deleteMatchingCookies = function (stringsToDelete) {
|
|
17
|
+
var cookies = document.cookie.split(';');
|
|
18
|
+
for (var _i = 0, cookies_1 = cookies; _i < cookies_1.length; _i++) {
|
|
19
|
+
var cookie = cookies_1[_i];
|
|
20
|
+
var trimmedCookie = cookie.trim();
|
|
21
|
+
var eqPos = trimmedCookie.indexOf('=');
|
|
22
|
+
var name_1 = eqPos > -1 ? trimmedCookie.substr(0, eqPos) : trimmedCookie;
|
|
23
|
+
for (var _a = 0, stringsToDelete_1 = stringsToDelete; _a < stringsToDelete_1.length; _a++) {
|
|
24
|
+
var str = stringsToDelete_1[_a];
|
|
25
|
+
if (name_1.includes(str)) {
|
|
26
|
+
document.cookie =
|
|
27
|
+
name_1 + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
17
33
|
export var CookiesBanner = function (_a) {
|
|
18
|
-
var show = _a.show, productName = _a.productName, onChange = _a.onChange, onClose = _a.onClose;
|
|
19
|
-
var _b =
|
|
20
|
-
var _c = useState(
|
|
21
|
-
var _d = useState(Object.fromEntries(Object.entries(cookies).map(function (_a) {
|
|
22
|
-
var key = _a[0], cookie = _a[1];
|
|
23
|
-
return [key, cookie.value];
|
|
24
|
-
}))), cookieValues = _d[0], setCookieValues = _d[1];
|
|
34
|
+
var show = _a.show, cookies = _a.cookies, productName = _a.productName, removeCookies = _a.removeCookies, onInit = _a.onInit, onChange = _a.onChange, onClose = _a.onClose;
|
|
35
|
+
var _b = useState(false), showCustomizeView = _b[0], setShowCustomizeView = _b[1];
|
|
36
|
+
var _c = useState(cookies), internalCookies = _c[0], setInternalCookies = _c[1];
|
|
25
37
|
var localStorageKey = productName + '-cookies-set';
|
|
26
38
|
var handleOnChange = useCallback(function (key) {
|
|
27
39
|
var newCookies = __assign({}, cookies);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
newCookies[key].value = !oldState[key];
|
|
40
|
+
setInternalCookies(function (oldState) {
|
|
41
|
+
newCookies[key].value = !oldState[key].value;
|
|
31
42
|
onChange === null || onChange === void 0 ? void 0 : onChange(newCookies);
|
|
32
|
-
return __assign(__assign({}, oldState),
|
|
43
|
+
return __assign(__assign({}, oldState), newCookies);
|
|
33
44
|
});
|
|
34
45
|
}, [cookies, onChange]);
|
|
35
46
|
var handleSaveOrAcceptAll = useCallback(function () {
|
|
@@ -38,11 +49,11 @@ export var CookiesBanner = function (_a) {
|
|
|
38
49
|
var cookieKey = _a[_i];
|
|
39
50
|
newCookies[cookieKey].value = !showCustomizeView
|
|
40
51
|
? true
|
|
41
|
-
:
|
|
52
|
+
: internalCookies[cookieKey].value;
|
|
42
53
|
}
|
|
43
54
|
setToLocalStorage(localStorageKey, newCookies);
|
|
44
55
|
onClose === null || onClose === void 0 ? void 0 : onClose(newCookies);
|
|
45
|
-
}, [localStorageKey, showCustomizeView,
|
|
56
|
+
}, [localStorageKey, showCustomizeView, internalCookies, cookies, onClose]);
|
|
46
57
|
var handleReject = useCallback(function () {
|
|
47
58
|
var newCookies = __assign({}, cookies);
|
|
48
59
|
for (var _i = 0, _a = Object.keys(cookies); _i < _a.length; _i++) {
|
|
@@ -50,18 +61,21 @@ export var CookiesBanner = function (_a) {
|
|
|
50
61
|
newCookies[cookieKey].value = false;
|
|
51
62
|
}
|
|
52
63
|
setToLocalStorage(localStorageKey, newCookies);
|
|
53
|
-
|
|
54
|
-
type: CookiesStoreActions.setCookies,
|
|
55
|
-
payload: newCookies,
|
|
56
|
-
});
|
|
64
|
+
setInternalCookies(newCookies);
|
|
57
65
|
onClose === null || onClose === void 0 ? void 0 : onClose(newCookies);
|
|
58
|
-
}, [cookies, localStorageKey,
|
|
66
|
+
}, [cookies, localStorageKey, onClose]);
|
|
59
67
|
var localStorageCookies = getFromLocalStorage(localStorageKey);
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
onInit === null || onInit === void 0 ? void 0 : onInit(localStorageCookies);
|
|
70
|
+
}, [localStorageCookies, onInit]);
|
|
60
71
|
if (!show || !!localStorageCookies) {
|
|
61
72
|
return null;
|
|
62
73
|
}
|
|
63
|
-
|
|
74
|
+
if ((removeCookies === null || removeCookies === void 0 ? void 0 : removeCookies.length) && document.cookie) {
|
|
75
|
+
deleteMatchingCookies(removeCookies);
|
|
76
|
+
}
|
|
77
|
+
return (_jsx(Drawer, __assign({ anchor: "bottom", open: show, disableEscapeKeyDown: true }, { children: _jsxs(Box, __assign({ display: "flex", flexDirection: "column", p: 4 }, { children: [showCustomizeView ? (_jsx(Box, __assign({ display: "flex", flexDirection: "column" }, { children: Object.entries(internalCookies).map(function (_a) {
|
|
64
78
|
var key = _a[0], cookie = _a[1];
|
|
65
|
-
return (_jsxs(Box, __assign({ display: "flex", alignItems: "center", mb: 3 }, { children: [_jsxs(Box, __assign({ display: "flex", flexDirection: "column", width: "90%" }, { children: [_jsx(Typography, __assign({ variant: "h5" }, { children: cookie.title })), _jsx(Typography, __assign({ variant: "body1" }, { children: cookie.description }))] })), _jsx(Box, __assign({ display: "flex" }, { children: _jsx(Switch, { checked:
|
|
79
|
+
return (_jsxs(Box, __assign({ display: "flex", alignItems: "center", mb: 3 }, { children: [_jsxs(Box, __assign({ display: "flex", flexDirection: "column", width: "90%" }, { children: [_jsx(Typography, __assign({ variant: "h5" }, { children: cookie.title })), _jsx(Typography, __assign({ variant: "body1" }, { children: cookie.description }))] })), _jsx(Box, __assign({ display: "flex" }, { children: _jsx(Switch, { checked: cookie.value, onChange: function () { return handleOnChange(key); }, disabled: cookie.required }) }))] }), key));
|
|
66
80
|
}) }))) : (_jsx(Box, __assign({ display: "flex", justifyContent: "center" }, { children: _jsxs(Typography, __assign({ variant: "body1" }, { children: ["We use cookies to enhance your browsing experience and analyze our traffic. By clicking \"Accept All\" you consent to our use of cookies. Read more about our", ' ', _jsx(Link, __assign({ href: "https://www.balena.io/privacy-policy", target: "_blank" }, { children: "privacy policy" })), "."] })) }))), _jsxs(Box, __assign({ display: "flex", mt: 4, ml: "auto", justifyContent: "space-around", width: "400px" }, { children: [_jsx(Button, __assign({ variant: "outlined", onClick: handleReject }, { children: "Reject all" })), _jsx(Button, __assign({ variant: "outlined", onClick: function () { return setShowCustomizeView(!showCustomizeView); } }, { children: showCustomizeView ? 'Back' : 'Customize' })), _jsx(Button, __assign({ variant: "contained", onClick: handleSaveOrAcceptAll }, { children: showCustomizeView ? 'Save selection' : 'Accept all' }))] }))] })) })));
|
|
67
81
|
};
|
|
@@ -28,7 +28,7 @@ var contextReducer = function (state, _a) {
|
|
|
28
28
|
var type = _a.type, payload = _a.payload;
|
|
29
29
|
switch (type) {
|
|
30
30
|
case AnalyticsStoreActions.setAnalyticsData: {
|
|
31
|
-
if (!payload) {
|
|
31
|
+
if (!payload || state.analyticsClient) {
|
|
32
32
|
return state;
|
|
33
33
|
}
|
|
34
34
|
var urlParamsHandler_1 = new AnalyticsUrlParams();
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { AnimatedText } from './components/AnimatedText';
|
|
|
4
4
|
export type { ButtonWithTrackingProps } from './components/ButtonWithTracking';
|
|
5
5
|
export { ButtonWithTracking } from './components/ButtonWithTracking';
|
|
6
6
|
export { Code } from './components/Code';
|
|
7
|
-
export type { CookiesBannerProps } from './components/CookiesBanner';
|
|
7
|
+
export type { CookiesBannerProps, Cookie } from './components/CookiesBanner';
|
|
8
8
|
export { CookiesBanner } from './components/CookiesBanner';
|
|
9
9
|
export type { CollapsedListProps } from './components/CollapsedList';
|
|
10
10
|
export { CollapsedList } from './components/CollapsedList';
|
|
@@ -22,6 +22,5 @@ export { Map } from './components/Map';
|
|
|
22
22
|
export { Markdown } from './components/Markdown';
|
|
23
23
|
export { Truncate } from './components/Truncate';
|
|
24
24
|
export { AnalyticsContextProvider, useAnalyticsContext, AnalyticsStoreActions, } from './contexts/AnalyticsContext';
|
|
25
|
-
export { CookiesContextProvider, useCookiesContext, CookiesStoreActions, } from './contexts/CookiesContext';
|
|
26
25
|
export * as Material from '@mui/material';
|
|
27
26
|
export * as IconsMaterial from '@mui/icons-material';
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,5 @@ export { Map } from './components/Map';
|
|
|
13
13
|
export { Markdown } from './components/Markdown';
|
|
14
14
|
export { Truncate } from './components/Truncate';
|
|
15
15
|
export { AnalyticsContextProvider, useAnalyticsContext, AnalyticsStoreActions, } from './contexts/AnalyticsContext';
|
|
16
|
-
export { CookiesContextProvider, useCookiesContext, CookiesStoreActions, } from './contexts/CookiesContext';
|
|
17
16
|
export * as Material from '@mui/material';
|
|
18
17
|
export * as IconsMaterial from '@mui/icons-material';
|
|
@@ -25,5 +25,18 @@ export var Default = {
|
|
|
25
25
|
args: {
|
|
26
26
|
show: false,
|
|
27
27
|
productName: 'ui-shared-components',
|
|
28
|
+
cookies: {
|
|
29
|
+
marketing: {
|
|
30
|
+
title: 'Marketing',
|
|
31
|
+
description: 'We use cookies to get marketing info from the traffic in our platform',
|
|
32
|
+
value: false,
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
analytics: {
|
|
36
|
+
title: 'Analytics',
|
|
37
|
+
description: 'We use cookies to get analytics from the traffic in our platform',
|
|
38
|
+
value: false,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
28
41
|
},
|
|
29
42
|
};
|
|
@@ -9,9 +9,12 @@ export interface Cookie {
|
|
|
9
9
|
}
|
|
10
10
|
export interface CookiesBannerProps {
|
|
11
11
|
show: boolean;
|
|
12
|
+
cookies: Dictionary<Cookie>;
|
|
12
13
|
productName: string;
|
|
14
|
+
removeCookies?: string[];
|
|
15
|
+
onInit?: (cookies?: Dictionary<Cookie>) => void;
|
|
13
16
|
onChange?: (cookies: Dictionary<Cookie>) => void;
|
|
14
17
|
onClose?: (cookies: Dictionary<Cookie>) => void;
|
|
15
18
|
}
|
|
16
|
-
export declare const CookiesBanner: ({ show, productName, onChange, onClose, }: CookiesBannerProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
19
|
+
export declare const CookiesBanner: ({ show, cookies, productName, removeCookies, onInit, onChange, onClose, }: CookiesBannerProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
17
20
|
export {};
|
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Box, Button, Drawer, Link, Switch, Typography } from '@mui/material';
|
|
4
|
-
import { useCallback, useState } from 'react';
|
|
4
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
5
5
|
import { getFromLocalStorage, setToLocalStorage } from '../../utils/storage';
|
|
6
|
-
|
|
6
|
+
var deleteMatchingCookies = function (stringsToDelete) {
|
|
7
|
+
var cookies = document.cookie.split(';');
|
|
8
|
+
for (var _i = 0, cookies_1 = cookies; _i < cookies_1.length; _i++) {
|
|
9
|
+
var cookie = cookies_1[_i];
|
|
10
|
+
var trimmedCookie = cookie.trim();
|
|
11
|
+
var eqPos = trimmedCookie.indexOf('=');
|
|
12
|
+
var name_1 = eqPos > -1 ? trimmedCookie.substr(0, eqPos) : trimmedCookie;
|
|
13
|
+
for (var _a = 0, stringsToDelete_1 = stringsToDelete; _a < stringsToDelete_1.length; _a++) {
|
|
14
|
+
var str = stringsToDelete_1[_a];
|
|
15
|
+
if (name_1.includes(str)) {
|
|
16
|
+
document.cookie =
|
|
17
|
+
name_1 + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
7
23
|
export var CookiesBanner = function (_a) {
|
|
8
|
-
var show = _a.show, productName = _a.productName, onChange = _a.onChange, onClose = _a.onClose;
|
|
9
|
-
var _b =
|
|
10
|
-
var _c = useState(
|
|
11
|
-
var _d = useState(Object.fromEntries(Object.entries(cookies).map(function (_a) {
|
|
12
|
-
var key = _a[0], cookie = _a[1];
|
|
13
|
-
return [key, cookie.value];
|
|
14
|
-
}))), cookieValues = _d[0], setCookieValues = _d[1];
|
|
24
|
+
var show = _a.show, cookies = _a.cookies, productName = _a.productName, removeCookies = _a.removeCookies, onInit = _a.onInit, onChange = _a.onChange, onClose = _a.onClose;
|
|
25
|
+
var _b = useState(false), showCustomizeView = _b[0], setShowCustomizeView = _b[1];
|
|
26
|
+
var _c = useState(cookies), internalCookies = _c[0], setInternalCookies = _c[1];
|
|
15
27
|
var localStorageKey = productName + '-cookies-set';
|
|
16
28
|
var handleOnChange = useCallback(function (key) {
|
|
17
29
|
var newCookies = __assign({}, cookies);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
newCookies[key].value = !oldState[key];
|
|
30
|
+
setInternalCookies(function (oldState) {
|
|
31
|
+
newCookies[key].value = !oldState[key].value;
|
|
21
32
|
onChange === null || onChange === void 0 ? void 0 : onChange(newCookies);
|
|
22
|
-
return __assign(__assign({}, oldState),
|
|
33
|
+
return __assign(__assign({}, oldState), newCookies);
|
|
23
34
|
});
|
|
24
35
|
}, [cookies, onChange]);
|
|
25
36
|
var handleSaveOrAcceptAll = useCallback(function () {
|
|
@@ -28,11 +39,11 @@ export var CookiesBanner = function (_a) {
|
|
|
28
39
|
var cookieKey = _a[_i];
|
|
29
40
|
newCookies[cookieKey].value = !showCustomizeView
|
|
30
41
|
? true
|
|
31
|
-
:
|
|
42
|
+
: internalCookies[cookieKey].value;
|
|
32
43
|
}
|
|
33
44
|
setToLocalStorage(localStorageKey, newCookies);
|
|
34
45
|
onClose === null || onClose === void 0 ? void 0 : onClose(newCookies);
|
|
35
|
-
}, [localStorageKey, showCustomizeView,
|
|
46
|
+
}, [localStorageKey, showCustomizeView, internalCookies, cookies, onClose]);
|
|
36
47
|
var handleReject = useCallback(function () {
|
|
37
48
|
var newCookies = __assign({}, cookies);
|
|
38
49
|
for (var _i = 0, _a = Object.keys(cookies); _i < _a.length; _i++) {
|
|
@@ -40,18 +51,21 @@ export var CookiesBanner = function (_a) {
|
|
|
40
51
|
newCookies[cookieKey].value = false;
|
|
41
52
|
}
|
|
42
53
|
setToLocalStorage(localStorageKey, newCookies);
|
|
43
|
-
|
|
44
|
-
type: CookiesStoreActions.setCookies,
|
|
45
|
-
payload: newCookies,
|
|
46
|
-
});
|
|
54
|
+
setInternalCookies(newCookies);
|
|
47
55
|
onClose === null || onClose === void 0 ? void 0 : onClose(newCookies);
|
|
48
|
-
}, [cookies, localStorageKey,
|
|
56
|
+
}, [cookies, localStorageKey, onClose]);
|
|
49
57
|
var localStorageCookies = getFromLocalStorage(localStorageKey);
|
|
58
|
+
useEffect(function () {
|
|
59
|
+
onInit === null || onInit === void 0 ? void 0 : onInit(localStorageCookies);
|
|
60
|
+
}, [localStorageCookies, onInit]);
|
|
50
61
|
if (!show || !!localStorageCookies) {
|
|
51
62
|
return null;
|
|
52
63
|
}
|
|
53
|
-
|
|
64
|
+
if ((removeCookies === null || removeCookies === void 0 ? void 0 : removeCookies.length) && document.cookie) {
|
|
65
|
+
deleteMatchingCookies(removeCookies);
|
|
66
|
+
}
|
|
67
|
+
return (_jsx(Drawer, __assign({ anchor: "bottom", open: show, disableEscapeKeyDown: true }, { children: _jsxs(Box, __assign({ display: "flex", flexDirection: "column", p: 4 }, { children: [showCustomizeView ? (_jsx(Box, __assign({ display: "flex", flexDirection: "column" }, { children: Object.entries(internalCookies).map(function (_a) {
|
|
54
68
|
var key = _a[0], cookie = _a[1];
|
|
55
|
-
return (_jsxs(Box, __assign({ display: "flex", alignItems: "center", mb: 3 }, { children: [_jsxs(Box, __assign({ display: "flex", flexDirection: "column", width: "90%" }, { children: [_jsx(Typography, __assign({ variant: "h5" }, { children: cookie.title })), _jsx(Typography, __assign({ variant: "body1" }, { children: cookie.description }))] })), _jsx(Box, __assign({ display: "flex" }, { children: _jsx(Switch, { checked:
|
|
69
|
+
return (_jsxs(Box, __assign({ display: "flex", alignItems: "center", mb: 3 }, { children: [_jsxs(Box, __assign({ display: "flex", flexDirection: "column", width: "90%" }, { children: [_jsx(Typography, __assign({ variant: "h5" }, { children: cookie.title })), _jsx(Typography, __assign({ variant: "body1" }, { children: cookie.description }))] })), _jsx(Box, __assign({ display: "flex" }, { children: _jsx(Switch, { checked: cookie.value, onChange: function () { return handleOnChange(key); }, disabled: cookie.required }) }))] }), key));
|
|
56
70
|
}) }))) : (_jsx(Box, __assign({ display: "flex", justifyContent: "center" }, { children: _jsxs(Typography, __assign({ variant: "body1" }, { children: ["We use cookies to enhance your browsing experience and analyze our traffic. By clicking \"Accept All\" you consent to our use of cookies. Read more about our", ' ', _jsx(Link, __assign({ href: "https://www.balena.io/privacy-policy", target: "_blank" }, { children: "privacy policy" })), "."] })) }))), _jsxs(Box, __assign({ display: "flex", mt: 4, ml: "auto", justifyContent: "space-around", width: "400px" }, { children: [_jsx(Button, __assign({ variant: "outlined", onClick: handleReject }, { children: "Reject all" })), _jsx(Button, __assign({ variant: "outlined", onClick: function () { return setShowCustomizeView(!showCustomizeView); } }, { children: showCustomizeView ? 'Back' : 'Customize' })), _jsx(Button, __assign({ variant: "contained", onClick: handleSaveOrAcceptAll }, { children: showCustomizeView ? 'Save selection' : 'Accept all' }))] }))] })) })));
|
|
57
71
|
};
|
|
@@ -18,7 +18,7 @@ var contextReducer = function (state, _a) {
|
|
|
18
18
|
var type = _a.type, payload = _a.payload;
|
|
19
19
|
switch (type) {
|
|
20
20
|
case AnalyticsStoreActions.setAnalyticsData: {
|
|
21
|
-
if (!payload) {
|
|
21
|
+
if (!payload || state.analyticsClient) {
|
|
22
22
|
return state;
|
|
23
23
|
}
|
|
24
24
|
var urlParamsHandler_1 = new AnalyticsUrlParams();
|
package/dist_esm5/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { AnimatedText } from './components/AnimatedText';
|
|
|
4
4
|
export type { ButtonWithTrackingProps } from './components/ButtonWithTracking';
|
|
5
5
|
export { ButtonWithTracking } from './components/ButtonWithTracking';
|
|
6
6
|
export { Code } from './components/Code';
|
|
7
|
-
export type { CookiesBannerProps } from './components/CookiesBanner';
|
|
7
|
+
export type { CookiesBannerProps, Cookie } from './components/CookiesBanner';
|
|
8
8
|
export { CookiesBanner } from './components/CookiesBanner';
|
|
9
9
|
export type { CollapsedListProps } from './components/CollapsedList';
|
|
10
10
|
export { CollapsedList } from './components/CollapsedList';
|
|
@@ -22,6 +22,5 @@ export { Map } from './components/Map';
|
|
|
22
22
|
export { Markdown } from './components/Markdown';
|
|
23
23
|
export { Truncate } from './components/Truncate';
|
|
24
24
|
export { AnalyticsContextProvider, useAnalyticsContext, AnalyticsStoreActions, } from './contexts/AnalyticsContext';
|
|
25
|
-
export { CookiesContextProvider, useCookiesContext, CookiesStoreActions, } from './contexts/CookiesContext';
|
|
26
25
|
export * as Material from '@mui/material';
|
|
27
26
|
export * as IconsMaterial from '@mui/icons-material';
|
package/dist_esm5/index.js
CHANGED
|
@@ -13,7 +13,6 @@ export { Map } from './components/Map';
|
|
|
13
13
|
export { Markdown } from './components/Markdown';
|
|
14
14
|
export { Truncate } from './components/Truncate';
|
|
15
15
|
export { AnalyticsContextProvider, useAnalyticsContext, AnalyticsStoreActions, } from './contexts/AnalyticsContext';
|
|
16
|
-
export { CookiesContextProvider, useCookiesContext, CookiesStoreActions, } from './contexts/CookiesContext';
|
|
17
16
|
import * as Material_1 from '@mui/material';
|
|
18
17
|
export { Material_1 as Material };
|
|
19
18
|
import * as IconsMaterial_1 from '@mui/icons-material';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/ui-shared-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist_esm5/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -100,6 +100,6 @@
|
|
|
100
100
|
},
|
|
101
101
|
"homepage": "https://github.com/balena-io/ui-shared-components#readme",
|
|
102
102
|
"versionist": {
|
|
103
|
-
"publishedAt": "2023-09-
|
|
103
|
+
"publishedAt": "2023-09-13T15:26:55.566Z"
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
type CookieObject = {
|
|
3
|
-
title: string;
|
|
4
|
-
description: string;
|
|
5
|
-
value: boolean;
|
|
6
|
-
required?: boolean;
|
|
7
|
-
};
|
|
8
|
-
type StoredCookies = {
|
|
9
|
-
[key: string]: CookieObject;
|
|
10
|
-
};
|
|
11
|
-
export declare enum CookiesStoreActions {
|
|
12
|
-
setCookies = "set_cookies"
|
|
13
|
-
}
|
|
14
|
-
type Action = {
|
|
15
|
-
type: CookiesStoreActions.setCookies;
|
|
16
|
-
payload: StoredCookies | undefined;
|
|
17
|
-
};
|
|
18
|
-
type Dispatch = (action: Action) => void;
|
|
19
|
-
export declare const CookiesContextProvider: ({ children, cookies, }: React.PropsWithChildren<{
|
|
20
|
-
cookies: StoredCookies;
|
|
21
|
-
}>) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
-
export declare const useCookiesContext: () => {
|
|
23
|
-
state: StoredCookies;
|
|
24
|
-
dispatch: Dispatch;
|
|
25
|
-
};
|
|
26
|
-
export {};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import * as React from 'react';
|
|
14
|
-
export var CookiesStoreActions;
|
|
15
|
-
(function (CookiesStoreActions) {
|
|
16
|
-
CookiesStoreActions["setCookies"] = "set_cookies";
|
|
17
|
-
})(CookiesStoreActions || (CookiesStoreActions = {}));
|
|
18
|
-
var CookiesContext = React.createContext(undefined);
|
|
19
|
-
var contextReducer = function (state, _a) {
|
|
20
|
-
var type = _a.type, payload = _a.payload;
|
|
21
|
-
switch (type) {
|
|
22
|
-
case CookiesStoreActions.setCookies: {
|
|
23
|
-
return __assign(__assign({}, state), payload);
|
|
24
|
-
}
|
|
25
|
-
default: {
|
|
26
|
-
throw new Error("Unhandled action type: ".concat(type));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
export var CookiesContextProvider = function (_a) {
|
|
31
|
-
var children = _a.children, cookies = _a.cookies;
|
|
32
|
-
var _b = React.useReducer(contextReducer, cookies), state = _b[0], dispatch = _b[1];
|
|
33
|
-
var value = { state: state, dispatch: dispatch };
|
|
34
|
-
return (_jsx(CookiesContext.Provider, __assign({ value: value }, { children: children })));
|
|
35
|
-
};
|
|
36
|
-
export var useCookiesContext = function () {
|
|
37
|
-
var context = React.useContext(CookiesContext);
|
|
38
|
-
if (context === undefined) {
|
|
39
|
-
throw new Error('useCookiesContext must be used within a ContextProvider');
|
|
40
|
-
}
|
|
41
|
-
return context;
|
|
42
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
type CookieObject = {
|
|
3
|
-
title: string;
|
|
4
|
-
description: string;
|
|
5
|
-
value: boolean;
|
|
6
|
-
required?: boolean;
|
|
7
|
-
};
|
|
8
|
-
type StoredCookies = {
|
|
9
|
-
[key: string]: CookieObject;
|
|
10
|
-
};
|
|
11
|
-
export declare enum CookiesStoreActions {
|
|
12
|
-
setCookies = "set_cookies"
|
|
13
|
-
}
|
|
14
|
-
type Action = {
|
|
15
|
-
type: CookiesStoreActions.setCookies;
|
|
16
|
-
payload: StoredCookies | undefined;
|
|
17
|
-
};
|
|
18
|
-
type Dispatch = (action: Action) => void;
|
|
19
|
-
export declare const CookiesContextProvider: ({ children, cookies, }: React.PropsWithChildren<{
|
|
20
|
-
cookies: StoredCookies;
|
|
21
|
-
}>) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
-
export declare const useCookiesContext: () => {
|
|
23
|
-
state: StoredCookies;
|
|
24
|
-
dispatch: Dispatch;
|
|
25
|
-
};
|
|
26
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
export var CookiesStoreActions;
|
|
5
|
-
(function (CookiesStoreActions) {
|
|
6
|
-
CookiesStoreActions["setCookies"] = "set_cookies";
|
|
7
|
-
})(CookiesStoreActions || (CookiesStoreActions = {}));
|
|
8
|
-
var CookiesContext = React.createContext(undefined);
|
|
9
|
-
var contextReducer = function (state, _a) {
|
|
10
|
-
var type = _a.type, payload = _a.payload;
|
|
11
|
-
switch (type) {
|
|
12
|
-
case CookiesStoreActions.setCookies: {
|
|
13
|
-
return __assign(__assign({}, state), payload);
|
|
14
|
-
}
|
|
15
|
-
default: {
|
|
16
|
-
throw new Error("Unhandled action type: ".concat(type));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
export var CookiesContextProvider = function (_a) {
|
|
21
|
-
var children = _a.children, cookies = _a.cookies;
|
|
22
|
-
var _b = React.useReducer(contextReducer, cookies), state = _b[0], dispatch = _b[1];
|
|
23
|
-
var value = { state: state, dispatch: dispatch };
|
|
24
|
-
return (_jsx(CookiesContext.Provider, __assign({ value: value }, { children: children })));
|
|
25
|
-
};
|
|
26
|
-
export var useCookiesContext = function () {
|
|
27
|
-
var context = React.useContext(CookiesContext);
|
|
28
|
-
if (context === undefined) {
|
|
29
|
-
throw new Error('useCookiesContext must be used within a ContextProvider');
|
|
30
|
-
}
|
|
31
|
-
return context;
|
|
32
|
-
};
|