d9-toast 2.5.42 → 2.5.44
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/README.md +3 -0
- package/dist/Toast.js +27 -41
- package/dist/ToastContext.js +1 -1
- package/dist/toast.css +22 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -287,3 +287,6 @@ MIT © **Athul / D9 Coder**
|
|
|
287
287
|
* 💻 Source: [https://github.com/psathul073/d9-toast](https://github.com/psathul073/d9-toast)
|
|
288
288
|
* 📦 npm: [https://www.npmjs.com/package/d9-toast](https://www.npmjs.com/package/d9-toast)
|
|
289
289
|
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
> See [CHANGELOG](https://psathul073.github.io/d9-toast-docs/docs/Changelog) for details.
|
package/dist/Toast.js
CHANGED
|
@@ -8,16 +8,16 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
8
8
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
9
9
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
10
10
|
import Icons from "./Icons.js";
|
|
11
|
+
|
|
12
|
+
// For animation direction.
|
|
11
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
var
|
|
13
|
-
top
|
|
14
|
-
bottom
|
|
15
|
-
center
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
bottom: "d9-upToDownExit",
|
|
20
|
-
center: "d9-centerExit"
|
|
14
|
+
var getAnimationDirection = function getAnimationDirection(position) {
|
|
15
|
+
if (position.startsWith("top")) return "top";
|
|
16
|
+
if (position.startsWith("bottom")) return "bottom";
|
|
17
|
+
if (position === "center") return "center";
|
|
18
|
+
if (position === "center-top") return "top";
|
|
19
|
+
if (position === "center-bottom") return "bottom";
|
|
20
|
+
return "top";
|
|
21
21
|
};
|
|
22
22
|
var Toast = function Toast(_ref) {
|
|
23
23
|
var id = _ref.id,
|
|
@@ -37,7 +37,7 @@ var Toast = function Toast(_ref) {
|
|
|
37
37
|
_ref$expand = _ref.expand,
|
|
38
38
|
expand = _ref$expand === void 0 ? "hover" : _ref$expand,
|
|
39
39
|
_ref$duration = _ref.duration,
|
|
40
|
-
duration = _ref$duration === void 0 ?
|
|
40
|
+
duration = _ref$duration === void 0 ? 4000 : _ref$duration,
|
|
41
41
|
_ref$actions = _ref.actions,
|
|
42
42
|
actions = _ref$actions === void 0 ? [] : _ref$actions,
|
|
43
43
|
remove = _ref.remove,
|
|
@@ -54,18 +54,19 @@ var Toast = function Toast(_ref) {
|
|
|
54
54
|
pauseOnHover = _ref$pauseOnHover === void 0 ? true : _ref$pauseOnHover,
|
|
55
55
|
_ref$pauseOnFocusLoss = _ref.pauseOnFocusLoss,
|
|
56
56
|
pauseOnFocusLoss = _ref$pauseOnFocusLoss === void 0 ? true : _ref$pauseOnFocusLoss;
|
|
57
|
+
// const [exiting, setExiting] = useState(false);
|
|
57
58
|
var _useState = useState(false),
|
|
58
59
|
_useState2 = _slicedToArray(_useState, 2),
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
isPaused = _useState2[0],
|
|
61
|
+
setIsPaused = _useState2[1];
|
|
61
62
|
var _useState3 = useState(false),
|
|
62
63
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var _useState5 = useState(
|
|
64
|
+
isMounted = _useState4[0],
|
|
65
|
+
setIsMounted = _useState4[1];
|
|
66
|
+
var _useState5 = useState("enter"),
|
|
66
67
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
phase = _useState6[0],
|
|
69
|
+
setPhase = _useState6[1];
|
|
69
70
|
var timeoutRef = useRef(null);
|
|
70
71
|
|
|
71
72
|
// For SSR Safety Guard.
|
|
@@ -74,34 +75,21 @@ var Toast = function Toast(_ref) {
|
|
|
74
75
|
}, []);
|
|
75
76
|
var shouldExpand = expand === "hover" ? isStackHovered : expand;
|
|
76
77
|
var ariaRole = type === "error" ? "alert" : "status";
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var isTop = position.includes("top");
|
|
82
|
-
var isBottom = position.includes("bottom");
|
|
83
|
-
var baseEnter = isTop ? ENTER_ANIMATIONS.top : isBottom ? ENTER_ANIMATIONS.bottom : ENTER_ANIMATIONS.center;
|
|
84
|
-
|
|
85
|
-
// exit animation [reverse direction]
|
|
86
|
-
var baseExit = isTop ? EXIT_ANIMATIONS.top : isBottom ? EXIT_ANIMATIONS.bottom : EXIT_ANIMATIONS.center;
|
|
87
|
-
return {
|
|
88
|
-
enterAnim: "".concat(baseEnter, " 450ms cubic-bezier(0.165, 0.84, 0.44, 1) "),
|
|
89
|
-
exitAnim: "".concat(baseExit, " 300ms ease-in")
|
|
90
|
-
};
|
|
91
|
-
}, [position]),
|
|
92
|
-
enterAnim = _useMemo.enterAnim,
|
|
93
|
-
exitAnim = _useMemo.exitAnim;
|
|
78
|
+
var direction = useMemo(function () {
|
|
79
|
+
return getAnimationDirection(position);
|
|
80
|
+
}, [position]);
|
|
81
|
+
var animationClass = phase === "exit" ? "toast--exit-".concat(direction) : "toast--enter-".concat(direction);
|
|
94
82
|
|
|
95
83
|
// --- Helpers Fun ---
|
|
96
84
|
|
|
97
85
|
// for exit
|
|
98
86
|
var triggerExit = useCallback(function () {
|
|
99
|
-
if (
|
|
100
|
-
|
|
87
|
+
if (phase === "exit") return;
|
|
88
|
+
setPhase("exit");
|
|
101
89
|
timeoutRef.current = setTimeout(function () {
|
|
102
90
|
return remove();
|
|
103
91
|
}, 300); // Set and match exit animation duration.
|
|
104
|
-
}, [remove,
|
|
92
|
+
}, [remove, phase]);
|
|
105
93
|
|
|
106
94
|
// for pause.
|
|
107
95
|
var handlePause = useCallback(function () {
|
|
@@ -175,11 +163,9 @@ var Toast = function Toast(_ref) {
|
|
|
175
163
|
tabIndex: 0,
|
|
176
164
|
"aria-hidden": !shouldExpand && stackIndex > 0,
|
|
177
165
|
style: {
|
|
178
|
-
|
|
179
|
-
opacity: exiting ? 0 : undefined,
|
|
180
|
-
pointerEvents: exiting ? "none" : "auto"
|
|
166
|
+
pointerEvents: phase === "exit" ? "none" : "auto"
|
|
181
167
|
},
|
|
182
|
-
className: "d9-toast toast ".concat(theme === "colored" ? type : theme, " ").concat(className),
|
|
168
|
+
className: "d9-toast toast ".concat(animationClass, " ").concat(theme === "colored" ? type : theme, " ").concat(className),
|
|
183
169
|
onMouseEnter: handleMouseEnter,
|
|
184
170
|
onMouseLeave: handleMouseLeave,
|
|
185
171
|
children: [title && /*#__PURE__*/_jsxs("div", {
|
package/dist/ToastContext.js
CHANGED
|
@@ -182,7 +182,7 @@ export var ToastProvider = function ToastProvider(_ref) {
|
|
|
182
182
|
});
|
|
183
183
|
// Limit to last 10 toasts to prevent memory overflow...
|
|
184
184
|
setToasts(function (prev) {
|
|
185
|
-
return [].concat(_toConsumableArray(prev)
|
|
185
|
+
return [newToast].concat(_toConsumableArray(prev)).slice(0, 10);
|
|
186
186
|
});
|
|
187
187
|
var audio = newToast.audio,
|
|
188
188
|
type = newToast.type;
|
package/dist/toast.css
CHANGED
|
@@ -238,6 +238,28 @@
|
|
|
238
238
|
pointer-events: none;
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
/* Animation */
|
|
242
|
+
.toast--enter-top {
|
|
243
|
+
animation: d9-upToDown 450ms cubic-bezier(0.165, 0.84, 0.44, 1);
|
|
244
|
+
}
|
|
245
|
+
.toast--exit-top {
|
|
246
|
+
animation: d9-downToUpExit 300ms ease-in;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.toast--enter-bottom {
|
|
250
|
+
animation: d9-downToUp 450ms cubic-bezier(0.165, 0.84, 0.44, 1);
|
|
251
|
+
}
|
|
252
|
+
.toast--exit-bottom {
|
|
253
|
+
animation: d9-upToDownExit 300ms ease-in;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.toast--enter-center {
|
|
257
|
+
animation: d9-centerEnter 450ms cubic-bezier(0.165, 0.84, 0.44, 1);
|
|
258
|
+
}
|
|
259
|
+
.toast--exit-center {
|
|
260
|
+
animation: d9-centerExit 300ms ease-in;
|
|
261
|
+
}
|
|
262
|
+
|
|
241
263
|
/* Type colors */
|
|
242
264
|
.default {
|
|
243
265
|
color: var(--primary-color);
|