@jonmilner/ui 0.2.6 → 0.2.7
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 +47 -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, useLayoutEffect as S, useMemo as C, useRef as w, useState as T } from "react";
|
|
15
|
+
import { Toast as E } from "@base-ui/react/toast";
|
|
16
16
|
//#region src/Toast/client.tsx
|
|
17
|
-
var
|
|
17
|
+
var D = {
|
|
18
18
|
info: {
|
|
19
19
|
Icon: l,
|
|
20
20
|
color: "fgMuted"
|
|
@@ -27,13 +27,13 @@ var E = {
|
|
|
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
|
+
}, O = y(null), k = y(null), A = (e) => e !== void 0 && Object.hasOwn(D, e);
|
|
31
|
+
function j({ limit: e = 3, closeLabel: n = "Dismiss", regionLabel: r = "Notifications", className: i, style: o, children: s }) {
|
|
32
|
+
let { container: c, ref: l } = a(), [u] = T(E.createToastManager);
|
|
33
|
+
return /* @__PURE__ */ _(E.Provider, {
|
|
34
34
|
limit: e,
|
|
35
35
|
toastManager: u,
|
|
36
|
-
children: /* @__PURE__ */ v(
|
|
36
|
+
children: /* @__PURE__ */ v(O, {
|
|
37
37
|
value: u,
|
|
38
38
|
children: [
|
|
39
39
|
/* @__PURE__ */ _(t, {
|
|
@@ -42,23 +42,23 @@ function A({ limit: e = 3, closeLabel: n = "Dismiss", regionLabel: r = "Notifica
|
|
|
42
42
|
ref: l
|
|
43
43
|
}),
|
|
44
44
|
s,
|
|
45
|
-
/* @__PURE__ */ _(
|
|
46
|
-
/* @__PURE__ */ _(
|
|
45
|
+
/* @__PURE__ */ _(N, {}),
|
|
46
|
+
/* @__PURE__ */ _(E.Portal, {
|
|
47
47
|
container: c,
|
|
48
|
-
children: /* @__PURE__ */ _(
|
|
48
|
+
children: /* @__PURE__ */ _(M, {
|
|
49
49
|
className: i,
|
|
50
50
|
regionLabel: r,
|
|
51
51
|
style: o,
|
|
52
|
-
children: /* @__PURE__ */ _(
|
|
52
|
+
children: /* @__PURE__ */ _(P, { closeLabel: n })
|
|
53
53
|
})
|
|
54
54
|
})
|
|
55
55
|
]
|
|
56
56
|
})
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
let o =
|
|
61
|
-
return /* @__PURE__ */ _(
|
|
59
|
+
function M({ regionLabel: n, className: r, style: i, children: a }) {
|
|
60
|
+
let o = w(null);
|
|
61
|
+
return /* @__PURE__ */ _(E.Viewport, {
|
|
62
62
|
"aria-atomic": void 0,
|
|
63
63
|
"aria-label": n,
|
|
64
64
|
"aria-live": "off",
|
|
@@ -75,15 +75,15 @@ function j({ regionLabel: n, className: r, style: i, children: a }) {
|
|
|
75
75
|
}),
|
|
76
76
|
children: /* @__PURE__ */ _("div", {
|
|
77
77
|
className: p,
|
|
78
|
-
children: /* @__PURE__ */ _(
|
|
78
|
+
children: /* @__PURE__ */ _(k, {
|
|
79
79
|
value: o,
|
|
80
80
|
children: a
|
|
81
81
|
})
|
|
82
82
|
})
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
-
function
|
|
86
|
-
let { toasts: e } =
|
|
85
|
+
function N() {
|
|
86
|
+
let { toasts: e } = E.useToastManager(), t = (t) => e.filter((e) => e.type === "error" === t).map((e) => /* @__PURE__ */ v("div", { children: [
|
|
87
87
|
e.title,
|
|
88
88
|
" ",
|
|
89
89
|
e.description
|
|
@@ -103,20 +103,29 @@ function M() {
|
|
|
103
103
|
})]
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
let { toasts: t } =
|
|
108
|
-
return t.map((t) => /* @__PURE__ */ _(
|
|
106
|
+
function P({ closeLabel: e }) {
|
|
107
|
+
let { toasts: t } = E.useToastManager();
|
|
108
|
+
return t.map((t) => /* @__PURE__ */ _(F, {
|
|
109
109
|
closeLabel: e,
|
|
110
110
|
toast: t
|
|
111
111
|
}, t.id));
|
|
112
112
|
}
|
|
113
|
-
function
|
|
114
|
-
let c =
|
|
115
|
-
e &&
|
|
116
|
-
}, []);
|
|
117
|
-
return
|
|
113
|
+
function F({ toast: a, closeLabel: o }) {
|
|
114
|
+
let c = A(a.type) ? a.type : "info", { Icon: l, color: u } = D[c], p = b(O), g = b(k), [y, C] = T(!1), j = x((e) => {
|
|
115
|
+
e && C(getComputedStyle(e).direction === "rtl");
|
|
116
|
+
}, []), M = w(!1), N = a.transitionStatus === "ending";
|
|
117
|
+
return S(() => {
|
|
118
|
+
let e = a.ref?.current, t = e?.ownerDocument.activeElement;
|
|
119
|
+
if (!N || M.current || !t || !e.contains(t)) return;
|
|
120
|
+
let n = g?.current;
|
|
121
|
+
n instanceof HTMLElement && n.isConnected && n.focus({ preventScroll: !0 });
|
|
122
|
+
}, [
|
|
123
|
+
N,
|
|
124
|
+
g,
|
|
125
|
+
a.ref
|
|
126
|
+
]), /* @__PURE__ */ v(E.Root, {
|
|
118
127
|
"aria-modal": void 0,
|
|
119
|
-
ref:
|
|
128
|
+
ref: j,
|
|
120
129
|
render: /* @__PURE__ */ _(t, {
|
|
121
130
|
alignItems: "start",
|
|
122
131
|
backgroundColor: "bgRaised",
|
|
@@ -145,28 +154,28 @@ function P({ toast: a, closeLabel: o }) {
|
|
|
145
154
|
flexGrow: 1,
|
|
146
155
|
gap: "8",
|
|
147
156
|
children: [
|
|
148
|
-
/* @__PURE__ */ _(
|
|
157
|
+
/* @__PURE__ */ _(E.Title, { render: /* @__PURE__ */ _(r, {
|
|
149
158
|
as: "div",
|
|
150
159
|
weight: "medium"
|
|
151
160
|
}) }),
|
|
152
|
-
/* @__PURE__ */ _(
|
|
161
|
+
/* @__PURE__ */ _(E.Description, { render: /* @__PURE__ */ _(r, {
|
|
153
162
|
as: "div",
|
|
154
163
|
color: "fgMuted",
|
|
155
164
|
size: "sm"
|
|
156
165
|
}) }),
|
|
157
|
-
/* @__PURE__ */ _(
|
|
166
|
+
/* @__PURE__ */ _(E.Action, { render: /* @__PURE__ */ _(i, {
|
|
158
167
|
size: "sm",
|
|
159
168
|
variant: "secondary"
|
|
160
169
|
}) })
|
|
161
170
|
]
|
|
162
171
|
}),
|
|
163
|
-
/* @__PURE__ */ _(
|
|
172
|
+
/* @__PURE__ */ _(E.Close, {
|
|
164
173
|
"aria-hidden": !1,
|
|
165
174
|
"aria-label": o,
|
|
166
175
|
onClick: (e) => {
|
|
167
176
|
if (e.detail !== 0 || !p) return;
|
|
168
|
-
let t = a.ref?.current, n = (t &&
|
|
169
|
-
n instanceof HTMLElement && (e.preventBaseUIHandler(), p.close(a.id), requestAnimationFrame(() => {
|
|
177
|
+
let t = a.ref?.current, n = (t && I(t)) ?? g?.current;
|
|
178
|
+
n instanceof HTMLElement && (e.preventBaseUIHandler(), M.current = !0, p.close(a.id), requestAnimationFrame(() => {
|
|
170
179
|
n.isConnected && n.focus();
|
|
171
180
|
}));
|
|
172
181
|
},
|
|
@@ -181,14 +190,14 @@ function P({ toast: a, closeLabel: o }) {
|
|
|
181
190
|
]
|
|
182
191
|
});
|
|
183
192
|
}
|
|
184
|
-
function
|
|
193
|
+
function I(e) {
|
|
185
194
|
let t = (e, n) => !e || !e.matches("[data-ending-style]") ? e : t(n ? e.nextElementSibling : e.previousElementSibling, n);
|
|
186
195
|
return (t(e.nextElementSibling, !0) ?? t(e.previousElementSibling, !1))?.querySelector(`.${d}`);
|
|
187
196
|
}
|
|
188
|
-
function
|
|
189
|
-
let e = b(
|
|
197
|
+
function L() {
|
|
198
|
+
let e = b(O);
|
|
190
199
|
if (!e) throw Error("useToast must be called under Toast.Provider.");
|
|
191
|
-
return
|
|
200
|
+
return C(() => {
|
|
192
201
|
let t = (t) => e.close(t);
|
|
193
202
|
return {
|
|
194
203
|
add: ({ title: n, description: r, variant: i = "info", duration: a = i === "error" ? 0 : 5e3, action: o }) => {
|
|
@@ -216,4 +225,4 @@ function I() {
|
|
|
216
225
|
}, [e]);
|
|
217
226
|
}
|
|
218
227
|
//#endregion
|
|
219
|
-
export {
|
|
228
|
+
export { N as ToastAnnouncer, F as ToastItem, j as ToastProvider, M as ToastStack, L as useToast };
|
package/dist/docs/manifest.json
CHANGED