@dreamtree-org/twreact-ui 1.1.72 → 1.1.73
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 +15 -4
- package/dist/components/feedback/Toast.d.ts +6 -8
- package/dist/components/feedback/Toast.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.js +310 -115
- package/dist/index.js +309 -114
- package/mcp/catalog.snapshot.json +38 -8
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -227,6 +227,22 @@ const Calendar = createLucideIcon$1("Calendar", [
|
|
|
227
227
|
*/
|
|
228
228
|
|
|
229
229
|
|
|
230
|
+
const CheckCircle2 = createLucideIcon$1("CheckCircle2", [
|
|
231
|
+
[
|
|
232
|
+
"path",
|
|
233
|
+
{
|
|
234
|
+
d: "M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z",
|
|
235
|
+
key: "14v8dr"
|
|
236
|
+
}
|
|
237
|
+
],
|
|
238
|
+
["path", { d: "m9 12 2 2 4-4", key: "dzmm74" }]
|
|
239
|
+
]);
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* lucide-react v0.0.1 - ISC
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
|
|
230
246
|
const CheckCircle = createLucideIcon$1("CheckCircle", [
|
|
231
247
|
["path", { d: "M22 11.08V12a10 10 0 1 1-5.93-9.14", key: "g774vq" }],
|
|
232
248
|
["polyline", { points: "22 4 12 14.01 9 11.01", key: "6xbx8j" }]
|
|
@@ -637,6 +653,17 @@ const User = createLucideIcon$1("User", [
|
|
|
637
653
|
*/
|
|
638
654
|
|
|
639
655
|
|
|
656
|
+
const XCircle = createLucideIcon$1("XCircle", [
|
|
657
|
+
["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
|
|
658
|
+
["path", { d: "m15 9-6 6", key: "1uzhvr" }],
|
|
659
|
+
["path", { d: "m9 9 6 6", key: "z0biqf" }]
|
|
660
|
+
]);
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* lucide-react v0.0.1 - ISC
|
|
664
|
+
*/
|
|
665
|
+
|
|
666
|
+
|
|
640
667
|
const X = createLucideIcon$1("X", [
|
|
641
668
|
["path", { d: "M18 6 6 18", key: "1bl5f8" }],
|
|
642
669
|
["path", { d: "m6 6 12 12", key: "d8bk6v" }]
|
|
@@ -19200,13 +19227,57 @@ Dialog.Footer = function (_ref6) {
|
|
|
19200
19227
|
}));
|
|
19201
19228
|
};
|
|
19202
19229
|
|
|
19203
|
-
var _excluded$7 = ["id", "title", "message", "type", "duration", "onClose", "position"];
|
|
19230
|
+
var _excluded$7 = ["id", "title", "message", "description", "type", "duration", "onClose", "position", "statusIcon", "actions", "color", "footerNote", "showFooterNote", "portal", "className"];
|
|
19204
19231
|
function ownKeys$b(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19205
19232
|
function _objectSpread$b(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$b(Object(t), true).forEach(function (r) { _defineProperty$4(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19206
|
-
var
|
|
19233
|
+
var STATUS_CONFIG = {
|
|
19234
|
+
success: {
|
|
19235
|
+
icon: CheckCircle2,
|
|
19236
|
+
iconClass: 'text-emerald-500 dark:text-emerald-400',
|
|
19237
|
+
progressClass: 'bg-emerald-500 dark:bg-emerald-400'
|
|
19238
|
+
},
|
|
19239
|
+
error: {
|
|
19240
|
+
icon: XCircle,
|
|
19241
|
+
iconClass: 'text-rose-500 dark:text-rose-400',
|
|
19242
|
+
progressClass: 'bg-rose-500 dark:bg-rose-400'
|
|
19243
|
+
},
|
|
19244
|
+
warning: {
|
|
19245
|
+
icon: AlertTriangle,
|
|
19246
|
+
iconClass: 'text-amber-500 dark:text-amber-400',
|
|
19247
|
+
progressClass: 'bg-amber-500 dark:bg-amber-400'
|
|
19248
|
+
},
|
|
19249
|
+
info: {
|
|
19250
|
+
icon: Info,
|
|
19251
|
+
iconClass: 'text-sky-500 dark:text-sky-400',
|
|
19252
|
+
progressClass: 'bg-sky-500 dark:bg-sky-400'
|
|
19253
|
+
},
|
|
19254
|
+
"default": {
|
|
19255
|
+
icon: Bell,
|
|
19256
|
+
iconClass: 'text-primary-500 dark:text-primary-400',
|
|
19257
|
+
progressClass: 'bg-primary-500 dark:bg-primary-400'
|
|
19258
|
+
}
|
|
19259
|
+
};
|
|
19260
|
+
var POSITION_CLASSES = {
|
|
19261
|
+
'top-right': 'top-4 right-4 items-end',
|
|
19262
|
+
'top-left': 'top-4 left-4 items-start',
|
|
19263
|
+
'bottom-right': 'bottom-4 right-4 items-end',
|
|
19264
|
+
'bottom-left': 'bottom-4 left-4 items-start',
|
|
19265
|
+
'top-center': 'top-4 left-1/2 transform -translate-x-1/2 items-center',
|
|
19266
|
+
'bottom-center': 'bottom-4 left-1/2 transform -translate-x-1/2 items-center'
|
|
19267
|
+
};
|
|
19268
|
+
var STANDALONE_POSITION_CLASSES = {
|
|
19269
|
+
'top-right': 'top-4 right-4',
|
|
19270
|
+
'top-left': 'top-4 left-4',
|
|
19271
|
+
'bottom-right': 'bottom-4 right-4',
|
|
19272
|
+
'bottom-left': 'bottom-4 left-4',
|
|
19273
|
+
'top-center': 'top-4 left-1/2 transform -translate-x-1/2',
|
|
19274
|
+
'bottom-center': 'bottom-4 left-1/2 transform -translate-x-1/2'
|
|
19275
|
+
};
|
|
19276
|
+
var Toast = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
19207
19277
|
var id = _ref.id,
|
|
19208
19278
|
title = _ref.title,
|
|
19209
19279
|
message = _ref.message,
|
|
19280
|
+
description = _ref.description,
|
|
19210
19281
|
_ref$type = _ref.type,
|
|
19211
19282
|
type = _ref$type === void 0 ? 'info' : _ref$type,
|
|
19212
19283
|
_ref$duration = _ref.duration,
|
|
@@ -19214,153 +19285,277 @@ var Toast = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
|
|
|
19214
19285
|
onClose = _ref.onClose,
|
|
19215
19286
|
_ref$position = _ref.position,
|
|
19216
19287
|
position = _ref$position === void 0 ? 'top-right' : _ref$position,
|
|
19288
|
+
statusIcon = _ref.statusIcon,
|
|
19289
|
+
_ref$actions = _ref.actions,
|
|
19290
|
+
actions = _ref$actions === void 0 ? [] : _ref$actions,
|
|
19291
|
+
color = _ref.color,
|
|
19292
|
+
footerNote = _ref.footerNote,
|
|
19293
|
+
_ref$showFooterNote = _ref.showFooterNote,
|
|
19294
|
+
showFooterNote = _ref$showFooterNote === void 0 ? false : _ref$showFooterNote,
|
|
19295
|
+
_ref$portal = _ref.portal,
|
|
19296
|
+
portal = _ref$portal === void 0 ? true : _ref$portal,
|
|
19297
|
+
_ref$className = _ref.className,
|
|
19298
|
+
className = _ref$className === void 0 ? '' : _ref$className,
|
|
19217
19299
|
props = _objectWithoutProperties$1(_ref, _excluded$7);
|
|
19218
19300
|
var _useState = useState(true),
|
|
19219
19301
|
_useState2 = _slicedToArray(_useState, 2),
|
|
19220
19302
|
isVisible = _useState2[0],
|
|
19221
19303
|
setIsVisible = _useState2[1];
|
|
19222
|
-
|
|
19223
|
-
|
|
19224
|
-
|
|
19225
|
-
|
|
19226
|
-
|
|
19227
|
-
|
|
19228
|
-
|
|
19229
|
-
|
|
19230
|
-
|
|
19231
|
-
|
|
19232
|
-
var
|
|
19233
|
-
|
|
19304
|
+
var _useState3 = useState(false),
|
|
19305
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
19306
|
+
isLeaving = _useState4[0],
|
|
19307
|
+
setIsLeaving = _useState4[1];
|
|
19308
|
+
var _useState5 = useState(false),
|
|
19309
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
19310
|
+
isPaused = _useState6[0],
|
|
19311
|
+
setIsPaused = _useState6[1];
|
|
19312
|
+
var progressBarRef = useRef(null);
|
|
19313
|
+
var timerTextRef = useRef(null);
|
|
19314
|
+
var startTimeRef = useRef(null);
|
|
19315
|
+
var remainingRef = useRef(duration);
|
|
19316
|
+
var timerRef = useRef(null);
|
|
19317
|
+
var animFrameRef = useRef(null);
|
|
19318
|
+
var handleClose = useCallback(function () {
|
|
19319
|
+
if (isLeaving) return;
|
|
19320
|
+
setIsLeaving(true);
|
|
19234
19321
|
setTimeout(function () {
|
|
19322
|
+
setIsVisible(false);
|
|
19235
19323
|
onClose === null || onClose === void 0 || onClose(id);
|
|
19236
19324
|
}, 300);
|
|
19237
|
-
};
|
|
19238
|
-
var
|
|
19239
|
-
|
|
19240
|
-
|
|
19241
|
-
|
|
19242
|
-
|
|
19243
|
-
|
|
19244
|
-
|
|
19245
|
-
|
|
19246
|
-
|
|
19247
|
-
|
|
19248
|
-
|
|
19249
|
-
|
|
19250
|
-
|
|
19251
|
-
|
|
19252
|
-
|
|
19253
|
-
|
|
19254
|
-
|
|
19255
|
-
|
|
19256
|
-
|
|
19257
|
-
|
|
19258
|
-
|
|
19259
|
-
|
|
19325
|
+
}, [id, onClose, isLeaving]);
|
|
19326
|
+
var handleStopTimer = useCallback(function (e) {
|
|
19327
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
19328
|
+
setIsPaused(true);
|
|
19329
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
19330
|
+
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
|
|
19331
|
+
}, []);
|
|
19332
|
+
// Direct DOM-based progress updates to prevent 60 FPS React re-renders and glitches
|
|
19333
|
+
useEffect(function () {
|
|
19334
|
+
if (duration <= 0) return;
|
|
19335
|
+
if (isPaused) {
|
|
19336
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
19337
|
+
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
|
|
19338
|
+
return;
|
|
19339
|
+
}
|
|
19340
|
+
startTimeRef.current = Date.now();
|
|
19341
|
+
timerRef.current = setTimeout(function () {
|
|
19342
|
+
handleClose();
|
|
19343
|
+
}, remainingRef.current);
|
|
19344
|
+
var _updateProgress = function updateProgress() {
|
|
19345
|
+
var elapsed = startTimeRef.current ? Date.now() - startTimeRef.current : 0;
|
|
19346
|
+
var currentRemaining = Math.max(0, remainingRef.current - elapsed);
|
|
19347
|
+
var pct = currentRemaining / duration * 100;
|
|
19348
|
+
if (progressBarRef.current) {
|
|
19349
|
+
progressBarRef.current.style.width = "".concat(pct, "%");
|
|
19350
|
+
}
|
|
19351
|
+
if (timerTextRef.current) {
|
|
19352
|
+
var secs = Math.ceil(currentRemaining / 1000);
|
|
19353
|
+
timerTextRef.current.textContent = "This message will close in ".concat(secs, " seconds. ");
|
|
19354
|
+
}
|
|
19355
|
+
if (currentRemaining > 0 && !isPaused) {
|
|
19356
|
+
animFrameRef.current = requestAnimationFrame(_updateProgress);
|
|
19357
|
+
}
|
|
19358
|
+
};
|
|
19359
|
+
animFrameRef.current = requestAnimationFrame(_updateProgress);
|
|
19360
|
+
return function () {
|
|
19361
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
19362
|
+
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
|
|
19363
|
+
if (!isPaused && startTimeRef.current) {
|
|
19364
|
+
var elapsed = Date.now() - startTimeRef.current;
|
|
19365
|
+
remainingRef.current = Math.max(0, remainingRef.current - elapsed);
|
|
19366
|
+
}
|
|
19367
|
+
};
|
|
19368
|
+
}, [duration, isPaused, handleClose]);
|
|
19260
19369
|
if (!isVisible) return null;
|
|
19261
|
-
|
|
19370
|
+
var statusStyle = STATUS_CONFIG[type] || STATUS_CONFIG.info || STATUS_CONFIG["default"];
|
|
19371
|
+
var StatusIconComponent = statusStyle.icon;
|
|
19372
|
+
var bodyText = description || message;
|
|
19373
|
+
var toastContent = jsxs("div", _objectSpread$b(_objectSpread$b({
|
|
19262
19374
|
ref: ref,
|
|
19263
|
-
|
|
19375
|
+
onMouseEnter: function onMouseEnter() {
|
|
19376
|
+
return setIsPaused(true);
|
|
19377
|
+
},
|
|
19378
|
+
onMouseLeave: function onMouseLeave() {
|
|
19379
|
+
return setIsPaused(false);
|
|
19380
|
+
},
|
|
19381
|
+
className: cn$1('relative overflow-hidden rounded-xl border border-slate-200/90 bg-white/95 shadow-xl backdrop-blur-md transition-all duration-300', 'dark:border-slate-800/80 dark:bg-[#18181b] dark:text-slate-100 dark:shadow-2xl', 'max-w-md w-full', isLeaving ? 'opacity-0 scale-95 translate-y-1' : 'animate-slide-up opacity-100 scale-100', portal ? ['fixed z-50', STANDALONE_POSITION_CLASSES[position] || STANDALONE_POSITION_CLASSES['top-right']] : '', className)
|
|
19264
19382
|
}, props), {}, {
|
|
19265
|
-
children:
|
|
19266
|
-
className: "
|
|
19267
|
-
children:
|
|
19268
|
-
className: "flex-
|
|
19269
|
-
children:
|
|
19270
|
-
|
|
19271
|
-
|
|
19272
|
-
|
|
19273
|
-
|
|
19274
|
-
|
|
19275
|
-
|
|
19276
|
-
|
|
19277
|
-
|
|
19383
|
+
children: [jsx("div", {
|
|
19384
|
+
className: "p-4",
|
|
19385
|
+
children: jsxs("div", {
|
|
19386
|
+
className: "flex items-start gap-3 justify-between",
|
|
19387
|
+
children: [jsx("span", {
|
|
19388
|
+
className: "flex-shrink-0 mt-0.5",
|
|
19389
|
+
children: statusIcon ? statusIcon : jsx(StatusIconComponent, {
|
|
19390
|
+
className: cn$1('h-5 w-5', statusStyle.iconClass)
|
|
19391
|
+
})
|
|
19392
|
+
}), jsxs("div", {
|
|
19393
|
+
className: "flex-1 min-w-0 pr-2",
|
|
19394
|
+
children: [title && jsx("h4", {
|
|
19395
|
+
className: "text-sm font-semibold text-slate-900 dark:text-slate-100 leading-snug",
|
|
19396
|
+
children: title
|
|
19397
|
+
}), bodyText && jsx("p", {
|
|
19398
|
+
className: "mt-1 text-xs text-slate-600 dark:text-slate-400 leading-relaxed whitespace-pre-line",
|
|
19399
|
+
children: bodyText
|
|
19400
|
+
}), actions && actions.length > 0 && jsx("div", {
|
|
19401
|
+
className: "mt-3 flex items-center gap-2 flex-wrap",
|
|
19402
|
+
children: actions.map(function (actItem, idx) {
|
|
19403
|
+
return jsx("button", {
|
|
19404
|
+
type: "button",
|
|
19405
|
+
onClick: function onClick(e) {
|
|
19406
|
+
var _actItem$onClick;
|
|
19407
|
+
(_actItem$onClick = actItem.onClick) === null || _actItem$onClick === void 0 || _actItem$onClick.call(actItem, e);
|
|
19408
|
+
if (actItem.dismiss !== false) {
|
|
19409
|
+
handleClose();
|
|
19410
|
+
}
|
|
19411
|
+
},
|
|
19412
|
+
className: cn$1('px-3 py-1.5 text-xs font-medium rounded-lg transition-colors border shadow-xs', actItem.variant === 'primary' ? 'bg-primary-600 hover:bg-primary-700 text-white border-primary-600' : 'bg-slate-100 dark:bg-zinc-800/80 text-slate-700 dark:text-zinc-200 border-slate-200 dark:border-zinc-700 hover:bg-slate-200 dark:hover:bg-zinc-700', actItem.className),
|
|
19413
|
+
children: actItem.label
|
|
19414
|
+
}, actItem.id || actItem.label || "act-".concat(idx));
|
|
19415
|
+
})
|
|
19416
|
+
})]
|
|
19417
|
+
}), jsx("button", {
|
|
19418
|
+
type: "button",
|
|
19419
|
+
"aria-label": "Close notification",
|
|
19420
|
+
className: "flex-shrink-0 rounded-lg p-1 text-slate-400 hover:text-slate-600 dark:hover:text-slate-200 hover:bg-slate-100 dark:hover:bg-zinc-800/70 transition-colors outline-none focus:ring-2 focus:ring-primary-500",
|
|
19421
|
+
onClick: handleClose,
|
|
19422
|
+
children: jsx(X, {
|
|
19423
|
+
className: "h-4 w-4"
|
|
19424
|
+
})
|
|
19278
19425
|
})]
|
|
19279
|
-
})
|
|
19280
|
-
|
|
19281
|
-
|
|
19282
|
-
|
|
19283
|
-
children:
|
|
19284
|
-
|
|
19426
|
+
})
|
|
19427
|
+
}), (showFooterNote || footerNote) && duration > 0 && jsx("div", {
|
|
19428
|
+
className: "px-4 py-2 bg-slate-50 dark:bg-zinc-950/40 border-t border-slate-100 dark:border-zinc-800/50 text-[11px] text-slate-500 dark:text-zinc-400 flex items-center justify-between",
|
|
19429
|
+
children: jsx("span", {
|
|
19430
|
+
children: footerNote ? footerNote : jsxs(Fragment, {
|
|
19431
|
+
children: [jsxs("span", {
|
|
19432
|
+
ref: timerTextRef,
|
|
19433
|
+
children: ["This message will close in ", Math.ceil(duration / 1000), " seconds.", ' ']
|
|
19434
|
+
}), jsx("button", {
|
|
19435
|
+
type: "button",
|
|
19436
|
+
onClick: handleStopTimer,
|
|
19437
|
+
className: "font-medium text-slate-700 dark:text-zinc-200 hover:underline inline",
|
|
19438
|
+
children: "Click to stop."
|
|
19439
|
+
})]
|
|
19285
19440
|
})
|
|
19286
|
-
})
|
|
19287
|
-
})
|
|
19288
|
-
|
|
19441
|
+
})
|
|
19442
|
+
}), duration > 0 && jsx("div", {
|
|
19443
|
+
className: "absolute bottom-0 left-0 right-0 h-0.5 bg-slate-100 dark:bg-zinc-800/80 overflow-hidden rounded-b-xl",
|
|
19444
|
+
children: jsx("div", {
|
|
19445
|
+
ref: progressBarRef,
|
|
19446
|
+
className: cn$1('h-full transition-all ease-linear', color ? '' : statusStyle.progressClass),
|
|
19447
|
+
style: {
|
|
19448
|
+
width: '100%',
|
|
19449
|
+
backgroundColor: color || undefined
|
|
19450
|
+
}
|
|
19451
|
+
})
|
|
19452
|
+
})]
|
|
19453
|
+
}));
|
|
19454
|
+
if (portal) {
|
|
19455
|
+
return /*#__PURE__*/createPortal(toastContent, document.body);
|
|
19456
|
+
}
|
|
19457
|
+
return toastContent;
|
|
19289
19458
|
});
|
|
19290
19459
|
Toast.displayName = 'Toast';
|
|
19291
|
-
// Toast Container Component
|
|
19460
|
+
// Toast Container Component for vertical stacking & scrollable overflow without visible scrollbars
|
|
19292
19461
|
var ToastContainer = function ToastContainer(_ref2) {
|
|
19293
19462
|
var _ref2$toasts = _ref2.toasts,
|
|
19294
19463
|
toasts = _ref2$toasts === void 0 ? [] : _ref2$toasts,
|
|
19295
19464
|
_ref2$position = _ref2.position,
|
|
19296
19465
|
position = _ref2$position === void 0 ? 'top-right' : _ref2$position,
|
|
19297
|
-
onRemove = _ref2.onRemove
|
|
19298
|
-
|
|
19299
|
-
className
|
|
19300
|
-
|
|
19301
|
-
|
|
19302
|
-
|
|
19303
|
-
|
|
19304
|
-
|
|
19305
|
-
|
|
19466
|
+
onRemove = _ref2.onRemove,
|
|
19467
|
+
_ref2$className = _ref2.className,
|
|
19468
|
+
className = _ref2$className === void 0 ? '' : _ref2$className;
|
|
19469
|
+
if (!toasts || toasts.length === 0) {
|
|
19470
|
+
return null;
|
|
19471
|
+
}
|
|
19472
|
+
var posClass = POSITION_CLASSES[position] || POSITION_CLASSES['top-right'];
|
|
19473
|
+
return /*#__PURE__*/createPortal(jsx("div", {
|
|
19474
|
+
className: cn$1('fixed z-50 flex flex-col gap-3 max-h-[calc(100vh-2rem)] overflow-y-auto overflow-x-hidden p-2 pointer-events-none', '[scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden', posClass, className),
|
|
19475
|
+
children: toasts.map(function (t) {
|
|
19476
|
+
return jsx("div", {
|
|
19477
|
+
className: "pointer-events-auto w-full max-w-md",
|
|
19478
|
+
children: jsx(Toast, _objectSpread$b(_objectSpread$b({}, t), {}, {
|
|
19479
|
+
portal: false,
|
|
19480
|
+
position: position,
|
|
19481
|
+
onClose: onRemove
|
|
19482
|
+
}))
|
|
19483
|
+
}, t.id);
|
|
19306
19484
|
})
|
|
19307
|
-
});
|
|
19485
|
+
}), document.body);
|
|
19308
19486
|
};
|
|
19309
19487
|
// Toast Hook
|
|
19310
19488
|
var useToast = function useToast() {
|
|
19311
|
-
var
|
|
19312
|
-
|
|
19313
|
-
toasts =
|
|
19314
|
-
setToasts =
|
|
19315
|
-
var addToast = function
|
|
19316
|
-
var id = Date.now().toString();
|
|
19489
|
+
var _useState7 = useState([]),
|
|
19490
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
19491
|
+
toasts = _useState8[0],
|
|
19492
|
+
setToasts = _useState8[1];
|
|
19493
|
+
var addToast = useCallback(function (toastOptions) {
|
|
19494
|
+
var id = toastOptions.id || "".concat(Date.now(), "-").concat(Math.random().toString(36).slice(2, 7));
|
|
19495
|
+
var newToast = _objectSpread$b(_objectSpread$b({}, toastOptions), {}, {
|
|
19496
|
+
id: id
|
|
19497
|
+
});
|
|
19317
19498
|
setToasts(function (prev) {
|
|
19318
|
-
return [].concat(_toConsumableArray$1(prev), [
|
|
19319
|
-
id: id
|
|
19320
|
-
})]);
|
|
19499
|
+
return [].concat(_toConsumableArray$1(prev), [newToast]);
|
|
19321
19500
|
});
|
|
19322
|
-
|
|
19323
|
-
|
|
19501
|
+
return id;
|
|
19502
|
+
}, []);
|
|
19503
|
+
var removeToast = useCallback(function (id) {
|
|
19324
19504
|
setToasts(function (prev) {
|
|
19325
|
-
return prev.filter(function (
|
|
19326
|
-
return
|
|
19505
|
+
return prev.filter(function (t) {
|
|
19506
|
+
return t.id !== id;
|
|
19327
19507
|
});
|
|
19328
19508
|
});
|
|
19509
|
+
}, []);
|
|
19510
|
+
var clearToasts = useCallback(function () {
|
|
19511
|
+
setToasts([]);
|
|
19512
|
+
}, []);
|
|
19513
|
+
var toast = useCallback(function (options) {
|
|
19514
|
+
return addToast(typeof options === 'string' ? {
|
|
19515
|
+
message: options
|
|
19516
|
+
} : options);
|
|
19517
|
+
}, [addToast]);
|
|
19518
|
+
toast.success = function (title, message, options) {
|
|
19519
|
+
return addToast(_objectSpread$b({
|
|
19520
|
+
title: title,
|
|
19521
|
+
message: message,
|
|
19522
|
+
type: 'success'
|
|
19523
|
+
}, _typeof$4(options) === 'object' ? options : {}));
|
|
19329
19524
|
};
|
|
19330
|
-
|
|
19331
|
-
|
|
19332
|
-
|
|
19333
|
-
|
|
19334
|
-
|
|
19335
|
-
|
|
19336
|
-
|
|
19337
|
-
|
|
19338
|
-
|
|
19339
|
-
|
|
19340
|
-
|
|
19341
|
-
|
|
19342
|
-
|
|
19343
|
-
|
|
19344
|
-
|
|
19345
|
-
|
|
19346
|
-
|
|
19347
|
-
|
|
19348
|
-
|
|
19349
|
-
|
|
19350
|
-
|
|
19351
|
-
|
|
19352
|
-
|
|
19353
|
-
|
|
19354
|
-
|
|
19355
|
-
|
|
19356
|
-
|
|
19357
|
-
}, options));
|
|
19358
|
-
}
|
|
19525
|
+
toast.error = function (title, message, options) {
|
|
19526
|
+
return addToast(_objectSpread$b({
|
|
19527
|
+
title: title,
|
|
19528
|
+
message: message,
|
|
19529
|
+
type: 'error'
|
|
19530
|
+
}, _typeof$4(options) === 'object' ? options : {}));
|
|
19531
|
+
};
|
|
19532
|
+
toast.warning = function (title, message, options) {
|
|
19533
|
+
return addToast(_objectSpread$b({
|
|
19534
|
+
title: title,
|
|
19535
|
+
message: message,
|
|
19536
|
+
type: 'warning'
|
|
19537
|
+
}, _typeof$4(options) === 'object' ? options : {}));
|
|
19538
|
+
};
|
|
19539
|
+
toast.info = function (title, message, options) {
|
|
19540
|
+
return addToast(_objectSpread$b({
|
|
19541
|
+
title: title,
|
|
19542
|
+
message: message,
|
|
19543
|
+
type: 'info'
|
|
19544
|
+
}, _typeof$4(options) === 'object' ? options : {}));
|
|
19545
|
+
};
|
|
19546
|
+
toast["default"] = function (title, message, options) {
|
|
19547
|
+
return addToast(_objectSpread$b({
|
|
19548
|
+
title: title,
|
|
19549
|
+
message: message,
|
|
19550
|
+
type: 'default'
|
|
19551
|
+
}, _typeof$4(options) === 'object' ? options : {}));
|
|
19359
19552
|
};
|
|
19360
19553
|
return {
|
|
19361
19554
|
toast: toast,
|
|
19362
19555
|
toasts: toasts,
|
|
19363
|
-
removeToast: removeToast
|
|
19556
|
+
removeToast: removeToast,
|
|
19557
|
+
clearToasts: clearToasts,
|
|
19558
|
+
addToast: addToast
|
|
19364
19559
|
};
|
|
19365
19560
|
};
|
|
19366
19561
|
|