@react-opener/toast 0.0.1-alpha.1
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/dist/Renderer.d.ts +7 -0
- package/dist/components/ToastBar.d.ts +11 -0
- package/dist/components/ToastIcon.d.ts +5 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +413 -0
- package/dist/store.d.ts +49 -0
- package/dist/useToast.d.ts +10 -0
- package/esm/Renderer.mjs +61 -0
- package/esm/_virtual/_rollupPluginBabelHelpers.mjs +61 -0
- package/esm/components/ToastBar.mjs +58 -0
- package/esm/components/ToastIcon.mjs +35 -0
- package/esm/index.mjs +12 -0
- package/esm/node_modules/.pnpm/goober@2.1.18_csstype@3.2.3/node_modules/goober/dist/goober.modern.mjs +115 -0
- package/esm/store.mjs +80 -0
- package/esm/useToast.mjs +25 -0
- package/package.json +59 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Options, createToastStore } from "./store";
|
|
2
|
+
export declare const ReactToastOpener: ({ store, style, className, options, }: {
|
|
3
|
+
store: ReturnType<typeof createToastStore>;
|
|
4
|
+
style?: React.CSSProperties;
|
|
5
|
+
className?: string;
|
|
6
|
+
options?: Options;
|
|
7
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Toast, ToastPositionType } from "../store";
|
|
2
|
+
export declare const ToastBar: React.FC<{
|
|
3
|
+
isOpen: boolean;
|
|
4
|
+
toast: Toast & {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
delay: number;
|
|
8
|
+
position: ToastPositionType;
|
|
9
|
+
close: (id: string) => void;
|
|
10
|
+
unmount: (id: string) => void;
|
|
11
|
+
}>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createToastStore } from "./store";
|
|
2
|
+
import { ReactToastOpener as _ReactToastOpener } from "./Renderer";
|
|
3
|
+
import { useToast } from "./useToast";
|
|
4
|
+
type CompoundedComponent = typeof _ReactToastOpener & {
|
|
5
|
+
createStore: typeof createToastStore;
|
|
6
|
+
useToast: typeof useToast;
|
|
7
|
+
};
|
|
8
|
+
declare const ReactToastOpener: CompoundedComponent;
|
|
9
|
+
export { ReactToastOpener };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactOpener = require('react-opener');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
function _defineProperty(e, r, t) {
|
|
8
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
9
|
+
value: t,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true
|
|
13
|
+
}) : e[r] = t, e;
|
|
14
|
+
}
|
|
15
|
+
function ownKeys(e, r) {
|
|
16
|
+
var t = Object.keys(e);
|
|
17
|
+
if (Object.getOwnPropertySymbols) {
|
|
18
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
19
|
+
r && (o = o.filter(function (r) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
21
|
+
})), t.push.apply(t, o);
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
}
|
|
25
|
+
function _objectSpread2(e) {
|
|
26
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
27
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
28
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
29
|
+
_defineProperty(e, r, t[r]);
|
|
30
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
31
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return e;
|
|
35
|
+
}
|
|
36
|
+
function _taggedTemplateLiteral(e, t) {
|
|
37
|
+
return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, {
|
|
38
|
+
raw: {
|
|
39
|
+
value: Object.freeze(t)
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
function _toPrimitive(t, r) {
|
|
44
|
+
if ("object" != typeof t || !t) return t;
|
|
45
|
+
var e = t[Symbol.toPrimitive];
|
|
46
|
+
if (void 0 !== e) {
|
|
47
|
+
var i = e.call(t, r);
|
|
48
|
+
if ("object" != typeof i) return i;
|
|
49
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
50
|
+
}
|
|
51
|
+
return ("string" === r ? String : Number)(t);
|
|
52
|
+
}
|
|
53
|
+
function _toPropertyKey(t) {
|
|
54
|
+
var i = _toPrimitive(t, "string");
|
|
55
|
+
return "symbol" == typeof i ? i : i + "";
|
|
56
|
+
}
|
|
57
|
+
function _typeof(o) {
|
|
58
|
+
"@babel/helpers - typeof";
|
|
59
|
+
|
|
60
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
61
|
+
return typeof o;
|
|
62
|
+
} : function (o) {
|
|
63
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
64
|
+
}, _typeof(o);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var e = {
|
|
68
|
+
data: ""
|
|
69
|
+
},
|
|
70
|
+
t = function t(_t) {
|
|
71
|
+
if ("object" == (typeof window === "undefined" ? "undefined" : _typeof(window))) {
|
|
72
|
+
var _e = (_t ? _t.querySelector("#_goober") : window._goober) || Object.assign(document.createElement("style"), {
|
|
73
|
+
innerHTML: " ",
|
|
74
|
+
id: "_goober"
|
|
75
|
+
});
|
|
76
|
+
return _e.nonce = window.__nonce__, _e.parentNode || (_t || document.head).appendChild(_e), _e.firstChild;
|
|
77
|
+
}
|
|
78
|
+
return _t || e;
|
|
79
|
+
},
|
|
80
|
+
l = /(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,
|
|
81
|
+
a = /\/\*[^]*?\*\/| +/g,
|
|
82
|
+
n = /\n+/g,
|
|
83
|
+
_o = function o(e, t) {
|
|
84
|
+
var r = "",
|
|
85
|
+
l = "",
|
|
86
|
+
a = "";
|
|
87
|
+
var _loop = function _loop(_n) {
|
|
88
|
+
var c = e[_n];
|
|
89
|
+
"@" == _n[0] ? "i" == _n[1] ? r = _n + " " + c + ";" : l += "f" == _n[1] ? _o(c, _n) : _n + "{" + _o(c, "k" == _n[1] ? "" : t) + "}" : "object" == _typeof(c) ? l += _o(c, t ? t.replace(/([^,])+/g, function (e) {
|
|
90
|
+
return _n.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g, function (t) {
|
|
91
|
+
return /&/.test(t) ? t.replace(/&/g, e) : e ? e + " " + t : t;
|
|
92
|
+
});
|
|
93
|
+
}) : _n) : null != c && (_n = /^--/.test(_n) ? _n : _n.replace(/[A-Z]/g, "-$&").toLowerCase(), a += _o.p ? _o.p(_n, c) : _n + ":" + c + ";");
|
|
94
|
+
};
|
|
95
|
+
for (var _n in e) {
|
|
96
|
+
_loop(_n);
|
|
97
|
+
}
|
|
98
|
+
return r + (t && a ? t + "{" + a + "}" : a) + l;
|
|
99
|
+
},
|
|
100
|
+
c = {},
|
|
101
|
+
_s = function s(e) {
|
|
102
|
+
if ("object" == _typeof(e)) {
|
|
103
|
+
var _t2 = "";
|
|
104
|
+
for (var _r in e) _t2 += _r + _s(e[_r]);
|
|
105
|
+
return _t2;
|
|
106
|
+
}
|
|
107
|
+
return e;
|
|
108
|
+
},
|
|
109
|
+
i = function i(e, t, r, _i, p) {
|
|
110
|
+
var u = _s(e),
|
|
111
|
+
d = c[u] || (c[u] = function (e) {
|
|
112
|
+
var t = 0,
|
|
113
|
+
r = 11;
|
|
114
|
+
for (; t < e.length;) r = 101 * r + e.charCodeAt(t++) >>> 0;
|
|
115
|
+
return "go" + r;
|
|
116
|
+
}(u));
|
|
117
|
+
if (!c[d]) {
|
|
118
|
+
var _t3 = u !== e ? e : function (e) {
|
|
119
|
+
var t,
|
|
120
|
+
r,
|
|
121
|
+
o = [{}];
|
|
122
|
+
for (; t = l.exec(e.replace(a, ""));) t[4] ? o.shift() : t[3] ? (r = t[3].replace(n, " ").trim(), o.unshift(o[0][r] = o[0][r] || {})) : o[0][t[1]] = t[2].replace(n, " ").trim();
|
|
123
|
+
return o[0];
|
|
124
|
+
}(e);
|
|
125
|
+
c[d] = _o(p ? _defineProperty({}, "@keyframes " + d, _t3) : _t3, r ? "" : "." + d);
|
|
126
|
+
}
|
|
127
|
+
var f = r && c.g ? c.g : null;
|
|
128
|
+
return r && (c.g = c[d]), function (e, t, r, l) {
|
|
129
|
+
l ? t.data = t.data.replace(l, e) : -1 === t.data.indexOf(e) && (t.data = r ? e + t.data : t.data + e);
|
|
130
|
+
}(c[d], t, _i, f), d;
|
|
131
|
+
},
|
|
132
|
+
p = function p(e, t, r) {
|
|
133
|
+
return e.reduce(function (e, l, a) {
|
|
134
|
+
var n = t[a];
|
|
135
|
+
if (n && n.call) {
|
|
136
|
+
var _e2 = n(r),
|
|
137
|
+
_t4 = _e2 && _e2.props && _e2.props.className || /^go/.test(_e2) && _e2;
|
|
138
|
+
n = _t4 ? "." + _t4 : _e2 && "object" == _typeof(_e2) ? _e2.props ? "" : _o(_e2, "") : false === _e2 ? "" : _e2;
|
|
139
|
+
}
|
|
140
|
+
return e + l + (null == n ? "" : n);
|
|
141
|
+
}, "");
|
|
142
|
+
};
|
|
143
|
+
function u(e) {
|
|
144
|
+
var r = this || {},
|
|
145
|
+
l = e.call ? e(r.p) : e;
|
|
146
|
+
return i(l.unshift ? l.raw ? p(l, [].slice.call(arguments, 1), r.p) : l.reduce(function (e, t) {
|
|
147
|
+
return Object.assign(e, t && t.call ? t(r.p) : t);
|
|
148
|
+
}, {}) : l, t(r.target), r.g, r.o, r.k);
|
|
149
|
+
}
|
|
150
|
+
var d,
|
|
151
|
+
f,
|
|
152
|
+
g;
|
|
153
|
+
u.bind({
|
|
154
|
+
g: 1
|
|
155
|
+
});
|
|
156
|
+
var h = u.bind({
|
|
157
|
+
k: 1
|
|
158
|
+
});
|
|
159
|
+
function m(e, t, r, l) {
|
|
160
|
+
_o.p = t, d = e, f = r, g = l;
|
|
161
|
+
}
|
|
162
|
+
function w(e, t) {
|
|
163
|
+
var r = this || {};
|
|
164
|
+
return function () {
|
|
165
|
+
var l = arguments;
|
|
166
|
+
function a(n, o) {
|
|
167
|
+
var c = Object.assign({}, n),
|
|
168
|
+
s = c.className || a.className;
|
|
169
|
+
r.p = Object.assign({
|
|
170
|
+
theme: f && f()
|
|
171
|
+
}, c), r.o = / *go\d+/.test(s), c.className = u.apply(r, l) + (s ? " " + s : "");
|
|
172
|
+
var i = e;
|
|
173
|
+
return e[0] && (i = c.as || e, delete c.as), g && i[0] && g(c), d(i, c);
|
|
174
|
+
}
|
|
175
|
+
return t ? t(a) : a;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var _templateObject$1, _templateObject2$1, _templateObject3$1, _templateObject4$1;
|
|
180
|
+
var WarningMark = w("i")(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n box-sizing: border-box;\n position: relative;\n display: block;\n width: 20px;\n height: 20px;\n border: 2px solid currentColor;\n color: #faad14;\n border-radius: 40px;\n\n &::after,\n &::before {\n content: \"\";\n display: block;\n box-sizing: border-box;\n position: absolute;\n border-radius: 3px;\n width: 2px;\n background: currentColor;\n left: 7px;\n }\n &::after {\n top: 2px;\n height: 8px;\n }\n &::before {\n height: 2px;\n bottom: 2px;\n }\n"])));
|
|
181
|
+
var InfoMark = w("i")(_templateObject2$1 || (_templateObject2$1 = _taggedTemplateLiteral(["\n box-sizing: border-box;\n position: relative;\n display: block;\n width: 20px;\n height: 20px;\n border: 2px solid currentColor;\n color: #1677ff;\n border-radius: 40px;\n\n &::after,\n &::before {\n content: \"\";\n display: block;\n box-sizing: border-box;\n position: absolute;\n border-radius: 3px;\n width: 2px;\n background: currentColor;\n left: 7px;\n }\n &::after {\n bottom: 2px;\n height: 8px;\n }\n &::before {\n height: 2px;\n top: 2px;\n }\n"])));
|
|
182
|
+
var SuccessMark = w("i")(_templateObject3$1 || (_templateObject3$1 = _taggedTemplateLiteral(["\n box-sizing: border-box;\n position: relative;\n display: block;\n width: 22px;\n height: 22px;\n border: 2px solid currentColor;\n color: #52c41a;\n border-radius: 100px;\n &::after {\n content: \"\";\n display: block;\n box-sizing: border-box;\n position: absolute;\n left: 3px;\n top: -1px;\n width: 6px;\n height: 10px;\n border-color: currentColor;\n border-width: 0 2px 2px 0;\n border-style: solid;\n transform-origin: bottom left;\n transform: rotate(45deg);\n }\n"])));
|
|
183
|
+
var ErrorMark = w("i")(_templateObject4$1 || (_templateObject4$1 = _taggedTemplateLiteral(["\n box-sizing: border-box;\n position: relative;\n display: block;\n width: 22px;\n height: 22px;\n border: 2px solid currentColor;\n color: #ff4d4f;\n border-radius: 40px;\n\n &::after,\n &::before {\n content: \"\";\n display: block;\n box-sizing: border-box;\n position: absolute;\n width: 12px;\n height: 2px;\n background: currentColor;\n transform: rotate(45deg);\n border-radius: 5px;\n top: 8px;\n left: 3px;\n }\n &::after {\n transform: rotate(-45deg);\n }\n"])));
|
|
184
|
+
var ToastIcon = function ToastIcon(_ref) {
|
|
185
|
+
var className = _ref.className,
|
|
186
|
+
icon = _ref.icon;
|
|
187
|
+
switch (icon) {
|
|
188
|
+
case "error":
|
|
189
|
+
return /*#__PURE__*/jsxRuntime.jsx(ErrorMark, {
|
|
190
|
+
className: className
|
|
191
|
+
});
|
|
192
|
+
case "success":
|
|
193
|
+
return /*#__PURE__*/jsxRuntime.jsx(SuccessMark, {
|
|
194
|
+
className: className
|
|
195
|
+
});
|
|
196
|
+
case "info":
|
|
197
|
+
return /*#__PURE__*/jsxRuntime.jsx(InfoMark, {
|
|
198
|
+
className: className
|
|
199
|
+
});
|
|
200
|
+
case "warning":
|
|
201
|
+
return /*#__PURE__*/jsxRuntime.jsx(WarningMark, {
|
|
202
|
+
className: className
|
|
203
|
+
});
|
|
204
|
+
default:
|
|
205
|
+
return icon;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
210
|
+
var enterAnimation = function enterAnimation(factor) {
|
|
211
|
+
return h(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n transform: translate3d(0,", "px,0) scale(.8);\n opacity:.5;\n }\n 100% {\n transform: translate3d(0,0,0) scale(1);\n opacity:1;\n }\n"])), factor * -150);
|
|
212
|
+
};
|
|
213
|
+
var exitAnimation = function exitAnimation(factor) {
|
|
214
|
+
return h(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n 0% {\n transform: translate3d(0,0,-1px) scale(1);\n opacity:1;\n }\n 100% {\n transform: translate3d(0,", "px,-1px) scale(.8);\n opacity:0;\n }\n"])), factor * -100);
|
|
215
|
+
};
|
|
216
|
+
var Component = w("div")(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n gap: 8px;\n background: #fff;\n color: #363636;\n line-height: 1.3;\n will-change: transform;\n box-shadow:\n 0 3px 10px rgba(0, 0, 0, 0.1),\n 0 3px 3px rgba(0, 0, 0, 0.05);\n max-width: 400px;\n pointer-events: auto;\n padding: 8px;\n border-radius: 8px;\n"])));
|
|
217
|
+
var Message = w("div")(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n display: flex;\n justify-content: center;\n color: inherit;\n flex: 1;\n white-space: pre-line;\n"])));
|
|
218
|
+
var getAnimationStyle = function getAnimationStyle(position, visible) {
|
|
219
|
+
var factor = position.includes("top") ? 1 : -1;
|
|
220
|
+
return {
|
|
221
|
+
animation: visible ? "".concat(enterAnimation(factor), " 0.35s cubic-bezier(.21,1.02,.73,1) forwards") : "".concat(exitAnimation(factor), " 0.6s forwards cubic-bezier(.06,.71,.55,1)")
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
var ToastBar = /*#__PURE__*/react.memo(function (_ref) {
|
|
225
|
+
var isOpen = _ref.isOpen,
|
|
226
|
+
toast = _ref.toast,
|
|
227
|
+
position = _ref.position,
|
|
228
|
+
delay = _ref.delay,
|
|
229
|
+
close = _ref.close,
|
|
230
|
+
unmount = _ref.unmount;
|
|
231
|
+
var animationStyle = getAnimationStyle(position, isOpen);
|
|
232
|
+
var icon = toast.icon && /*#__PURE__*/jsxRuntime.jsx(ToastIcon, {
|
|
233
|
+
className: "ro-toast-icon",
|
|
234
|
+
icon: toast.icon
|
|
235
|
+
});
|
|
236
|
+
var message = /*#__PURE__*/jsxRuntime.jsx(Message, {
|
|
237
|
+
className: "ro-toast-message",
|
|
238
|
+
children: toast.message
|
|
239
|
+
});
|
|
240
|
+
react.useEffect(function () {
|
|
241
|
+
var timeout = setTimeout(function () {
|
|
242
|
+
close(toast.id);
|
|
243
|
+
}, delay);
|
|
244
|
+
return function () {
|
|
245
|
+
clearTimeout(timeout);
|
|
246
|
+
};
|
|
247
|
+
}, []);
|
|
248
|
+
return /*#__PURE__*/jsxRuntime.jsxs(Component, {
|
|
249
|
+
className: "ro-toast-bar",
|
|
250
|
+
style: animationStyle,
|
|
251
|
+
onAnimationEnd: function onAnimationEnd() {
|
|
252
|
+
if (!isOpen) {
|
|
253
|
+
unmount(toast.id);
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
children: [icon, message]
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
var createToastStore = function createToastStore() {
|
|
261
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
262
|
+
var _options$delay = options.delay,
|
|
263
|
+
delay = _options$delay === void 0 ? 1000 : _options$delay,
|
|
264
|
+
_options$position = options.position,
|
|
265
|
+
position = _options$position === void 0 ? "top-center" : _options$position;
|
|
266
|
+
var store = reactOpener.createStore(function (_, state) {
|
|
267
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
268
|
+
position: position,
|
|
269
|
+
delay: delay
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
var openToast = function openToast(item) {
|
|
273
|
+
var element = function element(_ref) {
|
|
274
|
+
var _state$delay;
|
|
275
|
+
var close = _ref.close,
|
|
276
|
+
id = _ref.id,
|
|
277
|
+
isOpen = _ref.isOpen,
|
|
278
|
+
state = _ref.state,
|
|
279
|
+
unmount = _ref.unmount;
|
|
280
|
+
return /*#__PURE__*/jsxRuntime.jsx(ToastBar, {
|
|
281
|
+
isOpen: isOpen,
|
|
282
|
+
toast: _objectSpread2(_objectSpread2({}, state), {}, {
|
|
283
|
+
id: id
|
|
284
|
+
}),
|
|
285
|
+
close: close,
|
|
286
|
+
unmount: unmount,
|
|
287
|
+
position: position,
|
|
288
|
+
delay: (_state$delay = state.delay) !== null && _state$delay !== void 0 ? _state$delay : delay
|
|
289
|
+
}, id);
|
|
290
|
+
};
|
|
291
|
+
store.getState().open(element, typeof item === "string" ? {
|
|
292
|
+
message: item
|
|
293
|
+
} : item);
|
|
294
|
+
};
|
|
295
|
+
return _objectSpread2(_objectSpread2({}, store), {}, {
|
|
296
|
+
custom: function custom(item) {
|
|
297
|
+
openToast(item);
|
|
298
|
+
},
|
|
299
|
+
success: function success(item) {
|
|
300
|
+
var _item = typeof item === "string" ? {
|
|
301
|
+
message: item
|
|
302
|
+
} : item;
|
|
303
|
+
openToast(_objectSpread2(_objectSpread2({}, _item), {}, {
|
|
304
|
+
icon: "success"
|
|
305
|
+
}));
|
|
306
|
+
},
|
|
307
|
+
error: function error(item) {
|
|
308
|
+
var _item = typeof item === "string" ? {
|
|
309
|
+
message: item
|
|
310
|
+
} : item;
|
|
311
|
+
openToast(_objectSpread2(_objectSpread2({}, _item), {}, {
|
|
312
|
+
icon: "error"
|
|
313
|
+
}));
|
|
314
|
+
},
|
|
315
|
+
info: function info(item) {
|
|
316
|
+
var _item = typeof item === "string" ? {
|
|
317
|
+
message: item
|
|
318
|
+
} : item;
|
|
319
|
+
openToast(_objectSpread2(_objectSpread2({}, _item), {}, {
|
|
320
|
+
icon: "info"
|
|
321
|
+
}));
|
|
322
|
+
},
|
|
323
|
+
warn: function warn(item) {
|
|
324
|
+
var _item = typeof item === "string" ? {
|
|
325
|
+
message: item
|
|
326
|
+
} : item;
|
|
327
|
+
openToast(_objectSpread2(_objectSpread2({}, _item), {}, {
|
|
328
|
+
icon: "warning"
|
|
329
|
+
}));
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
var getStyle = function getStyle(position) {
|
|
335
|
+
return u(_objectSpread2(_objectSpread2({
|
|
336
|
+
position: "fixed",
|
|
337
|
+
left: 0,
|
|
338
|
+
right: 0
|
|
339
|
+
}, position.includes("top") ? {
|
|
340
|
+
top: 0
|
|
341
|
+
} : {
|
|
342
|
+
bottom: 0
|
|
343
|
+
}), {}, {
|
|
344
|
+
zIndex: 9999,
|
|
345
|
+
padding: "".concat(16, "px"),
|
|
346
|
+
pointerEvents: "none",
|
|
347
|
+
display: "flex",
|
|
348
|
+
flexDirection: "column",
|
|
349
|
+
alignItems: position.includes("center") ? "center" : position.includes("left") ? "flex-start" : "flex-end",
|
|
350
|
+
gap: "".concat(16, "px")
|
|
351
|
+
}));
|
|
352
|
+
};
|
|
353
|
+
var ReactToastOpener$1 = function ReactToastOpener(_ref) {
|
|
354
|
+
var _options$position;
|
|
355
|
+
var store = _ref.store,
|
|
356
|
+
style = _ref.style,
|
|
357
|
+
className = _ref.className,
|
|
358
|
+
options = _ref.options;
|
|
359
|
+
var _useSyncExternalStore = react.useSyncExternalStore(store.subscribe, store.getState, store.getInitialState),
|
|
360
|
+
items = _useSyncExternalStore.items,
|
|
361
|
+
_close = _useSyncExternalStore.close,
|
|
362
|
+
_unmount = _useSyncExternalStore.unmount,
|
|
363
|
+
unmountAll = _useSyncExternalStore.unmountAll,
|
|
364
|
+
_position = _useSyncExternalStore.position;
|
|
365
|
+
var position = (_options$position = options === null || options === void 0 ? void 0 : options.position) !== null && _options$position !== void 0 ? _options$position : _position;
|
|
366
|
+
react.useEffect(function () {
|
|
367
|
+
return function () {
|
|
368
|
+
unmountAll();
|
|
369
|
+
};
|
|
370
|
+
}, []);
|
|
371
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
372
|
+
style: style,
|
|
373
|
+
className: "".concat(getStyle(position), " ").concat(className !== null && className !== void 0 ? className : ""),
|
|
374
|
+
children: items.map(function (item) {
|
|
375
|
+
return /*#__PURE__*/jsxRuntime.jsx(react.Fragment, {
|
|
376
|
+
children: typeof item.element === "function" ? item.element(_objectSpread2(_objectSpread2({}, item), {}, {
|
|
377
|
+
close: function close() {
|
|
378
|
+
return _close(item.id);
|
|
379
|
+
},
|
|
380
|
+
unmount: function unmount() {
|
|
381
|
+
return _unmount(item.id);
|
|
382
|
+
}
|
|
383
|
+
})) : item.element
|
|
384
|
+
}, item.id);
|
|
385
|
+
})
|
|
386
|
+
});
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
function useToast() {
|
|
390
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
391
|
+
var ref = react.useRef();
|
|
392
|
+
if (!ref.current) {
|
|
393
|
+
ref.current = createToastStore(options);
|
|
394
|
+
}
|
|
395
|
+
return [{
|
|
396
|
+
close: ref.current.getState().close,
|
|
397
|
+
closeAll: ref.current.getState().closeAll,
|
|
398
|
+
custom: ref.current.custom,
|
|
399
|
+
success: ref.current.success,
|
|
400
|
+
error: ref.current.error,
|
|
401
|
+
info: ref.current.info,
|
|
402
|
+
warn: ref.current.warn
|
|
403
|
+
}, /*#__PURE__*/jsxRuntime.jsx(ReactToastOpener$1, {
|
|
404
|
+
store: ref.current
|
|
405
|
+
})];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
m(react.createElement);
|
|
409
|
+
var ReactToastOpener = ReactToastOpener$1;
|
|
410
|
+
ReactToastOpener.createStore = createToastStore;
|
|
411
|
+
ReactToastOpener.useToast = useToast;
|
|
412
|
+
|
|
413
|
+
exports.ReactToastOpener = ReactToastOpener;
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type Toast = {
|
|
2
|
+
icon?: ToastIconType;
|
|
3
|
+
delay?: number;
|
|
4
|
+
message: React.ReactNode;
|
|
5
|
+
};
|
|
6
|
+
export type ToastIconType = "error" | "success" | "info" | "warning" | React.ReactNode;
|
|
7
|
+
export type ToastPositionType = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
8
|
+
export interface Options {
|
|
9
|
+
delay?: number;
|
|
10
|
+
position?: ToastPositionType;
|
|
11
|
+
}
|
|
12
|
+
export declare const createToastStore: (options?: Options) => {
|
|
13
|
+
custom: (item: Toast | string) => void;
|
|
14
|
+
success: (item: Omit<Toast, "icon"> | string) => void;
|
|
15
|
+
error: (item: Omit<Toast, "icon"> | string) => void;
|
|
16
|
+
info: (item: Omit<Toast, "icon"> | string) => void;
|
|
17
|
+
warn: (item: Omit<Toast, "icon"> | string) => void;
|
|
18
|
+
setState: (partial: (import("react-opener").StoreState<Toast> & {
|
|
19
|
+
position: ToastPositionType;
|
|
20
|
+
delay: number;
|
|
21
|
+
}) | Partial<import("react-opener").StoreState<Toast> & {
|
|
22
|
+
position: ToastPositionType;
|
|
23
|
+
delay: number;
|
|
24
|
+
}> | ((state: import("react-opener").StoreState<Toast> & {
|
|
25
|
+
position: ToastPositionType;
|
|
26
|
+
delay: number;
|
|
27
|
+
}) => (import("react-opener").StoreState<Toast> & {
|
|
28
|
+
position: ToastPositionType;
|
|
29
|
+
delay: number;
|
|
30
|
+
}) | Partial<import("react-opener").StoreState<Toast> & {
|
|
31
|
+
position: ToastPositionType;
|
|
32
|
+
delay: number;
|
|
33
|
+
}>)) => void;
|
|
34
|
+
getState: () => import("react-opener").StoreState<Toast> & {
|
|
35
|
+
position: ToastPositionType;
|
|
36
|
+
delay: number;
|
|
37
|
+
};
|
|
38
|
+
subscribe: (listener: (state: import("react-opener").StoreState<Toast> & {
|
|
39
|
+
position: ToastPositionType;
|
|
40
|
+
delay: number;
|
|
41
|
+
}, prevState: import("react-opener").StoreState<Toast> & {
|
|
42
|
+
position: ToastPositionType;
|
|
43
|
+
delay: number;
|
|
44
|
+
}) => void) => () => void;
|
|
45
|
+
getInitialState: () => import("react-opener").StoreState<Toast> & {
|
|
46
|
+
position: ToastPositionType;
|
|
47
|
+
delay: number;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Options } from "./store";
|
|
2
|
+
export declare function useToast(options?: Options): readonly [{
|
|
3
|
+
readonly close: (id: string) => void;
|
|
4
|
+
readonly closeAll: () => void;
|
|
5
|
+
readonly custom: (item: import("./store").Toast | string) => void;
|
|
6
|
+
readonly success: (item: Omit<import("./store").Toast, "icon"> | string) => void;
|
|
7
|
+
readonly error: (item: Omit<import("./store").Toast, "icon"> | string) => void;
|
|
8
|
+
readonly info: (item: Omit<import("./store").Toast, "icon"> | string) => void;
|
|
9
|
+
readonly warn: (item: Omit<import("./store").Toast, "icon"> | string) => void;
|
|
10
|
+
}, import("react/jsx-runtime").JSX.Element];
|
package/esm/Renderer.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
+
import { useSyncExternalStore, useEffect, Fragment } from 'react';
|
|
3
|
+
import { css as u } from './node_modules/.pnpm/goober@2.1.18_csstype@3.2.3/node_modules/goober/dist/goober.modern.mjs';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var getStyle = function getStyle(position) {
|
|
7
|
+
return u(_objectSpread2(_objectSpread2({
|
|
8
|
+
position: "fixed",
|
|
9
|
+
left: 0,
|
|
10
|
+
right: 0
|
|
11
|
+
}, position.includes("top") ? {
|
|
12
|
+
top: 0
|
|
13
|
+
} : {
|
|
14
|
+
bottom: 0
|
|
15
|
+
}), {}, {
|
|
16
|
+
zIndex: 9999,
|
|
17
|
+
padding: "".concat(16, "px"),
|
|
18
|
+
pointerEvents: "none",
|
|
19
|
+
display: "flex",
|
|
20
|
+
flexDirection: "column",
|
|
21
|
+
alignItems: position.includes("center") ? "center" : position.includes("left") ? "flex-start" : "flex-end",
|
|
22
|
+
gap: "".concat(16, "px")
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
var ReactToastOpener = function ReactToastOpener(_ref) {
|
|
26
|
+
var _options$position;
|
|
27
|
+
var store = _ref.store,
|
|
28
|
+
style = _ref.style,
|
|
29
|
+
className = _ref.className,
|
|
30
|
+
options = _ref.options;
|
|
31
|
+
var _useSyncExternalStore = useSyncExternalStore(store.subscribe, store.getState, store.getInitialState),
|
|
32
|
+
items = _useSyncExternalStore.items,
|
|
33
|
+
_close = _useSyncExternalStore.close,
|
|
34
|
+
_unmount = _useSyncExternalStore.unmount,
|
|
35
|
+
unmountAll = _useSyncExternalStore.unmountAll,
|
|
36
|
+
_position = _useSyncExternalStore.position;
|
|
37
|
+
var position = (_options$position = options === null || options === void 0 ? void 0 : options.position) !== null && _options$position !== void 0 ? _options$position : _position;
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
return function () {
|
|
40
|
+
unmountAll();
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
return /*#__PURE__*/jsx("div", {
|
|
44
|
+
style: style,
|
|
45
|
+
className: "".concat(getStyle(position), " ").concat(className !== null && className !== void 0 ? className : ""),
|
|
46
|
+
children: items.map(function (item) {
|
|
47
|
+
return /*#__PURE__*/jsx(Fragment, {
|
|
48
|
+
children: typeof item.element === "function" ? item.element(_objectSpread2(_objectSpread2({}, item), {}, {
|
|
49
|
+
close: function close() {
|
|
50
|
+
return _close(item.id);
|
|
51
|
+
},
|
|
52
|
+
unmount: function unmount() {
|
|
53
|
+
return _unmount(item.id);
|
|
54
|
+
}
|
|
55
|
+
})) : item.element
|
|
56
|
+
}, item.id);
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { ReactToastOpener };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function _defineProperty(e, r, t) {
|
|
2
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
3
|
+
value: t,
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true
|
|
7
|
+
}) : e[r] = t, e;
|
|
8
|
+
}
|
|
9
|
+
function ownKeys(e, r) {
|
|
10
|
+
var t = Object.keys(e);
|
|
11
|
+
if (Object.getOwnPropertySymbols) {
|
|
12
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
13
|
+
r && (o = o.filter(function (r) {
|
|
14
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
15
|
+
})), t.push.apply(t, o);
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
}
|
|
19
|
+
function _objectSpread2(e) {
|
|
20
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
21
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
22
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
23
|
+
_defineProperty(e, r, t[r]);
|
|
24
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
25
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
function _taggedTemplateLiteral(e, t) {
|
|
31
|
+
return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, {
|
|
32
|
+
raw: {
|
|
33
|
+
value: Object.freeze(t)
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
function _toPrimitive(t, r) {
|
|
38
|
+
if ("object" != typeof t || !t) return t;
|
|
39
|
+
var e = t[Symbol.toPrimitive];
|
|
40
|
+
if (void 0 !== e) {
|
|
41
|
+
var i = e.call(t, r);
|
|
42
|
+
if ("object" != typeof i) return i;
|
|
43
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
44
|
+
}
|
|
45
|
+
return ("string" === r ? String : Number)(t);
|
|
46
|
+
}
|
|
47
|
+
function _toPropertyKey(t) {
|
|
48
|
+
var i = _toPrimitive(t, "string");
|
|
49
|
+
return "symbol" == typeof i ? i : i + "";
|
|
50
|
+
}
|
|
51
|
+
function _typeof(o) {
|
|
52
|
+
"@babel/helpers - typeof";
|
|
53
|
+
|
|
54
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
55
|
+
return typeof o;
|
|
56
|
+
} : function (o) {
|
|
57
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
58
|
+
}, _typeof(o);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { _defineProperty as defineProperty, _objectSpread2 as objectSpread2, _taggedTemplateLiteral as taggedTemplateLiteral, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey, _typeof as typeof };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { taggedTemplateLiteral as _taggedTemplateLiteral } from '../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
+
import { memo, useEffect } from 'react';
|
|
3
|
+
import { styled as w, keyframes as h } from '../node_modules/.pnpm/goober@2.1.18_csstype@3.2.3/node_modules/goober/dist/goober.modern.mjs';
|
|
4
|
+
import { ToastIcon } from './ToastIcon.mjs';
|
|
5
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
8
|
+
var enterAnimation = function enterAnimation(factor) {
|
|
9
|
+
return h(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n transform: translate3d(0,", "px,0) scale(.8);\n opacity:.5;\n }\n 100% {\n transform: translate3d(0,0,0) scale(1);\n opacity:1;\n }\n"])), factor * -150);
|
|
10
|
+
};
|
|
11
|
+
var exitAnimation = function exitAnimation(factor) {
|
|
12
|
+
return h(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n 0% {\n transform: translate3d(0,0,-1px) scale(1);\n opacity:1;\n }\n 100% {\n transform: translate3d(0,", "px,-1px) scale(.8);\n opacity:0;\n }\n"])), factor * -100);
|
|
13
|
+
};
|
|
14
|
+
var Component = w("div")(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n gap: 8px;\n background: #fff;\n color: #363636;\n line-height: 1.3;\n will-change: transform;\n box-shadow:\n 0 3px 10px rgba(0, 0, 0, 0.1),\n 0 3px 3px rgba(0, 0, 0, 0.05);\n max-width: 400px;\n pointer-events: auto;\n padding: 8px;\n border-radius: 8px;\n"])));
|
|
15
|
+
var Message = w("div")(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n display: flex;\n justify-content: center;\n color: inherit;\n flex: 1;\n white-space: pre-line;\n"])));
|
|
16
|
+
var getAnimationStyle = function getAnimationStyle(position, visible) {
|
|
17
|
+
var factor = position.includes("top") ? 1 : -1;
|
|
18
|
+
return {
|
|
19
|
+
animation: visible ? "".concat(enterAnimation(factor), " 0.35s cubic-bezier(.21,1.02,.73,1) forwards") : "".concat(exitAnimation(factor), " 0.6s forwards cubic-bezier(.06,.71,.55,1)")
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
var ToastBar = /*#__PURE__*/memo(function (_ref) {
|
|
23
|
+
var isOpen = _ref.isOpen,
|
|
24
|
+
toast = _ref.toast,
|
|
25
|
+
position = _ref.position,
|
|
26
|
+
delay = _ref.delay,
|
|
27
|
+
close = _ref.close,
|
|
28
|
+
unmount = _ref.unmount;
|
|
29
|
+
var animationStyle = getAnimationStyle(position, isOpen);
|
|
30
|
+
var icon = toast.icon && /*#__PURE__*/jsx(ToastIcon, {
|
|
31
|
+
className: "ro-toast-icon",
|
|
32
|
+
icon: toast.icon
|
|
33
|
+
});
|
|
34
|
+
var message = /*#__PURE__*/jsx(Message, {
|
|
35
|
+
className: "ro-toast-message",
|
|
36
|
+
children: toast.message
|
|
37
|
+
});
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
var timeout = setTimeout(function () {
|
|
40
|
+
close(toast.id);
|
|
41
|
+
}, delay);
|
|
42
|
+
return function () {
|
|
43
|
+
clearTimeout(timeout);
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
return /*#__PURE__*/jsxs(Component, {
|
|
47
|
+
className: "ro-toast-bar",
|
|
48
|
+
style: animationStyle,
|
|
49
|
+
onAnimationEnd: function onAnimationEnd() {
|
|
50
|
+
if (!isOpen) {
|
|
51
|
+
unmount(toast.id);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
children: [icon, message]
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export { ToastBar };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { taggedTemplateLiteral as _taggedTemplateLiteral } from '../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
+
import { styled as w } from '../node_modules/.pnpm/goober@2.1.18_csstype@3.2.3/node_modules/goober/dist/goober.modern.mjs';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
6
|
+
var WarningMark = w("i")(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n box-sizing: border-box;\n position: relative;\n display: block;\n width: 20px;\n height: 20px;\n border: 2px solid currentColor;\n color: #faad14;\n border-radius: 40px;\n\n &::after,\n &::before {\n content: \"\";\n display: block;\n box-sizing: border-box;\n position: absolute;\n border-radius: 3px;\n width: 2px;\n background: currentColor;\n left: 7px;\n }\n &::after {\n top: 2px;\n height: 8px;\n }\n &::before {\n height: 2px;\n bottom: 2px;\n }\n"])));
|
|
7
|
+
var InfoMark = w("i")(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n box-sizing: border-box;\n position: relative;\n display: block;\n width: 20px;\n height: 20px;\n border: 2px solid currentColor;\n color: #1677ff;\n border-radius: 40px;\n\n &::after,\n &::before {\n content: \"\";\n display: block;\n box-sizing: border-box;\n position: absolute;\n border-radius: 3px;\n width: 2px;\n background: currentColor;\n left: 7px;\n }\n &::after {\n bottom: 2px;\n height: 8px;\n }\n &::before {\n height: 2px;\n top: 2px;\n }\n"])));
|
|
8
|
+
var SuccessMark = w("i")(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n box-sizing: border-box;\n position: relative;\n display: block;\n width: 22px;\n height: 22px;\n border: 2px solid currentColor;\n color: #52c41a;\n border-radius: 100px;\n &::after {\n content: \"\";\n display: block;\n box-sizing: border-box;\n position: absolute;\n left: 3px;\n top: -1px;\n width: 6px;\n height: 10px;\n border-color: currentColor;\n border-width: 0 2px 2px 0;\n border-style: solid;\n transform-origin: bottom left;\n transform: rotate(45deg);\n }\n"])));
|
|
9
|
+
var ErrorMark = w("i")(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n box-sizing: border-box;\n position: relative;\n display: block;\n width: 22px;\n height: 22px;\n border: 2px solid currentColor;\n color: #ff4d4f;\n border-radius: 40px;\n\n &::after,\n &::before {\n content: \"\";\n display: block;\n box-sizing: border-box;\n position: absolute;\n width: 12px;\n height: 2px;\n background: currentColor;\n transform: rotate(45deg);\n border-radius: 5px;\n top: 8px;\n left: 3px;\n }\n &::after {\n transform: rotate(-45deg);\n }\n"])));
|
|
10
|
+
var ToastIcon = function ToastIcon(_ref) {
|
|
11
|
+
var className = _ref.className,
|
|
12
|
+
icon = _ref.icon;
|
|
13
|
+
switch (icon) {
|
|
14
|
+
case "error":
|
|
15
|
+
return /*#__PURE__*/jsx(ErrorMark, {
|
|
16
|
+
className: className
|
|
17
|
+
});
|
|
18
|
+
case "success":
|
|
19
|
+
return /*#__PURE__*/jsx(SuccessMark, {
|
|
20
|
+
className: className
|
|
21
|
+
});
|
|
22
|
+
case "info":
|
|
23
|
+
return /*#__PURE__*/jsx(InfoMark, {
|
|
24
|
+
className: className
|
|
25
|
+
});
|
|
26
|
+
case "warning":
|
|
27
|
+
return /*#__PURE__*/jsx(WarningMark, {
|
|
28
|
+
className: className
|
|
29
|
+
});
|
|
30
|
+
default:
|
|
31
|
+
return icon;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { ToastIcon };
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createToastStore } from './store.mjs';
|
|
2
|
+
import { ReactToastOpener as ReactToastOpener$1 } from './Renderer.mjs';
|
|
3
|
+
import { useToast } from './useToast.mjs';
|
|
4
|
+
import { setup as m } from './node_modules/.pnpm/goober@2.1.18_csstype@3.2.3/node_modules/goober/dist/goober.modern.mjs';
|
|
5
|
+
import { createElement } from 'react';
|
|
6
|
+
|
|
7
|
+
m(createElement);
|
|
8
|
+
var ReactToastOpener = ReactToastOpener$1;
|
|
9
|
+
ReactToastOpener.createStore = createToastStore;
|
|
10
|
+
ReactToastOpener.useToast = useToast;
|
|
11
|
+
|
|
12
|
+
export { ReactToastOpener };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { defineProperty as _defineProperty, typeof as _typeof } from '../../../../../../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
+
|
|
3
|
+
var e = {
|
|
4
|
+
data: ""
|
|
5
|
+
},
|
|
6
|
+
t = function t(_t) {
|
|
7
|
+
if ("object" == (typeof window === "undefined" ? "undefined" : _typeof(window))) {
|
|
8
|
+
var _e = (_t ? _t.querySelector("#_goober") : window._goober) || Object.assign(document.createElement("style"), {
|
|
9
|
+
innerHTML: " ",
|
|
10
|
+
id: "_goober"
|
|
11
|
+
});
|
|
12
|
+
return _e.nonce = window.__nonce__, _e.parentNode || (_t || document.head).appendChild(_e), _e.firstChild;
|
|
13
|
+
}
|
|
14
|
+
return _t || e;
|
|
15
|
+
},
|
|
16
|
+
l = /(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,
|
|
17
|
+
a = /\/\*[^]*?\*\/| +/g,
|
|
18
|
+
n = /\n+/g,
|
|
19
|
+
_o = function o(e, t) {
|
|
20
|
+
var r = "",
|
|
21
|
+
l = "",
|
|
22
|
+
a = "";
|
|
23
|
+
var _loop = function _loop(_n) {
|
|
24
|
+
var c = e[_n];
|
|
25
|
+
"@" == _n[0] ? "i" == _n[1] ? r = _n + " " + c + ";" : l += "f" == _n[1] ? _o(c, _n) : _n + "{" + _o(c, "k" == _n[1] ? "" : t) + "}" : "object" == _typeof(c) ? l += _o(c, t ? t.replace(/([^,])+/g, function (e) {
|
|
26
|
+
return _n.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g, function (t) {
|
|
27
|
+
return /&/.test(t) ? t.replace(/&/g, e) : e ? e + " " + t : t;
|
|
28
|
+
});
|
|
29
|
+
}) : _n) : null != c && (_n = /^--/.test(_n) ? _n : _n.replace(/[A-Z]/g, "-$&").toLowerCase(), a += _o.p ? _o.p(_n, c) : _n + ":" + c + ";");
|
|
30
|
+
};
|
|
31
|
+
for (var _n in e) {
|
|
32
|
+
_loop(_n);
|
|
33
|
+
}
|
|
34
|
+
return r + (t && a ? t + "{" + a + "}" : a) + l;
|
|
35
|
+
},
|
|
36
|
+
c = {},
|
|
37
|
+
_s = function s(e) {
|
|
38
|
+
if ("object" == _typeof(e)) {
|
|
39
|
+
var _t2 = "";
|
|
40
|
+
for (var _r in e) _t2 += _r + _s(e[_r]);
|
|
41
|
+
return _t2;
|
|
42
|
+
}
|
|
43
|
+
return e;
|
|
44
|
+
},
|
|
45
|
+
i = function i(e, t, r, _i, p) {
|
|
46
|
+
var u = _s(e),
|
|
47
|
+
d = c[u] || (c[u] = function (e) {
|
|
48
|
+
var t = 0,
|
|
49
|
+
r = 11;
|
|
50
|
+
for (; t < e.length;) r = 101 * r + e.charCodeAt(t++) >>> 0;
|
|
51
|
+
return "go" + r;
|
|
52
|
+
}(u));
|
|
53
|
+
if (!c[d]) {
|
|
54
|
+
var _t3 = u !== e ? e : function (e) {
|
|
55
|
+
var t,
|
|
56
|
+
r,
|
|
57
|
+
o = [{}];
|
|
58
|
+
for (; t = l.exec(e.replace(a, ""));) t[4] ? o.shift() : t[3] ? (r = t[3].replace(n, " ").trim(), o.unshift(o[0][r] = o[0][r] || {})) : o[0][t[1]] = t[2].replace(n, " ").trim();
|
|
59
|
+
return o[0];
|
|
60
|
+
}(e);
|
|
61
|
+
c[d] = _o(p ? _defineProperty({}, "@keyframes " + d, _t3) : _t3, r ? "" : "." + d);
|
|
62
|
+
}
|
|
63
|
+
var f = r && c.g ? c.g : null;
|
|
64
|
+
return r && (c.g = c[d]), function (e, t, r, l) {
|
|
65
|
+
l ? t.data = t.data.replace(l, e) : -1 === t.data.indexOf(e) && (t.data = r ? e + t.data : t.data + e);
|
|
66
|
+
}(c[d], t, _i, f), d;
|
|
67
|
+
},
|
|
68
|
+
p = function p(e, t, r) {
|
|
69
|
+
return e.reduce(function (e, l, a) {
|
|
70
|
+
var n = t[a];
|
|
71
|
+
if (n && n.call) {
|
|
72
|
+
var _e2 = n(r),
|
|
73
|
+
_t4 = _e2 && _e2.props && _e2.props.className || /^go/.test(_e2) && _e2;
|
|
74
|
+
n = _t4 ? "." + _t4 : _e2 && "object" == _typeof(_e2) ? _e2.props ? "" : _o(_e2, "") : false === _e2 ? "" : _e2;
|
|
75
|
+
}
|
|
76
|
+
return e + l + (null == n ? "" : n);
|
|
77
|
+
}, "");
|
|
78
|
+
};
|
|
79
|
+
function u(e) {
|
|
80
|
+
var r = this || {},
|
|
81
|
+
l = e.call ? e(r.p) : e;
|
|
82
|
+
return i(l.unshift ? l.raw ? p(l, [].slice.call(arguments, 1), r.p) : l.reduce(function (e, t) {
|
|
83
|
+
return Object.assign(e, t && t.call ? t(r.p) : t);
|
|
84
|
+
}, {}) : l, t(r.target), r.g, r.o, r.k);
|
|
85
|
+
}
|
|
86
|
+
var d,
|
|
87
|
+
f,
|
|
88
|
+
g;
|
|
89
|
+
u.bind({
|
|
90
|
+
g: 1
|
|
91
|
+
});
|
|
92
|
+
var h = u.bind({
|
|
93
|
+
k: 1
|
|
94
|
+
});
|
|
95
|
+
function m(e, t, r, l) {
|
|
96
|
+
_o.p = t, d = e, f = r, g = l;
|
|
97
|
+
}
|
|
98
|
+
function w(e, t) {
|
|
99
|
+
var r = this || {};
|
|
100
|
+
return function () {
|
|
101
|
+
var l = arguments;
|
|
102
|
+
function a(n, o) {
|
|
103
|
+
var c = Object.assign({}, n),
|
|
104
|
+
s = c.className || a.className;
|
|
105
|
+
r.p = Object.assign({
|
|
106
|
+
theme: f && f()
|
|
107
|
+
}, c), r.o = / *go\d+/.test(s), c.className = u.apply(r, l) + (s ? " " + s : "");
|
|
108
|
+
var i = e;
|
|
109
|
+
return e[0] && (i = c.as || e, delete c.as), g && i[0] && g(c), d(i, c);
|
|
110
|
+
}
|
|
111
|
+
return t ? t(a) : a;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { u as css, h as keyframes, m as setup, w as styled };
|
package/esm/store.mjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
+
import { createStore } from 'react-opener';
|
|
3
|
+
import { ToastBar } from './components/ToastBar.mjs';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var createToastStore = function createToastStore() {
|
|
7
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
8
|
+
var _options$delay = options.delay,
|
|
9
|
+
delay = _options$delay === void 0 ? 1000 : _options$delay,
|
|
10
|
+
_options$position = options.position,
|
|
11
|
+
position = _options$position === void 0 ? "top-center" : _options$position;
|
|
12
|
+
var store = createStore(function (_, state) {
|
|
13
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
14
|
+
position: position,
|
|
15
|
+
delay: delay
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
var openToast = function openToast(item) {
|
|
19
|
+
var element = function element(_ref) {
|
|
20
|
+
var _state$delay;
|
|
21
|
+
var close = _ref.close,
|
|
22
|
+
id = _ref.id,
|
|
23
|
+
isOpen = _ref.isOpen,
|
|
24
|
+
state = _ref.state,
|
|
25
|
+
unmount = _ref.unmount;
|
|
26
|
+
return /*#__PURE__*/jsx(ToastBar, {
|
|
27
|
+
isOpen: isOpen,
|
|
28
|
+
toast: _objectSpread2(_objectSpread2({}, state), {}, {
|
|
29
|
+
id: id
|
|
30
|
+
}),
|
|
31
|
+
close: close,
|
|
32
|
+
unmount: unmount,
|
|
33
|
+
position: position,
|
|
34
|
+
delay: (_state$delay = state.delay) !== null && _state$delay !== void 0 ? _state$delay : delay
|
|
35
|
+
}, id);
|
|
36
|
+
};
|
|
37
|
+
store.getState().open(element, typeof item === "string" ? {
|
|
38
|
+
message: item
|
|
39
|
+
} : item);
|
|
40
|
+
};
|
|
41
|
+
return _objectSpread2(_objectSpread2({}, store), {}, {
|
|
42
|
+
custom: function custom(item) {
|
|
43
|
+
openToast(item);
|
|
44
|
+
},
|
|
45
|
+
success: function success(item) {
|
|
46
|
+
var _item = typeof item === "string" ? {
|
|
47
|
+
message: item
|
|
48
|
+
} : item;
|
|
49
|
+
openToast(_objectSpread2(_objectSpread2({}, _item), {}, {
|
|
50
|
+
icon: "success"
|
|
51
|
+
}));
|
|
52
|
+
},
|
|
53
|
+
error: function error(item) {
|
|
54
|
+
var _item = typeof item === "string" ? {
|
|
55
|
+
message: item
|
|
56
|
+
} : item;
|
|
57
|
+
openToast(_objectSpread2(_objectSpread2({}, _item), {}, {
|
|
58
|
+
icon: "error"
|
|
59
|
+
}));
|
|
60
|
+
},
|
|
61
|
+
info: function info(item) {
|
|
62
|
+
var _item = typeof item === "string" ? {
|
|
63
|
+
message: item
|
|
64
|
+
} : item;
|
|
65
|
+
openToast(_objectSpread2(_objectSpread2({}, _item), {}, {
|
|
66
|
+
icon: "info"
|
|
67
|
+
}));
|
|
68
|
+
},
|
|
69
|
+
warn: function warn(item) {
|
|
70
|
+
var _item = typeof item === "string" ? {
|
|
71
|
+
message: item
|
|
72
|
+
} : item;
|
|
73
|
+
openToast(_objectSpread2(_objectSpread2({}, _item), {}, {
|
|
74
|
+
icon: "warning"
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export { createToastStore };
|
package/esm/useToast.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { createToastStore } from './store.mjs';
|
|
3
|
+
import { ReactToastOpener } from './Renderer.mjs';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
function useToast() {
|
|
7
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
8
|
+
var ref = useRef();
|
|
9
|
+
if (!ref.current) {
|
|
10
|
+
ref.current = createToastStore(options);
|
|
11
|
+
}
|
|
12
|
+
return [{
|
|
13
|
+
close: ref.current.getState().close,
|
|
14
|
+
closeAll: ref.current.getState().closeAll,
|
|
15
|
+
custom: ref.current.custom,
|
|
16
|
+
success: ref.current.success,
|
|
17
|
+
error: ref.current.error,
|
|
18
|
+
info: ref.current.info,
|
|
19
|
+
warn: ref.current.warn
|
|
20
|
+
}, /*#__PURE__*/jsx(ReactToastOpener, {
|
|
21
|
+
store: ref.current
|
|
22
|
+
})];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { useToast };
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-opener/toast",
|
|
3
|
+
"version": "0.0.1-alpha.1",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"description": "Toast notifications for react-opener",
|
|
6
|
+
"author": "Yunho Seo",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/yunho1017/react-opener.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://react-opener.vercel.app/",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react",
|
|
15
|
+
"notifications",
|
|
16
|
+
"toast",
|
|
17
|
+
"snackbar"
|
|
18
|
+
],
|
|
19
|
+
"import": "./esm/index.mjs",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./esm/index.mjs",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
"./package.json": "./package.json",
|
|
25
|
+
".": {
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"import": "./esm/index.mjs",
|
|
28
|
+
"types": "./dist/index.d.ts"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"goober": "^2.1.14"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@types/react": ">=18.0.0",
|
|
36
|
+
"react": ">=18.0.0",
|
|
37
|
+
"react-opener": ">=1.4.0"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"esm"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "rm -rf dist esm && tsc -p tsconfig.json --declaration --emitDeclarationOnly --declarationDir dist && rollup -c rollup.config.js"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@babel/core": "^7.24.6",
|
|
48
|
+
"@babel/preset-env": "^7.24.6",
|
|
49
|
+
"@babel/preset-react": "^7.24.6",
|
|
50
|
+
"@babel/preset-typescript": "^7.24.6",
|
|
51
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
52
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
53
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
54
|
+
"@types/react": "^18.3.2",
|
|
55
|
+
"react-opener": "workspace:*",
|
|
56
|
+
"rollup": "^4.18.0",
|
|
57
|
+
"typescript": "^5.4.5"
|
|
58
|
+
}
|
|
59
|
+
}
|