@vuu-ui/vuu-notifications 2.1.19-beta.2 → 2.1.19-beta.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/cjs/NotificationsCenter.js +231 -0
- package/cjs/NotificationsCenter.js.map +1 -0
- package/cjs/NotificationsContext.js +13 -0
- package/cjs/NotificationsContext.js.map +1 -0
- package/cjs/NotificationsProvider.js +64 -0
- package/cjs/NotificationsProvider.js.map +1 -0
- package/cjs/ToastNotification.css.js +6 -0
- package/cjs/ToastNotification.css.js.map +1 -0
- package/cjs/ToastNotification.js +112 -0
- package/cjs/ToastNotification.js.map +1 -0
- package/cjs/WorkspaceNotification.css.js +6 -0
- package/cjs/WorkspaceNotification.css.js.map +1 -0
- package/cjs/WorkspaceNotification.js +52 -0
- package/cjs/WorkspaceNotification.js.map +1 -0
- package/cjs/index.js +13 -0
- package/cjs/index.js.map +1 -0
- package/esm/NotificationsCenter.js +229 -0
- package/esm/NotificationsCenter.js.map +1 -0
- package/esm/NotificationsContext.js +9 -0
- package/esm/NotificationsContext.js.map +1 -0
- package/esm/NotificationsProvider.js +61 -0
- package/esm/NotificationsProvider.js.map +1 -0
- package/esm/ToastNotification.css.js +4 -0
- package/esm/ToastNotification.css.js.map +1 -0
- package/esm/ToastNotification.js +110 -0
- package/esm/ToastNotification.js.map +1 -0
- package/esm/WorkspaceNotification.css.js +4 -0
- package/esm/WorkspaceNotification.css.js.map +1 -0
- package/esm/WorkspaceNotification.js +50 -0
- package/esm/WorkspaceNotification.js.map +1 -0
- package/esm/index.js +4 -0
- package/esm/index.js.map +1 -0
- package/package.json +10 -7
- package/src/NotificationsCenter.js +0 -185
- package/src/NotificationsContext.js +0 -7
- package/src/NotificationsProvider.js +0 -43
- package/src/ToastNotification.css.js +0 -132
- package/src/ToastNotification.js +0 -85
- package/src/WorkspaceNotification.css.js +0 -16
- package/src/WorkspaceNotification.js +0 -53
- package/src/index.js +0 -3
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { getUniqueId, saveLocalEntity } from "@vuu-ui/vuu-utils";
|
|
3
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
-
import { isToastNotification, isWorkspaceNotification } from "./NotificationsContext.js";
|
|
5
|
-
import { ToastNotification } from "./ToastNotification.js";
|
|
6
|
-
import { WorkspaceNotification } from "./WorkspaceNotification.js";
|
|
7
|
-
const ZeroSize = {
|
|
8
|
-
height: 0,
|
|
9
|
-
width: 0
|
|
10
|
-
};
|
|
11
|
-
const toastContainerRightPadding = 20;
|
|
12
|
-
const toastOffsetTop = 60;
|
|
13
|
-
const toastDisplayDuration = 6000;
|
|
14
|
-
const toastDisplayDurationPostHover = 2000;
|
|
15
|
-
const toastContainerContentGap = 10;
|
|
16
|
-
const RuntimeToast = (toast)=>{
|
|
17
|
-
const slidesIn = !!toast.animationType?.includes("slide-in");
|
|
18
|
-
return {
|
|
19
|
-
...toast,
|
|
20
|
-
hidden: slidesIn,
|
|
21
|
-
id: getUniqueId(),
|
|
22
|
-
left: document.body.clientWidth,
|
|
23
|
-
opacity: slidesIn ? void 0 : 0,
|
|
24
|
-
size: ZeroSize
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const NotificationsCenter = ({ notificationsContext, startupToastNotification })=>{
|
|
28
|
-
const toastNotifications = useMemo(()=>startupToastNotification ? [
|
|
29
|
-
RuntimeToast(startupToastNotification)
|
|
30
|
-
] : [], [
|
|
31
|
-
startupToastNotification
|
|
32
|
-
]);
|
|
33
|
-
const [workspaceNotification, setWorkspaceNotification] = useState(null);
|
|
34
|
-
const hoveredToastRef = useRef(void 0);
|
|
35
|
-
const notificationsRef = useRef(toastNotifications);
|
|
36
|
-
const [notifications, _setNotifications] = useState(toastNotifications);
|
|
37
|
-
const setNotifications = useCallback((notifications)=>{
|
|
38
|
-
_setNotifications(notificationsRef.current = notifications);
|
|
39
|
-
}, []);
|
|
40
|
-
const showNotification = useCallback((notification)=>{
|
|
41
|
-
if (isToastNotification(notification)) if (notification.renderPostRefresh) saveLocalEntity("startup-notification", {
|
|
42
|
-
...notification,
|
|
43
|
-
expires: +new Date() + 10000
|
|
44
|
-
});
|
|
45
|
-
else setNotifications(notificationsRef.current.concat(RuntimeToast(notification)));
|
|
46
|
-
else if (isWorkspaceNotification(notification)) setWorkspaceNotification(/*#__PURE__*/ jsx(WorkspaceNotification, {
|
|
47
|
-
children: notification.content
|
|
48
|
-
}));
|
|
49
|
-
else throw Error("[NotificationsCenter] invalid notification received");
|
|
50
|
-
}, [
|
|
51
|
-
setNotifications
|
|
52
|
-
]);
|
|
53
|
-
const hideNotification = useCallback(()=>{
|
|
54
|
-
setWorkspaceNotification(null);
|
|
55
|
-
}, []);
|
|
56
|
-
useMemo(()=>{
|
|
57
|
-
notificationsContext.setNotify(showNotification, hideNotification);
|
|
58
|
-
}, [
|
|
59
|
-
hideNotification,
|
|
60
|
-
notificationsContext,
|
|
61
|
-
showNotification
|
|
62
|
-
]);
|
|
63
|
-
const onMeasured = useCallback((id, height, width)=>{
|
|
64
|
-
let scheduledUpdate;
|
|
65
|
-
const pageWidth = document.body.clientWidth;
|
|
66
|
-
setNotifications(notificationsRef.current.map((n)=>{
|
|
67
|
-
if (n.id !== id) return n;
|
|
68
|
-
{
|
|
69
|
-
const slideIn = n.animationType?.includes("slide-in");
|
|
70
|
-
const newToast = {
|
|
71
|
-
...n,
|
|
72
|
-
hidden: !!slideIn,
|
|
73
|
-
left: slideIn ? pageWidth + width - toastContainerRightPadding : pageWidth - width - toastContainerRightPadding,
|
|
74
|
-
size: {
|
|
75
|
-
height,
|
|
76
|
-
width
|
|
77
|
-
},
|
|
78
|
-
transitionStatus: "entry"
|
|
79
|
-
};
|
|
80
|
-
scheduledUpdate = slideIn ? {
|
|
81
|
-
...newToast,
|
|
82
|
-
hidden: false,
|
|
83
|
-
left: pageWidth - width - toastContainerRightPadding
|
|
84
|
-
} : {
|
|
85
|
-
...newToast,
|
|
86
|
-
opacity: 1
|
|
87
|
-
};
|
|
88
|
-
return newToast;
|
|
89
|
-
}
|
|
90
|
-
}));
|
|
91
|
-
if (scheduledUpdate) {
|
|
92
|
-
const updateNotifications = notificationsRef.current.map((n)=>{
|
|
93
|
-
if (n.id === scheduledUpdate?.id) return scheduledUpdate;
|
|
94
|
-
return n;
|
|
95
|
-
});
|
|
96
|
-
requestAnimationFrame(()=>{
|
|
97
|
-
setNotifications(updateNotifications);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}, [
|
|
101
|
-
setNotifications
|
|
102
|
-
]);
|
|
103
|
-
useEffect(()=>{
|
|
104
|
-
document.body.addEventListener("transitionend", (e)=>{
|
|
105
|
-
const { classList, id } = e.target;
|
|
106
|
-
if (classList?.contains("vuuToastNotification")) {
|
|
107
|
-
const notification = notificationsRef.current.find((n)=>n.id === id);
|
|
108
|
-
if (notification?.transitionStatus === "exit") setNotifications(notificationsRef.current.filter((n)=>n.id !== id));
|
|
109
|
-
else if (notification?.dismissal !== "manual") setTimeout(()=>{
|
|
110
|
-
if (notification && hoveredToastRef.current !== id) {
|
|
111
|
-
const pageWidth = document.body.clientWidth;
|
|
112
|
-
setNotifications(notificationsRef.current.map((n)=>{
|
|
113
|
-
if (n.id !== id) return n;
|
|
114
|
-
if (n.animationType?.includes("slide-out")) return {
|
|
115
|
-
...n,
|
|
116
|
-
transitionStatus: "exit",
|
|
117
|
-
left: pageWidth + toastContainerRightPadding
|
|
118
|
-
};
|
|
119
|
-
return {
|
|
120
|
-
...n,
|
|
121
|
-
transitionStatus: "exit",
|
|
122
|
-
opacity: 0
|
|
123
|
-
};
|
|
124
|
-
}).filter((v)=>null !== v));
|
|
125
|
-
}
|
|
126
|
-
}, toastDisplayDuration);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}, [
|
|
130
|
-
setNotifications
|
|
131
|
-
]);
|
|
132
|
-
const handleDismiss = useCallback((id)=>{
|
|
133
|
-
if (id) setNotifications(notificationsRef.current.filter((n)=>n.id !== id));
|
|
134
|
-
}, [
|
|
135
|
-
setNotifications
|
|
136
|
-
]);
|
|
137
|
-
const handleHoverEntry = useCallback((id)=>{
|
|
138
|
-
hoveredToastRef.current = id;
|
|
139
|
-
}, []);
|
|
140
|
-
const handleHoverExit = useCallback((id)=>{
|
|
141
|
-
hoveredToastRef.current = void 0;
|
|
142
|
-
const notification = notificationsRef.current.find((n)=>n.id === id);
|
|
143
|
-
setTimeout(()=>{
|
|
144
|
-
if (notification) {
|
|
145
|
-
const pageWidth = document.body.clientWidth;
|
|
146
|
-
setNotifications(notificationsRef.current.map((n)=>{
|
|
147
|
-
if (n.id !== id) return n;
|
|
148
|
-
if (n.animationType?.includes("slide-out")) return {
|
|
149
|
-
...n,
|
|
150
|
-
transitionStatus: "exit",
|
|
151
|
-
left: pageWidth + toastContainerRightPadding
|
|
152
|
-
};
|
|
153
|
-
return {
|
|
154
|
-
...n,
|
|
155
|
-
transitionStatus: "exit",
|
|
156
|
-
opacity: 0
|
|
157
|
-
};
|
|
158
|
-
}).filter((v)=>null !== v));
|
|
159
|
-
}
|
|
160
|
-
}, toastDisplayDurationPostHover);
|
|
161
|
-
}, [
|
|
162
|
-
setNotifications
|
|
163
|
-
]);
|
|
164
|
-
return /*#__PURE__*/ jsxs(Fragment, {
|
|
165
|
-
children: [
|
|
166
|
-
workspaceNotification,
|
|
167
|
-
notifications.map(({ hidden, id, left = 0, opacity, size, ...toast }, i)=>{
|
|
168
|
-
const height = size ? size.height : 80;
|
|
169
|
-
return /*#__PURE__*/ jsx(ToastNotification, {
|
|
170
|
-
hidden: hidden,
|
|
171
|
-
id: id,
|
|
172
|
-
left: left,
|
|
173
|
-
notification: toast,
|
|
174
|
-
onHoverEntry: handleHoverEntry,
|
|
175
|
-
onHoverExit: handleHoverExit,
|
|
176
|
-
onMeasured: onMeasured,
|
|
177
|
-
onDismiss: handleDismiss,
|
|
178
|
-
opacity: opacity,
|
|
179
|
-
top: toastOffsetTop + (height + toastContainerContentGap) * i
|
|
180
|
-
}, id);
|
|
181
|
-
})
|
|
182
|
-
]
|
|
183
|
-
});
|
|
184
|
-
};
|
|
185
|
-
export { NotificationsCenter };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const NotificationType = {
|
|
2
|
-
Toast: "toast",
|
|
3
|
-
Workspace: "workspace"
|
|
4
|
-
};
|
|
5
|
-
const isToastNotification = (n)=>n.type === NotificationType.Toast;
|
|
6
|
-
const isWorkspaceNotification = (n)=>n.type === NotificationType.Workspace;
|
|
7
|
-
export { NotificationType, isToastNotification, isWorkspaceNotification };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import react, { useContext, useMemo } from "react";
|
|
3
|
-
import { NotificationsCenter } from "./NotificationsCenter.js";
|
|
4
|
-
import { getLocalEntity } from "@vuu-ui/vuu-utils";
|
|
5
|
-
class NotificationsContextObject {
|
|
6
|
-
#showNotification = ()=>console.log("have you forgotten to provide a NotificationsCenter?");
|
|
7
|
-
#hideNotification = ()=>console.log("have you forgotten to provide a NotificationsCenter?");
|
|
8
|
-
showNotification = (notification)=>this.#showNotification(notification);
|
|
9
|
-
hideNotification = ()=>this.#hideNotification();
|
|
10
|
-
setNotify = (showNotificationDispatcher, hideNotificationDispatcher)=>{
|
|
11
|
-
this.#showNotification = showNotificationDispatcher;
|
|
12
|
-
this.#hideNotification = hideNotificationDispatcher;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
const NotificationsContext = /*#__PURE__*/ react.createContext(new NotificationsContextObject());
|
|
16
|
-
const NotificationsProvider = (props)=>{
|
|
17
|
-
const context = useContext(NotificationsContext);
|
|
18
|
-
const startupToastNotification = useMemo(()=>{
|
|
19
|
-
const toast = getLocalEntity("startup-notification", true);
|
|
20
|
-
if (toast && toast.expires >= +Date.now()) {
|
|
21
|
-
const { expires, ...toastDescriptor } = toast;
|
|
22
|
-
return toastDescriptor;
|
|
23
|
-
}
|
|
24
|
-
}, []);
|
|
25
|
-
return /*#__PURE__*/ jsxs(NotificationsContext.Provider, {
|
|
26
|
-
value: context,
|
|
27
|
-
children: [
|
|
28
|
-
/*#__PURE__*/ jsx(NotificationsCenter, {
|
|
29
|
-
startupToastNotification: startupToastNotification,
|
|
30
|
-
notificationsContext: context
|
|
31
|
-
}),
|
|
32
|
-
props.children
|
|
33
|
-
]
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
const useNotifications = ()=>{
|
|
37
|
-
const { hideNotification, showNotification } = useContext(NotificationsContext);
|
|
38
|
-
return {
|
|
39
|
-
hideNotification,
|
|
40
|
-
showNotification
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
export { NotificationsProvider, useNotifications };
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
const css = `
|
|
2
|
-
.vuuToastNotification {
|
|
3
|
-
--toast-transition-duration: .4s;
|
|
4
|
-
--padding-base: var(--vuuToast-padding, var(--salt-spacing-300));
|
|
5
|
-
background: var(--vuuToast-background, var(--toast-background));
|
|
6
|
-
border-radius: var(--vuuToast-borderRadius, var(--salt-curve-100, 0));
|
|
7
|
-
box-sizing: border-box;
|
|
8
|
-
box-shadow: var(--salt-overlayable-shadow-popout);
|
|
9
|
-
color: var(--vuuToast-foreground, var(--toast-foreground));
|
|
10
|
-
align-items: center;
|
|
11
|
-
column-gap: var(--salt-spacing-100);
|
|
12
|
-
grid-template-areas: var(--vuuToast-grid-template-areas, "toast-header");
|
|
13
|
-
max-width: var(--vuuToast-maxWidth, 600px);
|
|
14
|
-
min-width: var(--vuuToast-minWidth, 300px);
|
|
15
|
-
opacity: 1;
|
|
16
|
-
padding: var(--padding-base);
|
|
17
|
-
row-gap: var(--salt-spacing-100);
|
|
18
|
-
z-index: var(--salt-zIndex-notification);
|
|
19
|
-
grid-template-columns: auto;
|
|
20
|
-
transition: opacity .4s, top;
|
|
21
|
-
display: grid;
|
|
22
|
-
|
|
23
|
-
&.vuuToastNotification-hidden {
|
|
24
|
-
visibility: hidden;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
&.vuuToastNotification-withCloseButton {
|
|
28
|
-
grid-template-areas: var(--vuuToast-grid-template-areas, "toast-header close-button");
|
|
29
|
-
grid-template-columns: 1fr 36px;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
&.vuuToastNotification-withIcon {
|
|
33
|
-
grid-template-areas: var(--vuuToast-grid-template-areas, "toast-icon toast-header");
|
|
34
|
-
grid-template-columns: var(--vuuToast-gridTemplateColumns, 36px auto);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
&.vuuToastNotification-withIcon.vuuToastNotification-withCloseButton {
|
|
38
|
-
grid-template-areas: var(--vuuToast-grid-template-areas, "toast-icon toast-header close-button");
|
|
39
|
-
grid-template-columns: var(--vuuToast-gridTemplateColumns, 36px auto 36px);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
&.vuuToastNotification-withContent {
|
|
43
|
-
grid-template-areas: var(--vuuToast-grid-template-areas, "toast-header"
|
|
44
|
-
"toast-content");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
&.vuuToastNotification-withContent.vuuToastNotification-withCloseButton {
|
|
48
|
-
grid-template-areas: var(--vuuToast-grid-template-areas, "toast-header close-button"
|
|
49
|
-
"toast-content close-button");
|
|
50
|
-
grid-template-columns: 1fr 36px;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
&.vuuToastNotification-withTransition {
|
|
54
|
-
transition: top .2s ease-out, left var(--toast-transition-duration) ease-in, opacity .4s;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
&.vuuToastNotification-transparent {
|
|
58
|
-
opacity: 0;
|
|
59
|
-
transition: top .2s ease-out, opacity .4s;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
&.vuuToastNotification-withIcon.vuuToastNotification-withContent {
|
|
63
|
-
grid-template-areas: var(--vuuToast-grid-template-areas, "toast-icon toast-header"
|
|
64
|
-
"toast-icon toast-content");
|
|
65
|
-
grid-template-columns: var(--vuuToast-gridTemplateColumns, 36px auto);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
&.vuuToastNotification-withIcon.vuuToastNotification-withContent.vuuToastNotification-withCloseButton {
|
|
69
|
-
grid-template-areas: var(--vuuToast-grid-template-areas, "toast-icon toast-header close-button"
|
|
70
|
-
"toast-icon toast-content close-button");
|
|
71
|
-
grid-template-columns: var(--vuuToast-gridTemplateColumns, 36px auto 36px);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
&.vuuToastNotification-error {
|
|
75
|
-
--toast-background: var(--vuuToast-error-background, var(--salt-container-primary-background));
|
|
76
|
-
--toast-foreground: var(--vuuToast-error-foreground, var(--salt-content-primary-foreground));
|
|
77
|
-
--vuu-icon-svg: var(--vuuToast-error-icon, var(--vuu-svg-info-circle));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
&.vuuToastNotification-success {
|
|
81
|
-
--toast-background: var(--vuuToast-success-background, var(--salt-container-primary-background));
|
|
82
|
-
--toast-foreground: var(--vuuToast-success-foreground, var(--salt-content-primary-foreground));
|
|
83
|
-
--vuu-icon-svg: var(--vuuToast-success-icon, var(--vuu-svg-tick));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
&.vuuToastNotification-warning {
|
|
87
|
-
--toast-background: var(--vuuToast-warning-background, var(--salt-container-primary-background));
|
|
88
|
-
--toast-foreground: var(--vuuToast-warning-foreground, var(--salt-content-primary-foreground));
|
|
89
|
-
--vuu-icon-svg: var(--vuuToast-warning-icon, var(--vuu-svg-info-circle));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
&.vuuToastNotification-info {
|
|
93
|
-
--toast-background: var(--vuuToast-info-background, var(--salt-container-primary-background));
|
|
94
|
-
--toast-foreground: var(--vuuToast-info-foreground, var(--salt-content-primary-foreground));
|
|
95
|
-
--vuu-icon-svg: var(--vuuToast-info-icon, var(--vuu-svg-info-circle));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
& .vuuIcon {
|
|
99
|
-
--vuu-icon-color: var(--toast-foreground);
|
|
100
|
-
--vuu-icon-size: 20px;
|
|
101
|
-
grid-area: toast-icon;
|
|
102
|
-
justify-self: center;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
& .vuuToastNotification-header {
|
|
106
|
-
font-size: var(--vuuToast-header-fontSize, var(--salt-text-h3-fontSize));
|
|
107
|
-
font-weight: var(--salt-text-display1-fontWeight-strong);
|
|
108
|
-
line-height: var(--salt-text-h3-lineHeight);
|
|
109
|
-
white-space: nowrap;
|
|
110
|
-
grid-area: toast-header;
|
|
111
|
-
justify-self: start;
|
|
112
|
-
margin: 0;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
& .vuuToastNotification-content {
|
|
116
|
-
grid-area: toast-content;
|
|
117
|
-
justify-self: start;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
& .vuuToastNotification-closeButton.saltButton {
|
|
121
|
-
grid-area: close-button;
|
|
122
|
-
justify-self: center;
|
|
123
|
-
|
|
124
|
-
& .vuuIcon {
|
|
125
|
-
--vuu-icon-size: 16px;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
`;
|
|
132
|
-
export default css;
|
package/src/ToastNotification.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useFloatingComponent } from "@salt-ds/core";
|
|
3
|
-
import { useComponentCssInjection } from "@salt-ds/styles";
|
|
4
|
-
import { useWindow } from "@salt-ds/window";
|
|
5
|
-
import { Icon, IconButton } from "@vuu-ui/vuu-ui-controls";
|
|
6
|
-
import clsx from "clsx";
|
|
7
|
-
import { useCallback } from "react";
|
|
8
|
-
import ToastNotification from "./ToastNotification.css";
|
|
9
|
-
const classBase = "vuuToastNotification";
|
|
10
|
-
const ToastNotification_ToastNotification = ({ hidden, id, left, onDismiss, onMeasured, top, notification, onHoverEntry, onHoverExit, opacity = 1 })=>{
|
|
11
|
-
const targetWindow = useWindow();
|
|
12
|
-
useComponentCssInjection({
|
|
13
|
-
testId: "vuu-toast-notification",
|
|
14
|
-
css: ToastNotification,
|
|
15
|
-
window: targetWindow
|
|
16
|
-
});
|
|
17
|
-
const { Component: FloatingComponent } = useFloatingComponent();
|
|
18
|
-
const { animationType, content, dismissal, header, icon, showCloseButton, status } = notification;
|
|
19
|
-
const iconName = false === icon ? void 0 : icon ?? status;
|
|
20
|
-
const callbackRef = useCallback((el)=>{
|
|
21
|
-
if (el) setTimeout(()=>{
|
|
22
|
-
const { height, width } = el.getBoundingClientRect();
|
|
23
|
-
if (id) onMeasured?.(id, height, width);
|
|
24
|
-
}, 60);
|
|
25
|
-
}, [
|
|
26
|
-
id,
|
|
27
|
-
onMeasured
|
|
28
|
-
]);
|
|
29
|
-
const handleDismiss = useCallback(()=>{
|
|
30
|
-
onDismiss?.(id);
|
|
31
|
-
}, [
|
|
32
|
-
id,
|
|
33
|
-
onDismiss
|
|
34
|
-
]);
|
|
35
|
-
const handleMouseEnter = useCallback(()=>onHoverEntry?.(id), [
|
|
36
|
-
id,
|
|
37
|
-
onHoverEntry
|
|
38
|
-
]);
|
|
39
|
-
const handleMouseLeave = useCallback(()=>onHoverExit?.(id), [
|
|
40
|
-
id,
|
|
41
|
-
onHoverExit
|
|
42
|
-
]);
|
|
43
|
-
if ("manual" === dismissal && false === showCloseButton) console.warn("[ToastNotification] invalid props, if dismissal is manual, showCloseButton should not be false");
|
|
44
|
-
const withCloseButton = showCloseButton || "manual" === dismissal;
|
|
45
|
-
return /*#__PURE__*/ jsxs(FloatingComponent, {
|
|
46
|
-
className: clsx(classBase, `${classBase}-${notification.status}`, {
|
|
47
|
-
[`${classBase}-hidden`]: hidden,
|
|
48
|
-
[`${classBase}-transparent`]: 0 === opacity,
|
|
49
|
-
[`${classBase}-withContent`]: void 0 !== content,
|
|
50
|
-
[`${classBase}-withIcon`]: false !== icon,
|
|
51
|
-
[`${classBase}-withTransition`]: void 0 !== animationType && !hidden,
|
|
52
|
-
[`${classBase}-withCloseButton`]: withCloseButton
|
|
53
|
-
}),
|
|
54
|
-
id: id,
|
|
55
|
-
left: left,
|
|
56
|
-
onMouseEnter: handleMouseEnter,
|
|
57
|
-
onMouseLeave: handleMouseLeave,
|
|
58
|
-
open: true,
|
|
59
|
-
position: "absolute",
|
|
60
|
-
ref: callbackRef,
|
|
61
|
-
role: "alert",
|
|
62
|
-
top: top,
|
|
63
|
-
children: [
|
|
64
|
-
iconName ? /*#__PURE__*/ jsx(Icon, {
|
|
65
|
-
name: iconName
|
|
66
|
-
}) : null,
|
|
67
|
-
/*#__PURE__*/ jsx("h3", {
|
|
68
|
-
className: `${classBase}-header`,
|
|
69
|
-
children: header
|
|
70
|
-
}),
|
|
71
|
-
content ? /*#__PURE__*/ jsx("div", {
|
|
72
|
-
className: `${classBase}-content`,
|
|
73
|
-
children: content
|
|
74
|
-
}) : null,
|
|
75
|
-
withCloseButton ? /*#__PURE__*/ jsx(IconButton, {
|
|
76
|
-
className: `${classBase}-closeButton`,
|
|
77
|
-
icon: "close",
|
|
78
|
-
onClick: handleDismiss,
|
|
79
|
-
appearance: "transparent",
|
|
80
|
-
sentiment: "neutral"
|
|
81
|
-
}) : null
|
|
82
|
-
]
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
export { ToastNotification_ToastNotification as ToastNotification };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const css = `
|
|
2
|
-
.vuuWorkspaceNotification {
|
|
3
|
-
z-index: var(--salt-zIndex-notification);
|
|
4
|
-
position: absolute;
|
|
5
|
-
|
|
6
|
-
& .vuuWorkspaceNotification-content {
|
|
7
|
-
background: var(--salt-container-primary-background);
|
|
8
|
-
justify-content: center;
|
|
9
|
-
align-items: center;
|
|
10
|
-
display: flex;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
`;
|
|
16
|
-
export default css;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useFloatingComponent } from "@salt-ds/core";
|
|
3
|
-
import { useComponentCssInjection } from "@salt-ds/styles";
|
|
4
|
-
import { useWindow } from "@salt-ds/window";
|
|
5
|
-
import { VuuShellLocation } from "@vuu-ui/vuu-utils";
|
|
6
|
-
import clsx from "clsx";
|
|
7
|
-
import { useMemo } from "react";
|
|
8
|
-
import WorkspaceNotification from "./WorkspaceNotification.css";
|
|
9
|
-
const classBase = "vuuWorkspaceNotification";
|
|
10
|
-
const WorkspaceNotification_WorkspaceNotification = ({ children, className, style: styleProp, ...htmlAttributes })=>{
|
|
11
|
-
const targetWindow = useWindow();
|
|
12
|
-
useComponentCssInjection({
|
|
13
|
-
testId: "vuu-toast-notification",
|
|
14
|
-
css: WorkspaceNotification,
|
|
15
|
-
window: targetWindow
|
|
16
|
-
});
|
|
17
|
-
const { Component: FloatingComponent } = useFloatingComponent();
|
|
18
|
-
const [left, top, width, height] = useMemo(()=>{
|
|
19
|
-
const target = document.querySelector(`#${VuuShellLocation.WorkspaceContainer}`);
|
|
20
|
-
if (!target) return [
|
|
21
|
-
0,
|
|
22
|
-
0,
|
|
23
|
-
200,
|
|
24
|
-
200
|
|
25
|
-
];
|
|
26
|
-
{
|
|
27
|
-
const { left, top, width, height } = target.getBoundingClientRect();
|
|
28
|
-
return [
|
|
29
|
-
left,
|
|
30
|
-
top,
|
|
31
|
-
width,
|
|
32
|
-
height
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
}, []);
|
|
36
|
-
return /*#__PURE__*/ jsx(FloatingComponent, {
|
|
37
|
-
...htmlAttributes,
|
|
38
|
-
className: clsx(classBase, className),
|
|
39
|
-
open: true,
|
|
40
|
-
role: "alert",
|
|
41
|
-
left: left,
|
|
42
|
-
top: top,
|
|
43
|
-
children: /*#__PURE__*/ jsx("div", {
|
|
44
|
-
className: `${classBase}-content`,
|
|
45
|
-
style: {
|
|
46
|
-
height,
|
|
47
|
-
width
|
|
48
|
-
},
|
|
49
|
-
children: children
|
|
50
|
-
})
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
export { WorkspaceNotification_WorkspaceNotification as WorkspaceNotification };
|
package/src/index.js
DELETED