@unitedstatespowersquadrons/components 1.2.12 → 1.2.14

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.
@@ -19,13 +19,13 @@ export function handleToasts<T extends AppStateWithToasts>(draft: Draft<T>, toas
19
19
  }
20
20
 
21
21
  export function addToast<T extends AppStateWithToasts>(draft: Draft<T>, toastOptions: Toast) {
22
- const { body, status, timeout, title } = toastOptions;
22
+ const { body, id, status, timeout, title } = toastOptions;
23
23
 
24
24
  // Increment current toastId to prevent collisions
25
- const id = draft.toastId ? draft.toastId + 1 : 1;
26
- draft.toastId = id;
25
+ const toastId = draft.toastId ? draft.toastId + 1 : 1;
26
+ draft.toastId = toastId;
27
27
 
28
- const toast = { body, id, status, timeout, title } as ToastProps;
28
+ const toast = { body, id: id || toastId, status, timeout, title } as ToastProps;
29
29
 
30
30
  // Initialize toasts array if not provided by the server
31
31
  if (!draft.toasts) draft.toasts = [];
@@ -41,3 +41,22 @@ export function addToast<T extends AppStateWithToasts>(draft: Draft<T>, toastOpt
41
41
 
42
42
  draft.toasts.push(toast);
43
43
  }
44
+
45
+ export function removeToast<T extends AppStateWithToasts>(draft: Draft<T>, toast: Toast) {
46
+ const beforeToasts: ToastProps[] = [];
47
+ const afterToasts: ToastProps[] = [];
48
+ let beforeToast = true;
49
+
50
+ // draft.toasts.splice was removing toasts too quickly
51
+ draft.toasts.forEach(t => {
52
+ if (t === toast) {
53
+ beforeToast = false;
54
+ } else if (beforeToast) {
55
+ beforeToasts.push(t);
56
+ } else {
57
+ afterToasts.push(t);
58
+ }
59
+
60
+ draft.toasts = beforeToasts.concat(afterToasts);
61
+ });
62
+ }
package/Toasts/types.ts CHANGED
@@ -12,6 +12,7 @@ export type ToastAppAction =
12
12
  | ToastRemoveAppAction;
13
13
 
14
14
  export interface Toast {
15
+ id?: number;
15
16
  status: Toast_Status;
16
17
  title: string;
17
18
  body: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitedstatespowersquadrons/components",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
4
4
  "description": "USPS shared React components library",
5
5
  "main": "index.tsx",
6
6
  "scripts": {