@skiddph/prui 0.8.0 → 0.9.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/core/combobox.js +123 -113
- package/dist/core/date-picker.d.ts +26 -5
- package/dist/core/date-picker.js +245 -133
- package/dist/core/dialog.d.ts +7 -0
- package/dist/core/dialog.js +63 -44
- package/dist/core/index.d.ts +3 -2
- package/dist/core/modal.js +133 -126
- package/dist/core/select.js +136 -128
- package/dist/core/time-picker.d.ts +68 -0
- package/dist/core/time-picker.js +305 -0
- package/dist/core/toast.js +73 -64
- package/dist/core.js +113 -105
- package/dist/i18n/index.d.ts +6 -0
- package/dist/i18n.js +17 -11
- package/dist/index.js +210 -202
- package/dist/prui-utilities.css +1 -1
- package/dist/prui.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { jsxs as N, Fragment as U, jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import * as R from "react";
|
|
3
|
+
import { Clock as G } from "lucide-react";
|
|
4
|
+
import { cn as I } from "./cn.js";
|
|
5
|
+
import { Portal as L, useOverlayStack as J, useEscapeKey as Q } from "./overlay.js";
|
|
6
|
+
import { useAnchoredPosition as W } from "./anchor.js";
|
|
7
|
+
import { moveIndex as F } from "./list-nav.js";
|
|
8
|
+
import { usePruiI18n as V } from "../i18n.js";
|
|
9
|
+
const P = (s) => String(s).padStart(2, "0");
|
|
10
|
+
function _(s) {
|
|
11
|
+
if (!s || !/^\d{2}:\d{2}(:\d{2})?$/.test(s)) return null;
|
|
12
|
+
const [o, c, d] = s.split(":").map(Number);
|
|
13
|
+
return { h: o ?? 0, m: c ?? 0, s: d ?? 0 };
|
|
14
|
+
}
|
|
15
|
+
function X(s, o, c = 0, d) {
|
|
16
|
+
return d ? `${P(s)}:${P(o)}:${P(c)}` : `${P(s)}:${P(o)}`;
|
|
17
|
+
}
|
|
18
|
+
function z(s) {
|
|
19
|
+
const o = _(s);
|
|
20
|
+
return o ? o.h * 3600 + o.m * 60 + o.s : -1;
|
|
21
|
+
}
|
|
22
|
+
function Y(s) {
|
|
23
|
+
const o = [];
|
|
24
|
+
for (let c = 0; c < 60; c += Math.max(1, s)) o.push(c);
|
|
25
|
+
return o;
|
|
26
|
+
}
|
|
27
|
+
function C({ value: s, onSelect: o, minuteStep: c = 1, seconds: d = !1, min: h, max: y, compact: k, className: w }) {
|
|
28
|
+
const { t: b } = V(), t = _(s), x = h ? z(h) : -1 / 0, A = y ? z(y) : 1 / 0, p = [
|
|
29
|
+
{ label: b.hours, items: Array.from({ length: 24 }, (e, a) => a), selected: (t == null ? void 0 : t.h) ?? null, unit: "h" },
|
|
30
|
+
{ label: b.minutes, items: Y(c), selected: (t == null ? void 0 : t.m) ?? null, unit: "m" }
|
|
31
|
+
];
|
|
32
|
+
d && p.push({ label: b.seconds, items: Array.from({ length: 60 }, (e, a) => a), selected: (t == null ? void 0 : t.s) ?? null, unit: "s" });
|
|
33
|
+
const H = (e, a) => {
|
|
34
|
+
const n = e === "h" ? a : (t == null ? void 0 : t.h) ?? 0, m = e === "m" ? a : (t == null ? void 0 : t.m) ?? 0, i = e === "s" ? a : (t == null ? void 0 : t.s) ?? 0, f = n * 3600 + m * 60 + i;
|
|
35
|
+
return f < x || f > A;
|
|
36
|
+
}, E = (e, a) => {
|
|
37
|
+
const n = e === "h" ? a : (t == null ? void 0 : t.h) ?? 0, m = e === "m" ? a : (t == null ? void 0 : t.m) ?? 0, i = e === "s" ? a : (t == null ? void 0 : t.s) ?? 0;
|
|
38
|
+
o(X(n, m, i, d));
|
|
39
|
+
}, S = (e, a) => {
|
|
40
|
+
var T, v, g, l, D, $, M, K;
|
|
41
|
+
const n = Array.from(
|
|
42
|
+
e.currentTarget.querySelectorAll("[role='option']:not([aria-disabled='true'])")
|
|
43
|
+
), m = n.findIndex((r) => r.getAttribute("aria-selected") === "true"), i = n.indexOf(document.activeElement), f = i >= 0 ? i : m;
|
|
44
|
+
switch (e.key) {
|
|
45
|
+
case "ArrowDown":
|
|
46
|
+
e.preventDefault(), (T = n[F(f, 1, n.length)]) == null || T.focus();
|
|
47
|
+
break;
|
|
48
|
+
case "ArrowUp":
|
|
49
|
+
e.preventDefault(), (v = n[F(f, -1, n.length)]) == null || v.focus();
|
|
50
|
+
break;
|
|
51
|
+
case "Home":
|
|
52
|
+
e.preventDefault(), (g = n[0]) == null || g.focus();
|
|
53
|
+
break;
|
|
54
|
+
case "End":
|
|
55
|
+
e.preventDefault(), (l = n[n.length - 1]) == null || l.focus();
|
|
56
|
+
break;
|
|
57
|
+
case "ArrowLeft":
|
|
58
|
+
if (a > 0) {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
const r = (D = e.currentTarget.previousElementSibling) == null ? void 0 : D.querySelectorAll("[role='option']:not([aria-disabled='true'])");
|
|
61
|
+
($ = r == null ? void 0 : r[Math.min(f < 0 ? 0 : f, r.length - 1)]) == null || $.focus();
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case "ArrowRight":
|
|
65
|
+
if (a < p.length - 1) {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
const r = (M = e.currentTarget.nextElementSibling) == null ? void 0 : M.querySelectorAll("[role='option']:not([aria-disabled='true'])");
|
|
68
|
+
(K = r == null ? void 0 : r[Math.min(f < 0 ? 0 : f, r.length - 1)]) == null || K.focus();
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return /* @__PURE__ */ u("div", { className: I("prui-time-panel flex gap-1", w), role: "group", "aria-label": b.time, children: p.map((e, a) => /* @__PURE__ */ N(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
role: "listbox",
|
|
77
|
+
"aria-label": e.label,
|
|
78
|
+
tabIndex: -1,
|
|
79
|
+
onKeyDown: (n) => S(n, a),
|
|
80
|
+
className: I("flex w-16 flex-col rounded-[var(--prui-radius-1)] outline-none", !k && "bg-[var(--prui-raise)]/40"),
|
|
81
|
+
children: [
|
|
82
|
+
k ? null : /* @__PURE__ */ u("div", { className: "px-2 pb-1 pt-2 text-center text-[10px] font-semibold uppercase tracking-wide text-[var(--prui-dim)]", children: e.label }),
|
|
83
|
+
/* @__PURE__ */ u("div", { className: "flex max-h-56 flex-col overflow-y-auto p-1", children: e.items.map((n) => {
|
|
84
|
+
const m = e.selected === n, i = H(e.unit, n);
|
|
85
|
+
return /* @__PURE__ */ u(
|
|
86
|
+
"button",
|
|
87
|
+
{
|
|
88
|
+
type: "button",
|
|
89
|
+
role: "option",
|
|
90
|
+
"aria-selected": m,
|
|
91
|
+
"aria-disabled": i || void 0,
|
|
92
|
+
tabIndex: m ? 0 : -1,
|
|
93
|
+
"data-testid": `time-${e.unit}`,
|
|
94
|
+
onClick: () => !i && E(e.unit, n),
|
|
95
|
+
className: I(
|
|
96
|
+
"rounded-[calc(var(--prui-radius-1))] py-1 text-center text-sm tabular-nums cursor-pointer outline-none",
|
|
97
|
+
"focus-visible:bg-[var(--prui-raise)]",
|
|
98
|
+
m ? "bg-[var(--prui-brand)] text-[var(--prui-brand-fg,#fff)] font-medium" : "text-[var(--prui-fg)] hover:bg-[var(--prui-raise)]",
|
|
99
|
+
i && "opacity-40 pointer-events-none"
|
|
100
|
+
),
|
|
101
|
+
children: P(n)
|
|
102
|
+
},
|
|
103
|
+
n
|
|
104
|
+
);
|
|
105
|
+
}) })
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
e.unit
|
|
109
|
+
)) });
|
|
110
|
+
}
|
|
111
|
+
function B(s, o, c) {
|
|
112
|
+
const { setElement: d, isTop: h } = J(o);
|
|
113
|
+
Q(o, h, c);
|
|
114
|
+
const { ref: y, position: k } = W({ active: o, anchorRef: s, side: "bottom", align: "start", offsetHeight: 280 });
|
|
115
|
+
return R.useEffect(() => {
|
|
116
|
+
if (!o) return;
|
|
117
|
+
const w = (b) => {
|
|
118
|
+
var x;
|
|
119
|
+
const t = b.target;
|
|
120
|
+
(x = s.current) != null && x.contains(t) || (!(t instanceof Element) || !t.closest("[data-prui-time-panel-wrap]")) && c();
|
|
121
|
+
};
|
|
122
|
+
return document.addEventListener("mousedown", w), () => document.removeEventListener("mousedown", w);
|
|
123
|
+
}), { setElement: d, floatingRef: y, position: k };
|
|
124
|
+
}
|
|
125
|
+
const Z = R.forwardRef(function({ value: o, defaultValue: c, onChange: d, minuteStep: h, seconds: y, min: k, max: w, disabled: b, placeholder: t = "HH:mm", ariaLabel: x, className: A }, p) {
|
|
126
|
+
const [H, E] = R.useState(c ?? ""), [S, e] = R.useState(!1), a = R.useRef(null), n = o !== void 0, m = n ? o : H, i = a, { setElement: f, floatingRef: T, position: v } = B(i, S, () => {
|
|
127
|
+
var l;
|
|
128
|
+
e(!1), (l = a.current) == null || l.focus();
|
|
129
|
+
}), g = (l) => {
|
|
130
|
+
n || E(l), d == null || d(l);
|
|
131
|
+
};
|
|
132
|
+
return /* @__PURE__ */ N(U, { children: [
|
|
133
|
+
/* @__PURE__ */ u(
|
|
134
|
+
"input",
|
|
135
|
+
{
|
|
136
|
+
ref: (l) => {
|
|
137
|
+
a.current = l, typeof p == "function" ? p(l) : p && (p.current = l);
|
|
138
|
+
},
|
|
139
|
+
type: "text",
|
|
140
|
+
readOnly: !0,
|
|
141
|
+
role: "combobox",
|
|
142
|
+
"aria-expanded": S,
|
|
143
|
+
"aria-haspopup": "dialog",
|
|
144
|
+
"aria-label": x,
|
|
145
|
+
placeholder: t,
|
|
146
|
+
disabled: b,
|
|
147
|
+
value: m,
|
|
148
|
+
onClick: () => e(!0),
|
|
149
|
+
onFocus: () => {
|
|
150
|
+
!b && !S && e(!0);
|
|
151
|
+
},
|
|
152
|
+
className: I(
|
|
153
|
+
"prui-time-picker h-9 w-full cursor-pointer rounded-[var(--prui-radius)] border border-[var(--prui-line)]",
|
|
154
|
+
"bg-[var(--prui-background)] px-3 pr-8 text-sm tabular-nums text-[var(--prui-fg)] placeholder:text-[var(--prui-dim)]",
|
|
155
|
+
"outline-none transition-colors focus:border-[var(--prui-brand)] focus:ring-2 focus:ring-[var(--prui-brand)]/30",
|
|
156
|
+
"disabled:opacity-50 disabled:cursor-not-allowed",
|
|
157
|
+
A
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
),
|
|
161
|
+
S ? /* @__PURE__ */ u(L, { children: /* @__PURE__ */ u(
|
|
162
|
+
"div",
|
|
163
|
+
{
|
|
164
|
+
ref: (l) => {
|
|
165
|
+
T(l), f(l);
|
|
166
|
+
},
|
|
167
|
+
role: "dialog",
|
|
168
|
+
"aria-label": x ?? "Choose time",
|
|
169
|
+
"data-prui-time-panel-wrap": !0,
|
|
170
|
+
className: "fixed z-[var(--prui-z-overlay)] rounded-[var(--prui-radius)] border border-[var(--prui-line)] bg-[var(--prui-surface)] p-2 shadow-[var(--prui-shadow-lg)]",
|
|
171
|
+
style: { top: (v == null ? void 0 : v.top) ?? -9999, left: (v == null ? void 0 : v.left) ?? -9999 },
|
|
172
|
+
children: /* @__PURE__ */ u(C, { value: m, onSelect: g, minuteStep: h, seconds: y, min: k, max: w })
|
|
173
|
+
}
|
|
174
|
+
) }) : null
|
|
175
|
+
] });
|
|
176
|
+
});
|
|
177
|
+
Z.displayName = "TimePicker";
|
|
178
|
+
const ee = R.forwardRef(function({ value: o, defaultValue: c, onChange: d, minuteStep: h, seconds: y, min: k, max: w, disabled: b, placeholder: t = "HH:mm – HH:mm", ariaLabel: x, className: A }, p) {
|
|
179
|
+
const { t: H } = V(), [E, S] = R.useState(c ?? {}), [e, a] = R.useState(!1), n = R.useRef(null), m = o !== void 0, i = m ? o : E, f = n, { setElement: T, floatingRef: v, position: g } = B(f, e, () => {
|
|
180
|
+
var r;
|
|
181
|
+
a(!1), (r = n.current) == null || r.focus();
|
|
182
|
+
}), l = (r) => {
|
|
183
|
+
m || S(r), d == null || d(r);
|
|
184
|
+
}, D = (r, q) => {
|
|
185
|
+
const O = r === "from" ? q : i.from, j = r === "to" ? q : i.to;
|
|
186
|
+
if (O && j && z(j) < z(O)) {
|
|
187
|
+
l(r === "to" ? { from: q, to: void 0 } : { from: j, to: O });
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
l({ from: O, to: j });
|
|
191
|
+
}, $ = i.from ? i.to ? `${i.from} – ${i.to}` : `${i.from} – …` : "", M = i.to ?? w, K = i.from ?? k;
|
|
192
|
+
return /* @__PURE__ */ N(U, { children: [
|
|
193
|
+
/* @__PURE__ */ u(
|
|
194
|
+
"input",
|
|
195
|
+
{
|
|
196
|
+
ref: (r) => {
|
|
197
|
+
n.current = r, typeof p == "function" ? p(r) : p && (p.current = r);
|
|
198
|
+
},
|
|
199
|
+
type: "text",
|
|
200
|
+
readOnly: !0,
|
|
201
|
+
role: "combobox",
|
|
202
|
+
"aria-expanded": e,
|
|
203
|
+
"aria-haspopup": "dialog",
|
|
204
|
+
"aria-label": x,
|
|
205
|
+
placeholder: t,
|
|
206
|
+
disabled: b,
|
|
207
|
+
value: $,
|
|
208
|
+
onClick: () => a(!0),
|
|
209
|
+
onFocus: () => {
|
|
210
|
+
!b && !e && a(!0);
|
|
211
|
+
},
|
|
212
|
+
className: I(
|
|
213
|
+
"prui-time-range-picker h-9 w-full cursor-pointer rounded-[var(--prui-radius)] border border-[var(--prui-line)]",
|
|
214
|
+
"bg-[var(--prui-background)] px-3 pr-8 text-sm tabular-nums text-[var(--prui-fg)] placeholder:text-[var(--prui-dim)]",
|
|
215
|
+
"outline-none transition-colors focus:border-[var(--prui-brand)] focus:ring-2 focus:ring-[var(--prui-brand)]/30",
|
|
216
|
+
"disabled:opacity-50 disabled:cursor-not-allowed",
|
|
217
|
+
A
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
/* @__PURE__ */ u(G, { className: "pointer-events-none -ml-7 h-4 w-4 text-[var(--prui-dim)]", "aria-hidden": !0 }),
|
|
222
|
+
e ? /* @__PURE__ */ u(L, { children: /* @__PURE__ */ u(
|
|
223
|
+
"div",
|
|
224
|
+
{
|
|
225
|
+
ref: (r) => {
|
|
226
|
+
v(r), T(r);
|
|
227
|
+
},
|
|
228
|
+
role: "dialog",
|
|
229
|
+
"aria-label": x ?? "Choose time range",
|
|
230
|
+
"data-prui-time-panel-wrap": !0,
|
|
231
|
+
className: "fixed z-[var(--prui-z-overlay)] rounded-[var(--prui-radius)] border border-[var(--prui-line)] bg-[var(--prui-surface)] p-3 shadow-[var(--prui-shadow-lg)]",
|
|
232
|
+
style: { top: (g == null ? void 0 : g.top) ?? -9999, left: (g == null ? void 0 : g.left) ?? -9999 },
|
|
233
|
+
children: /* @__PURE__ */ N("div", { className: "flex flex-col gap-3", children: [
|
|
234
|
+
/* @__PURE__ */ N("div", { className: "flex gap-4", children: [
|
|
235
|
+
/* @__PURE__ */ N("div", { children: [
|
|
236
|
+
/* @__PURE__ */ u("div", { className: "mb-1 text-xs font-semibold text-[var(--prui-dim)]", children: H.from }),
|
|
237
|
+
/* @__PURE__ */ u(C, { compact: !0, value: i.from, onSelect: (r) => D("from", r), minuteStep: h, seconds: y, min: k, max: M })
|
|
238
|
+
] }),
|
|
239
|
+
/* @__PURE__ */ N("div", { children: [
|
|
240
|
+
/* @__PURE__ */ u("div", { className: "mb-1 text-xs font-semibold text-[var(--prui-dim)]", children: H.to }),
|
|
241
|
+
/* @__PURE__ */ u(C, { compact: !0, value: i.to, onSelect: (r) => D("to", r), minuteStep: h, seconds: y, min: K, max: w })
|
|
242
|
+
] })
|
|
243
|
+
] }),
|
|
244
|
+
/* @__PURE__ */ N("div", { className: "flex items-center justify-between border-t border-[var(--prui-line)] pt-2 text-xs text-[var(--prui-dim)]", children: [
|
|
245
|
+
/* @__PURE__ */ u("span", { "data-testid": "timerange-label", children: $ || H.time }),
|
|
246
|
+
/* @__PURE__ */ N("div", { className: "flex gap-2", children: [
|
|
247
|
+
/* @__PURE__ */ u(
|
|
248
|
+
"button",
|
|
249
|
+
{
|
|
250
|
+
type: "button",
|
|
251
|
+
onClick: () => l({}),
|
|
252
|
+
className: "cursor-pointer rounded-[var(--prui-radius-1)] px-2 py-1 transition-colors hover:bg-[var(--prui-raise)]",
|
|
253
|
+
children: H.clear
|
|
254
|
+
}
|
|
255
|
+
),
|
|
256
|
+
/* @__PURE__ */ u(
|
|
257
|
+
"button",
|
|
258
|
+
{
|
|
259
|
+
type: "button",
|
|
260
|
+
onClick: () => {
|
|
261
|
+
var r;
|
|
262
|
+
a(!1), (r = n.current) == null || r.focus();
|
|
263
|
+
},
|
|
264
|
+
className: "cursor-pointer rounded-[var(--prui-radius-1)] bg-[var(--prui-brand)]/15 px-2 py-1 text-[var(--prui-brand)] transition-colors hover:bg-[var(--prui-brand)]/25",
|
|
265
|
+
children: H.apply
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
] })
|
|
269
|
+
] })
|
|
270
|
+
] })
|
|
271
|
+
}
|
|
272
|
+
) }) : null
|
|
273
|
+
] });
|
|
274
|
+
});
|
|
275
|
+
ee.displayName = "TimeRangePicker";
|
|
276
|
+
const le = {
|
|
277
|
+
name: "TimePicker",
|
|
278
|
+
props: [
|
|
279
|
+
{ name: "value", type: "string 'HH:mm' | 'HH:mm:ss'", default: "undefined", control: "text" },
|
|
280
|
+
{ name: "defaultValue", type: "string", default: "undefined", control: "text" },
|
|
281
|
+
{ name: "onChange", type: "(time: string) => void", default: null, control: "none" },
|
|
282
|
+
{ name: "minuteStep", type: "number (minutes)", default: "1", control: "number" },
|
|
283
|
+
{ name: "seconds", type: "boolean", default: "false", control: "boolean", description: "Adds a seconds column ('HH:mm:ss')." },
|
|
284
|
+
{ name: "min", type: "string 'HH:mm'", default: "undefined", control: "text" },
|
|
285
|
+
{ name: "max", type: "string 'HH:mm'", default: "undefined", control: "text" }
|
|
286
|
+
]
|
|
287
|
+
}, ue = {
|
|
288
|
+
name: "TimeRangePicker",
|
|
289
|
+
props: [
|
|
290
|
+
{ name: "value", type: "{ from?: string, to?: string }", default: "{}", control: "object" },
|
|
291
|
+
{ name: "defaultValue", type: "{ from?: string, to?: string }", default: "{}", control: "object" },
|
|
292
|
+
{ name: "onChange", type: "(range: TimeRange) => void", default: null, control: "none" },
|
|
293
|
+
{ name: "minuteStep", type: "number (minutes)", default: "1", control: "number" },
|
|
294
|
+
{ name: "seconds", type: "boolean", default: "false", control: "boolean" },
|
|
295
|
+
{ name: "min", type: "string 'HH:mm'", default: "undefined", control: "text" },
|
|
296
|
+
{ name: "max", type: "string 'HH:mm'", default: "undefined", control: "text" }
|
|
297
|
+
]
|
|
298
|
+
};
|
|
299
|
+
export {
|
|
300
|
+
C as TimePanel,
|
|
301
|
+
Z as TimePicker,
|
|
302
|
+
ee as TimeRangePicker,
|
|
303
|
+
le as timePickerPropsMeta,
|
|
304
|
+
ue as timeRangePickerPropsMeta
|
|
305
|
+
};
|
package/dist/core/toast.js
CHANGED
|
@@ -1,97 +1,106 @@
|
|
|
1
|
-
import { jsx as a, jsxs as
|
|
2
|
-
import * as
|
|
3
|
-
import { createPortal as
|
|
4
|
-
import { XCircle as
|
|
5
|
-
import { cn as
|
|
6
|
-
import { usePruiI18n as
|
|
7
|
-
import { useReducedMotion as
|
|
8
|
-
const
|
|
9
|
-
neutral: { icon:
|
|
10
|
-
info: { icon:
|
|
11
|
-
success: { icon:
|
|
12
|
-
warning: { icon:
|
|
13
|
-
danger: { icon:
|
|
1
|
+
import { jsx as a, jsxs as p } from "react/jsx-runtime";
|
|
2
|
+
import * as f from "react";
|
|
3
|
+
import { createPortal as w } from "react-dom";
|
|
4
|
+
import { XCircle as N, AlertTriangle as T, CheckCircle2 as C, Info as b, X as k } from "lucide-react";
|
|
5
|
+
import { cn as l } from "./cn.js";
|
|
6
|
+
import { usePruiI18n as I } from "../i18n.js";
|
|
7
|
+
import { useReducedMotion as M } from "./overlay.js";
|
|
8
|
+
const v = {
|
|
9
|
+
neutral: { icon: b, accent: "text-[var(--prui-brand)]" },
|
|
10
|
+
info: { icon: b, accent: "text-[var(--prui-brand)]" },
|
|
11
|
+
success: { icon: C, accent: "text-[var(--prui-ok)]" },
|
|
12
|
+
warning: { icon: T, accent: "text-[var(--prui-warn)]" },
|
|
13
|
+
danger: { icon: N, accent: "text-[var(--prui-danger)]" }
|
|
14
14
|
};
|
|
15
15
|
let P = 1, r = [];
|
|
16
|
-
const
|
|
17
|
-
function
|
|
18
|
-
for (const
|
|
16
|
+
const u = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map();
|
|
17
|
+
function m() {
|
|
18
|
+
for (const e of u) e(r);
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
var
|
|
22
|
-
const
|
|
23
|
-
|
|
20
|
+
function d(e) {
|
|
21
|
+
var n;
|
|
22
|
+
const o = s.get(e);
|
|
23
|
+
o && (clearTimeout(o), s.delete(e));
|
|
24
|
+
const t = r.find((c) => c.id === e);
|
|
25
|
+
r = r.filter((c) => c.id !== e), t && ((n = t.onDismiss) == null || n.call(t)), m();
|
|
24
26
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
r = [...r, { ...
|
|
28
|
-
const
|
|
29
|
-
return
|
|
27
|
+
function X(e) {
|
|
28
|
+
const o = P++;
|
|
29
|
+
r = [...r, { ...e, id: o }], m();
|
|
30
|
+
const t = e.duration ?? 5e3;
|
|
31
|
+
return t > 0 && typeof setTimeout == "function" && s.set(
|
|
32
|
+
o,
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
s.delete(o), d(o);
|
|
35
|
+
}, t)
|
|
36
|
+
), { dismiss: () => d(o) };
|
|
30
37
|
}
|
|
31
|
-
function
|
|
32
|
-
var
|
|
33
|
-
const
|
|
38
|
+
function E() {
|
|
39
|
+
var o;
|
|
40
|
+
const e = r;
|
|
34
41
|
r = [];
|
|
35
|
-
for (const
|
|
36
|
-
|
|
42
|
+
for (const t of s.values()) clearTimeout(t);
|
|
43
|
+
s.clear();
|
|
44
|
+
for (const t of e) (o = t.onDismiss) == null || o.call(t);
|
|
45
|
+
m();
|
|
37
46
|
}
|
|
38
47
|
function R() {
|
|
39
|
-
const [
|
|
40
|
-
return
|
|
41
|
-
const
|
|
42
|
-
return
|
|
43
|
-
|
|
48
|
+
const [e, o] = f.useState(r);
|
|
49
|
+
return f.useEffect(() => {
|
|
50
|
+
const t = (n) => o([...n]);
|
|
51
|
+
return u.add(t), t(r), () => {
|
|
52
|
+
u.delete(t);
|
|
44
53
|
};
|
|
45
|
-
}, []),
|
|
54
|
+
}, []), e;
|
|
46
55
|
}
|
|
47
|
-
function
|
|
48
|
-
const
|
|
56
|
+
function L({ position: e = "bottom-right", className: o } = {}) {
|
|
57
|
+
const t = R(), { t: n } = I(), c = M();
|
|
49
58
|
if (typeof document > "u") return null;
|
|
50
|
-
const
|
|
59
|
+
const h = {
|
|
51
60
|
"top-right": "top-4 right-4",
|
|
52
61
|
"top-center": "top-4 left-1/2 -translate-x-1/2",
|
|
53
62
|
"bottom-right": "bottom-4 right-4",
|
|
54
63
|
"bottom-center": "bottom-4 left-1/2 -translate-x-1/2",
|
|
55
64
|
"bottom-left": "bottom-4 left-4"
|
|
56
|
-
}[
|
|
57
|
-
return
|
|
65
|
+
}[e];
|
|
66
|
+
return w(
|
|
58
67
|
/* @__PURE__ */ a(
|
|
59
68
|
"ol",
|
|
60
69
|
{
|
|
61
70
|
"aria-live": "polite",
|
|
62
|
-
"aria-label":
|
|
63
|
-
className:
|
|
64
|
-
children:
|
|
65
|
-
const
|
|
66
|
-
return /* @__PURE__ */
|
|
71
|
+
"aria-label": n.notifications,
|
|
72
|
+
className: l("fixed z-[var(--prui-z-toast)] flex w-80 flex-col gap-2", h, o),
|
|
73
|
+
children: t.map((i) => {
|
|
74
|
+
const g = v[i.variant ?? "neutral"].icon, x = v[i.variant ?? "neutral"].accent;
|
|
75
|
+
return /* @__PURE__ */ p(
|
|
67
76
|
"li",
|
|
68
77
|
{
|
|
69
78
|
"data-testid": "toast",
|
|
70
|
-
"data-variant":
|
|
71
|
-
className:
|
|
79
|
+
"data-variant": i.variant ?? "neutral",
|
|
80
|
+
className: l(
|
|
72
81
|
"prui-toast flex items-start gap-3 rounded-[var(--prui-radius)] border border-[var(--prui-line)]",
|
|
73
82
|
"bg-[var(--prui-surface)] p-4 text-sm shadow-[var(--prui-shadow-md)]",
|
|
74
|
-
!
|
|
83
|
+
!c && "prui-anim-slide"
|
|
75
84
|
),
|
|
76
85
|
children: [
|
|
77
|
-
/* @__PURE__ */ a(
|
|
78
|
-
/* @__PURE__ */
|
|
79
|
-
/* @__PURE__ */ a("div", { className: "font-medium text-[var(--prui-fg)]", children:
|
|
80
|
-
|
|
86
|
+
/* @__PURE__ */ a(g, { className: l("mt-0.5 h-4 w-4 shrink-0", x), "aria-hidden": !0 }),
|
|
87
|
+
/* @__PURE__ */ p("div", { className: "min-w-0 flex-1", children: [
|
|
88
|
+
/* @__PURE__ */ a("div", { className: "font-medium text-[var(--prui-fg)]", children: i.title }),
|
|
89
|
+
i.description ? /* @__PURE__ */ a("div", { className: "mt-0.5 text-[var(--prui-dim)]", children: i.description }) : null
|
|
81
90
|
] }),
|
|
82
91
|
/* @__PURE__ */ a(
|
|
83
92
|
"button",
|
|
84
93
|
{
|
|
85
94
|
type: "button",
|
|
86
|
-
"aria-label":
|
|
87
|
-
onClick: () =>
|
|
95
|
+
"aria-label": n.dismiss,
|
|
96
|
+
onClick: () => d(i.id),
|
|
88
97
|
className: "-m-1 rounded-[var(--prui-radius-1)] p-1 cursor-pointer text-[var(--prui-dim)] transition-colors hover:text-[var(--prui-fg)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--prui-brand)]",
|
|
89
|
-
children: /* @__PURE__ */ a(
|
|
98
|
+
children: /* @__PURE__ */ a(k, { className: "h-4 w-4", "aria-hidden": !0 })
|
|
90
99
|
}
|
|
91
100
|
)
|
|
92
101
|
]
|
|
93
102
|
},
|
|
94
|
-
|
|
103
|
+
i.id
|
|
95
104
|
);
|
|
96
105
|
})
|
|
97
106
|
}
|
|
@@ -99,13 +108,13 @@ function E({ position: o = "bottom-right", className: t } = {}) {
|
|
|
99
108
|
document.body
|
|
100
109
|
);
|
|
101
110
|
}
|
|
102
|
-
const
|
|
111
|
+
const q = {
|
|
103
112
|
name: "Toaster",
|
|
104
113
|
props: [
|
|
105
114
|
{ name: "position", type: "'top-right' | 'top-center' | 'bottom-right' | 'bottom-center' | 'bottom-left'", default: "'bottom-right'", control: "select", options: ["top-right", "top-center", "bottom-right", "bottom-center", "bottom-left"] },
|
|
106
115
|
{ name: "className", type: "string", default: "undefined", control: "text" }
|
|
107
116
|
]
|
|
108
|
-
},
|
|
117
|
+
}, B = {
|
|
109
118
|
name: "toast()",
|
|
110
119
|
props: [
|
|
111
120
|
{ name: "title", type: "ReactNode", default: null, control: "text" },
|
|
@@ -115,9 +124,9 @@ const L = {
|
|
|
115
124
|
]
|
|
116
125
|
};
|
|
117
126
|
export {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
L as Toaster,
|
|
128
|
+
E as dismissAllToasts,
|
|
129
|
+
X as toast,
|
|
130
|
+
B as toastPropsMeta,
|
|
131
|
+
q as toasterPropsMeta
|
|
123
132
|
};
|