@swan-io/shared-business 10.0.1 → 11.0.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/package.json +6 -6
- package/src/assets/3d-card/environment/nx.png +0 -0
- package/src/assets/3d-card/environment/ny.png +0 -0
- package/src/assets/3d-card/environment/nz.png +0 -0
- package/src/assets/3d-card/environment/px.png +0 -0
- package/src/assets/3d-card/environment/py.png +0 -0
- package/src/assets/3d-card/environment/pz.png +0 -0
- package/src/assets/3d-card/model/MaisonNeue-Book.woff +0 -0
- package/src/assets/3d-card/model/MarkPro-Regular.ttf +0 -0
- package/src/assets/3d-card/model/band_roughness.jpg +0 -0
- package/src/assets/3d-card/model/card.gltf +850 -0
- package/src/assets/3d-card/model/chip.jpg +0 -0
- package/src/assets/3d-card/model/color_black.jpg +0 -0
- package/src/assets/3d-card/model/color_silver.jpg +0 -0
- package/src/assets/images/flags.svg +1 -0
- package/src/components/ConfirmModal.js +1 -1
- package/src/components/CountryPicker.js +1 -1
- package/src/components/Filters.d.ts +59 -0
- package/src/components/Filters.js +208 -0
- package/src/components/Flag.d.ts +8 -0
- package/src/components/Flag.js +32 -0
- package/src/components/PlacekitAddressSearchInput.d.ts +1 -1
- package/src/components/PlacekitAddressSearchInput.js +1 -1
- package/src/components/ToastStack.d.ts +1 -0
- package/src/components/ToastStack.js +142 -0
- package/src/constants/countries.d.ts +7 -7
- package/src/state/toasts.d.ts +31 -0
- package/src/state/toasts.js +88 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { atom, useAtom } from "react-atomic-state";
|
|
2
|
+
// based on https://gist.github.com/ncou/3a0a1f89c8e22416d0d607f621a948a9
|
|
3
|
+
const createProgress = ({ duration, onEnd }) => {
|
|
4
|
+
const callbacks = new Set();
|
|
5
|
+
let endDate = 0;
|
|
6
|
+
let timerId = 0;
|
|
7
|
+
const step = () => {
|
|
8
|
+
const value = (endDate - Date.now()) / duration;
|
|
9
|
+
callbacks.forEach(callback => callback(value));
|
|
10
|
+
animationRequest = window.requestAnimationFrame(step);
|
|
11
|
+
};
|
|
12
|
+
let animationRequest = window.requestAnimationFrame(step);
|
|
13
|
+
const start = () => {
|
|
14
|
+
endDate = Date.now() + duration;
|
|
15
|
+
timerId = window.setTimeout(() => {
|
|
16
|
+
clear();
|
|
17
|
+
onEnd();
|
|
18
|
+
}, duration);
|
|
19
|
+
};
|
|
20
|
+
const reset = () => {
|
|
21
|
+
window.clearTimeout(timerId);
|
|
22
|
+
start();
|
|
23
|
+
};
|
|
24
|
+
const subscribe = (callback) => {
|
|
25
|
+
callbacks.add(callback);
|
|
26
|
+
return () => {
|
|
27
|
+
callbacks.delete(callback);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const clear = () => {
|
|
31
|
+
document.removeEventListener("visibilitychange", onDocumentVisible);
|
|
32
|
+
window.clearTimeout(timerId);
|
|
33
|
+
window.cancelAnimationFrame(animationRequest);
|
|
34
|
+
};
|
|
35
|
+
const onDocumentVisible = () => {
|
|
36
|
+
document.removeEventListener("visibilitychange", onDocumentVisible);
|
|
37
|
+
reset();
|
|
38
|
+
};
|
|
39
|
+
if (document.hidden) {
|
|
40
|
+
document.addEventListener("visibilitychange", onDocumentVisible);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
reset();
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
clear,
|
|
47
|
+
reset,
|
|
48
|
+
subscribe,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const toasts = atom([]);
|
|
52
|
+
export const useToasts = () => useAtom(toasts);
|
|
53
|
+
export const hideToast = (uid) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const toast = toasts.get().find(toast => toast.uid === uid);
|
|
56
|
+
if (toast != null) {
|
|
57
|
+
(_a = toast.progress) === null || _a === void 0 ? void 0 : _a.clear();
|
|
58
|
+
toasts.set(toasts => toasts.filter(toast => toast.uid !== uid));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
let errorToRequestId = new WeakMap();
|
|
62
|
+
export const registerErrorToRequestId = (value) => {
|
|
63
|
+
errorToRequestId = value;
|
|
64
|
+
};
|
|
65
|
+
export const getErrorToRequestId = () => {
|
|
66
|
+
return errorToRequestId;
|
|
67
|
+
};
|
|
68
|
+
export const showToast = ({ variant, title, description, error, autoClose }) => {
|
|
69
|
+
var _a;
|
|
70
|
+
const uid = `${variant} - ${title} - ${description !== null && description !== void 0 ? description : ""}`;
|
|
71
|
+
const toast = toasts.get().find(toast => toast.uid === uid);
|
|
72
|
+
if (toast != null) {
|
|
73
|
+
(_a = toast.progress) === null || _a === void 0 ? void 0 : _a.reset();
|
|
74
|
+
return uid;
|
|
75
|
+
}
|
|
76
|
+
// by default, only info and success toasts are auto-closing
|
|
77
|
+
const shouldAutoClose = autoClose !== null && autoClose !== void 0 ? autoClose : (variant === "info" || variant === "success");
|
|
78
|
+
const progress = shouldAutoClose
|
|
79
|
+
? createProgress({
|
|
80
|
+
duration: 10000,
|
|
81
|
+
onEnd: () => {
|
|
82
|
+
hideToast(uid);
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
: undefined;
|
|
86
|
+
toasts.set(toasts => [{ uid, variant, title, description, error, progress }, ...toasts]);
|
|
87
|
+
return uid;
|
|
88
|
+
};
|