@deepnoid/ui 0.1.222 → 0.1.223
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/.turbo/turbo-build.log +154 -154
- package/dist/{chunk-YMXYJUOP.mjs → chunk-2URJGQFC.mjs} +1 -1
- package/dist/chunk-RY5VVXQ4.mjs +163 -0
- package/dist/components/table/index.mjs +2 -2
- package/dist/components/table/table-body.mjs +2 -2
- package/dist/components/table/table-head.mjs +2 -2
- package/dist/components/table/table.mjs +2 -2
- package/dist/components/toast/index.d.mts +1 -1
- package/dist/components/toast/index.d.ts +1 -1
- package/dist/components/toast/index.js +104 -12
- package/dist/components/toast/index.mjs +2 -2
- package/dist/components/toast/toast.d.mts +1 -0
- package/dist/components/toast/toast.d.ts +1 -0
- package/dist/components/toast/toast.js +1 -1
- package/dist/components/toast/toast.mjs +1 -1
- package/dist/components/toast/use-toast.d.mts +17 -3
- package/dist/components/toast/use-toast.d.ts +17 -3
- package/dist/components/toast/use-toast.js +104 -12
- package/dist/components/toast/use-toast.mjs +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +104 -12
- package/dist/index.mjs +12 -12
- package/package.json +2 -1
- package/dist/chunk-6S6PH233.mjs +0 -71
- package/dist/{chunk-DQHNPDVN.mjs → chunk-Q3KBMVJS.mjs} +3 -3
|
@@ -55,7 +55,7 @@ var Toast = forwardRef((originalProps, ref) => {
|
|
|
55
55
|
style: hasShadow ? { boxShadow: "0px 6px 18px rgba(0, 0, 0, 0.10)" } : {},
|
|
56
56
|
children: [
|
|
57
57
|
/* @__PURE__ */ jsxs("div", { className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }), children: [
|
|
58
|
-
showIcon && /* @__PURE__ */ jsx(Icon_default, { name: originalProps.icon || "info-circle", fill: true, className: "mt-[2px]" }),
|
|
58
|
+
showIcon && (originalProps.isLoading ? /* @__PURE__ */ jsx(Icon_default, { name: "loading", className: "mt-[2px] animate-spin" }) : /* @__PURE__ */ jsx(Icon_default, { name: originalProps.icon || "info-circle", fill: true, className: "mt-[2px]" })),
|
|
59
59
|
/* @__PURE__ */ jsx("div", { className: slots.title({ class: classNames == null ? void 0 : classNames.title }), children: title }),
|
|
60
60
|
showCloseButton && /* @__PURE__ */ jsx(Icon_default, { name: "close", className: "cursor-pointer", onClick: onClose })
|
|
61
61
|
] }),
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
getToastPosition
|
|
4
|
+
} from "./chunk-ZOTHPHXA.mjs";
|
|
5
|
+
import {
|
|
6
|
+
toast_default
|
|
7
|
+
} from "./chunk-2URJGQFC.mjs";
|
|
8
|
+
|
|
9
|
+
// src/components/toast/use-toast.tsx
|
|
10
|
+
import { createContext, useContext, useState, useCallback, useEffect, useRef, useMemo } from "react";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
var ToastContext = createContext(null);
|
|
13
|
+
var useToast = () => {
|
|
14
|
+
const context = useContext(ToastContext);
|
|
15
|
+
if (!context) {
|
|
16
|
+
throw new Error("useToast must be used within a ToastProvider");
|
|
17
|
+
}
|
|
18
|
+
return context;
|
|
19
|
+
};
|
|
20
|
+
var ToastProvider = ({
|
|
21
|
+
globalOptions,
|
|
22
|
+
children
|
|
23
|
+
}) => {
|
|
24
|
+
const [toasts, setToasts] = useState([]);
|
|
25
|
+
const [containerStyle, setContainerStyle] = useState({});
|
|
26
|
+
const toastRef = useRef(null);
|
|
27
|
+
const timersRef = useRef(/* @__PURE__ */ new Map());
|
|
28
|
+
const startTimer = useCallback((id, duration) => {
|
|
29
|
+
const existing = timersRef.current.get(id);
|
|
30
|
+
if (existing) clearTimeout(existing);
|
|
31
|
+
if (!isFinite(duration) || duration <= 0) {
|
|
32
|
+
timersRef.current.delete(id);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const timer = setTimeout(() => {
|
|
36
|
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
37
|
+
timersRef.current.delete(id);
|
|
38
|
+
}, duration);
|
|
39
|
+
timersRef.current.set(id, timer);
|
|
40
|
+
}, []);
|
|
41
|
+
const clearTimer = useCallback((id) => {
|
|
42
|
+
const timer = timersRef.current.get(id);
|
|
43
|
+
if (timer) {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
timersRef.current.delete(id);
|
|
46
|
+
}
|
|
47
|
+
}, []);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const timers = timersRef.current;
|
|
50
|
+
return () => {
|
|
51
|
+
timers.forEach((timer) => clearTimeout(timer));
|
|
52
|
+
timers.clear();
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
const addToast = useCallback(
|
|
56
|
+
(title, options = {}) => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const id = Date.now() + Math.floor(Math.random() * 1e5);
|
|
59
|
+
const duration = options.isLoading ? Infinity : (_b = (_a = options.duration) != null ? _a : globalOptions == null ? void 0 : globalOptions.duration) != null ? _b : 3e3;
|
|
60
|
+
const newToast = {
|
|
61
|
+
...globalOptions,
|
|
62
|
+
...options,
|
|
63
|
+
id,
|
|
64
|
+
title,
|
|
65
|
+
duration
|
|
66
|
+
};
|
|
67
|
+
setToasts((prev) => [...prev, newToast]);
|
|
68
|
+
startTimer(id, duration);
|
|
69
|
+
return id;
|
|
70
|
+
},
|
|
71
|
+
[globalOptions, startTimer]
|
|
72
|
+
);
|
|
73
|
+
const removeToast = useCallback(
|
|
74
|
+
(id) => {
|
|
75
|
+
clearTimer(id);
|
|
76
|
+
setToasts((prevToasts) => prevToasts.filter((toast) => toast.id !== id));
|
|
77
|
+
},
|
|
78
|
+
[clearTimer]
|
|
79
|
+
);
|
|
80
|
+
const updateToast = useCallback(
|
|
81
|
+
(id, options) => {
|
|
82
|
+
setToasts(
|
|
83
|
+
(prev) => prev.map((t) => {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
if (t.id !== id) return t;
|
|
86
|
+
const updated = { ...t, ...options };
|
|
87
|
+
if (t.isLoading && options.isLoading === false) {
|
|
88
|
+
const duration = (_b = (_a = options.duration) != null ? _a : globalOptions == null ? void 0 : globalOptions.duration) != null ? _b : 3e3;
|
|
89
|
+
updated.duration = duration;
|
|
90
|
+
startTimer(id, duration);
|
|
91
|
+
}
|
|
92
|
+
return updated;
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
[globalOptions == null ? void 0 : globalOptions.duration, startTimer]
|
|
97
|
+
);
|
|
98
|
+
const dismissToast = useCallback(
|
|
99
|
+
(id) => {
|
|
100
|
+
if (id !== void 0) {
|
|
101
|
+
removeToast(id);
|
|
102
|
+
} else {
|
|
103
|
+
timersRef.current.forEach((timer) => clearTimeout(timer));
|
|
104
|
+
timersRef.current.clear();
|
|
105
|
+
setToasts([]);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
[removeToast]
|
|
109
|
+
);
|
|
110
|
+
const loadingToast = useCallback(
|
|
111
|
+
(title, options = {}) => {
|
|
112
|
+
return addToast(title, { ...options, isLoading: true });
|
|
113
|
+
},
|
|
114
|
+
[addToast]
|
|
115
|
+
);
|
|
116
|
+
const contextValue = useMemo(() => {
|
|
117
|
+
const fn = (title, options) => {
|
|
118
|
+
return addToast(title, options);
|
|
119
|
+
};
|
|
120
|
+
fn.loading = loadingToast;
|
|
121
|
+
fn.update = updateToast;
|
|
122
|
+
fn.dismiss = dismissToast;
|
|
123
|
+
fn.promise = (promise, messages, options = {}) => {
|
|
124
|
+
const id = loadingToast(messages.loading, options);
|
|
125
|
+
return promise.then(
|
|
126
|
+
(data) => {
|
|
127
|
+
const title = typeof messages.success === "function" ? messages.success(data) : messages.success;
|
|
128
|
+
updateToast(id, { title, color: "success", isLoading: false });
|
|
129
|
+
return data;
|
|
130
|
+
},
|
|
131
|
+
(err) => {
|
|
132
|
+
const title = typeof messages.error === "function" ? messages.error(err) : messages.error;
|
|
133
|
+
updateToast(id, { title, color: "danger", isLoading: false });
|
|
134
|
+
throw err;
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
return fn;
|
|
139
|
+
}, [addToast, loadingToast, updateToast, dismissToast]);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
var _a;
|
|
142
|
+
const width = (globalOptions == null ? void 0 : globalOptions.width) ? globalOptions.width : typeof ((_a = toastRef.current) == null ? void 0 : _a.getWidth) === "function" ? toastRef.current.getWidth() : 300;
|
|
143
|
+
const offset = 20;
|
|
144
|
+
const placement = (globalOptions == null ? void 0 : globalOptions.placement) || "bottom-right";
|
|
145
|
+
const { top, left, bottom, right } = getToastPosition(placement, width, offset);
|
|
146
|
+
setContainerStyle({
|
|
147
|
+
position: "fixed",
|
|
148
|
+
top: top !== void 0 ? `${top}px` : void 0,
|
|
149
|
+
left: left !== void 0 ? `${left}px` : void 0,
|
|
150
|
+
bottom: bottom !== void 0 ? `${bottom}px` : void 0,
|
|
151
|
+
right: right !== void 0 ? `${right}px` : void 0
|
|
152
|
+
});
|
|
153
|
+
}, [globalOptions == null ? void 0 : globalOptions.placement, globalOptions == null ? void 0 : globalOptions.width]);
|
|
154
|
+
return /* @__PURE__ */ jsxs(ToastContext.Provider, { value: contextValue, children: [
|
|
155
|
+
children,
|
|
156
|
+
/* @__PURE__ */ jsx("div", { id: "deepnoid-toast-container", className: "flex flex-col gap-[10px]", style: containerStyle, children: toasts.map((toast) => /* @__PURE__ */ jsx(toast_default, { ref: toastRef, onClose: () => removeToast(toast.id), ...toast }, toast.id)) })
|
|
157
|
+
] });
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export {
|
|
161
|
+
useToast,
|
|
162
|
+
ToastProvider
|
|
163
|
+
};
|
|
@@ -5,16 +5,16 @@ import {
|
|
|
5
5
|
} from "../../chunk-BH3I4LIZ.mjs";
|
|
6
6
|
import {
|
|
7
7
|
table_default
|
|
8
|
-
} from "../../chunk-
|
|
8
|
+
} from "../../chunk-Q3KBMVJS.mjs";
|
|
9
9
|
import "../../chunk-7B7LRG5J.mjs";
|
|
10
10
|
import "../../chunk-TE5JU3WA.mjs";
|
|
11
11
|
import "../../chunk-F3HENRVM.mjs";
|
|
12
12
|
import "../../chunk-QZ3LVYJW.mjs";
|
|
13
|
+
import "../../chunk-3DCUMRYP.mjs";
|
|
13
14
|
import "../../chunk-2GCSFWHD.mjs";
|
|
14
15
|
import "../../chunk-EJ4GDC6K.mjs";
|
|
15
16
|
import "../../chunk-DQRAFUDA.mjs";
|
|
16
17
|
import "../../chunk-EWS3FESG.mjs";
|
|
17
|
-
import "../../chunk-3DCUMRYP.mjs";
|
|
18
18
|
import "../../chunk-ZYIIXWVY.mjs";
|
|
19
19
|
import "../../chunk-6AID2NLT.mjs";
|
|
20
20
|
import "../../chunk-P5L4YI54.mjs";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
table_body_default
|
|
4
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-Q3KBMVJS.mjs";
|
|
5
5
|
import "../../chunk-7B7LRG5J.mjs";
|
|
6
6
|
import "../../chunk-TE5JU3WA.mjs";
|
|
7
7
|
import "../../chunk-F3HENRVM.mjs";
|
|
8
8
|
import "../../chunk-QZ3LVYJW.mjs";
|
|
9
|
+
import "../../chunk-3DCUMRYP.mjs";
|
|
9
10
|
import "../../chunk-2GCSFWHD.mjs";
|
|
10
11
|
import "../../chunk-EJ4GDC6K.mjs";
|
|
11
12
|
import "../../chunk-DQRAFUDA.mjs";
|
|
12
13
|
import "../../chunk-EWS3FESG.mjs";
|
|
13
|
-
import "../../chunk-3DCUMRYP.mjs";
|
|
14
14
|
import "../../chunk-ZYIIXWVY.mjs";
|
|
15
15
|
import "../../chunk-6AID2NLT.mjs";
|
|
16
16
|
import "../../chunk-P5L4YI54.mjs";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
table_head_default
|
|
4
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-Q3KBMVJS.mjs";
|
|
5
5
|
import "../../chunk-7B7LRG5J.mjs";
|
|
6
6
|
import "../../chunk-TE5JU3WA.mjs";
|
|
7
7
|
import "../../chunk-F3HENRVM.mjs";
|
|
8
8
|
import "../../chunk-QZ3LVYJW.mjs";
|
|
9
|
+
import "../../chunk-3DCUMRYP.mjs";
|
|
9
10
|
import "../../chunk-2GCSFWHD.mjs";
|
|
10
11
|
import "../../chunk-EJ4GDC6K.mjs";
|
|
11
12
|
import "../../chunk-DQRAFUDA.mjs";
|
|
12
13
|
import "../../chunk-EWS3FESG.mjs";
|
|
13
|
-
import "../../chunk-3DCUMRYP.mjs";
|
|
14
14
|
import "../../chunk-ZYIIXWVY.mjs";
|
|
15
15
|
import "../../chunk-6AID2NLT.mjs";
|
|
16
16
|
import "../../chunk-P5L4YI54.mjs";
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
import {
|
|
3
3
|
getCellStyle,
|
|
4
4
|
table_default
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-Q3KBMVJS.mjs";
|
|
6
6
|
import "../../chunk-7B7LRG5J.mjs";
|
|
7
7
|
import "../../chunk-TE5JU3WA.mjs";
|
|
8
8
|
import "../../chunk-F3HENRVM.mjs";
|
|
9
9
|
import "../../chunk-QZ3LVYJW.mjs";
|
|
10
|
+
import "../../chunk-3DCUMRYP.mjs";
|
|
10
11
|
import "../../chunk-2GCSFWHD.mjs";
|
|
11
12
|
import "../../chunk-EJ4GDC6K.mjs";
|
|
12
13
|
import "../../chunk-DQRAFUDA.mjs";
|
|
13
14
|
import "../../chunk-EWS3FESG.mjs";
|
|
14
|
-
import "../../chunk-3DCUMRYP.mjs";
|
|
15
15
|
import "../../chunk-ZYIIXWVY.mjs";
|
|
16
16
|
import "../../chunk-6AID2NLT.mjs";
|
|
17
17
|
import "../../chunk-P5L4YI54.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { default as Toast, ToastProps } from './toast.mjs';
|
|
2
|
-
export { ToastProvider, useToast } from './use-toast.mjs';
|
|
2
|
+
export { CreateToastOptions, ToastFunction, ToastId, ToastPromiseMessages, ToastProvider, useToast } from './use-toast.mjs';
|
|
3
3
|
import 'tailwind-variants';
|
|
4
4
|
import 'react';
|
|
5
5
|
import './toast-utils.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { default as Toast, ToastProps } from './toast.js';
|
|
2
|
-
export { ToastProvider, useToast } from './use-toast.js';
|
|
2
|
+
export { CreateToastOptions, ToastFunction, ToastId, ToastPromiseMessages, ToastProvider, useToast } from './use-toast.js';
|
|
3
3
|
import 'tailwind-variants';
|
|
4
4
|
import 'react';
|
|
5
5
|
import './toast-utils.js';
|
|
@@ -5332,7 +5332,7 @@ var Toast = (0, import_react.forwardRef)((originalProps, ref) => {
|
|
|
5332
5332
|
style: hasShadow ? { boxShadow: "0px 6px 18px rgba(0, 0, 0, 0.10)" } : {},
|
|
5333
5333
|
children: [
|
|
5334
5334
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }), children: [
|
|
5335
|
-
showIcon && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon_default, { name: originalProps.icon || "info-circle", fill: true, className: "mt-[2px]" }),
|
|
5335
|
+
showIcon && (originalProps.isLoading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon_default, { name: "loading", className: "mt-[2px] animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon_default, { name: originalProps.icon || "info-circle", fill: true, className: "mt-[2px]" })),
|
|
5336
5336
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: slots.title({ class: classNames == null ? void 0 : classNames.title }), children: title }),
|
|
5337
5337
|
showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon_default, { name: "close", className: "cursor-pointer", onClick: onClose })
|
|
5338
5338
|
] }),
|
|
@@ -5496,27 +5496,119 @@ var ToastProvider = ({
|
|
|
5496
5496
|
const [toasts, setToasts] = (0, import_react2.useState)([]);
|
|
5497
5497
|
const [containerStyle, setContainerStyle] = (0, import_react2.useState)({});
|
|
5498
5498
|
const toastRef = (0, import_react2.useRef)(null);
|
|
5499
|
+
const timersRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
5500
|
+
const startTimer = (0, import_react2.useCallback)((id, duration) => {
|
|
5501
|
+
const existing = timersRef.current.get(id);
|
|
5502
|
+
if (existing) clearTimeout(existing);
|
|
5503
|
+
if (!isFinite(duration) || duration <= 0) {
|
|
5504
|
+
timersRef.current.delete(id);
|
|
5505
|
+
return;
|
|
5506
|
+
}
|
|
5507
|
+
const timer = setTimeout(() => {
|
|
5508
|
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
5509
|
+
timersRef.current.delete(id);
|
|
5510
|
+
}, duration);
|
|
5511
|
+
timersRef.current.set(id, timer);
|
|
5512
|
+
}, []);
|
|
5513
|
+
const clearTimer = (0, import_react2.useCallback)((id) => {
|
|
5514
|
+
const timer = timersRef.current.get(id);
|
|
5515
|
+
if (timer) {
|
|
5516
|
+
clearTimeout(timer);
|
|
5517
|
+
timersRef.current.delete(id);
|
|
5518
|
+
}
|
|
5519
|
+
}, []);
|
|
5520
|
+
(0, import_react2.useEffect)(() => {
|
|
5521
|
+
const timers = timersRef.current;
|
|
5522
|
+
return () => {
|
|
5523
|
+
timers.forEach((timer) => clearTimeout(timer));
|
|
5524
|
+
timers.clear();
|
|
5525
|
+
};
|
|
5526
|
+
}, []);
|
|
5499
5527
|
const addToast = (0, import_react2.useCallback)(
|
|
5500
5528
|
(title, options = {}) => {
|
|
5529
|
+
var _a, _b;
|
|
5501
5530
|
const id = Date.now() + Math.floor(Math.random() * 1e5);
|
|
5531
|
+
const duration = options.isLoading ? Infinity : (_b = (_a = options.duration) != null ? _a : globalOptions == null ? void 0 : globalOptions.duration) != null ? _b : 3e3;
|
|
5502
5532
|
const newToast = {
|
|
5533
|
+
...globalOptions,
|
|
5534
|
+
...options,
|
|
5503
5535
|
id,
|
|
5504
5536
|
title,
|
|
5505
|
-
duration
|
|
5506
|
-
...globalOptions,
|
|
5507
|
-
...options
|
|
5537
|
+
duration
|
|
5508
5538
|
};
|
|
5509
5539
|
setToasts((prev) => [...prev, newToast]);
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
}, newToast.duration || 3e3);
|
|
5540
|
+
startTimer(id, duration);
|
|
5541
|
+
return id;
|
|
5513
5542
|
},
|
|
5514
|
-
[globalOptions]
|
|
5543
|
+
[globalOptions, startTimer]
|
|
5515
5544
|
);
|
|
5516
|
-
const removeToast = (0, import_react2.useCallback)(
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5545
|
+
const removeToast = (0, import_react2.useCallback)(
|
|
5546
|
+
(id) => {
|
|
5547
|
+
clearTimer(id);
|
|
5548
|
+
setToasts((prevToasts) => prevToasts.filter((toast2) => toast2.id !== id));
|
|
5549
|
+
},
|
|
5550
|
+
[clearTimer]
|
|
5551
|
+
);
|
|
5552
|
+
const updateToast = (0, import_react2.useCallback)(
|
|
5553
|
+
(id, options) => {
|
|
5554
|
+
setToasts(
|
|
5555
|
+
(prev) => prev.map((t) => {
|
|
5556
|
+
var _a, _b;
|
|
5557
|
+
if (t.id !== id) return t;
|
|
5558
|
+
const updated = { ...t, ...options };
|
|
5559
|
+
if (t.isLoading && options.isLoading === false) {
|
|
5560
|
+
const duration = (_b = (_a = options.duration) != null ? _a : globalOptions == null ? void 0 : globalOptions.duration) != null ? _b : 3e3;
|
|
5561
|
+
updated.duration = duration;
|
|
5562
|
+
startTimer(id, duration);
|
|
5563
|
+
}
|
|
5564
|
+
return updated;
|
|
5565
|
+
})
|
|
5566
|
+
);
|
|
5567
|
+
},
|
|
5568
|
+
[globalOptions == null ? void 0 : globalOptions.duration, startTimer]
|
|
5569
|
+
);
|
|
5570
|
+
const dismissToast = (0, import_react2.useCallback)(
|
|
5571
|
+
(id) => {
|
|
5572
|
+
if (id !== void 0) {
|
|
5573
|
+
removeToast(id);
|
|
5574
|
+
} else {
|
|
5575
|
+
timersRef.current.forEach((timer) => clearTimeout(timer));
|
|
5576
|
+
timersRef.current.clear();
|
|
5577
|
+
setToasts([]);
|
|
5578
|
+
}
|
|
5579
|
+
},
|
|
5580
|
+
[removeToast]
|
|
5581
|
+
);
|
|
5582
|
+
const loadingToast = (0, import_react2.useCallback)(
|
|
5583
|
+
(title, options = {}) => {
|
|
5584
|
+
return addToast(title, { ...options, isLoading: true });
|
|
5585
|
+
},
|
|
5586
|
+
[addToast]
|
|
5587
|
+
);
|
|
5588
|
+
const contextValue = (0, import_react2.useMemo)(() => {
|
|
5589
|
+
const fn = (title, options) => {
|
|
5590
|
+
return addToast(title, options);
|
|
5591
|
+
};
|
|
5592
|
+
fn.loading = loadingToast;
|
|
5593
|
+
fn.update = updateToast;
|
|
5594
|
+
fn.dismiss = dismissToast;
|
|
5595
|
+
fn.promise = (promise, messages, options = {}) => {
|
|
5596
|
+
const id = loadingToast(messages.loading, options);
|
|
5597
|
+
return promise.then(
|
|
5598
|
+
(data) => {
|
|
5599
|
+
const title = typeof messages.success === "function" ? messages.success(data) : messages.success;
|
|
5600
|
+
updateToast(id, { title, color: "success", isLoading: false });
|
|
5601
|
+
return data;
|
|
5602
|
+
},
|
|
5603
|
+
(err) => {
|
|
5604
|
+
const title = typeof messages.error === "function" ? messages.error(err) : messages.error;
|
|
5605
|
+
updateToast(id, { title, color: "danger", isLoading: false });
|
|
5606
|
+
throw err;
|
|
5607
|
+
}
|
|
5608
|
+
);
|
|
5609
|
+
};
|
|
5610
|
+
return fn;
|
|
5611
|
+
}, [addToast, loadingToast, updateToast, dismissToast]);
|
|
5520
5612
|
(0, import_react2.useEffect)(() => {
|
|
5521
5613
|
var _a;
|
|
5522
5614
|
const width = (globalOptions == null ? void 0 : globalOptions.width) ? globalOptions.width : typeof ((_a = toastRef.current) == null ? void 0 : _a.getWidth) === "function" ? toastRef.current.getWidth() : 300;
|
|
@@ -3,11 +3,11 @@ import "../../chunk-LUWGOKLG.mjs";
|
|
|
3
3
|
import {
|
|
4
4
|
ToastProvider,
|
|
5
5
|
useToast
|
|
6
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-RY5VVXQ4.mjs";
|
|
7
7
|
import "../../chunk-ZOTHPHXA.mjs";
|
|
8
8
|
import {
|
|
9
9
|
toast_default
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-2URJGQFC.mjs";
|
|
11
11
|
import "../../chunk-ZYIIXWVY.mjs";
|
|
12
12
|
import "../../chunk-6AID2NLT.mjs";
|
|
13
13
|
import "../../chunk-P5L4YI54.mjs";
|
|
@@ -5328,7 +5328,7 @@ var Toast = (0, import_react.forwardRef)((originalProps, ref) => {
|
|
|
5328
5328
|
style: hasShadow ? { boxShadow: "0px 6px 18px rgba(0, 0, 0, 0.10)" } : {},
|
|
5329
5329
|
children: [
|
|
5330
5330
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }), children: [
|
|
5331
|
-
showIcon && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon_default, { name: originalProps.icon || "info-circle", fill: true, className: "mt-[2px]" }),
|
|
5331
|
+
showIcon && (originalProps.isLoading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon_default, { name: "loading", className: "mt-[2px] animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon_default, { name: originalProps.icon || "info-circle", fill: true, className: "mt-[2px]" })),
|
|
5332
5332
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: slots.title({ class: classNames == null ? void 0 : classNames.title }), children: title }),
|
|
5333
5333
|
showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon_default, { name: "close", className: "cursor-pointer", onClick: onClose })
|
|
5334
5334
|
] }),
|
|
@@ -5,8 +5,9 @@ import { IconName } from '../icon/Icon.mjs';
|
|
|
5
5
|
import '../icon/template.mjs';
|
|
6
6
|
import '../../utils/types.mjs';
|
|
7
7
|
|
|
8
|
+
type ToastId = string | number;
|
|
8
9
|
interface ToastOptions {
|
|
9
|
-
id:
|
|
10
|
+
id: ToastId;
|
|
10
11
|
title: string;
|
|
11
12
|
width?: number;
|
|
12
13
|
duration?: number;
|
|
@@ -15,9 +16,22 @@ interface ToastOptions {
|
|
|
15
16
|
icon?: IconName;
|
|
16
17
|
showIcon?: boolean;
|
|
17
18
|
showCloseButton?: boolean;
|
|
19
|
+
isLoading?: boolean;
|
|
20
|
+
content?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
type CreateToastOptions = Omit<ToastOptions, "id" | "placement" | "width" | "title">;
|
|
23
|
+
type UpdateToastOptions = Partial<Omit<ToastOptions, "id" | "placement" | "width">>;
|
|
24
|
+
interface ToastPromiseMessages<T> {
|
|
25
|
+
loading: string;
|
|
26
|
+
success: string | ((data: T) => string);
|
|
27
|
+
error: string | ((err: unknown) => string);
|
|
18
28
|
}
|
|
19
29
|
interface ToastFunction {
|
|
20
|
-
(title: string, options?:
|
|
30
|
+
(title: string, options?: CreateToastOptions): ToastId;
|
|
31
|
+
loading: (title: string, options?: Omit<CreateToastOptions, "isLoading">) => ToastId;
|
|
32
|
+
update: (id: ToastId, options: UpdateToastOptions) => void;
|
|
33
|
+
dismiss: (id?: ToastId) => void;
|
|
34
|
+
promise: <T>(promise: Promise<T>, messages: ToastPromiseMessages<T>, options?: Omit<CreateToastOptions, "isLoading">) => Promise<T>;
|
|
21
35
|
}
|
|
22
36
|
declare const useToast: () => ToastFunction;
|
|
23
37
|
declare const ToastProvider: ({ globalOptions, children, }: {
|
|
@@ -25,4 +39,4 @@ declare const ToastProvider: ({ globalOptions, children, }: {
|
|
|
25
39
|
children: ReactNode;
|
|
26
40
|
}) => react_jsx_runtime.JSX.Element;
|
|
27
41
|
|
|
28
|
-
export { ToastProvider, useToast };
|
|
42
|
+
export { type CreateToastOptions, type ToastFunction, type ToastId, type ToastOptions, type ToastPromiseMessages, ToastProvider, type UpdateToastOptions, useToast };
|
|
@@ -5,8 +5,9 @@ import { IconName } from '../icon/Icon.js';
|
|
|
5
5
|
import '../icon/template.js';
|
|
6
6
|
import '../../utils/types.js';
|
|
7
7
|
|
|
8
|
+
type ToastId = string | number;
|
|
8
9
|
interface ToastOptions {
|
|
9
|
-
id:
|
|
10
|
+
id: ToastId;
|
|
10
11
|
title: string;
|
|
11
12
|
width?: number;
|
|
12
13
|
duration?: number;
|
|
@@ -15,9 +16,22 @@ interface ToastOptions {
|
|
|
15
16
|
icon?: IconName;
|
|
16
17
|
showIcon?: boolean;
|
|
17
18
|
showCloseButton?: boolean;
|
|
19
|
+
isLoading?: boolean;
|
|
20
|
+
content?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
type CreateToastOptions = Omit<ToastOptions, "id" | "placement" | "width" | "title">;
|
|
23
|
+
type UpdateToastOptions = Partial<Omit<ToastOptions, "id" | "placement" | "width">>;
|
|
24
|
+
interface ToastPromiseMessages<T> {
|
|
25
|
+
loading: string;
|
|
26
|
+
success: string | ((data: T) => string);
|
|
27
|
+
error: string | ((err: unknown) => string);
|
|
18
28
|
}
|
|
19
29
|
interface ToastFunction {
|
|
20
|
-
(title: string, options?:
|
|
30
|
+
(title: string, options?: CreateToastOptions): ToastId;
|
|
31
|
+
loading: (title: string, options?: Omit<CreateToastOptions, "isLoading">) => ToastId;
|
|
32
|
+
update: (id: ToastId, options: UpdateToastOptions) => void;
|
|
33
|
+
dismiss: (id?: ToastId) => void;
|
|
34
|
+
promise: <T>(promise: Promise<T>, messages: ToastPromiseMessages<T>, options?: Omit<CreateToastOptions, "isLoading">) => Promise<T>;
|
|
21
35
|
}
|
|
22
36
|
declare const useToast: () => ToastFunction;
|
|
23
37
|
declare const ToastProvider: ({ globalOptions, children, }: {
|
|
@@ -25,4 +39,4 @@ declare const ToastProvider: ({ globalOptions, children, }: {
|
|
|
25
39
|
children: ReactNode;
|
|
26
40
|
}) => react_jsx_runtime.JSX.Element;
|
|
27
41
|
|
|
28
|
-
export { ToastProvider, useToast };
|
|
42
|
+
export { type CreateToastOptions, type ToastFunction, type ToastId, type ToastOptions, type ToastPromiseMessages, ToastProvider, type UpdateToastOptions, useToast };
|