@uxland/primary-shell 7.35.1 → 7.35.3
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/{component-Bz7NzBsL.js → component-DiipSu_7.js} +2 -2
- package/dist/{component-Bz7NzBsL.js.map → component-DiipSu_7.js.map} +1 -1
- package/dist/{index-umjRq-RK.js → index-DWSBg7Ti.js} +53 -51
- package/dist/index-DWSBg7Ti.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +16 -16
- package/dist/index.umd.cjs.map +1 -1
- package/dist/primary/shell/src/api/notification-service/notification.service-impl.d.ts +2 -0
- package/package.json +1 -1
- package/src/api/notification-service/notification-service-impl.test.ts +27 -0
- package/src/api/notification-service/notification.service-impl.ts +29 -5
- package/dist/index-umjRq-RK.js.map +0 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { PrimariaNotificationService } from './notification-service';
|
|
2
2
|
export declare class PrimariaNotificationServiceImpl extends PrimariaNotificationService {
|
|
3
|
+
private getOrCreateContainer;
|
|
4
|
+
private removeContainerIfEmpty;
|
|
3
5
|
private notify;
|
|
4
6
|
info(message: string, duration?: number): void;
|
|
5
7
|
warning(message: string, duration?: number): void;
|
package/package.json
CHANGED
|
@@ -37,6 +37,13 @@ describe("PrimariaNotificationServiceImpl", () => {
|
|
|
37
37
|
assertToast(state, message);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
it("should create a container for toasts", () => {
|
|
41
|
+
service.info("Test");
|
|
42
|
+
const container = document.getElementById("primaria-toast-container");
|
|
43
|
+
expect(container).not.toBeNull();
|
|
44
|
+
expect(container?.style.position).toBe("fixed");
|
|
45
|
+
});
|
|
46
|
+
|
|
40
47
|
it("should remove the toast after the duration", () => {
|
|
41
48
|
service.info("Temporary toast", 2000);
|
|
42
49
|
|
|
@@ -53,4 +60,24 @@ describe("PrimariaNotificationServiceImpl", () => {
|
|
|
53
60
|
toast = document.querySelector("dss-toast") as HTMLElement;
|
|
54
61
|
expect(toast).toBeNull();
|
|
55
62
|
});
|
|
63
|
+
|
|
64
|
+
it("should remove the container when all toasts are dismissed", () => {
|
|
65
|
+
service.info("Toast 1", 1000);
|
|
66
|
+
|
|
67
|
+
vi.advanceTimersByTime(1000);
|
|
68
|
+
vi.advanceTimersByTime(300);
|
|
69
|
+
|
|
70
|
+
const container = document.getElementById("primaria-toast-container");
|
|
71
|
+
expect(container).toBeNull();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should stack multiple toasts in the same container", () => {
|
|
75
|
+
service.info("Toast 1");
|
|
76
|
+
service.warning("Toast 2");
|
|
77
|
+
service.error("Toast 3");
|
|
78
|
+
|
|
79
|
+
const container = document.getElementById("primaria-toast-container");
|
|
80
|
+
const toasts = container?.querySelectorAll("dss-toast");
|
|
81
|
+
expect(toasts?.length).toBe(3);
|
|
82
|
+
});
|
|
56
83
|
});
|
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
import { PrimariaNotificationService } from "./notification-service";
|
|
2
2
|
|
|
3
|
+
const CONTAINER_ID = "primaria-toast-container";
|
|
4
|
+
|
|
3
5
|
export class PrimariaNotificationServiceImpl extends PrimariaNotificationService {
|
|
6
|
+
private getOrCreateContainer(): HTMLElement {
|
|
7
|
+
let container = document.getElementById(CONTAINER_ID);
|
|
8
|
+
if (!container) {
|
|
9
|
+
container = document.createElement("div");
|
|
10
|
+
container.id = CONTAINER_ID;
|
|
11
|
+
container.style.cssText =
|
|
12
|
+
"position:fixed;bottom:var(--dss-spacing-xxs,8px);left:var(--dss-spacing-xxs,8px);display:flex;flex-direction:column-reverse;gap:var(--dss-spacing-xs,4px);z-index:999;pointer-events:none;";
|
|
13
|
+
document.body.appendChild(container);
|
|
14
|
+
}
|
|
15
|
+
return container;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private removeContainerIfEmpty(container: HTMLElement): void {
|
|
19
|
+
if (container.childElementCount === 0) {
|
|
20
|
+
container.remove();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
4
24
|
private notify(
|
|
5
25
|
message: string,
|
|
6
26
|
state: "info" | "warning" | "error" | "success",
|
|
7
27
|
duration = 3000,
|
|
8
28
|
): void {
|
|
9
|
-
|
|
29
|
+
const container = this.getOrCreateContainer();
|
|
30
|
+
|
|
10
31
|
const toast = document.createElement("dss-toast");
|
|
11
32
|
toast.setAttribute("isshow", "true");
|
|
12
33
|
toast.setAttribute("state", state);
|
|
@@ -14,16 +35,19 @@ export class PrimariaNotificationServiceImpl extends PrimariaNotificationService
|
|
|
14
35
|
toast.setAttribute("text", message);
|
|
15
36
|
toast.setAttribute("hasicon", "true");
|
|
16
37
|
toast.setAttribute("duration", duration.toString());
|
|
38
|
+
toast.style.position = "relative";
|
|
39
|
+
toast.style.bottom = "auto";
|
|
40
|
+
toast.style.left = "auto";
|
|
41
|
+
toast.style.pointerEvents = "auto";
|
|
17
42
|
|
|
18
|
-
|
|
19
|
-
document.body.appendChild(toast);
|
|
43
|
+
container.appendChild(toast);
|
|
20
44
|
|
|
21
|
-
// Remover después del tiempo de duración
|
|
22
45
|
setTimeout(() => {
|
|
23
46
|
toast.setAttribute("isshow", "false");
|
|
24
47
|
setTimeout(() => {
|
|
25
48
|
toast.remove();
|
|
26
|
-
|
|
49
|
+
this.removeContainerIfEmpty(container);
|
|
50
|
+
}, 300);
|
|
27
51
|
}, duration);
|
|
28
52
|
}
|
|
29
53
|
|