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 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 ENTER_ANIMATIONS = {
13
- top: "d9-upToDown",
14
- bottom: "d9-downToUp",
15
- center: "d9-centerEnter"
16
- };
17
- var EXIT_ANIMATIONS = {
18
- top: "d9-downToUpExit",
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 ? 3000 : _ref$duration,
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
- exiting = _useState2[0],
60
- setExiting = _useState2[1];
60
+ isPaused = _useState2[0],
61
+ setIsPaused = _useState2[1];
61
62
  var _useState3 = useState(false),
62
63
  _useState4 = _slicedToArray(_useState3, 2),
63
- isPaused = _useState4[0],
64
- setIsPaused = _useState4[1];
65
- var _useState5 = useState(false),
64
+ isMounted = _useState4[0],
65
+ setIsMounted = _useState4[1];
66
+ var _useState5 = useState("enter"),
66
67
  _useState6 = _slicedToArray(_useState5, 2),
67
- isMounted = _useState6[0],
68
- setIsMounted = _useState6[1];
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
- // Styles [Animation]
79
- var _useMemo = useMemo(function () {
80
- // entry animation [based on position]
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 (exiting) return;
100
- setExiting(true);
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, exiting]);
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
- animation: exiting ? exitAnim : enterAnim,
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", {
@@ -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), [newToast]).slice(-10);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d9-toast",
3
- "version": "2.5.42",
3
+ "version": "2.5.44",
4
4
  "description": "Customizable toast notifications for React",
5
5
  "homepage": "https://psathul073.github.io/d9-toast-docs/",
6
6
  "repository": {