@vuu-ui/vuu-notifications 2.0.0-alpha.1 → 2.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/cjs/NotificationsCenter.js +207 -38
- package/cjs/NotificationsCenter.js.map +1 -1
- package/cjs/NotificationsContext.js.map +1 -1
- package/cjs/NotificationsProvider.js +0 -1
- package/cjs/NotificationsProvider.js.map +1 -1
- package/cjs/ToastNotification.css.js +1 -1
- package/cjs/ToastNotification.js +83 -54
- package/cjs/ToastNotification.js.map +1 -1
- package/esm/NotificationsCenter.js +209 -40
- package/esm/NotificationsCenter.js.map +1 -1
- package/esm/NotificationsContext.js.map +1 -1
- package/esm/NotificationsProvider.js +0 -1
- package/esm/NotificationsProvider.js.map +1 -1
- package/esm/ToastNotification.css.js +1 -1
- package/esm/ToastNotification.js +85 -54
- package/esm/ToastNotification.js.map +1 -1
- package/package.json +3 -2
- package/types/NotificationsContext.d.ts +14 -1
- package/types/ToastNotification.d.ts +11 -5
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { getUniqueId, saveLocalEntity } from '@vuu-ui/vuu-utils';
|
|
3
|
-
import { useMemo, useState, useCallback } from 'react';
|
|
3
|
+
import { useMemo, useState, useRef, useCallback, useEffect } from 'react';
|
|
4
4
|
import { isToastNotification, isWorkspaceNotification } from './NotificationsContext.js';
|
|
5
|
-
import { ToastNotification
|
|
5
|
+
import { ToastNotification } from './ToastNotification.js';
|
|
6
6
|
import { WorkspaceNotification } from './WorkspaceNotification.js';
|
|
7
7
|
|
|
8
|
+
const ZeroSize = { height: 0, width: 0 };
|
|
9
|
+
const toastContainerRightPadding = 20;
|
|
10
|
+
const NO_NOTIFICATIONS = [];
|
|
8
11
|
const toastOffsetTop = 60;
|
|
9
|
-
const toastDisplayDuration =
|
|
10
|
-
const
|
|
12
|
+
const toastDisplayDuration = 6e3;
|
|
13
|
+
const toastDisplayDurationPostHover = 2e3;
|
|
11
14
|
const toastContainerContentGap = 10;
|
|
12
15
|
const NotificationsCenter = ({
|
|
13
16
|
notificationsContext,
|
|
@@ -17,59 +20,225 @@ const NotificationsCenter = ({
|
|
|
17
20
|
() => startupToastNotification ? [
|
|
18
21
|
{
|
|
19
22
|
...startupToastNotification,
|
|
20
|
-
|
|
23
|
+
hidden: false,
|
|
24
|
+
id: getUniqueId(),
|
|
25
|
+
left: -1,
|
|
26
|
+
size: ZeroSize
|
|
21
27
|
}
|
|
22
28
|
] : [],
|
|
23
29
|
[startupToastNotification]
|
|
24
30
|
);
|
|
25
31
|
const [workspaceNotification, setWorkspaceNotification] = useState(null);
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
const hoveredToastRef = useRef(void 0);
|
|
33
|
+
const notificationsRef = useRef(NO_NOTIFICATIONS);
|
|
34
|
+
const [notifications, _setNotifications] = useState(toastNotifications);
|
|
35
|
+
const setNotifications = useCallback(
|
|
36
|
+
(notifications2) => {
|
|
37
|
+
_setNotifications(notificationsRef.current = notifications2);
|
|
38
|
+
},
|
|
39
|
+
[]
|
|
40
|
+
);
|
|
41
|
+
const showNotification = useCallback(
|
|
42
|
+
(notification) => {
|
|
43
|
+
if (isToastNotification(notification)) {
|
|
44
|
+
const { animationType = "none", renderPostRefresh } = notification;
|
|
45
|
+
if (renderPostRefresh) {
|
|
46
|
+
saveLocalEntity("startup-notification", {
|
|
47
|
+
...notification,
|
|
48
|
+
expires: +/* @__PURE__ */ new Date() + 1e4
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
if (animationType.includes("slide-in")) {
|
|
42
52
|
setNotifications(
|
|
43
|
-
|
|
53
|
+
notificationsRef.current.concat({
|
|
54
|
+
...notification,
|
|
55
|
+
hidden: true,
|
|
56
|
+
id: getUniqueId(),
|
|
57
|
+
left: -1,
|
|
58
|
+
size: ZeroSize
|
|
59
|
+
})
|
|
44
60
|
);
|
|
45
|
-
}
|
|
46
|
-
|
|
61
|
+
} else
|
|
62
|
+
setNotifications(
|
|
63
|
+
notificationsRef.current.concat({
|
|
64
|
+
...notification,
|
|
65
|
+
hidden: false,
|
|
66
|
+
id: getUniqueId(),
|
|
67
|
+
left: -1,
|
|
68
|
+
opacity: 0,
|
|
69
|
+
size: ZeroSize
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
} else if (isWorkspaceNotification(notification)) {
|
|
74
|
+
setWorkspaceNotification(
|
|
75
|
+
/* @__PURE__ */ jsx(WorkspaceNotification, { children: notification.content })
|
|
47
76
|
);
|
|
77
|
+
} else {
|
|
78
|
+
throw Error("[NotificationsCenter] invalid notification received");
|
|
48
79
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
} else {
|
|
54
|
-
throw Error("[NotificationsCenter] invalid notification received");
|
|
55
|
-
}
|
|
56
|
-
}, []);
|
|
80
|
+
},
|
|
81
|
+
[setNotifications]
|
|
82
|
+
);
|
|
57
83
|
const hideNotification = useCallback(() => {
|
|
58
84
|
setWorkspaceNotification(null);
|
|
59
85
|
}, []);
|
|
60
86
|
useMemo(() => {
|
|
61
87
|
notificationsContext.setNotify(showNotification, hideNotification);
|
|
62
88
|
}, [hideNotification, notificationsContext, showNotification]);
|
|
89
|
+
const onMeasured = useCallback(
|
|
90
|
+
(id, height, width) => {
|
|
91
|
+
let scheduledUpdate = void 0;
|
|
92
|
+
const pageWidth = document.body.clientWidth;
|
|
93
|
+
setNotifications(
|
|
94
|
+
notificationsRef.current.map((n) => {
|
|
95
|
+
if (n.id === id) {
|
|
96
|
+
const slideIn = n.animationType?.includes("slide-in");
|
|
97
|
+
const newToast = {
|
|
98
|
+
...n,
|
|
99
|
+
hidden: slideIn ? true : false,
|
|
100
|
+
left: slideIn ? pageWidth + width - toastContainerRightPadding : pageWidth - width - toastContainerRightPadding,
|
|
101
|
+
size: { height, width },
|
|
102
|
+
transitionStatus: "entry"
|
|
103
|
+
};
|
|
104
|
+
if (slideIn) {
|
|
105
|
+
scheduledUpdate = {
|
|
106
|
+
...newToast,
|
|
107
|
+
hidden: false,
|
|
108
|
+
left: pageWidth - width - toastContainerRightPadding
|
|
109
|
+
};
|
|
110
|
+
} else {
|
|
111
|
+
scheduledUpdate = {
|
|
112
|
+
...newToast,
|
|
113
|
+
opacity: 1
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return newToast;
|
|
117
|
+
} else {
|
|
118
|
+
return n;
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
if (scheduledUpdate) {
|
|
123
|
+
const updateNotifications = notificationsRef.current.map((n) => {
|
|
124
|
+
if (n.id === scheduledUpdate?.id) {
|
|
125
|
+
return scheduledUpdate;
|
|
126
|
+
} else {
|
|
127
|
+
return n;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
requestAnimationFrame(() => {
|
|
131
|
+
setNotifications(updateNotifications);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
[setNotifications]
|
|
136
|
+
);
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
document.body.addEventListener("transitionend", (e) => {
|
|
139
|
+
const { classList, id } = e.target;
|
|
140
|
+
if (classList?.contains("vuuToastNotification")) {
|
|
141
|
+
const notification = notificationsRef.current.find((n) => n.id === id);
|
|
142
|
+
if (notification?.transitionStatus === "exit") {
|
|
143
|
+
setNotifications(notificationsRef.current.filter((n) => n.id !== id));
|
|
144
|
+
} else if (notification?.dismissal !== "manual") {
|
|
145
|
+
setTimeout(() => {
|
|
146
|
+
if (notification && hoveredToastRef.current !== id) {
|
|
147
|
+
const pageWidth = document.body.clientWidth;
|
|
148
|
+
setNotifications(
|
|
149
|
+
notificationsRef.current.map((n) => {
|
|
150
|
+
if (n.id === id) {
|
|
151
|
+
if (n.animationType?.includes("slide-out")) {
|
|
152
|
+
return {
|
|
153
|
+
...n,
|
|
154
|
+
transitionStatus: "exit",
|
|
155
|
+
left: pageWidth + toastContainerRightPadding
|
|
156
|
+
};
|
|
157
|
+
} else {
|
|
158
|
+
return {
|
|
159
|
+
...n,
|
|
160
|
+
transitionStatus: "exit",
|
|
161
|
+
opacity: 0
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
return n;
|
|
166
|
+
}
|
|
167
|
+
}).filter((v) => v !== null)
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
}, toastDisplayDuration);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}, [setNotifications]);
|
|
175
|
+
const handleDismiss = useCallback(
|
|
176
|
+
(id) => {
|
|
177
|
+
if (id) {
|
|
178
|
+
setNotifications(notificationsRef.current.filter((n) => n.id !== id));
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
[setNotifications]
|
|
182
|
+
);
|
|
183
|
+
const handleHoverEntry = useCallback((id) => {
|
|
184
|
+
hoveredToastRef.current = id;
|
|
185
|
+
}, []);
|
|
186
|
+
const handleHoverExit = useCallback(
|
|
187
|
+
(id) => {
|
|
188
|
+
hoveredToastRef.current = void 0;
|
|
189
|
+
const notification = notificationsRef.current.find((n) => n.id === id);
|
|
190
|
+
setTimeout(() => {
|
|
191
|
+
if (notification) {
|
|
192
|
+
const pageWidth = document.body.clientWidth;
|
|
193
|
+
setNotifications(
|
|
194
|
+
notificationsRef.current.map((n) => {
|
|
195
|
+
if (n.id === id) {
|
|
196
|
+
if (n.animationType?.includes("slide-out")) {
|
|
197
|
+
return {
|
|
198
|
+
...n,
|
|
199
|
+
transitionStatus: "exit",
|
|
200
|
+
left: pageWidth + toastContainerRightPadding
|
|
201
|
+
};
|
|
202
|
+
} else {
|
|
203
|
+
return {
|
|
204
|
+
...n,
|
|
205
|
+
transitionStatus: "exit",
|
|
206
|
+
opacity: 0
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
return n;
|
|
211
|
+
}
|
|
212
|
+
}).filter((v) => v !== null)
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}, toastDisplayDurationPostHover);
|
|
216
|
+
},
|
|
217
|
+
[setNotifications]
|
|
218
|
+
);
|
|
63
219
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
64
220
|
workspaceNotification,
|
|
65
|
-
notifications.map(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
221
|
+
notifications.map(
|
|
222
|
+
({ hidden, id, left = 0, opacity, size, ...toast }, i) => {
|
|
223
|
+
const height = size ? size.height : 80;
|
|
224
|
+
return /* @__PURE__ */ jsx(
|
|
225
|
+
ToastNotification,
|
|
226
|
+
{
|
|
227
|
+
hidden,
|
|
228
|
+
id,
|
|
229
|
+
left,
|
|
230
|
+
notification: toast,
|
|
231
|
+
onHoverEntry: handleHoverEntry,
|
|
232
|
+
onHoverExit: handleHoverExit,
|
|
233
|
+
onMeasured,
|
|
234
|
+
onDismiss: handleDismiss,
|
|
235
|
+
opacity,
|
|
236
|
+
top: toastOffsetTop + (height + toastContainerContentGap) * i
|
|
237
|
+
},
|
|
238
|
+
id
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
)
|
|
73
242
|
] });
|
|
74
243
|
};
|
|
75
244
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationsCenter.js","sources":["../../../packages/vuu-notifications/src/NotificationsCenter.tsx"],"sourcesContent":["import { getUniqueId, saveLocalEntity } from \"@vuu-ui/vuu-utils\";\nimport { ReactNode, useCallback, useMemo, useState } from \"react\";\nimport {\n isToastNotification,\n isWorkspaceNotification,\n Notification,\n NotificationsContext,\n ToastNotificationDescriptor,\n} from \"./NotificationsContext\";\nimport { TOAST_HEIGHT, ToastNotification } from \"./ToastNotification\";\nimport { WorkspaceNotification } from \"./WorkspaceNotification\";\n\nexport interface NotificationsCenterProps {\n notificationsContext: NotificationsContext;\n startupToastNotification?: ToastNotificationDescriptor;\n}\n\ninterface ToastNotificationWithId extends ToastNotificationDescriptor {\n id: string;\n}\n\n// animation times in milliseconds\nconst toastOffsetTop = 60;\n// const toastDisplayDuration = 6000;\nconst toastDisplayDuration = 6000000;\n// const horizontalTransitionDuration = 1000;\nconst horizontalTransitionDuration = 100000000;\n\nconst toastContainerContentGap = 10;\n// rightPadding is used together with the toastWidth to compute the toast position\n// at the beginning and at the end of the animation\n\nexport const NotificationsCenter = ({\n notificationsContext,\n startupToastNotification,\n}: NotificationsCenterProps) => {\n const toastNotifications = useMemo<ToastNotificationWithId[]>(\n () =>\n startupToastNotification\n ? [\n {\n ...startupToastNotification,\n id: getUniqueId(),\n },\n ]\n : [],\n [startupToastNotification],\n );\n\n const [workspaceNotification, setWorkspaceNotification] =\n useState<ReactNode>(null);\n\n const [notifications, setNotifications] =\n useState<ToastNotificationWithId[]>(toastNotifications);\n\n const showNotification = useCallback((notification: Notification) => {\n if (isToastNotification(notification)) {\n if (notification.renderPostRefresh) {\n saveLocalEntity(\"startup-notification\", {\n ...notification,\n expires: +new Date() + 10000,\n });\n } else {\n const newNotification: ToastNotificationWithId = {\n ...notification,\n id: getUniqueId(),\n };\n setNotifications((prev) => prev.concat(newNotification));\n setTimeout(\n () => {\n setNotifications((prev) =>\n prev.filter((n) => n !== newNotification),\n );\n },\n toastDisplayDuration + horizontalTransitionDuration * 2,\n );\n }\n } else if (isWorkspaceNotification(notification)) {\n setWorkspaceNotification(\n <WorkspaceNotification>{notification.content}</WorkspaceNotification>,\n );\n } else {\n throw Error(\"[NotificationsCenter] invalid notification received\");\n }\n }, []);\n\n const hideNotification = useCallback(() => {\n setWorkspaceNotification(null);\n }, []);\n\n useMemo(() => {\n notificationsContext.setNotify(showNotification, hideNotification);\n }, [hideNotification, notificationsContext, showNotification]);\n\n return (\n <>\n {workspaceNotification}\n {notifications.map((notification, i) => (\n <ToastNotification\n top={toastOffsetTop + (TOAST_HEIGHT + toastContainerContentGap) * i}\n notification={notification}\n key={notification.id}\n />\n ))}\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;AAsBA,MAAM,cAAiB,GAAA,EAAA;AAEvB,MAAM,oBAAuB,GAAA,GAAA;AAE7B,MAAM,4BAA+B,GAAA,GAAA;AAErC,MAAM,wBAA2B,GAAA,EAAA;AAI1B,MAAM,sBAAsB,CAAC;AAAA,EAClC,oBAAA;AAAA,EACA;AACF,CAAgC,KAAA;AAC9B,EAAA,MAAM,kBAAqB,GAAA,OAAA;AAAA,IACzB,MACE,wBACI,GAAA;AAAA,MACE;AAAA,QACE,GAAG,wBAAA;AAAA,QACH,IAAI,WAAY;AAAA;AAClB,QAEF,EAAC;AAAA,IACP,CAAC,wBAAwB;AAAA,GAC3B;AAEA,EAAA,MAAM,CAAC,qBAAA,EAAuB,wBAAwB,CAAA,GACpD,SAAoB,IAAI,CAAA;AAE1B,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GACpC,SAAoC,kBAAkB,CAAA;AAExD,EAAM,MAAA,gBAAA,GAAmB,WAAY,CAAA,CAAC,YAA+B,KAAA;AACnE,IAAI,IAAA,mBAAA,CAAoB,YAAY,CAAG,EAAA;AACrC,MAAA,IAAI,aAAa,iBAAmB,EAAA;AAClC,QAAA,eAAA,CAAgB,sBAAwB,EAAA;AAAA,UACtC,GAAG,YAAA;AAAA,UACH,OAAS,EAAA,iBAAK,IAAA,IAAA,EAAS,GAAA;AAAA,SACxB,CAAA;AAAA,OACI,MAAA;AACL,QAAA,MAAM,eAA2C,GAAA;AAAA,UAC/C,GAAG,YAAA;AAAA,UACH,IAAI,WAAY;AAAA,SAClB;AACA,QAAA,gBAAA,CA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ificationsCenter.tsx"],"sourcesContent":["import { getUniqueId, saveLocalEntity } from \"@vuu-ui/vuu-utils\";\nimport {\n ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n isToastNotification,\n isWorkspaceNotification,\n Notification,\n NotificationsContext,\n ToastNotificationDescriptor,\n} from \"./NotificationsContext\";\nimport { ToastHoverHandler, ToastNotification } from \"./ToastNotification\";\nimport { WorkspaceNotification } from \"./WorkspaceNotification\";\nimport { MeasuredSize } from \"@vuu-ui/vuu-ui-controls\";\n\nconst ZeroSize: MeasuredSize = { height: 0, width: 0 };\nconst toastContainerRightPadding = 20;\nconst NO_NOTIFICATIONS: RuntimeToastNotification[] = [];\nexport interface NotificationsCenterProps {\n notificationsContext: NotificationsContext;\n startupToastNotification?: ToastNotificationDescriptor;\n}\n\ntype TransitionStatus = \"entry\" | \"exit\";\ninterface RuntimeToastNotification extends ToastNotificationDescriptor {\n hidden: boolean;\n id: string;\n left: number;\n opacity?: number;\n size: MeasuredSize;\n transitionStatus?: TransitionStatus;\n}\n\n// animation times in milliseconds\nconst toastOffsetTop = 60;\nconst toastDisplayDuration = 6000;\nconst toastDisplayDurationPostHover = 2000;\n\nconst toastContainerContentGap = 10;\n// rightPadding is used together with the toastWidth to compute the toast position\n// at the beginning and at the end of the animation\n\nexport const NotificationsCenter = ({\n notificationsContext,\n startupToastNotification,\n}: NotificationsCenterProps) => {\n const toastNotifications = useMemo<RuntimeToastNotification[]>(\n () =>\n startupToastNotification\n ? [\n {\n ...startupToastNotification,\n hidden: false,\n id: getUniqueId(),\n left: -1,\n size: ZeroSize,\n },\n ]\n : [],\n [startupToastNotification],\n );\n\n const [workspaceNotification, setWorkspaceNotification] =\n useState<ReactNode>(null);\n\n const hoveredToastRef = useRef<string | undefined>(undefined);\n const notificationsRef = useRef<RuntimeToastNotification[]>(NO_NOTIFICATIONS);\n const [notifications, _setNotifications] =\n useState<RuntimeToastNotification[]>(toastNotifications);\n\n const setNotifications = useCallback(\n (notifications: RuntimeToastNotification[]) => {\n _setNotifications((notificationsRef.current = notifications));\n },\n [],\n );\n\n const showNotification = useCallback(\n (notification: Notification) => {\n if (isToastNotification(notification)) {\n const { animationType = \"none\", renderPostRefresh } = notification;\n if (renderPostRefresh) {\n saveLocalEntity(\"startup-notification\", {\n ...notification,\n expires: +new Date() + 10000,\n });\n } else {\n if (animationType.includes(\"slide-in\")) {\n setNotifications(\n notificationsRef.current.concat({\n ...notification,\n hidden: true,\n id: getUniqueId(),\n left: -1,\n size: ZeroSize,\n }),\n );\n } else\n setNotifications(\n notificationsRef.current.concat({\n ...notification,\n hidden: false,\n id: getUniqueId(),\n left: -1,\n opacity: 0,\n size: ZeroSize,\n }),\n );\n }\n } else if (isWorkspaceNotification(notification)) {\n setWorkspaceNotification(\n <WorkspaceNotification>{notification.content}</WorkspaceNotification>,\n );\n } else {\n throw Error(\"[NotificationsCenter] invalid notification received\");\n }\n },\n [setNotifications],\n );\n\n const hideNotification = useCallback(() => {\n setWorkspaceNotification(null);\n }, []);\n\n useMemo(() => {\n notificationsContext.setNotify(showNotification, hideNotification);\n }, [hideNotification, notificationsContext, showNotification]);\n\n const onMeasured = useCallback(\n (id: string, height: number, width: number) => {\n let scheduledUpdate: RuntimeToastNotification | undefined = undefined;\n const pageWidth = document.body.clientWidth;\n\n setNotifications(\n notificationsRef.current.map((n) => {\n if (n.id === id) {\n const slideIn = n.animationType?.includes(\"slide-in\");\n const newToast: RuntimeToastNotification = {\n ...n,\n hidden: slideIn ? true : false,\n left: slideIn\n ? pageWidth + width - toastContainerRightPadding\n : pageWidth - width - toastContainerRightPadding,\n size: { height, width },\n transitionStatus: \"entry\",\n };\n\n if (slideIn) {\n scheduledUpdate = {\n ...newToast,\n hidden: false,\n left: pageWidth - width - toastContainerRightPadding,\n };\n } else {\n scheduledUpdate = {\n ...newToast,\n opacity: 1,\n };\n }\n\n return newToast;\n } else {\n return n;\n }\n }),\n );\n\n if (scheduledUpdate) {\n const updateNotifications = notificationsRef.current.map((n) => {\n if (n.id === scheduledUpdate?.id) {\n return scheduledUpdate;\n } else {\n return n;\n }\n });\n requestAnimationFrame(() => {\n setNotifications(updateNotifications);\n });\n }\n },\n [setNotifications],\n );\n\n useEffect(() => {\n // This handles both the entry transition and the exit transition\n document.body.addEventListener(\"transitionend\", (e) => {\n const { classList, id } = e.target as HTMLElement;\n if (classList?.contains(\"vuuToastNotification\")) {\n const notification = notificationsRef.current.find((n) => n.id === id);\n if (notification?.transitionStatus === \"exit\") {\n setNotifications(notificationsRef.current.filter((n) => n.id !== id));\n } else if (notification?.dismissal !== \"manual\") {\n setTimeout(() => {\n // In case notification has been manually cancelled ...\n if (notification && hoveredToastRef.current !== id) {\n const pageWidth = document.body.clientWidth;\n setNotifications(\n notificationsRef.current\n .map((n) => {\n if (n.id === id) {\n if (n.animationType?.includes(\"slide-out\")) {\n return {\n ...n,\n transitionStatus: \"exit\" as TransitionStatus,\n left: pageWidth + toastContainerRightPadding,\n };\n } else {\n return {\n ...n,\n transitionStatus: \"exit\" as TransitionStatus,\n opacity: 0,\n };\n }\n } else {\n return n;\n }\n })\n .filter((v) => v !== null),\n );\n }\n }, toastDisplayDuration);\n }\n }\n });\n }, [setNotifications]);\n\n const handleDismiss = useCallback(\n (id?: string) => {\n if (id) {\n setNotifications(notificationsRef.current.filter((n) => n.id !== id));\n }\n },\n [setNotifications],\n );\n\n const handleHoverEntry = useCallback<ToastHoverHandler>((id) => {\n hoveredToastRef.current = id;\n }, []);\n\n const handleHoverExit = useCallback<ToastHoverHandler>(\n (id) => {\n hoveredToastRef.current = undefined;\n const notification = notificationsRef.current.find((n) => n.id === id);\n setTimeout(() => {\n // In case notification has been manually cancelled ...\n if (notification) {\n const pageWidth = document.body.clientWidth;\n setNotifications(\n notificationsRef.current\n .map((n) => {\n if (n.id === id) {\n if (n.animationType?.includes(\"slide-out\")) {\n return {\n ...n,\n transitionStatus: \"exit\" as TransitionStatus,\n left: pageWidth + toastContainerRightPadding,\n };\n } else {\n return {\n ...n,\n transitionStatus: \"exit\" as TransitionStatus,\n opacity: 0,\n };\n }\n } else {\n return n;\n }\n })\n .filter((v) => v !== null),\n );\n }\n }, toastDisplayDurationPostHover);\n },\n [setNotifications],\n );\n\n return (\n <>\n {workspaceNotification}\n {notifications.map(\n ({ hidden, id, left = 0, opacity, size, ...toast }, i) => {\n const height = size ? size.height : 80;\n return (\n <ToastNotification\n hidden={hidden}\n id={id}\n key={id}\n left={left}\n notification={toast}\n onHoverEntry={handleHoverEntry}\n onHoverExit={handleHoverExit}\n onMeasured={onMeasured}\n onDismiss={handleDismiss}\n opacity={opacity}\n top={toastOffsetTop + (height + toastContainerContentGap) * i}\n />\n );\n },\n )}\n </>\n );\n};\n"],"names":["notifications"],"mappings":";;;;;;;AAoBA,MAAM,QAAyB,GAAA,EAAE,MAAQ,EAAA,CAAA,EAAG,OAAO,CAAE,EAAA;AACrD,MAAM,0BAA6B,GAAA,EAAA;AACnC,MAAM,mBAA+C,EAAC;AAiBtD,MAAM,cAAiB,GAAA,EAAA;AACvB,MAAM,oBAAuB,GAAA,GAAA;AAC7B,MAAM,6BAAgC,GAAA,GAAA;AAEtC,MAAM,wBAA2B,GAAA,EAAA;AAI1B,MAAM,sBAAsB,CAAC;AAAA,EAClC,oBAAA;AAAA,EACA;AACF,CAAgC,KAAA;AAC9B,EAAA,MAAM,kBAAqB,GAAA,OAAA;AAAA,IACzB,MACE,wBACI,GAAA;AAAA,MACE;AAAA,QACE,GAAG,wBAAA;AAAA,QACH,MAAQ,EAAA,KAAA;AAAA,QACR,IAAI,WAAY,EAAA;AAAA,QAChB,IAAM,EAAA,CAAA,CAAA;AAAA,QACN,IAAM,EAAA;AAAA;AACR,QAEF,EAAC;AAAA,IACP,CAAC,wBAAwB;AAAA,GAC3B;AAEA,EAAA,MAAM,CAAC,qBAAA,EAAuB,wBAAwB,CAAA,GACpD,SAAoB,IAAI,CAAA;AAE1B,EAAM,MAAA,eAAA,GAAkB,OAA2B,KA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AEA,EAAA,uBAEK,IAAA,CAAA,QAAA,EAAA,EAAA,QAAA,EAAA;AAAA,IAAA,qBAAA;AAAA,IACA,aAAc,CAAA,GAAA;AAAA,MACb,CAAC,EAAE,MAAA,EAAQ,EAAI,EAAA,IAAA,GAAO,CAAG,EAAA,OAAA,EAAS,IAAM,EAAA,GAAG,KAAM,EAAA,EAAG,CAAM,KAAA;AACxD,QAAM,MAAA,MAAA,GAAS,IAAO,GAAA,IAAA,CAAK,MAAS,GAAA,EAAA;AACpC,QACE,uBAAA,GAAA;AAAA,UAAC,iBAAA;AAAA,UAAA;AAAA,YACC,MAAA;AAAA,YACA,EAAA;AAAA,YAEA,IAAA;AAAA,YACA,YAAc,EAAA,KAAA;AAAA,YACd,YAAc,EAAA,gBAAA;AAAA,YACd,WAAa,EAAA,eAAA;AAAA,YACb,UAAA;AAAA,YACA,SAAW,EAAA,aAAA;AAAA,YACX,OAAA;AAAA,YACA,GAAA,EAAK,cAAkB,GAAA,CAAA,MAAA,GAAS,wBAA4B,IAAA;AAAA,WAAA;AAAA,UARvD;AAAA,SASP;AAAA;AAEJ;AACF,GACF,EAAA,CAAA;AAEJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationsContext.js","sources":["../../../packages/vuu-notifications/src/NotificationsContext.tsx"],"sourcesContent":["import { type ValidationStatus } from \"@salt-ds/core\";\nimport { ValueOf } from \"@vuu-ui/vuu-utils\";\nimport { ReactNode } from \"react\";\n\nexport type DispatchShowNotification = (notification: Notification) => void;\nexport type DispatchHideNotification = () => void;\n\nexport const NotificationType = {\n Toast: \"toast\",\n Workspace: \"workspace\",\n} as const;\n\nexport type NotificationType = ValueOf<typeof NotificationType>;\n\nexport type NotificationAnimationType =\n | \"slide-in\"\n | \"slide-out\"\n | \"slide-in,slide-out\";\n\ninterface NotificationDescriptorBase<T extends NotificationType> {\n animationType?: NotificationAnimationType;\n renderPostRefresh?: boolean;\n status: ValidationStatus;\n type: T;\n}\n\nexport interface ToastNotificationDescriptor\n extends NotificationDescriptorBase<\"toast\"> {\n content
|
|
1
|
+
{"version":3,"file":"NotificationsContext.js","sources":["../../../packages/vuu-notifications/src/NotificationsContext.tsx"],"sourcesContent":["import { type ValidationStatus } from \"@salt-ds/core\";\nimport { ValueOf } from \"@vuu-ui/vuu-utils\";\nimport { ReactNode } from \"react\";\n\nexport type DispatchShowNotification = (notification: Notification) => void;\nexport type DispatchHideNotification = () => void;\n\nexport const NotificationType = {\n Toast: \"toast\",\n Workspace: \"workspace\",\n} as const;\n\nexport type NotificationType = ValueOf<typeof NotificationType>;\n\nexport type DismissalStyle = \"automatic\" | \"manual\";\n\nexport type NotificationAnimationType =\n | \"slide-in\"\n | \"slide-out\"\n | \"slide-in,slide-out\";\n\ninterface NotificationDescriptorBase<T extends NotificationType> {\n animationType?: NotificationAnimationType;\n /**\n * 'automatic' dismissal means the Notification will be removed after a configurable delay\n * (6 seconds by default). 'manual' means a close button will be rendered and user must\n * manually dismiss by clicking the close button.\n */\n dismissal?: DismissalStyle;\n /**\n * A custom icon can be provided or false can be used to suppress rendering of any icon.\n * Default icons will be rendered for the different status values.\n */\n icon?: string | false;\n renderPostRefresh?: boolean;\n showCloseButton?: boolean;\n status: ValidationStatus;\n type: T;\n}\n\nexport interface ToastNotificationDescriptor\n extends NotificationDescriptorBase<\"toast\"> {\n content?: ReactNode;\n header: string;\n}\n\nexport interface WorkspaceNotificationDescriptor\n extends NotificationDescriptorBase<\"workspace\"> {\n content: ReactNode;\n}\n\nexport type Notification =\n | ToastNotificationDescriptor\n | WorkspaceNotificationDescriptor;\n\nexport const isToastNotification = (\n n: Notification,\n): n is ToastNotificationDescriptor => n.type === NotificationType.Toast;\n\nexport const isWorkspaceNotification = (\n n: Notification,\n): n is WorkspaceNotificationDescriptor =>\n n.type === NotificationType.Workspace;\n\nexport type NotificationsContext = {\n hideNotification: DispatchHideNotification;\n showNotification: DispatchShowNotification;\n setNotify: (\n showNotificationDispatcher: DispatchShowNotification,\n hideNotificationDispatcher: DispatchHideNotification,\n ) => void;\n};\n"],"names":[],"mappings":"AAOO,MAAM,gBAAmB,GAAA;AAAA,EAC9B,KAAO,EAAA,OAAA;AAAA,EACP,SAAW,EAAA;AACb;AA6CO,MAAM,mBAAsB,GAAA,CACjC,CACqC,KAAA,CAAA,CAAE,SAAS,gBAAiB,CAAA;AAE5D,MAAM,uBAA0B,GAAA,CACrC,CAEA,KAAA,CAAA,CAAE,SAAS,gBAAiB,CAAA;;;;"}
|
|
@@ -33,7 +33,6 @@ const NotificationsContext = React.createContext(
|
|
|
33
33
|
new NotificationsContextObject()
|
|
34
34
|
);
|
|
35
35
|
const NotificationsProvider = (props) => {
|
|
36
|
-
console.log(`%c[NotificationsProvider]`, "color:green;font-weight: bold;");
|
|
37
36
|
const context = useContext(NotificationsContext);
|
|
38
37
|
const startupToastNotification = useMemo(() => {
|
|
39
38
|
const toast = getLocalEntity("startup-notification", true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationsProvider.js","sources":["../../../packages/vuu-notifications/src/NotificationsProvider.tsx"],"sourcesContent":["import React, { ReactElement, useContext, useMemo } from \"react\";\nimport { NotificationsCenter } from \"./NotificationsCenter\";\nimport {\n DispatchHideNotification,\n DispatchShowNotification,\n type NotificationsContext,\n ToastNotificationDescriptor,\n} from \"./NotificationsContext\";\nimport { getLocalEntity } from \"@vuu-ui/vuu-utils\";\n\ninterface ToastWithExpiry extends ToastNotificationDescriptor {\n expires: number;\n}\n\n/*\n The Context is not exposed outside this module, only the notify\n prop can be accessed via the useNotifications hook.\n The NotificationsCenter receives the full context object and\n sets the notify method. State management around dispatched\n notifications is handled entirely within the NotificationsCenter,\n avoiding rerendering our children when notifications are \n dispatched.\n*/\nclass NotificationsContextObject implements NotificationsContext {\n #showNotification: DispatchShowNotification = () =>\n console.log(\"have you forgotten to provide a NotificationsCenter?\");\n #hideNotification: DispatchHideNotification = () =>\n console.log(\"have you forgotten to provide a NotificationsCenter?\");\n // We want the public notify method to be stable, setNotify call should not trigger re-renders\n showNotification: DispatchShowNotification = (notification) =>\n this.#showNotification(notification);\n hideNotification: DispatchHideNotification = () => this.#hideNotification();\n setNotify = (\n showNotificationDispatcher: DispatchShowNotification,\n hideNotificationDispatcher: DispatchHideNotification,\n ) => {\n this.#showNotification = showNotificationDispatcher;\n this.#hideNotification = hideNotificationDispatcher;\n };\n}\n\nconst NotificationsContext = React.createContext<NotificationsContext>(\n new NotificationsContextObject(),\n);\n\nexport const NotificationsProvider = (props: {\n children: ReactElement | ReactElement[];\n}) => {\n
|
|
1
|
+
{"version":3,"file":"NotificationsProvider.js","sources":["../../../packages/vuu-notifications/src/NotificationsProvider.tsx"],"sourcesContent":["import React, { ReactElement, useContext, useMemo } from \"react\";\nimport { NotificationsCenter } from \"./NotificationsCenter\";\nimport {\n DispatchHideNotification,\n DispatchShowNotification,\n type NotificationsContext,\n ToastNotificationDescriptor,\n} from \"./NotificationsContext\";\nimport { getLocalEntity } from \"@vuu-ui/vuu-utils\";\n\ninterface ToastWithExpiry extends ToastNotificationDescriptor {\n expires: number;\n}\n\n/*\n The Context is not exposed outside this module, only the notify\n prop can be accessed via the useNotifications hook.\n The NotificationsCenter receives the full context object and\n sets the notify method. State management around dispatched\n notifications is handled entirely within the NotificationsCenter,\n avoiding rerendering our children when notifications are \n dispatched.\n*/\nclass NotificationsContextObject implements NotificationsContext {\n #showNotification: DispatchShowNotification = () =>\n console.log(\"have you forgotten to provide a NotificationsCenter?\");\n #hideNotification: DispatchHideNotification = () =>\n console.log(\"have you forgotten to provide a NotificationsCenter?\");\n // We want the public notify method to be stable, setNotify call should not trigger re-renders\n showNotification: DispatchShowNotification = (notification) =>\n this.#showNotification(notification);\n hideNotification: DispatchHideNotification = () => this.#hideNotification();\n setNotify = (\n showNotificationDispatcher: DispatchShowNotification,\n hideNotificationDispatcher: DispatchHideNotification,\n ) => {\n this.#showNotification = showNotificationDispatcher;\n this.#hideNotification = hideNotificationDispatcher;\n };\n}\n\nconst NotificationsContext = React.createContext<NotificationsContext>(\n new NotificationsContextObject(),\n);\n\nexport const NotificationsProvider = (props: {\n children: ReactElement | ReactElement[];\n}) => {\n const context = useContext(NotificationsContext);\n const startupToastNotification = useMemo<\n ToastNotificationDescriptor | undefined\n >(() => {\n const toast = getLocalEntity<ToastWithExpiry>(\"startup-notification\", true);\n if (toast && toast.expires >= +Date.now()) {\n const { expires, ...toastDescriptor } = toast;\n return toastDescriptor;\n }\n }, []);\n return (\n <NotificationsContext.Provider value={context}>\n <NotificationsCenter\n startupToastNotification={startupToastNotification}\n notificationsContext={context}\n />\n {props.children}\n </NotificationsContext.Provider>\n );\n};\n\nexport const useNotifications = () => {\n const { hideNotification, showNotification } =\n useContext(NotificationsContext);\n return { hideNotification, showNotification };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,IAAA,iBAAA,EAAA,iBAAA;AAuBA,MAAM,0BAA2D,CAAA;AAAA,EAAjE,WAAA,GAAA;AACE,IAA8C,YAAA,CAAA,IAAA,EAAA,iBAAA,EAAA,MAC5C,OAAQ,CAAA,GAAA,CAAI,sDAAsD,CAAA,CAAA;AACpE,IAA8C,YAAA,CAAA,IAAA,EAAA,iBAAA,EAAA,MAC5C,OAAQ,CAAA,GAAA,CAAI,sDAAsD,CAAA,CAAA;AAEpE;AAAA,IAAA,aAAA,CAAA,IAAA,EAAA,kBAAA,EAA6C,CAAC,YAAA,KAC5C,YAAK,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAL,IAAuB,CAAA,IAAA,EAAA,YAAA,CAAA,CAAA;AACzB,IAA6C,aAAA,CAAA,IAAA,EAAA,kBAAA,EAAA,MAAM,mBAAK,iBAAL,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,CAAA;AACnD,IAAY,aAAA,CAAA,IAAA,EAAA,WAAA,EAAA,CACV,4BACA,0BACG,KAAA;AACH,MAAA,YAAA,CAAA,IAAA,EAAK,iBAAoB,EAAA,0BAAA,CAAA;AACzB,MAAA,YAAA,CAAA,IAAA,EAAK,iBAAoB,EAAA,0BAAA,CAAA;AAAA,KAC3B,CAAA;AAAA;AACF;AAfE,iBAAA,GAAA,IAAA,OAAA,EAAA;AAEA,iBAAA,GAAA,IAAA,OAAA,EAAA;AAeF,MAAM,uBAAuB,KAAM,CAAA,aAAA;AAAA,EACjC,IAAI,0BAA2B;AACjC,CAAA;AAEa,MAAA,qBAAA,GAAwB,CAAC,KAEhC,KAAA;AACJ,EAAM,MAAA,OAAA,GAAU,WAAW,oBAAoB,CAAA;AAC/C,EAAM,MAAA,wBAAA,GAA2B,QAE/B,MAAM;AACN,IAAM,MAAA,KAAA,GAAQ,cAAgC,CAAA,sBAAA,EAAwB,IAAI,CAAA;AAC1E,IAAA,IAAI,SAAS,KAAM,CAAA,OAAA,IAAW,CAAC,IAAA,CAAK,KAAO,EAAA;AACzC,MAAA,MAAM,EAAE,OAAA,EAAS,GAAG,eAAA,EAAoB,GAAA,KAAA;AACxC,MAAO,OAAA,eAAA;AAAA;AACT,GACF,EAAG,EAAE,CAAA;AACL,EAAA,uBACG,IAAA,CAAA,oBAAA,CAAqB,QAArB,EAAA,EAA8B,OAAO,OACpC,EAAA,QAAA,EAAA;AAAA,oBAAA,GAAA;AAAA,MAAC,mBAAA;AAAA,MAAA;AAAA,QACC,wBAAA;AAAA,QACA,oBAAsB,EAAA;AAAA;AAAA,KACxB;AAAA,IACC,KAAM,CAAA;AAAA,GACT,EAAA,CAAA;AAEJ;AAEO,MAAM,mBAAmB,MAAM;AACpC,EAAA,MAAM,EAAE,gBAAA,EAAkB,gBAAiB,EAAA,GACzC,WAAW,oBAAoB,CAAA;AACjC,EAAO,OAAA,EAAE,kBAAkB,gBAAiB,EAAA;AAC9C;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var toastNotificationCss = ".vuuToastNotification {\n\n background: var(--
|
|
1
|
+
var toastNotificationCss = ".vuuToastNotification {\n --toast-transition-duration: .4s;\n --padding-base: var(--vuuToast-padding, var(--salt-spacing-300));\n\n align-items: center;;\n background: var(--vuuToast-background, var(--toast-background));\n border-radius: var(--vuuToast-borderRadius, var(--salt-curve-100, 0));\n box-sizing: border-box;\n box-shadow: var(--salt-overlayable-shadow-popout);\n color: var(--vuuToast-foreground, var(--toast-foreground));\n column-gap: var(--salt-spacing-100);\n display: grid;\n grid-template-areas: var(--vuuToast-grid-template-areas, \n \"toast-header\"\n );\n grid-template-columns: auto;\n max-width: var(--vuuToast-maxWidth, 600px);\n min-width: var(--vuuToast-minWidth, 300px);\n opacity: 1;\n padding: var(--padding-base);\n row-gap: var(--salt-spacing-100);\n transition: opacity .4s, top;\n\n &.vuuToastNotification-hidden {\n visibility: hidden;\n }\n\n &.vuuToastNotification-withCloseButton {\n grid-template-areas: var(--vuuToast-grid-template-areas, \n \"toast-header close-button\"\n );\n grid-template-columns: 1fr 36px;\n }\n\n &.vuuToastNotification-withIcon {\n grid-template-areas: var(--vuuToast-grid-template-areas, \n \"toast-icon toast-header\"\n );\n grid-template-columns: var(--vuuToast-gridTemplateColumns, 36px auto);\n }\n\n &.vuuToastNotification-withIcon.vuuToastNotification-withCloseButton {\n grid-template-areas: var(--vuuToast-grid-template-areas, \n \"toast-icon toast-header close-button\"\n );\n grid-template-columns: var(--vuuToast-gridTemplateColumns, 36px auto 36px);\n }\n\n &.vuuToastNotification-withContent {\n grid-template-areas: var(--vuuToast-grid-template-areas, \n \"toast-header\"\n \"toast-content\"\n );\n }\n &.vuuToastNotification-withContent.vuuToastNotification-withCloseButton {\n grid-template-areas: var(--vuuToast-grid-template-areas, \n \"toast-header close-button\"\n \"toast-content close-button\"\n );\n grid-template-columns: 1fr 36px;\n }\n\n &.vuuToastNotification-withTransition {\n transition: top .2s ease-out, left var(--toast-transition-duration) ease-in, opacity .4s;\n }\n\n &.vuuToastNotification-transparent {\n opacity: 0;\n transition: top .2s ease-out, opacity .4s;\n }\n\n &.vuuToastNotification-withIcon.vuuToastNotification-withContent {\n grid-template-areas: var(--vuuToast-grid-template-areas, \n \"toast-icon toast-header\"\n \"toast-icon toast-content\"\n );\n grid-template-columns: var(--vuuToast-gridTemplateColumns, 36px auto);\n }\n\n &.vuuToastNotification-withIcon.vuuToastNotification-withContent.vuuToastNotification-withCloseButton {\n grid-template-areas: var(--vuuToast-grid-template-areas, \n \"toast-icon toast-header close-button\"\n \"toast-icon toast-content close-button\"\n );\n grid-template-columns: var(--vuuToast-gridTemplateColumns, 36px auto 36px);\n }\n\n &.vuuToastNotification-error {\n --toast-background: var(--vuuToast-error-background, var(--salt-container-primary-background));\n --toast-foreground: var(--vuuToast-error-foreground, var(--salt-content-primary-foreground));\n }\n\n &.vuuToastNotification-success {\n --toast-background: var(--vuuToast-success-background, var(--salt-container-primary-background));\n --toast-foreground: var(--vuuToast-success-foreground, var(--salt-content-primary-foreground));\n --vuu-icon-svg: var(--vuuToast-success-icon, var(--vuu-svg-tick));\n }\n &.vuuToastNotification-warning {\n --toast-background: var(--vuuToast-warning-background, var(--salt-container-primary-background));\n --toast-foreground: var(--vuuToast-warning-foreground, var(--salt-content-primary-foreground));\n --vuu-icon-svg: var(--vuuToast-warning-icon, var(--vuu-svg-tick));\n }\n &.vuuToastNotification-info {\n --toast-background: var(--vuuToast-info-background, var(--salt-container-primary-background));\n --toast-foreground: var(--vuuToast-info-foreground, var(--salt-content-primary-foreground));\n --vuu-icon-svg: var(--vuuToast-info-icon, var(--vuu-svg-tick));\n }\n\n .vuuIcon {\n --vuu-icon-color: var(--toast-foreground);\n --vuu-icon-size: 20px;\n grid-area:toast-icon;\n justify-self: center;\n }\n\n .vuuToastNotification-header {\n font-size: var(--vuuToast-header-fontSize, var(--salt-text-h3-fontSize));\n font-weight: var(--salt-text-display1-fontWeight-strong);\n grid-area: toast-header;\n justify-self: start;\n line-height: var(--salt-text-h3-lineHeight);\n margin: 0;\n white-space: nowrap;\n }\n\n .vuuToastNotification-content {\n grid-area: toast-content;\n justify-self: start;\n }\n\n .vuuToastNotification-closeButton.saltButton {\n grid-area: close-button;\n justify-self: center;\n .vuuIcon {\n --vuu-icon-size: 16px;\n }\n }\n\n}";
|
|
2
2
|
|
|
3
3
|
export { toastNotificationCss as default };
|
|
4
4
|
//# sourceMappingURL=ToastNotification.css.js.map
|
package/esm/ToastNotification.js
CHANGED
|
@@ -1,79 +1,110 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import cx from 'clsx';
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
2
|
import { useFloatingComponent } from '@salt-ds/core';
|
|
4
|
-
import { useMemo, useState, useEffect } from 'react';
|
|
5
3
|
import { useComponentCssInjection } from '@salt-ds/styles';
|
|
6
4
|
import { useWindow } from '@salt-ds/window';
|
|
5
|
+
import { Icon, IconButton } from '@vuu-ui/vuu-ui-controls';
|
|
6
|
+
import cx from 'clsx';
|
|
7
|
+
import { useCallback } from 'react';
|
|
7
8
|
import toastNotificationCss from './ToastNotification.css.js';
|
|
8
9
|
|
|
9
|
-
const toastContainerRightPadding = 20;
|
|
10
|
-
const toastDisplayDuration = 12e5;
|
|
11
|
-
const horizontalTransitionDuration = 400;
|
|
12
|
-
const TOAST_HEIGHT = 80;
|
|
13
|
-
const TOAST_WIDTH = 300;
|
|
14
|
-
const verticalTransitionDuration = 300;
|
|
15
10
|
const classBase = "vuuToastNotification";
|
|
16
|
-
const ToastNotification = (
|
|
11
|
+
const ToastNotification = ({
|
|
12
|
+
hidden,
|
|
13
|
+
id,
|
|
14
|
+
left,
|
|
15
|
+
onDismiss,
|
|
16
|
+
onMeasured,
|
|
17
|
+
top,
|
|
18
|
+
notification,
|
|
19
|
+
onHoverEntry,
|
|
20
|
+
onHoverExit,
|
|
21
|
+
opacity = 1
|
|
22
|
+
}) => {
|
|
17
23
|
const targetWindow = useWindow();
|
|
18
24
|
useComponentCssInjection({
|
|
19
25
|
testId: "vuu-toast-notification",
|
|
20
26
|
css: toastNotificationCss,
|
|
21
27
|
window: targetWindow
|
|
22
28
|
});
|
|
23
|
-
const { top, notification, animated = true } = props;
|
|
24
29
|
const { Component: FloatingComponent } = useFloatingComponent();
|
|
25
|
-
const {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const {
|
|
31
|
+
animationType,
|
|
32
|
+
content,
|
|
33
|
+
dismissal,
|
|
34
|
+
header,
|
|
35
|
+
icon,
|
|
36
|
+
showCloseButton,
|
|
37
|
+
status
|
|
38
|
+
} = notification;
|
|
39
|
+
const iconName = icon === false ? void 0 : icon ?? status;
|
|
40
|
+
const callbackRef = useCallback(
|
|
41
|
+
(el) => {
|
|
42
|
+
if (el) {
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
const { height, width } = el.getBoundingClientRect();
|
|
45
|
+
if (id) {
|
|
46
|
+
onMeasured?.(id, height, width);
|
|
47
|
+
}
|
|
48
|
+
}, 60);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
[id, onMeasured]
|
|
30
52
|
);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
const handleDismiss = useCallback(() => {
|
|
54
|
+
onDismiss?.(id);
|
|
55
|
+
}, [id, onDismiss]);
|
|
56
|
+
const handleMouseEnter = useCallback(
|
|
57
|
+
() => onHoverEntry?.(id),
|
|
58
|
+
[id, onHoverEntry]
|
|
59
|
+
);
|
|
60
|
+
const handleMouseLeave = useCallback(
|
|
61
|
+
() => onHoverExit?.(id),
|
|
62
|
+
[id, onHoverExit]
|
|
63
|
+
);
|
|
64
|
+
if (dismissal === "manual" && showCloseButton === false) {
|
|
65
|
+
console.warn(
|
|
66
|
+
"[ToastNotification] invalid props, if dismissal is manual, showCloseButton should not be false"
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const withCloseButton = showCloseButton || dismissal === "manual";
|
|
70
|
+
return /* @__PURE__ */ jsxs(
|
|
47
71
|
FloatingComponent,
|
|
48
72
|
{
|
|
49
|
-
className: cx(
|
|
50
|
-
classBase,
|
|
51
|
-
`${classBase}
|
|
52
|
-
`${classBase}
|
|
53
|
-
|
|
73
|
+
className: cx(classBase, `${classBase}-${notification.status}`, {
|
|
74
|
+
[`${classBase}-hidden`]: hidden,
|
|
75
|
+
[`${classBase}-transparent`]: opacity === 0,
|
|
76
|
+
[`${classBase}-withContent`]: content !== void 0,
|
|
77
|
+
[`${classBase}-withIcon`]: icon !== false,
|
|
78
|
+
[`${classBase}-withTransition`]: animationType !== void 0 && !hidden,
|
|
79
|
+
[`${classBase}-withCloseButton`]: withCloseButton
|
|
80
|
+
}),
|
|
81
|
+
id,
|
|
54
82
|
left,
|
|
83
|
+
onMouseEnter: handleMouseEnter,
|
|
84
|
+
onMouseLeave: handleMouseLeave,
|
|
55
85
|
open: true,
|
|
56
86
|
position: "absolute",
|
|
87
|
+
ref: callbackRef,
|
|
88
|
+
role: "alert",
|
|
57
89
|
top,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
90
|
+
children: [
|
|
91
|
+
iconName ? /* @__PURE__ */ jsx(Icon, { name: iconName }) : null,
|
|
92
|
+
/* @__PURE__ */ jsx("h3", { className: `${classBase}-header`, children: header }),
|
|
93
|
+
content ? /* @__PURE__ */ jsx("div", { className: `${classBase}-content`, children: content }) : null,
|
|
94
|
+
withCloseButton ? /* @__PURE__ */ jsx(
|
|
95
|
+
IconButton,
|
|
96
|
+
{
|
|
97
|
+
className: `${classBase}-closeButton`,
|
|
98
|
+
icon: "close",
|
|
99
|
+
onClick: handleDismiss,
|
|
100
|
+
appearance: "transparent",
|
|
101
|
+
sentiment: "neutral"
|
|
102
|
+
}
|
|
103
|
+
) : null
|
|
104
|
+
]
|
|
74
105
|
}
|
|
75
106
|
);
|
|
76
107
|
};
|
|
77
108
|
|
|
78
|
-
export {
|
|
109
|
+
export { ToastNotification };
|
|
79
110
|
//# sourceMappingURL=ToastNotification.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToastNotification.js","sources":["../../../packages/vuu-notifications/src/ToastNotification.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"ToastNotification.js","sources":["../../../packages/vuu-notifications/src/ToastNotification.tsx"],"sourcesContent":["import { useFloatingComponent } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { Icon, IconButton } from \"@vuu-ui/vuu-ui-controls\";\nimport cx from \"clsx\";\nimport { RefCallback, useCallback } from \"react\";\nimport type { ToastNotificationDescriptor } from \"./NotificationsContext\";\n\nimport toastNotificationCss from \"./ToastNotification.css\";\n\nexport type ToastHoverHandler = (id?: string) => void;\n\nexport type ToastNotificationProps = {\n hidden?: boolean;\n id?: string;\n left?: number;\n notification: ToastNotificationDescriptor;\n onMeasured?: (id: string, height: number, width: number) => void;\n onDismiss?: (id?: string) => void;\n onHoverEntry?: ToastHoverHandler;\n onHoverExit?: ToastHoverHandler;\n opacity?: number;\n top?: number;\n};\n\nconst classBase = \"vuuToastNotification\";\n\nexport const ToastNotification = ({\n hidden,\n id,\n left,\n onDismiss,\n onMeasured,\n top,\n notification,\n onHoverEntry,\n onHoverExit,\n opacity = 1,\n}: ToastNotificationProps) => {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"vuu-toast-notification\",\n css: toastNotificationCss,\n window: targetWindow,\n });\n\n const { Component: FloatingComponent } = useFloatingComponent();\n\n const {\n animationType,\n content,\n dismissal,\n header,\n icon,\n showCloseButton,\n status,\n } = notification;\n\n const iconName = icon === false ? undefined : (icon ?? status);\n\n const callbackRef = useCallback<RefCallback<HTMLDivElement>>(\n (el) => {\n if (el) {\n setTimeout(() => {\n const { height, width } = el.getBoundingClientRect();\n if (id) {\n onMeasured?.(id, height, width);\n }\n }, 60);\n }\n },\n [id, onMeasured],\n );\n\n const handleDismiss = useCallback(() => {\n onDismiss?.(id);\n }, [id, onDismiss]);\n\n const handleMouseEnter = useCallback(\n () => onHoverEntry?.(id),\n [id, onHoverEntry],\n );\n const handleMouseLeave = useCallback(\n () => onHoverExit?.(id),\n [id, onHoverExit],\n );\n\n if (dismissal === \"manual\" && showCloseButton === false) {\n console.warn(\n \"[ToastNotification] invalid props, if dismissal is manual, showCloseButton should not be false\",\n );\n }\n\n const withCloseButton = showCloseButton || dismissal === \"manual\";\n\n return (\n <FloatingComponent\n className={cx(classBase, `${classBase}-${notification.status}`, {\n [`${classBase}-hidden`]: hidden,\n [`${classBase}-transparent`]: opacity === 0,\n [`${classBase}-withContent`]: content !== undefined,\n [`${classBase}-withIcon`]: icon !== false,\n [`${classBase}-withTransition`]: animationType !== undefined && !hidden,\n [`${classBase}-withCloseButton`]: withCloseButton,\n })}\n id={id}\n left={left}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n open\n position=\"absolute\"\n ref={callbackRef}\n role=\"alert\"\n top={top}\n >\n {iconName ? <Icon name={iconName} /> : null}\n <h3 className={`${classBase}-header`}>{header}</h3>\n {content ? <div className={`${classBase}-content`}>{content}</div> : null}\n {withCloseButton ? (\n <IconButton\n className={`${classBase}-closeButton`}\n icon=\"close\"\n onClick={handleDismiss}\n appearance=\"transparent\"\n sentiment=\"neutral\"\n />\n ) : null}\n </FloatingComponent>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AAyBA,MAAM,SAAY,GAAA,sBAAA;AAEX,MAAM,oBAAoB,CAAC;AAAA,EAChC,MAAA;AAAA,EACA,EAAA;AAAA,EACA,IAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;A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AAM,EAAA,QAAA,EAAU,CAAK,GAAA,IAAA;AAAA,4BACtC,IAAG,EAAA,EAAA,SAAA,EAAW,CAAG,EAAA,SAAS,WAAY,QAAO,EAAA,MAAA,EAAA,CAAA;AAAA,QAC7C,OAAA,uBAAW,KAAI,EAAA,EAAA,SAAA,EAAW,GAAG,SAAS,CAAA,QAAA,CAAA,EAAa,mBAAQ,CAAS,GAAA,IAAA;AAAA,QACpE,eACC,mBAAA,GAAA;AAAA,UAAC,UAAA;AAAA,UAAA;AAAA,YACC,SAAA,EAAW,GAAG,SAAS,CAAA,YAAA,CAAA;AAAA,YACvB,IAAK,EAAA,OAAA;AAAA,YACL,OAAS,EAAA,aAAA;AAAA,YACT,UAAW,EAAA,aAAA;AAAA,YACX,SAAU,EAAA;AAAA;AAAA,SAEV,GAAA;AAAA;AAAA;AAAA,GACN;AAEJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0.0
|
|
2
|
+
"version": "2.0.0",
|
|
3
3
|
"description": "VUU notifications - Toast, WorkspaceNotification etc",
|
|
4
4
|
"author": "heswell",
|
|
5
5
|
"license": "Apache-2.0",
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
"@salt-ds/core": "1.54.1",
|
|
8
8
|
"@salt-ds/styles": "0.2.1",
|
|
9
9
|
"@salt-ds/window": "0.1.1",
|
|
10
|
-
"@vuu-ui/vuu-
|
|
10
|
+
"@vuu-ui/vuu-ui-controls": "2.0.0",
|
|
11
|
+
"@vuu-ui/vuu-utils": "2.0.0"
|
|
11
12
|
},
|
|
12
13
|
"peerDependencies": {
|
|
13
14
|
"clsx": "^2.0.0",
|