kitzo 2.3.24 → 2.3.25
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/index.d.ts +1 -0
- package/dist/react/components/toast/Toaster.js +47 -38
- package/dist/react/components/toast/context/ToasterContext.js +12 -0
- package/dist/react/components/toast/helpers/manageToasts/timers.js +63 -26
- package/dist/react/components/toast/partials/Toast.js +26 -21
- package/dist/react/components/toast/partials/ToastContainer.js +18 -18
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { subscribe as
|
|
1
|
+
import { jsx as s } from "react/jsx-runtime";
|
|
2
|
+
import { useState as k, useEffect as v, useRef as x, useCallback as T, useLayoutEffect as E } from "react";
|
|
3
|
+
import { subscribe as O } from "./helpers/listenar.js";
|
|
4
4
|
import z from "./helpers/manageToasts/manageToasts.js";
|
|
5
|
-
import
|
|
6
|
-
|
|
5
|
+
import C from "./partials/ToastContainer.js";
|
|
6
|
+
import { ToasterContext as $ } from "./context/ToasterContext.js";
|
|
7
|
+
function S(m) {
|
|
7
8
|
const {
|
|
8
|
-
position:
|
|
9
|
-
richColors:
|
|
10
|
-
animateTransformOrigin:
|
|
11
|
-
gap:
|
|
12
|
-
edgeOffset:
|
|
13
|
-
isDark:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
position: d = "top-center",
|
|
10
|
+
richColors: c = !1,
|
|
11
|
+
animateTransformOrigin: h = !0,
|
|
12
|
+
gap: e = 8,
|
|
13
|
+
edgeOffset: r = 16,
|
|
14
|
+
isDark: f = window.matchMedia("(prefers-color-scheme: dark)").matches,
|
|
15
|
+
pauseOnHover: g = !0
|
|
16
|
+
} = m, [p, l] = k([]);
|
|
17
|
+
v(() => O((o) => z({ toast: o, setToasts: l })), []);
|
|
18
|
+
const a = x(null), i = T(() => {
|
|
19
|
+
if (!a.current) return;
|
|
20
|
+
const t = a.current.querySelectorAll("[data-toast-container]"), o = {
|
|
19
21
|
"top-left": 0,
|
|
20
22
|
"top-center": 0,
|
|
21
23
|
"top-right": 0,
|
|
@@ -23,49 +25,56 @@ function w(p) {
|
|
|
23
25
|
"bottom-center": 0,
|
|
24
26
|
"bottom-right": 0
|
|
25
27
|
};
|
|
26
|
-
t.forEach((
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
28
|
+
t.forEach((n) => {
|
|
29
|
+
const u = n.getAttribute("data-toast-position") || "top-center", y = parseFloat(n.style.getPropertyValue("--toast-height")) || 0;
|
|
30
|
+
n.style.setProperty("--toast-offset-y", `${o[u]}px`);
|
|
31
|
+
const b = isNaN(+e) ? 8 : +e;
|
|
32
|
+
o[u] += y + b;
|
|
31
33
|
});
|
|
32
|
-
}, [
|
|
34
|
+
}, [e]);
|
|
33
35
|
return E(() => {
|
|
34
|
-
|
|
35
|
-
}, [
|
|
36
|
+
i();
|
|
37
|
+
}, [p, i]), /* @__PURE__ */ s(
|
|
36
38
|
"div",
|
|
37
39
|
{
|
|
38
|
-
ref:
|
|
40
|
+
ref: a,
|
|
39
41
|
style: {
|
|
40
42
|
position: "fixed",
|
|
41
43
|
inset: 0,
|
|
42
44
|
zIndex: 2147483647,
|
|
43
45
|
pointerEvents: "none",
|
|
44
46
|
display: "grid",
|
|
45
|
-
padding:
|
|
47
|
+
padding: r != null ? `${Math.max(Math.min(+r, 200), 0)}px` : 16
|
|
46
48
|
},
|
|
47
|
-
className: `kitzo-toaster ${
|
|
48
|
-
children: /* @__PURE__ */
|
|
49
|
+
className: `kitzo-toaster ${c ? "kitzo-toaster-rich-colors" : ""} ${f ? "kitzo-toaster-dark" : ""}`,
|
|
50
|
+
children: /* @__PURE__ */ s(
|
|
49
51
|
"div",
|
|
50
52
|
{
|
|
51
53
|
style: {
|
|
52
54
|
position: "relative"
|
|
53
55
|
},
|
|
54
|
-
children:
|
|
55
|
-
|
|
56
|
+
children: /* @__PURE__ */ s(
|
|
57
|
+
$.Provider,
|
|
56
58
|
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
value: {
|
|
60
|
+
position: d,
|
|
61
|
+
richColors: c,
|
|
62
|
+
isDark: f,
|
|
63
|
+
gap: e,
|
|
64
|
+
edgeOffset: r,
|
|
65
|
+
animateTransformOrigin: h,
|
|
66
|
+
pauseOnHover: g,
|
|
67
|
+
setToasts: l,
|
|
68
|
+
updateOffsets: i
|
|
69
|
+
},
|
|
70
|
+
children: p.map((t) => /* @__PURE__ */ s(C, { t }, t.id))
|
|
71
|
+
}
|
|
72
|
+
)
|
|
64
73
|
}
|
|
65
74
|
)
|
|
66
75
|
}
|
|
67
76
|
);
|
|
68
77
|
}
|
|
69
78
|
export {
|
|
70
|
-
|
|
79
|
+
S as default
|
|
71
80
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createContext as e, useContext as o } from "react";
|
|
2
|
+
const n = e(null);
|
|
3
|
+
function s() {
|
|
4
|
+
const t = o(n);
|
|
5
|
+
if (!t)
|
|
6
|
+
throw new Error("Toast components must be used inside <Toaster />");
|
|
7
|
+
return t;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
n as ToasterContext,
|
|
11
|
+
s as useToasterContext
|
|
12
|
+
};
|
|
@@ -1,39 +1,76 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const o = /* @__PURE__ */ new Map(), u = 280, s = 500, f = 0;
|
|
2
|
+
function c(e) {
|
|
3
3
|
const i = Number(e);
|
|
4
4
|
if (!isFinite(i)) return null;
|
|
5
|
-
const
|
|
5
|
+
const t = Math.max(f, i);
|
|
6
6
|
return {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
totalTime: t,
|
|
8
|
+
leavingDuration: t,
|
|
9
|
+
leftDuration: t + s
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
const i =
|
|
13
|
-
i && (clearTimeout(i.
|
|
12
|
+
function T(e) {
|
|
13
|
+
const i = o.get(e);
|
|
14
|
+
i && (clearTimeout(i.leavingTimeoutId), clearTimeout(i.leftTimeoutId), o.delete(e));
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
16
|
+
function g() {
|
|
17
|
+
o.forEach(({ leavingTimeoutId: e, leftTimeoutId: i }) => {
|
|
17
18
|
clearTimeout(e), clearTimeout(i);
|
|
18
|
-
}),
|
|
19
|
+
}), o.clear();
|
|
19
20
|
}
|
|
20
|
-
function
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
23
|
-
|
|
24
|
-
const
|
|
21
|
+
function d(e, i) {
|
|
22
|
+
const t = c(e.duration);
|
|
23
|
+
if (!t) return;
|
|
24
|
+
T(e.id);
|
|
25
|
+
const r = setTimeout(() => {
|
|
25
26
|
i(
|
|
26
|
-
(
|
|
27
|
+
(a) => a.map((n) => n.id === e.id ? { ...n, status: "leaving" } : n)
|
|
27
28
|
);
|
|
28
|
-
},
|
|
29
|
-
i((
|
|
30
|
-
},
|
|
31
|
-
|
|
29
|
+
}, t.leavingDuration + u), m = setTimeout(() => {
|
|
30
|
+
i((a) => a.filter((n) => n.id !== e.id)), T(e.id), o.delete(e.id);
|
|
31
|
+
}, t.leftDuration + u), l = Date.now();
|
|
32
|
+
o.set(e.id, {
|
|
33
|
+
leavingTimeoutId: r,
|
|
34
|
+
leftTimeoutId: m,
|
|
35
|
+
startingTime: l,
|
|
36
|
+
totalTime: t.totalTime,
|
|
37
|
+
remainningTime: 0
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function I(e) {
|
|
41
|
+
const i = o.get(e);
|
|
42
|
+
if (!i || i.remainningTime > 0) return;
|
|
43
|
+
const r = Date.now() - i.startingTime, m = Math.max(i.totalTime - r, 0);
|
|
44
|
+
m !== 0 && (o.set(e, { ...i, remainningTime: m }), clearTimeout(i.leavingTimeoutId), clearTimeout(i.leftTimeoutId));
|
|
45
|
+
}
|
|
46
|
+
function D(e, i) {
|
|
47
|
+
const t = o.get(e);
|
|
48
|
+
if (!t) return;
|
|
49
|
+
const r = c(t.remainningTime);
|
|
50
|
+
if (!r) return;
|
|
51
|
+
const m = setTimeout(() => {
|
|
52
|
+
i(
|
|
53
|
+
(a) => a.map((n) => n.id === e ? { ...n, status: "leaving" } : n)
|
|
54
|
+
);
|
|
55
|
+
}, r.leavingDuration + u), l = setTimeout(() => {
|
|
56
|
+
i((a) => a.filter((n) => n.id !== e)), T(e), o.delete(e);
|
|
57
|
+
}, r.leftDuration + u);
|
|
58
|
+
o.set(e, {
|
|
59
|
+
...t,
|
|
60
|
+
startingTime: Date.now(),
|
|
61
|
+
totalTime: t.remainningTime,
|
|
62
|
+
remainningTime: 0,
|
|
63
|
+
leavingTimeoutId: m,
|
|
64
|
+
leftTimeoutId: l
|
|
65
|
+
});
|
|
32
66
|
}
|
|
33
67
|
export {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
68
|
+
s as LEAVE_DELAY,
|
|
69
|
+
f as MIN_VISIBLE,
|
|
70
|
+
u as TRANSITION_DURATION,
|
|
71
|
+
d as addTimers,
|
|
72
|
+
g as clearAllTimers,
|
|
73
|
+
T as clearTimer,
|
|
74
|
+
I as pauseToast,
|
|
75
|
+
D as resumeToast
|
|
39
76
|
};
|
|
@@ -1,48 +1,53 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { jsxs as g, jsx as t, Fragment as s } from "react/jsx-runtime";
|
|
2
|
+
import { resumeToast as v, pauseToast as h } from "../helpers/manageToasts/timers.js";
|
|
3
|
+
import y from "../helpers/triggerToasts.js";
|
|
4
|
+
import { InfoSvg as x, ErrorSvg as S, WarningSvg as $, SuccessSvg as T, LoadingSvg as k } from "./Svgs.js";
|
|
5
|
+
import { useToasterContext as E } from "../context/ToasterContext.js";
|
|
6
|
+
function C({
|
|
7
|
+
t: n,
|
|
8
|
+
position: o,
|
|
9
|
+
shouldAnimateTransformOrigin: d
|
|
8
10
|
}) {
|
|
9
|
-
const { id:
|
|
10
|
-
loading: /* @__PURE__ */
|
|
11
|
-
success: /* @__PURE__ */
|
|
12
|
-
warning: /* @__PURE__ */
|
|
13
|
-
error: /* @__PURE__ */
|
|
14
|
-
info: /* @__PURE__ */
|
|
11
|
+
const { setToasts: m, pauseOnHover: a } = E(), { id: l, type: r, action: f, content: i, status: p, showIcon: u, icon: e } = n, c = {
|
|
12
|
+
loading: /* @__PURE__ */ t(k, {}),
|
|
13
|
+
success: /* @__PURE__ */ t(T, {}),
|
|
14
|
+
warning: /* @__PURE__ */ t($, {}),
|
|
15
|
+
error: /* @__PURE__ */ t(S, {}),
|
|
16
|
+
info: /* @__PURE__ */ t(x, {}),
|
|
15
17
|
default: null,
|
|
16
18
|
custom: null
|
|
17
19
|
};
|
|
18
|
-
return /* @__PURE__ */
|
|
20
|
+
return /* @__PURE__ */ g(
|
|
19
21
|
"div",
|
|
20
22
|
{
|
|
23
|
+
id: `toast-id-${l}`,
|
|
21
24
|
style: {
|
|
22
25
|
pointerEvents: "all",
|
|
23
26
|
display: "flex",
|
|
24
27
|
alignItems: "center",
|
|
25
28
|
gap: 8
|
|
26
29
|
},
|
|
27
|
-
|
|
30
|
+
onMouseEnter: () => a && h(n.id),
|
|
31
|
+
onMouseLeave: () => a && v(n.id, m),
|
|
32
|
+
className: `kitzo-toast type-${r} action-${f} status-${p} pos-y-${o.split("-")[0]} pos-x-${o.split("-")[1]} ${d ? `transform-origin-${o}` : ""}`,
|
|
28
33
|
children: [
|
|
29
|
-
|
|
34
|
+
u && /* @__PURE__ */ t(s, { children: e ? /* @__PURE__ */ t(s, { children: typeof e == "string" || typeof e == "number" ? /* @__PURE__ */ t(
|
|
30
35
|
"div",
|
|
31
36
|
{
|
|
32
37
|
style: {
|
|
33
38
|
flexShrink: 0
|
|
34
39
|
},
|
|
35
40
|
className: "svg-container",
|
|
36
|
-
children:
|
|
41
|
+
children: e
|
|
37
42
|
}
|
|
38
|
-
) : /* @__PURE__ */
|
|
39
|
-
/* @__PURE__ */
|
|
43
|
+
) : /* @__PURE__ */ t(s, { children: e }) }) : /* @__PURE__ */ t(s, { children: c[r] && /* @__PURE__ */ t("div", { style: { flexShrink: 0 }, className: "svg-container", children: c[r] }) }) }),
|
|
44
|
+
/* @__PURE__ */ t(
|
|
40
45
|
"div",
|
|
41
46
|
{
|
|
42
47
|
style: {
|
|
43
48
|
flex: 1
|
|
44
49
|
},
|
|
45
|
-
children: typeof
|
|
50
|
+
children: typeof i == "function" ? i(() => y.dismiss(l)) : i
|
|
46
51
|
}
|
|
47
52
|
)
|
|
48
53
|
]
|
|
@@ -50,5 +55,5 @@ function I({
|
|
|
50
55
|
);
|
|
51
56
|
}
|
|
52
57
|
export {
|
|
53
|
-
|
|
58
|
+
C as default
|
|
54
59
|
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as f } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as d, useLayoutEffect as b } from "react";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import g from "./Toast.js";
|
|
4
|
+
import { useToasterContext as h } from "../context/ToasterContext.js";
|
|
5
|
+
function v({ t }) {
|
|
6
|
+
const {
|
|
7
|
+
updateOffsets: s,
|
|
8
|
+
position: c,
|
|
9
|
+
animateTransformOrigin: l
|
|
10
|
+
} = h(), r = d(null);
|
|
11
11
|
b(() => {
|
|
12
|
-
const e =
|
|
12
|
+
const e = r.current;
|
|
13
13
|
if (!e) return;
|
|
14
14
|
const a = new ResizeObserver(() => {
|
|
15
15
|
const p = e.offsetHeight;
|
|
16
|
-
e.style.setProperty("--toast-height", `${p}px`),
|
|
16
|
+
e.style.setProperty("--toast-height", `${p}px`), s();
|
|
17
17
|
});
|
|
18
18
|
return a.observe(e), () => a.disconnect();
|
|
19
|
-
}, [
|
|
19
|
+
}, [s]);
|
|
20
20
|
const m = [
|
|
21
21
|
"top-left",
|
|
22
22
|
"top-center",
|
|
@@ -24,11 +24,11 @@ function v({
|
|
|
24
24
|
"bottom-left",
|
|
25
25
|
"bottom-center",
|
|
26
26
|
"bottom-right"
|
|
27
|
-
], i = t.position ||
|
|
28
|
-
return /* @__PURE__ */
|
|
27
|
+
], i = t.position || c, o = m.includes(i) ? i : "top-center", n = o?.includes("bottom"), u = typeof t.animateTransformOrigin == "boolean" ? t.animateTransformOrigin : l;
|
|
28
|
+
return /* @__PURE__ */ f(
|
|
29
29
|
"div",
|
|
30
30
|
{
|
|
31
|
-
ref:
|
|
31
|
+
ref: r,
|
|
32
32
|
"data-toast-container": !0,
|
|
33
33
|
"data-toast-position": o,
|
|
34
34
|
style: {
|
|
@@ -38,13 +38,13 @@ function v({
|
|
|
38
38
|
right: 0,
|
|
39
39
|
transition: "transform 180ms",
|
|
40
40
|
display: "flex",
|
|
41
|
-
justifyContent: o
|
|
41
|
+
justifyContent: o?.includes("left") ? "flex-start" : o?.includes("center") ? "center" : "flex-end",
|
|
42
42
|
top: n ? "auto" : 0,
|
|
43
43
|
bottom: n ? 0 : "auto",
|
|
44
44
|
transform: `translateY(calc(var(--toast-offset-y, 0px) * ${n ? -1 : 1}))`
|
|
45
45
|
},
|
|
46
|
-
children: /* @__PURE__ */
|
|
47
|
-
|
|
46
|
+
children: /* @__PURE__ */ f(
|
|
47
|
+
g,
|
|
48
48
|
{
|
|
49
49
|
t,
|
|
50
50
|
position: o,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kitzo",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.25",
|
|
4
4
|
"description": "A lightweight React micro-utility.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"dev": "vite",
|
|
24
|
+
"dev:host": "vite --host",
|
|
24
25
|
"build": "tsc -b && vite build",
|
|
25
26
|
"lint": "eslint .",
|
|
26
27
|
"preview": "vite preview"
|