goey-toast 0.2.2 → 0.4.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/README.md +99 -72
- package/dist/index.cjs +170 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +146 -81
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +34 -31
- package/dist/index.d.ts +34 -31
- package/dist/index.js +167 -123
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ var sonner = require('sonner');
|
|
|
5
5
|
var framerMotion = require('framer-motion');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
|
|
8
|
-
// src/components/
|
|
8
|
+
// src/components/GooeyToaster.tsx
|
|
9
9
|
|
|
10
10
|
// src/presets.ts
|
|
11
11
|
var animationPresets = {
|
|
@@ -21,71 +21,78 @@ var _dir = "ltr";
|
|
|
21
21
|
var _spring = true;
|
|
22
22
|
var _bounce = void 0;
|
|
23
23
|
var _theme = "light";
|
|
24
|
-
function
|
|
24
|
+
function setGooeyTheme(theme) {
|
|
25
25
|
_theme = theme;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function getGooeyTheme() {
|
|
28
28
|
return _theme;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function setGooeyPosition(position) {
|
|
31
31
|
_position = position;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function getGooeyPosition() {
|
|
34
34
|
return _position;
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function setGooeyDir(dir) {
|
|
37
37
|
_dir = dir;
|
|
38
38
|
}
|
|
39
|
-
function
|
|
39
|
+
function getGooeyDir() {
|
|
40
40
|
return _dir;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function setGooeySpring(spring) {
|
|
43
43
|
_spring = spring;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function getGooeySpring() {
|
|
46
46
|
return _spring;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function setGooeyBounce(bounce) {
|
|
49
49
|
_bounce = bounce;
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function getGooeyBounce() {
|
|
52
52
|
return _bounce;
|
|
53
53
|
}
|
|
54
54
|
var _visibleToasts = 3;
|
|
55
|
-
function
|
|
55
|
+
function setGooeyVisibleToasts(n) {
|
|
56
56
|
_visibleToasts = n;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function getGooeyVisibleToasts() {
|
|
59
59
|
return _visibleToasts;
|
|
60
60
|
}
|
|
61
61
|
var _swipeToDismiss = true;
|
|
62
|
-
function
|
|
62
|
+
function setGooeySwipeToDismiss(enabled) {
|
|
63
63
|
_swipeToDismiss = enabled;
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function getGooeySwipeToDismiss() {
|
|
66
66
|
return _swipeToDismiss;
|
|
67
67
|
}
|
|
68
68
|
var _maxQueue = Infinity;
|
|
69
|
-
function
|
|
69
|
+
function setGooeyMaxQueue(n) {
|
|
70
70
|
_maxQueue = n;
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function getGooeyMaxQueue() {
|
|
73
73
|
return _maxQueue;
|
|
74
74
|
}
|
|
75
75
|
var _queueOverflow = "drop-oldest";
|
|
76
|
-
function
|
|
76
|
+
function setGooeyQueueOverflow(strategy) {
|
|
77
77
|
_queueOverflow = strategy;
|
|
78
78
|
}
|
|
79
|
-
function
|
|
79
|
+
function getGooeyQueueOverflow() {
|
|
80
80
|
return _queueOverflow;
|
|
81
81
|
}
|
|
82
82
|
var _showProgress = false;
|
|
83
|
-
function
|
|
83
|
+
function setGooeyShowProgress(show) {
|
|
84
84
|
_showProgress = show;
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function getGooeyShowProgress() {
|
|
87
87
|
return _showProgress;
|
|
88
88
|
}
|
|
89
|
+
var _closeButton = false;
|
|
90
|
+
function setGooeyCloseButton(value) {
|
|
91
|
+
_closeButton = value;
|
|
92
|
+
}
|
|
93
|
+
function getGooeyCloseButton() {
|
|
94
|
+
return _closeButton;
|
|
95
|
+
}
|
|
89
96
|
var _containerHovered = false;
|
|
90
97
|
var _hoverSubs = /* @__PURE__ */ new Set();
|
|
91
98
|
function setContainerHovered(hovered) {
|
|
@@ -249,40 +256,42 @@ function usePrefersReducedMotion() {
|
|
|
249
256
|
return prefersReducedMotion;
|
|
250
257
|
}
|
|
251
258
|
|
|
252
|
-
// src/components/
|
|
259
|
+
// src/components/gooey-styles.ts
|
|
253
260
|
var styles = {
|
|
254
|
-
spinnerSpin: "
|
|
255
|
-
wrapper: "
|
|
256
|
-
blobSvg: "
|
|
257
|
-
content: "
|
|
258
|
-
contentCompact: "
|
|
259
|
-
contentExpanded: "
|
|
260
|
-
header: "
|
|
261
|
-
iconWrapper: "
|
|
262
|
-
title: "
|
|
263
|
-
titleDefault: "
|
|
264
|
-
titleSuccess: "
|
|
265
|
-
titleError: "
|
|
266
|
-
titleWarning: "
|
|
267
|
-
titleInfo: "
|
|
268
|
-
titleLoading: "
|
|
269
|
-
description: "
|
|
270
|
-
actionWrapper: "
|
|
271
|
-
actionButton: "
|
|
272
|
-
actionDefault: "
|
|
273
|
-
actionSuccess: "
|
|
274
|
-
actionError: "
|
|
275
|
-
actionWarning: "
|
|
276
|
-
actionInfo: "
|
|
277
|
-
progressWrapper: "
|
|
278
|
-
progressBar: "
|
|
279
|
-
progressDefault: "
|
|
280
|
-
progressSuccess: "
|
|
281
|
-
progressError: "
|
|
282
|
-
progressWarning: "
|
|
283
|
-
progressInfo: "
|
|
284
|
-
progressPaused: "
|
|
285
|
-
timestamp: "
|
|
261
|
+
spinnerSpin: "gooey-spinnerSpin",
|
|
262
|
+
wrapper: "gooey-wrapper",
|
|
263
|
+
blobSvg: "gooey-blobSvg",
|
|
264
|
+
content: "gooey-content",
|
|
265
|
+
contentCompact: "gooey-contentCompact",
|
|
266
|
+
contentExpanded: "gooey-contentExpanded",
|
|
267
|
+
header: "gooey-header",
|
|
268
|
+
iconWrapper: "gooey-iconWrapper",
|
|
269
|
+
title: "gooey-title",
|
|
270
|
+
titleDefault: "gooey-titleDefault",
|
|
271
|
+
titleSuccess: "gooey-titleSuccess",
|
|
272
|
+
titleError: "gooey-titleError",
|
|
273
|
+
titleWarning: "gooey-titleWarning",
|
|
274
|
+
titleInfo: "gooey-titleInfo",
|
|
275
|
+
titleLoading: "gooey-titleLoading",
|
|
276
|
+
description: "gooey-description",
|
|
277
|
+
actionWrapper: "gooey-actionWrapper",
|
|
278
|
+
actionButton: "gooey-actionButton",
|
|
279
|
+
actionDefault: "gooey-actionDefault",
|
|
280
|
+
actionSuccess: "gooey-actionSuccess",
|
|
281
|
+
actionError: "gooey-actionError",
|
|
282
|
+
actionWarning: "gooey-actionWarning",
|
|
283
|
+
actionInfo: "gooey-actionInfo",
|
|
284
|
+
progressWrapper: "gooey-progressWrapper",
|
|
285
|
+
progressBar: "gooey-progressBar",
|
|
286
|
+
progressDefault: "gooey-progressDefault",
|
|
287
|
+
progressSuccess: "gooey-progressSuccess",
|
|
288
|
+
progressError: "gooey-progressError",
|
|
289
|
+
progressWarning: "gooey-progressWarning",
|
|
290
|
+
progressInfo: "gooey-progressInfo",
|
|
291
|
+
progressPaused: "gooey-progressPaused",
|
|
292
|
+
timestamp: "gooey-timestamp",
|
|
293
|
+
closeButton: "gooey-closeButton",
|
|
294
|
+
closeButtonRight: "gooey-closeButtonRight"
|
|
286
295
|
};
|
|
287
296
|
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? react.useLayoutEffect : react.useEffect;
|
|
288
297
|
var phaseIconMap = {
|
|
@@ -522,7 +531,7 @@ function morphPathCenterRaw(pw, bw, th, t) {
|
|
|
522
531
|
var morphPath = memoizePath(morphPathRaw);
|
|
523
532
|
var morphPathCenter = memoizePath(morphPathCenterRaw);
|
|
524
533
|
var SMOOTH_EASE = [0.4, 0, 0.2, 1];
|
|
525
|
-
var
|
|
534
|
+
var GooeyToast = ({
|
|
526
535
|
title,
|
|
527
536
|
description,
|
|
528
537
|
action,
|
|
@@ -536,21 +545,24 @@ var GoeyToast = ({
|
|
|
536
545
|
preset,
|
|
537
546
|
spring: springProp,
|
|
538
547
|
bounce: bounceProp,
|
|
548
|
+
showTimestamp = true,
|
|
539
549
|
showProgress: showProgressProp,
|
|
540
550
|
toastId
|
|
541
551
|
}) => {
|
|
542
|
-
const theme =
|
|
552
|
+
const theme = getGooeyTheme();
|
|
553
|
+
const closeButtonSetting = getGooeyCloseButton();
|
|
554
|
+
const showCloseButton = closeButtonSetting !== false;
|
|
543
555
|
const fillColor = fillColorProp ?? (theme === "dark" ? "#1a1a1a" : "#ffffff");
|
|
544
|
-
const position =
|
|
545
|
-
const dir =
|
|
556
|
+
const position = getGooeyPosition();
|
|
557
|
+
const dir = getGooeyDir();
|
|
546
558
|
const posIsRight = position?.includes("right") ?? false;
|
|
547
559
|
const isCenter = position?.includes("center") ?? false;
|
|
548
560
|
const isRight = dir === "rtl" ? isCenter ? false : !posIsRight : posIsRight;
|
|
549
561
|
const prefersReducedMotion = usePrefersReducedMotion();
|
|
550
562
|
const presetConfig = preset ? animationPresets[preset] : void 0;
|
|
551
|
-
const useSpring = springProp ?? presetConfig?.spring ??
|
|
552
|
-
const bounceVal = bounceProp ?? presetConfig?.bounce ??
|
|
553
|
-
const showProgress = showProgressProp ??
|
|
563
|
+
const useSpring = springProp ?? presetConfig?.spring ?? getGooeySpring();
|
|
564
|
+
const bounceVal = bounceProp ?? presetConfig?.bounce ?? getGooeyBounce() ?? 0.4;
|
|
565
|
+
const showProgress = showProgressProp ?? getGooeyShowProgress();
|
|
554
566
|
const [actionSuccess, setActionSuccess] = react.useState(null);
|
|
555
567
|
const [dismissing, setDismissing] = react.useState(false);
|
|
556
568
|
const [progressKey, setProgressKey] = react.useState(0);
|
|
@@ -596,8 +608,8 @@ var GoeyToast = ({
|
|
|
596
608
|
const { pw: p, bw: b, th: h } = aDims.current;
|
|
597
609
|
if (p <= 0 || b <= 0 || h <= 0) return;
|
|
598
610
|
const t = Math.max(0, Math.min(1, morphTRef.current));
|
|
599
|
-
const pos =
|
|
600
|
-
const d =
|
|
611
|
+
const pos = getGooeyPosition();
|
|
612
|
+
const d = getGooeyDir();
|
|
601
613
|
const centerPos = pos?.includes("center") ?? false;
|
|
602
614
|
const posRight = pos?.includes("right") ?? false;
|
|
603
615
|
const rightSide = d === "rtl" ? centerPos ? false : !posRight : posRight;
|
|
@@ -1094,13 +1106,13 @@ var GoeyToast = ({
|
|
|
1094
1106
|
const [swipeOffsetX, setSwipeOffsetX] = react.useState(0);
|
|
1095
1107
|
const isSwipingRef = react.useRef(false);
|
|
1096
1108
|
const handleTouchStart = react.useCallback((e) => {
|
|
1097
|
-
if (!
|
|
1109
|
+
if (!getGooeySwipeToDismiss()) return;
|
|
1098
1110
|
const touch = e.touches[0];
|
|
1099
1111
|
swipeStartRef.current = { x: touch.clientX, y: touch.clientY };
|
|
1100
1112
|
isSwipingRef.current = false;
|
|
1101
1113
|
}, []);
|
|
1102
1114
|
const handleTouchMove = react.useCallback((e) => {
|
|
1103
|
-
if (!swipeStartRef.current || !
|
|
1115
|
+
if (!swipeStartRef.current || !getGooeySwipeToDismiss()) return;
|
|
1104
1116
|
const touch = e.touches[0];
|
|
1105
1117
|
const dx = touch.clientX - swipeStartRef.current.x;
|
|
1106
1118
|
const dy = touch.clientY - swipeStartRef.current.y;
|
|
@@ -1116,7 +1128,7 @@ var GoeyToast = ({
|
|
|
1116
1128
|
}
|
|
1117
1129
|
}, []);
|
|
1118
1130
|
const handleTouchEnd = react.useCallback(() => {
|
|
1119
|
-
if (!
|
|
1131
|
+
if (!getGooeySwipeToDismiss()) {
|
|
1120
1132
|
swipeStartRef.current = null;
|
|
1121
1133
|
return;
|
|
1122
1134
|
}
|
|
@@ -1204,6 +1216,30 @@ var GoeyToast = ({
|
|
|
1204
1216
|
)
|
|
1205
1217
|
}
|
|
1206
1218
|
),
|
|
1219
|
+
showCloseButton && effectivePhase !== "loading" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1220
|
+
"button",
|
|
1221
|
+
{
|
|
1222
|
+
className: `${styles.closeButton}${(isRight ? closeButtonSetting !== "top-right" : closeButtonSetting === "top-right") ? ` ${styles.closeButtonRight}` : ""}`,
|
|
1223
|
+
"aria-label": "Close toast",
|
|
1224
|
+
type: "button",
|
|
1225
|
+
style: {
|
|
1226
|
+
background: fillColor,
|
|
1227
|
+
borderColor: borderColor || "transparent",
|
|
1228
|
+
borderWidth: borderColor ? borderWidth ?? 1.5 : 0,
|
|
1229
|
+
boxShadow: borderColor ? "none" : "0 1px 4px rgba(0, 0, 0, 0.2)",
|
|
1230
|
+
...isCenter && closeButtonSetting !== "top-right" ? { top: 6, left: -1 } : {}
|
|
1231
|
+
},
|
|
1232
|
+
onClick: (e) => {
|
|
1233
|
+
e.stopPropagation();
|
|
1234
|
+
const id = toastId;
|
|
1235
|
+
if (id != null) sonner.toast.dismiss(id);
|
|
1236
|
+
},
|
|
1237
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
1238
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
1239
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
1240
|
+
] })
|
|
1241
|
+
}
|
|
1242
|
+
),
|
|
1207
1243
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1208
1244
|
"div",
|
|
1209
1245
|
{
|
|
@@ -1213,9 +1249,9 @@ var GoeyToast = ({
|
|
|
1213
1249
|
children: [
|
|
1214
1250
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { ref: headerRef, className: `${styles.header} ${titleColorMap[effectivePhase]}${classNames?.header ? ` ${classNames.header}` : ""}`, children: [
|
|
1215
1251
|
iconAndTitle,
|
|
1216
|
-
!hasDescription && !hasAction && !actionSuccess && /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.timestamp, children: timestampStr })
|
|
1252
|
+
!hasDescription && !hasAction && !actionSuccess && showTimestamp && /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.timestamp, children: timestampStr })
|
|
1217
1253
|
] }),
|
|
1218
|
-
/* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: showBody && hasDescription && !dismissing && /* @__PURE__ */ jsxRuntime.
|
|
1254
|
+
/* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: showBody && hasDescription && !dismissing && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1219
1255
|
framerMotion.motion.div,
|
|
1220
1256
|
{
|
|
1221
1257
|
className: `${styles.description}${classNames?.description ? ` ${classNames.description}` : ""}`,
|
|
@@ -1224,14 +1260,14 @@ var GoeyToast = ({
|
|
|
1224
1260
|
animate: { opacity: 1 },
|
|
1225
1261
|
exit: { opacity: 0 },
|
|
1226
1262
|
transition: prefersReducedMotion ? { duration: 0.01 } : { duration: 0.35, ease: [0.4, 0, 0.2, 1] },
|
|
1227
|
-
children: [
|
|
1228
|
-
/* @__PURE__ */ jsxRuntime.jsx("
|
|
1229
|
-
|
|
1230
|
-
]
|
|
1263
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "flex-start", gap: "10px" }, children: [
|
|
1264
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1, minWidth: 0 }, children: effectiveDescription }),
|
|
1265
|
+
showTimestamp && /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.timestamp, children: timestampStr })
|
|
1266
|
+
] })
|
|
1231
1267
|
},
|
|
1232
1268
|
"description"
|
|
1233
1269
|
) }),
|
|
1234
|
-
/* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: showBody && !hasDescription && hasAction && !dismissing && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1270
|
+
/* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: showBody && !hasDescription && hasAction && !dismissing && showTimestamp && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1235
1271
|
framerMotion.motion.div,
|
|
1236
1272
|
{
|
|
1237
1273
|
className: styles.timestamp,
|
|
@@ -1274,7 +1310,7 @@ var GoeyToast = ({
|
|
|
1274
1310
|
"div",
|
|
1275
1311
|
{
|
|
1276
1312
|
className: `${styles.progressBar} ${progressColorMap[effectivePhase]}`,
|
|
1277
|
-
style: { "--
|
|
1313
|
+
style: { "--gooey-progress-duration": `${progressDelayRef.current || (timing?.displayDuration ?? DEFAULT_DISPLAY_DURATION)}ms` }
|
|
1278
1314
|
}
|
|
1279
1315
|
)
|
|
1280
1316
|
},
|
|
@@ -1295,7 +1331,7 @@ var ToastErrorBoundary = class extends react.Component {
|
|
|
1295
1331
|
}
|
|
1296
1332
|
componentDidCatch(error, errorInfo) {
|
|
1297
1333
|
if (process.env.NODE_ENV !== "production") {
|
|
1298
|
-
console.error("[
|
|
1334
|
+
console.error("[GooeyToast] Rendering error:", error, errorInfo);
|
|
1299
1335
|
}
|
|
1300
1336
|
}
|
|
1301
1337
|
render() {
|
|
@@ -1324,7 +1360,7 @@ function _getMostRecentActiveId() {
|
|
|
1324
1360
|
return last;
|
|
1325
1361
|
}
|
|
1326
1362
|
function _processQueue() {
|
|
1327
|
-
const max =
|
|
1363
|
+
const max = getGooeyVisibleToasts();
|
|
1328
1364
|
while (_queue.length > 0 && _activeIds.size < max) {
|
|
1329
1365
|
const next = _queue.shift();
|
|
1330
1366
|
_activeIds.set(next.id, next.type);
|
|
@@ -1332,8 +1368,8 @@ function _processQueue() {
|
|
|
1332
1368
|
}
|
|
1333
1369
|
}
|
|
1334
1370
|
function _enqueue(entry) {
|
|
1335
|
-
const maxQueue =
|
|
1336
|
-
const overflow =
|
|
1371
|
+
const maxQueue = getGooeyMaxQueue();
|
|
1372
|
+
const overflow = getGooeyQueueOverflow();
|
|
1337
1373
|
if (_queue.length >= maxQueue) {
|
|
1338
1374
|
if (overflow === "drop-newest") return false;
|
|
1339
1375
|
_queue.shift();
|
|
@@ -1366,7 +1402,7 @@ function _onToastDismissed(id) {
|
|
|
1366
1402
|
_processQueue();
|
|
1367
1403
|
}
|
|
1368
1404
|
var _toastUpdateListeners = /* @__PURE__ */ new Map();
|
|
1369
|
-
function
|
|
1405
|
+
function updateGooeyToast(id, options) {
|
|
1370
1406
|
const listener = _toastUpdateListeners.get(id);
|
|
1371
1407
|
if (listener) {
|
|
1372
1408
|
listener(options);
|
|
@@ -1381,7 +1417,7 @@ function updateGoeyToast(id, options) {
|
|
|
1381
1417
|
}
|
|
1382
1418
|
}
|
|
1383
1419
|
}
|
|
1384
|
-
function
|
|
1420
|
+
function GooeyToastWrapper({
|
|
1385
1421
|
initialPhase,
|
|
1386
1422
|
title: initialTitle,
|
|
1387
1423
|
type: initialType,
|
|
@@ -1397,22 +1433,23 @@ function GoeyToastWrapper({
|
|
|
1397
1433
|
spring,
|
|
1398
1434
|
bounce,
|
|
1399
1435
|
showProgress,
|
|
1436
|
+
showTimestamp: initialShowTimestamp,
|
|
1400
1437
|
toastId,
|
|
1401
|
-
activeId,
|
|
1402
1438
|
onDismiss,
|
|
1403
1439
|
onAutoClose
|
|
1404
1440
|
}) {
|
|
1405
1441
|
react.useEffect(() => {
|
|
1406
1442
|
if (onDismiss || onAutoClose) {
|
|
1407
|
-
_toastCallbacks.set(
|
|
1443
|
+
_toastCallbacks.set(toastId, { onDismiss, onAutoClose });
|
|
1408
1444
|
}
|
|
1409
|
-
}, [
|
|
1445
|
+
}, [toastId, onDismiss, onAutoClose]);
|
|
1410
1446
|
const [title, setTitle] = react.useState(initialTitle);
|
|
1411
1447
|
const [type, setType] = react.useState(initialType);
|
|
1412
1448
|
const [phase, setPhase] = react.useState(initialPhase);
|
|
1413
1449
|
const [description, setDescription] = react.useState(initialDescription);
|
|
1414
1450
|
const [action, setAction] = react.useState(initialAction);
|
|
1415
1451
|
const [currentIcon, setCurrentIcon] = react.useState(icon);
|
|
1452
|
+
const [showTimestamp, setShowTimestamp] = react.useState(initialShowTimestamp ?? true);
|
|
1416
1453
|
react.useEffect(() => {
|
|
1417
1454
|
const handleUpdate = (opts) => {
|
|
1418
1455
|
if (opts.title !== void 0) setTitle(opts.title);
|
|
@@ -1423,24 +1460,25 @@ function GoeyToastWrapper({
|
|
|
1423
1460
|
}
|
|
1424
1461
|
if (opts.action !== void 0) setAction(opts.action);
|
|
1425
1462
|
if ("icon" in opts) setCurrentIcon(opts.icon ?? void 0);
|
|
1463
|
+
if (opts.showTimestamp !== void 0) setShowTimestamp(opts.showTimestamp);
|
|
1426
1464
|
};
|
|
1427
|
-
_toastUpdateListeners.set(
|
|
1465
|
+
_toastUpdateListeners.set(toastId, handleUpdate);
|
|
1428
1466
|
return () => {
|
|
1429
|
-
_toastUpdateListeners.delete(
|
|
1467
|
+
_toastUpdateListeners.delete(toastId);
|
|
1430
1468
|
};
|
|
1431
|
-
}, [
|
|
1469
|
+
}, [toastId]);
|
|
1432
1470
|
const mountedRef = react.useRef(true);
|
|
1433
1471
|
react.useEffect(() => {
|
|
1434
1472
|
mountedRef.current = true;
|
|
1435
1473
|
return () => {
|
|
1436
1474
|
mountedRef.current = false;
|
|
1437
1475
|
setTimeout(() => {
|
|
1438
|
-
if (!mountedRef.current) _onToastDismissed(
|
|
1476
|
+
if (!mountedRef.current) _onToastDismissed(toastId);
|
|
1439
1477
|
}, 100);
|
|
1440
1478
|
};
|
|
1441
|
-
}, [
|
|
1479
|
+
}, [toastId]);
|
|
1442
1480
|
return /* @__PURE__ */ jsxRuntime.jsx(ToastErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1443
|
-
|
|
1481
|
+
GooeyToast,
|
|
1444
1482
|
{
|
|
1445
1483
|
title,
|
|
1446
1484
|
description,
|
|
@@ -1457,6 +1495,7 @@ function GoeyToastWrapper({
|
|
|
1457
1495
|
spring,
|
|
1458
1496
|
bounce,
|
|
1459
1497
|
showProgress,
|
|
1498
|
+
showTimestamp,
|
|
1460
1499
|
toastId
|
|
1461
1500
|
}
|
|
1462
1501
|
) });
|
|
@@ -1515,7 +1554,7 @@ function PromiseToastWrapper({
|
|
|
1515
1554
|
});
|
|
1516
1555
|
}, []);
|
|
1517
1556
|
return /* @__PURE__ */ jsxRuntime.jsx(ToastErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1518
|
-
|
|
1557
|
+
GooeyToast,
|
|
1519
1558
|
{
|
|
1520
1559
|
title,
|
|
1521
1560
|
description,
|
|
@@ -1529,11 +1568,13 @@ function PromiseToastWrapper({
|
|
|
1529
1568
|
timing: data.timing,
|
|
1530
1569
|
preset: data.preset,
|
|
1531
1570
|
spring: data.spring,
|
|
1532
|
-
bounce: data.bounce
|
|
1571
|
+
bounce: data.bounce,
|
|
1572
|
+
showTimestamp: data.showTimestamp ?? true,
|
|
1573
|
+
toastId
|
|
1533
1574
|
}
|
|
1534
1575
|
) });
|
|
1535
1576
|
}
|
|
1536
|
-
function
|
|
1577
|
+
function createGooeyToast(title, type, options) {
|
|
1537
1578
|
const hasExpandedContent = Boolean(options?.description || options?.action);
|
|
1538
1579
|
const baseDuration = options?.timing?.displayDuration ?? options?.duration ?? (options?.description ? DEFAULT_EXPANDED_DURATION : void 0);
|
|
1539
1580
|
const duration = hasExpandedContent ? Infinity : baseDuration;
|
|
@@ -1541,7 +1582,7 @@ function createGoeyToast(title, type, options) {
|
|
|
1541
1582
|
const create = () => {
|
|
1542
1583
|
sonner.toast.custom(
|
|
1543
1584
|
() => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1544
|
-
|
|
1585
|
+
GooeyToastWrapper,
|
|
1545
1586
|
{
|
|
1546
1587
|
initialPhase: type,
|
|
1547
1588
|
title,
|
|
@@ -1558,8 +1599,8 @@ function createGoeyToast(title, type, options) {
|
|
|
1558
1599
|
spring: options?.spring,
|
|
1559
1600
|
bounce: options?.bounce,
|
|
1560
1601
|
showProgress: options?.showProgress,
|
|
1561
|
-
|
|
1562
|
-
|
|
1602
|
+
showTimestamp: options?.showTimestamp,
|
|
1603
|
+
toastId,
|
|
1563
1604
|
onDismiss: options?.onDismiss,
|
|
1564
1605
|
onAutoClose: options?.onAutoClose
|
|
1565
1606
|
}
|
|
@@ -1577,7 +1618,7 @@ function createGoeyToast(title, type, options) {
|
|
|
1577
1618
|
buildAnnouncementMessage(title, options?.description),
|
|
1578
1619
|
getAnnouncePoliteness(type)
|
|
1579
1620
|
);
|
|
1580
|
-
if (_activeIds.size <
|
|
1621
|
+
if (_activeIds.size < getGooeyVisibleToasts()) {
|
|
1581
1622
|
_activeIds.set(toastId, type);
|
|
1582
1623
|
create();
|
|
1583
1624
|
} else {
|
|
@@ -1585,7 +1626,7 @@ function createGoeyToast(title, type, options) {
|
|
|
1585
1626
|
}
|
|
1586
1627
|
return toastId;
|
|
1587
1628
|
}
|
|
1588
|
-
function
|
|
1629
|
+
function dismissGooeyToast(idOrFilter) {
|
|
1589
1630
|
if (idOrFilter != null && typeof idOrFilter === "object") {
|
|
1590
1631
|
const filterTypes = Array.isArray(idOrFilter.type) ? idOrFilter.type : [idOrFilter.type];
|
|
1591
1632
|
const typesSet = new Set(filterTypes);
|
|
@@ -1617,13 +1658,13 @@ function dismissGoeyToast(idOrFilter) {
|
|
|
1617
1658
|
sonner.toast.dismiss();
|
|
1618
1659
|
}
|
|
1619
1660
|
}
|
|
1620
|
-
var
|
|
1621
|
-
(title, options) =>
|
|
1661
|
+
var gooeyToast = Object.assign(
|
|
1662
|
+
(title, options) => createGooeyToast(title, "default", options),
|
|
1622
1663
|
{
|
|
1623
|
-
success: (title, options) =>
|
|
1624
|
-
error: (title, options) =>
|
|
1625
|
-
warning: (title, options) =>
|
|
1626
|
-
info: (title, options) =>
|
|
1664
|
+
success: (title, options) => createGooeyToast(title, "success", options),
|
|
1665
|
+
error: (title, options) => createGooeyToast(title, "error", options),
|
|
1666
|
+
warning: (title, options) => createGooeyToast(title, "warning", options),
|
|
1667
|
+
info: (title, options) => createGooeyToast(title, "info", options),
|
|
1627
1668
|
promise: (promise, data) => {
|
|
1628
1669
|
const id = Math.random().toString(36).slice(2);
|
|
1629
1670
|
announce(buildAnnouncementMessage(data.loading, data.description?.loading), "polite");
|
|
@@ -1636,7 +1677,7 @@ var goeyToast = Object.assign(
|
|
|
1636
1677
|
duration: data.timing?.displayDuration != null || data.description ? Infinity : void 0
|
|
1637
1678
|
});
|
|
1638
1679
|
};
|
|
1639
|
-
if (_activeIds.size <
|
|
1680
|
+
if (_activeIds.size < getGooeyVisibleToasts()) {
|
|
1640
1681
|
_activeIds.set(id, "info");
|
|
1641
1682
|
create();
|
|
1642
1683
|
} else {
|
|
@@ -1644,8 +1685,8 @@ var goeyToast = Object.assign(
|
|
|
1644
1685
|
}
|
|
1645
1686
|
return id;
|
|
1646
1687
|
},
|
|
1647
|
-
dismiss:
|
|
1648
|
-
update:
|
|
1688
|
+
dismiss: dismissGooeyToast,
|
|
1689
|
+
update: updateGooeyToast
|
|
1649
1690
|
}
|
|
1650
1691
|
);
|
|
1651
1692
|
function AriaLiveAnnouncer() {
|
|
@@ -1707,7 +1748,7 @@ function AriaLiveAnnouncer() {
|
|
|
1707
1748
|
)
|
|
1708
1749
|
] });
|
|
1709
1750
|
}
|
|
1710
|
-
function
|
|
1751
|
+
function GooeyToaster({
|
|
1711
1752
|
position = "bottom-right",
|
|
1712
1753
|
duration,
|
|
1713
1754
|
gap = 14,
|
|
@@ -1732,22 +1773,22 @@ function GoeyToaster({
|
|
|
1732
1773
|
const resolvedSpring = spring ?? presetConfig?.spring ?? true;
|
|
1733
1774
|
const resolvedBounce = bounce ?? presetConfig?.bounce;
|
|
1734
1775
|
react.useEffect(() => {
|
|
1735
|
-
|
|
1776
|
+
setGooeyPosition(position);
|
|
1736
1777
|
}, [position]);
|
|
1737
1778
|
react.useEffect(() => {
|
|
1738
|
-
|
|
1779
|
+
setGooeyDir(dir ?? "ltr");
|
|
1739
1780
|
}, [dir]);
|
|
1740
1781
|
react.useEffect(() => {
|
|
1741
|
-
|
|
1782
|
+
setGooeyTheme(theme);
|
|
1742
1783
|
}, [theme]);
|
|
1743
1784
|
react.useEffect(() => {
|
|
1744
|
-
|
|
1785
|
+
setGooeySpring(resolvedSpring);
|
|
1745
1786
|
}, [resolvedSpring]);
|
|
1746
1787
|
react.useEffect(() => {
|
|
1747
|
-
|
|
1788
|
+
setGooeyBounce(resolvedBounce);
|
|
1748
1789
|
}, [resolvedBounce]);
|
|
1749
1790
|
react.useEffect(() => {
|
|
1750
|
-
|
|
1791
|
+
setGooeySwipeToDismiss(swipeToDismiss);
|
|
1751
1792
|
}, [swipeToDismiss]);
|
|
1752
1793
|
react.useEffect(() => {
|
|
1753
1794
|
}, [closeOnEscape]);
|
|
@@ -1757,7 +1798,7 @@ function GoeyToaster({
|
|
|
1757
1798
|
if (e.key === "Escape") {
|
|
1758
1799
|
const recentId = _getMostRecentActiveId();
|
|
1759
1800
|
if (recentId != null) {
|
|
1760
|
-
|
|
1801
|
+
gooeyToast.dismiss(recentId);
|
|
1761
1802
|
}
|
|
1762
1803
|
}
|
|
1763
1804
|
};
|
|
@@ -1765,17 +1806,20 @@ function GoeyToaster({
|
|
|
1765
1806
|
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
1766
1807
|
}, [closeOnEscape]);
|
|
1767
1808
|
react.useEffect(() => {
|
|
1768
|
-
|
|
1809
|
+
setGooeyVisibleToasts(visibleToasts ?? 3);
|
|
1769
1810
|
}, [visibleToasts]);
|
|
1770
1811
|
react.useEffect(() => {
|
|
1771
|
-
|
|
1812
|
+
setGooeyMaxQueue(maxQueue);
|
|
1772
1813
|
}, [maxQueue]);
|
|
1773
1814
|
react.useEffect(() => {
|
|
1774
|
-
|
|
1815
|
+
setGooeyQueueOverflow(queueOverflow);
|
|
1775
1816
|
}, [queueOverflow]);
|
|
1776
1817
|
react.useEffect(() => {
|
|
1777
|
-
|
|
1818
|
+
setGooeyShowProgress(showProgress);
|
|
1778
1819
|
}, [showProgress]);
|
|
1820
|
+
react.useEffect(() => {
|
|
1821
|
+
setGooeyCloseButton(closeButton ?? false);
|
|
1822
|
+
}, [closeButton]);
|
|
1779
1823
|
react.useEffect(() => {
|
|
1780
1824
|
let expandObs = null;
|
|
1781
1825
|
let currentOl = null;
|
|
@@ -1819,18 +1863,18 @@ function GoeyToaster({
|
|
|
1819
1863
|
react.useEffect(() => {
|
|
1820
1864
|
if (process.env.NODE_ENV !== "development") return;
|
|
1821
1865
|
const el = document.createElement("div");
|
|
1822
|
-
el.setAttribute("data-
|
|
1866
|
+
el.setAttribute("data-gooey-toast-css", "");
|
|
1823
1867
|
el.style.position = "absolute";
|
|
1824
1868
|
el.style.width = "0";
|
|
1825
1869
|
el.style.height = "0";
|
|
1826
1870
|
el.style.overflow = "hidden";
|
|
1827
1871
|
el.style.pointerEvents = "none";
|
|
1828
1872
|
document.body.appendChild(el);
|
|
1829
|
-
const value = getComputedStyle(el).getPropertyValue("--
|
|
1873
|
+
const value = getComputedStyle(el).getPropertyValue("--gooey-toast");
|
|
1830
1874
|
document.body.removeChild(el);
|
|
1831
1875
|
if (!value) {
|
|
1832
1876
|
console.warn(
|
|
1833
|
-
'[
|
|
1877
|
+
'[gooey-toast] Styles not found. Make sure to import the CSS:\n\n import "goey-toast/styles.css";\n'
|
|
1834
1878
|
);
|
|
1835
1879
|
}
|
|
1836
1880
|
}, []);
|
|
@@ -1845,7 +1889,7 @@ function GoeyToaster({
|
|
|
1845
1889
|
theme,
|
|
1846
1890
|
toastOptions: { unstyled: true, ...toastOptions },
|
|
1847
1891
|
expand,
|
|
1848
|
-
closeButton,
|
|
1892
|
+
closeButton: false,
|
|
1849
1893
|
richColors,
|
|
1850
1894
|
visibleToasts: 99,
|
|
1851
1895
|
dir
|
|
@@ -1855,8 +1899,10 @@ function GoeyToaster({
|
|
|
1855
1899
|
] });
|
|
1856
1900
|
}
|
|
1857
1901
|
|
|
1858
|
-
exports.GoeyToaster =
|
|
1902
|
+
exports.GoeyToaster = GooeyToaster;
|
|
1903
|
+
exports.GooeyToaster = GooeyToaster;
|
|
1859
1904
|
exports.animationPresets = animationPresets;
|
|
1860
|
-
exports.goeyToast =
|
|
1905
|
+
exports.goeyToast = gooeyToast;
|
|
1906
|
+
exports.gooeyToast = gooeyToast;
|
|
1861
1907
|
//# sourceMappingURL=index.cjs.map
|
|
1862
1908
|
//# sourceMappingURL=index.cjs.map
|