@jonmilner/ui 0.5.4 → 0.5.5
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/Toast/client.mjs +54 -38
- package/dist/docs/manifest.json +1 -1
- package/package.json +1 -1
package/dist/Toast/client.mjs
CHANGED
|
@@ -11,10 +11,10 @@ import { CircleCheckIcon as c } from "../icons/CircleCheckIcon.mjs";
|
|
|
11
11
|
import { InfoIcon as l } from "../icons/InfoIcon.mjs";
|
|
12
12
|
import { announcer as u, close as d, content as f, list as p, root as m, toast as h, viewport as g } from "./Toast.css.mjs";
|
|
13
13
|
import { jsx as _, jsxs as v } from "react/jsx-runtime";
|
|
14
|
-
import { createContext as y, use as b, useCallback as x,
|
|
15
|
-
import { Toast as
|
|
14
|
+
import { createContext as y, use as b, useCallback as x, useEffect as S, useLayoutEffect as C, useMemo as w, useRef as T, useState as E } from "react";
|
|
15
|
+
import { Toast as D } from "@base-ui/react/toast";
|
|
16
16
|
//#region src/Toast/client.tsx
|
|
17
|
-
var
|
|
17
|
+
var O = {
|
|
18
18
|
info: {
|
|
19
19
|
Icon: l,
|
|
20
20
|
color: "fgMuted"
|
|
@@ -27,13 +27,13 @@ var D = {
|
|
|
27
27
|
Icon: o,
|
|
28
28
|
color: "danger"
|
|
29
29
|
}
|
|
30
|
-
},
|
|
31
|
-
function
|
|
32
|
-
let { container: c, ref: l } = a(), [u] =
|
|
33
|
-
return /* @__PURE__ */ _(
|
|
30
|
+
}, k = y(null), A = y(null), j = (e) => e !== void 0 && Object.hasOwn(O, e);
|
|
31
|
+
function M({ limit: e = 3, closeLabel: n = "Dismiss", regionLabel: r = "Notifications", className: i, style: o, children: s }) {
|
|
32
|
+
let { container: c, ref: l } = a(), [u] = E(D.createToastManager);
|
|
33
|
+
return /* @__PURE__ */ _(D.Provider, {
|
|
34
34
|
limit: e,
|
|
35
35
|
toastManager: u,
|
|
36
|
-
children: /* @__PURE__ */ v(
|
|
36
|
+
children: /* @__PURE__ */ v(k, {
|
|
37
37
|
value: u,
|
|
38
38
|
children: [
|
|
39
39
|
/* @__PURE__ */ _(t, {
|
|
@@ -42,23 +42,38 @@ function j({ limit: e = 3, closeLabel: n = "Dismiss", regionLabel: r = "Notifica
|
|
|
42
42
|
ref: l
|
|
43
43
|
}),
|
|
44
44
|
s,
|
|
45
|
-
/* @__PURE__ */ _(
|
|
46
|
-
/* @__PURE__ */ _(
|
|
45
|
+
/* @__PURE__ */ _(P, {}),
|
|
46
|
+
/* @__PURE__ */ _(D.Portal, {
|
|
47
47
|
container: c,
|
|
48
|
-
children: /* @__PURE__ */ _(
|
|
48
|
+
children: /* @__PURE__ */ _(N, {
|
|
49
49
|
className: i,
|
|
50
50
|
regionLabel: r,
|
|
51
51
|
style: o,
|
|
52
|
-
children: /* @__PURE__ */ _(
|
|
52
|
+
children: /* @__PURE__ */ _(F, { closeLabel: n })
|
|
53
53
|
})
|
|
54
54
|
})
|
|
55
55
|
]
|
|
56
56
|
})
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
let o =
|
|
61
|
-
return
|
|
59
|
+
function N({ regionLabel: n, className: r, style: i, children: a }) {
|
|
60
|
+
let o = T(null), s = T(null);
|
|
61
|
+
return S(() => {
|
|
62
|
+
let e = s.current;
|
|
63
|
+
if (!e) return;
|
|
64
|
+
let t = e.ownerDocument, n = !1, r = (t) => {
|
|
65
|
+
e.contains(t.target) ? n = !0 : n && (n = !1, e.dispatchEvent(new MouseEvent("mouseout", {
|
|
66
|
+
bubbles: !0,
|
|
67
|
+
relatedTarget: e.parentElement
|
|
68
|
+
})));
|
|
69
|
+
}, i = (t) => {
|
|
70
|
+
let r = t.relatedTarget;
|
|
71
|
+
(!r || !e.contains(r)) && (n = !1);
|
|
72
|
+
};
|
|
73
|
+
return t.addEventListener("mouseover", r), t.addEventListener("mouseout", i), () => {
|
|
74
|
+
t.removeEventListener("mouseover", r), t.removeEventListener("mouseout", i);
|
|
75
|
+
};
|
|
76
|
+
}, []), /* @__PURE__ */ _(D.Viewport, {
|
|
62
77
|
"aria-atomic": void 0,
|
|
63
78
|
"aria-label": n,
|
|
64
79
|
"aria-live": "off",
|
|
@@ -67,6 +82,7 @@ function M({ regionLabel: n, className: r, style: i, children: a }) {
|
|
|
67
82
|
let t = e.relatedTarget;
|
|
68
83
|
t && !e.currentTarget.contains(t) && (o.current = t);
|
|
69
84
|
},
|
|
85
|
+
ref: s,
|
|
70
86
|
render: /* @__PURE__ */ _(t, {
|
|
71
87
|
className: e(g, r),
|
|
72
88
|
position: "fixed",
|
|
@@ -75,15 +91,15 @@ function M({ regionLabel: n, className: r, style: i, children: a }) {
|
|
|
75
91
|
}),
|
|
76
92
|
children: /* @__PURE__ */ _("div", {
|
|
77
93
|
className: p,
|
|
78
|
-
children: /* @__PURE__ */ _(
|
|
94
|
+
children: /* @__PURE__ */ _(A, {
|
|
79
95
|
value: o,
|
|
80
96
|
children: a
|
|
81
97
|
})
|
|
82
98
|
})
|
|
83
99
|
});
|
|
84
100
|
}
|
|
85
|
-
function
|
|
86
|
-
let { toasts: e } =
|
|
101
|
+
function P() {
|
|
102
|
+
let { toasts: e } = D.useToastManager(), t = (t) => e.filter((e) => e.type === "error" === t).map((e) => /* @__PURE__ */ v("div", { children: [
|
|
87
103
|
e.title,
|
|
88
104
|
" ",
|
|
89
105
|
e.description
|
|
@@ -103,18 +119,18 @@ function N() {
|
|
|
103
119
|
})]
|
|
104
120
|
});
|
|
105
121
|
}
|
|
106
|
-
function
|
|
107
|
-
let { toasts: t } =
|
|
108
|
-
return t.map((t) => /* @__PURE__ */ _(
|
|
122
|
+
function F({ closeLabel: e }) {
|
|
123
|
+
let { toasts: t } = D.useToastManager();
|
|
124
|
+
return t.map((t) => /* @__PURE__ */ _(I, {
|
|
109
125
|
closeLabel: e,
|
|
110
126
|
toast: t
|
|
111
127
|
}, t.id));
|
|
112
128
|
}
|
|
113
|
-
function
|
|
114
|
-
let c =
|
|
115
|
-
e &&
|
|
116
|
-
}, []), M =
|
|
117
|
-
return
|
|
129
|
+
function I({ toast: a, closeLabel: o }) {
|
|
130
|
+
let c = j(a.type) ? a.type : "info", { Icon: l, color: u } = O[c], p = b(k), g = b(A), [y, S] = E(!1), w = x((e) => {
|
|
131
|
+
e && S(getComputedStyle(e).direction === "rtl");
|
|
132
|
+
}, []), M = T(!1), N = a.transitionStatus === "ending";
|
|
133
|
+
return C(() => {
|
|
118
134
|
let e = a.ref?.current, t = e?.ownerDocument.activeElement;
|
|
119
135
|
if (!N || M.current || !t || !e.contains(t)) return;
|
|
120
136
|
let n = g?.current;
|
|
@@ -123,9 +139,9 @@ function F({ toast: a, closeLabel: o }) {
|
|
|
123
139
|
N,
|
|
124
140
|
g,
|
|
125
141
|
a.ref
|
|
126
|
-
]), /* @__PURE__ */ v(
|
|
142
|
+
]), /* @__PURE__ */ v(D.Root, {
|
|
127
143
|
"aria-modal": void 0,
|
|
128
|
-
ref:
|
|
144
|
+
ref: w,
|
|
129
145
|
render: /* @__PURE__ */ _(t, {
|
|
130
146
|
alignItems: "start",
|
|
131
147
|
backgroundColor: "bgRaised",
|
|
@@ -154,27 +170,27 @@ function F({ toast: a, closeLabel: o }) {
|
|
|
154
170
|
flexGrow: 1,
|
|
155
171
|
gap: "8",
|
|
156
172
|
children: [
|
|
157
|
-
/* @__PURE__ */ _(
|
|
173
|
+
/* @__PURE__ */ _(D.Title, { render: /* @__PURE__ */ _(r, {
|
|
158
174
|
as: "div",
|
|
159
175
|
weight: "medium"
|
|
160
176
|
}) }),
|
|
161
|
-
/* @__PURE__ */ _(
|
|
177
|
+
/* @__PURE__ */ _(D.Description, { render: /* @__PURE__ */ _(r, {
|
|
162
178
|
as: "div",
|
|
163
179
|
color: "fgMuted",
|
|
164
180
|
size: "sm"
|
|
165
181
|
}) }),
|
|
166
|
-
/* @__PURE__ */ _(
|
|
182
|
+
/* @__PURE__ */ _(D.Action, { render: /* @__PURE__ */ _(i, {
|
|
167
183
|
size: "sm",
|
|
168
184
|
variant: "secondary"
|
|
169
185
|
}) })
|
|
170
186
|
]
|
|
171
187
|
}),
|
|
172
|
-
/* @__PURE__ */ _(
|
|
188
|
+
/* @__PURE__ */ _(D.Close, {
|
|
173
189
|
"aria-hidden": !1,
|
|
174
190
|
"aria-label": o,
|
|
175
191
|
onClick: (e) => {
|
|
176
192
|
if (e.detail !== 0 || !p) return;
|
|
177
|
-
let t = a.ref?.current, n = (t &&
|
|
193
|
+
let t = a.ref?.current, n = (t && L(t)) ?? g?.current;
|
|
178
194
|
n instanceof HTMLElement && (e.preventBaseUIHandler(), M.current = !0, p.close(a.id), requestAnimationFrame(() => {
|
|
179
195
|
n.isConnected && n.focus();
|
|
180
196
|
}));
|
|
@@ -190,14 +206,14 @@ function F({ toast: a, closeLabel: o }) {
|
|
|
190
206
|
]
|
|
191
207
|
});
|
|
192
208
|
}
|
|
193
|
-
function
|
|
209
|
+
function L(e) {
|
|
194
210
|
let t = (e, n) => !e || !e.matches("[data-ending-style]") ? e : t(n ? e.nextElementSibling : e.previousElementSibling, n);
|
|
195
211
|
return (t(e.nextElementSibling, !0) ?? t(e.previousElementSibling, !1))?.querySelector(`.${d}`);
|
|
196
212
|
}
|
|
197
|
-
function
|
|
198
|
-
let e = b(
|
|
213
|
+
function R() {
|
|
214
|
+
let e = b(k);
|
|
199
215
|
if (!e) throw Error("useToast must be called under Toast.Provider.");
|
|
200
|
-
return
|
|
216
|
+
return w(() => {
|
|
201
217
|
let t = (t) => e.close(t);
|
|
202
218
|
return {
|
|
203
219
|
add: ({ title: n, description: r, variant: i = "info", duration: a = i === "error" ? 0 : 5e3, action: o }) => {
|
|
@@ -225,4 +241,4 @@ function L() {
|
|
|
225
241
|
}, [e]);
|
|
226
242
|
}
|
|
227
243
|
//#endregion
|
|
228
|
-
export {
|
|
244
|
+
export { P as ToastAnnouncer, I as ToastItem, M as ToastProvider, N as ToastStack, R as useToast };
|
package/dist/docs/manifest.json
CHANGED