echo-toast 1.0.0 → 1.0.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/echo-toast.d.ts +36 -0
- package/dist/echo-toast.js +331 -0
- package/package.json +2 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { JSX } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
export declare const echo: {
|
|
4
|
+
notify: (data: IToast) => void;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
declare interface IToast {
|
|
8
|
+
id?: number;
|
|
9
|
+
type?: 'loading' | 'succesful' | 'error' | 'warning' | 'info' | 'blank';
|
|
10
|
+
action?: {
|
|
11
|
+
label: string;
|
|
12
|
+
onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
13
|
+
styling?: string;
|
|
14
|
+
};
|
|
15
|
+
label: string;
|
|
16
|
+
title?: string;
|
|
17
|
+
icon?: React.ElementType;
|
|
18
|
+
closeButton?: boolean;
|
|
19
|
+
border?: boolean;
|
|
20
|
+
duration?: {
|
|
21
|
+
animation?: number;
|
|
22
|
+
notification?: number;
|
|
23
|
+
};
|
|
24
|
+
swipe?: boolean;
|
|
25
|
+
swipeDirection?: 'left' | 'right';
|
|
26
|
+
deleteToast?: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare interface IToaster {
|
|
30
|
+
positionX?: 'left' | 'center' | 'right';
|
|
31
|
+
positionY?: 'up' | 'middle' | 'bottom';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export declare function Toaster({ positionX, positionY }: IToaster): JSX.Element;
|
|
35
|
+
|
|
36
|
+
export { }
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { m as e, motion as t } from "framer-motion";
|
|
2
|
+
import { Check as n, Info as r, LoaderCircle as i, ShieldAlert as a, X as o } from "lucide-react";
|
|
3
|
+
import { useEffect as s, useState as c } from "react";
|
|
4
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
6
|
+
var d = Object.defineProperty, f = Object.getOwnPropertyDescriptor, p = Object.getOwnPropertyNames, m = Object.prototype.hasOwnProperty, h = (e, t) => {
|
|
7
|
+
let n = {};
|
|
8
|
+
for (var r in e) d(n, r, {
|
|
9
|
+
get: e[r],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
return t || d(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
13
|
+
}, g = (e, t, n, r) => {
|
|
14
|
+
if (t && typeof t == "object" || typeof t == "function") for (var i = p(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !m.call(e, s) && s !== n && d(e, s, {
|
|
15
|
+
get: ((e) => t[e]).bind(null, s),
|
|
16
|
+
enumerable: !(r = f(t, s)) || r.enumerable
|
|
17
|
+
});
|
|
18
|
+
return e;
|
|
19
|
+
}, _ = (e, t, n) => (g(e, t, "default"), n && g(n, t, "default")), v = new class {
|
|
20
|
+
observers = [];
|
|
21
|
+
counter = 0;
|
|
22
|
+
subscribe(e) {
|
|
23
|
+
return this.observers.push(e), () => {
|
|
24
|
+
this.observers = this.observers.filter((t) => t !== e);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
notify(e) {
|
|
28
|
+
this.counter++, this.observers.forEach((t) => t({
|
|
29
|
+
...e,
|
|
30
|
+
id: this.counter
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
}(), y = /* @__PURE__ */ h({
|
|
34
|
+
m: () => e,
|
|
35
|
+
motion: () => t
|
|
36
|
+
});
|
|
37
|
+
import * as b from "framer-motion";
|
|
38
|
+
_(y, b);
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region lib/static/static.ts
|
|
41
|
+
var x = {
|
|
42
|
+
left: {
|
|
43
|
+
up: {
|
|
44
|
+
left: 16,
|
|
45
|
+
top: 16
|
|
46
|
+
},
|
|
47
|
+
middle: {
|
|
48
|
+
left: 16,
|
|
49
|
+
top: "50%",
|
|
50
|
+
translateY: "-50%"
|
|
51
|
+
},
|
|
52
|
+
bottom: {
|
|
53
|
+
left: 16,
|
|
54
|
+
bottom: 16
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
center: {
|
|
58
|
+
up: {
|
|
59
|
+
top: 16,
|
|
60
|
+
left: "50%",
|
|
61
|
+
translateX: "-50%"
|
|
62
|
+
},
|
|
63
|
+
middle: {
|
|
64
|
+
top: "50%",
|
|
65
|
+
left: "50%",
|
|
66
|
+
translateY: "-50%",
|
|
67
|
+
translateX: "-50%"
|
|
68
|
+
},
|
|
69
|
+
bottom: {
|
|
70
|
+
bottom: 16,
|
|
71
|
+
left: "50%",
|
|
72
|
+
translateX: "-50%"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
right: {
|
|
76
|
+
up: {
|
|
77
|
+
top: 16,
|
|
78
|
+
right: 16
|
|
79
|
+
},
|
|
80
|
+
middle: {
|
|
81
|
+
right: 16,
|
|
82
|
+
top: "50%",
|
|
83
|
+
translateY: "-50%"
|
|
84
|
+
},
|
|
85
|
+
bottom: {
|
|
86
|
+
right: 16,
|
|
87
|
+
bottom: 16
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}, S = {
|
|
91
|
+
borderRadius: 8,
|
|
92
|
+
boxShadow: "0px 0px 4px #efefef",
|
|
93
|
+
maxWidth: "350px",
|
|
94
|
+
width: "calc(100vw - 40px)"
|
|
95
|
+
}, C = {
|
|
96
|
+
blank: {
|
|
97
|
+
backgroundColor: "#e5e7eb",
|
|
98
|
+
color: "#4b5563"
|
|
99
|
+
},
|
|
100
|
+
loading: {
|
|
101
|
+
backgroundColor: "#e5e7eb",
|
|
102
|
+
color: "#4b5563"
|
|
103
|
+
},
|
|
104
|
+
succesful: {
|
|
105
|
+
backgroundColor: "#4ade80",
|
|
106
|
+
color: "#166534"
|
|
107
|
+
},
|
|
108
|
+
error: {
|
|
109
|
+
backgroundColor: "#fecaca",
|
|
110
|
+
color: "#991b1b"
|
|
111
|
+
},
|
|
112
|
+
warning: {
|
|
113
|
+
backgroundColor: "#f97316",
|
|
114
|
+
color: "white"
|
|
115
|
+
},
|
|
116
|
+
info: {
|
|
117
|
+
backgroundColor: "#1e3a8a",
|
|
118
|
+
color: "white"
|
|
119
|
+
}
|
|
120
|
+
}, w = {
|
|
121
|
+
blank: {
|
|
122
|
+
backgroundColor: "#ffffff",
|
|
123
|
+
border: "1px solid #eeeff1"
|
|
124
|
+
},
|
|
125
|
+
loading: {
|
|
126
|
+
backgroundColor: "#ffffff",
|
|
127
|
+
border: "1px solid #eeeff1"
|
|
128
|
+
},
|
|
129
|
+
succesful: {
|
|
130
|
+
backgroundColor: "#dcfce7",
|
|
131
|
+
border: "1px solid #bbf7d0"
|
|
132
|
+
},
|
|
133
|
+
error: {
|
|
134
|
+
backgroundColor: "#fef2f2",
|
|
135
|
+
border: "1px solid #fee2e2"
|
|
136
|
+
},
|
|
137
|
+
warning: {
|
|
138
|
+
backgroundColor: "#ffedd5",
|
|
139
|
+
border: "1px solid #fed7aa"
|
|
140
|
+
},
|
|
141
|
+
info: {
|
|
142
|
+
backgroundColor: "#dbeafe",
|
|
143
|
+
border: "1px solid #ddd6fe"
|
|
144
|
+
}
|
|
145
|
+
}, T = {
|
|
146
|
+
blank: "#1f2937",
|
|
147
|
+
loading: "#1f2937",
|
|
148
|
+
succesful: "#166534",
|
|
149
|
+
error: "#b91c1c",
|
|
150
|
+
warning: "#ea580c",
|
|
151
|
+
info: "#1e3a8a"
|
|
152
|
+
}, E = {
|
|
153
|
+
loading: i,
|
|
154
|
+
succesful: n,
|
|
155
|
+
error: o,
|
|
156
|
+
warning: a,
|
|
157
|
+
info: r,
|
|
158
|
+
blank: void 0
|
|
159
|
+
};
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region lib/components/Toast.tsx
|
|
162
|
+
function D({ type: e = "blank", label: n, icon: r, action: i, closeButton: a = !0, title: s, duration: d, swipe: f = !0, swipeDirection: p = "right", deleteToast: m }) {
|
|
163
|
+
let [h, g] = c(0), _ = E[e] && e !== "blank" ? E[e] : r || void 0, v = {
|
|
164
|
+
...S,
|
|
165
|
+
...w[e]
|
|
166
|
+
};
|
|
167
|
+
return /* @__PURE__ */ l(t.section, {
|
|
168
|
+
drag: "x",
|
|
169
|
+
exit: { opacity: 0 },
|
|
170
|
+
dragDirectionLock: !0,
|
|
171
|
+
dragConstraints: {
|
|
172
|
+
left: 0,
|
|
173
|
+
top: 0,
|
|
174
|
+
right: 0,
|
|
175
|
+
bottom: 0
|
|
176
|
+
},
|
|
177
|
+
initial: {
|
|
178
|
+
opacity: 0,
|
|
179
|
+
scale: .9
|
|
180
|
+
},
|
|
181
|
+
animate: {
|
|
182
|
+
opacity: 1,
|
|
183
|
+
scale: 1,
|
|
184
|
+
transition: { duration: d?.animation ?? .2 }
|
|
185
|
+
},
|
|
186
|
+
onPointerDown: f ? (e) => {
|
|
187
|
+
e.currentTarget.setPointerCapture(e.pointerId), g(e.clientX);
|
|
188
|
+
} : void 0,
|
|
189
|
+
onPointerUp: f ? (e) => {
|
|
190
|
+
let t = h - e.clientX;
|
|
191
|
+
Math.abs(t) > 100 && (t < 0 && p === "right" && m && m(), t > 0 && p === "left" && m && m());
|
|
192
|
+
} : void 0,
|
|
193
|
+
style: v,
|
|
194
|
+
children: /* @__PURE__ */ u("section", {
|
|
195
|
+
style: {
|
|
196
|
+
position: "relative",
|
|
197
|
+
paddingLeft: "1rem",
|
|
198
|
+
paddingTop: "0.8rem",
|
|
199
|
+
paddingRight: i ? a ? "2.5Arem" : "1rem" : "8rem",
|
|
200
|
+
paddingBottom: "0.8rem",
|
|
201
|
+
display: "flex",
|
|
202
|
+
alignItems: "center",
|
|
203
|
+
gap: 16
|
|
204
|
+
},
|
|
205
|
+
children: [
|
|
206
|
+
_ && _ !== void 0 && /* @__PURE__ */ l(t.div, {
|
|
207
|
+
style: {
|
|
208
|
+
display: "flex",
|
|
209
|
+
alignItems: "center"
|
|
210
|
+
},
|
|
211
|
+
animate: e === "loading" ? { rotate: 360 } : {},
|
|
212
|
+
transition: e === "loading" ? {
|
|
213
|
+
repeat: Infinity,
|
|
214
|
+
duration: 1,
|
|
215
|
+
ease: "linear"
|
|
216
|
+
} : {},
|
|
217
|
+
children: /* @__PURE__ */ l(_, {
|
|
218
|
+
size: 18,
|
|
219
|
+
color: T[e]
|
|
220
|
+
})
|
|
221
|
+
}),
|
|
222
|
+
/* @__PURE__ */ u("section", {
|
|
223
|
+
style: {
|
|
224
|
+
display: "flex",
|
|
225
|
+
flexDirection: i ? "row" : "column",
|
|
226
|
+
alignItems: "center",
|
|
227
|
+
justifyContent: "space-between",
|
|
228
|
+
gap: 16
|
|
229
|
+
},
|
|
230
|
+
children: [/* @__PURE__ */ u("section", { children: [s && /* @__PURE__ */ l("p", {
|
|
231
|
+
style: {
|
|
232
|
+
fontFamily: "Inter, system-ui, -apple-system, sans-serif",
|
|
233
|
+
fontSize: "0.9rem",
|
|
234
|
+
fontWeight: 700,
|
|
235
|
+
marginBottom: "4px",
|
|
236
|
+
marginTop: "0px",
|
|
237
|
+
color: T[e]
|
|
238
|
+
},
|
|
239
|
+
children: s
|
|
240
|
+
}), /* @__PURE__ */ l("p", {
|
|
241
|
+
style: {
|
|
242
|
+
fontFamily: "Inter, system-ui, -apple-system, sans-serif",
|
|
243
|
+
fontSize: "0.8rem",
|
|
244
|
+
marginTop: "0px",
|
|
245
|
+
marginBottom: "0px",
|
|
246
|
+
color: T[e]
|
|
247
|
+
},
|
|
248
|
+
children: n
|
|
249
|
+
})] }), i && /* @__PURE__ */ l("button", {
|
|
250
|
+
onClick: i.onClick,
|
|
251
|
+
style: {
|
|
252
|
+
border: "none",
|
|
253
|
+
backgroundColor: C[e].backgroundColor,
|
|
254
|
+
paddingTop: "0.4rem",
|
|
255
|
+
paddingBottom: "0.4rem",
|
|
256
|
+
paddingLeft: "0.8rem",
|
|
257
|
+
paddingRight: "0.8rem",
|
|
258
|
+
borderRadius: "8px",
|
|
259
|
+
fontSize: "0.8rem",
|
|
260
|
+
fontFamily: "Inter, system-ui, -apple-system, sans-serif",
|
|
261
|
+
cursor: "pointer",
|
|
262
|
+
fontWeight: 600,
|
|
263
|
+
color: C[e].color
|
|
264
|
+
},
|
|
265
|
+
children: i.label
|
|
266
|
+
})]
|
|
267
|
+
}),
|
|
268
|
+
a && /* @__PURE__ */ l("button", {
|
|
269
|
+
style: {
|
|
270
|
+
background: "transparent",
|
|
271
|
+
border: "0px",
|
|
272
|
+
color: T[e],
|
|
273
|
+
position: "absolute",
|
|
274
|
+
top: 8,
|
|
275
|
+
right: 8,
|
|
276
|
+
cursor: "pointer",
|
|
277
|
+
zIndex: 10
|
|
278
|
+
},
|
|
279
|
+
onPointerDown: (e) => {
|
|
280
|
+
m && (e.stopPropagation(), m());
|
|
281
|
+
},
|
|
282
|
+
children: /* @__PURE__ */ l(o, { size: 18 })
|
|
283
|
+
})
|
|
284
|
+
]
|
|
285
|
+
})
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region lib/hooks/useToaster.tsx
|
|
290
|
+
function O(e) {
|
|
291
|
+
let [t, n] = c([]);
|
|
292
|
+
return s(() => {
|
|
293
|
+
let t = [], r = e.subscribe((e) => {
|
|
294
|
+
function r() {
|
|
295
|
+
n((t) => t.filter((t) => t.id !== e.id)), clearTimeout(i), t = t.filter((e) => e !== i);
|
|
296
|
+
}
|
|
297
|
+
n((t) => [...t, {
|
|
298
|
+
...e,
|
|
299
|
+
deleteToast: r
|
|
300
|
+
}]);
|
|
301
|
+
let i = setTimeout(() => {
|
|
302
|
+
r();
|
|
303
|
+
}, 5e3);
|
|
304
|
+
t.push(i);
|
|
305
|
+
});
|
|
306
|
+
return () => {
|
|
307
|
+
r(), t.forEach((e) => {
|
|
308
|
+
e && clearTimeout(e);
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
}, [e]), t;
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region lib/components/Toaster.tsx
|
|
315
|
+
function k({ positionX: e = "right", positionY: t = "bottom" }) {
|
|
316
|
+
let n = O(v);
|
|
317
|
+
return /* @__PURE__ */ l("section", {
|
|
318
|
+
style: {
|
|
319
|
+
position: "fixed",
|
|
320
|
+
display: "grid",
|
|
321
|
+
gap: 8,
|
|
322
|
+
...x[e][t]
|
|
323
|
+
},
|
|
324
|
+
children: /* @__PURE__ */ l(y.AnimatePresence, { children: n.filter((e, t) => t < 5).map((e) => /* @__PURE__ */ l(D, { ...e }, e.id)) })
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region lib/main.ts
|
|
329
|
+
var A = { notify: v.notify.bind(v) };
|
|
330
|
+
//#endregion
|
|
331
|
+
export { k as Toaster, A as echo };
|
package/package.json
CHANGED