@skiddph/prui 0.9.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/modal.js +133 -126
- package/dist/core/toast.js +73 -64
- package/package.json +1 -1
package/dist/core/modal.js
CHANGED
|
@@ -1,79 +1,86 @@
|
|
|
1
|
-
import { jsx as e, jsxs as
|
|
2
|
-
import * as
|
|
3
|
-
import { createRoot as
|
|
4
|
-
import { X as
|
|
5
|
-
import { cn as
|
|
6
|
-
import { useReducedMotion as
|
|
7
|
-
import { getPruiDictionary as
|
|
8
|
-
const
|
|
1
|
+
import { jsx as e, jsxs as n } from "react/jsx-runtime";
|
|
2
|
+
import * as r from "react";
|
|
3
|
+
import { createRoot as q } from "react-dom/client";
|
|
4
|
+
import { X as G } from "lucide-react";
|
|
5
|
+
import { cn as H } from "./cn.js";
|
|
6
|
+
import { useReducedMotion as F, useOverlay as O, Portal as J } from "./overlay.js";
|
|
7
|
+
import { getPruiDictionary as K } from "../i18n.js";
|
|
8
|
+
const Y = {
|
|
9
9
|
xs: { width: "320px", minWidth: "280px" },
|
|
10
10
|
sm: { width: "448px", minWidth: "320px" },
|
|
11
11
|
md: { width: "640px", minWidth: "384px" },
|
|
12
12
|
lg: { width: "896px", minWidth: "512px" },
|
|
13
13
|
xl: { width: "1152px", minWidth: "640px" }
|
|
14
|
-
},
|
|
14
|
+
}, Q = {
|
|
15
15
|
xs: "24px 32px",
|
|
16
16
|
sm: "24px 32px",
|
|
17
17
|
md: "32px 40px",
|
|
18
18
|
lg: "32px 40px",
|
|
19
19
|
xl: "40px 48px"
|
|
20
|
-
},
|
|
21
|
-
open:
|
|
22
|
-
onClose:
|
|
20
|
+
}, U = r.forwardRef(function({
|
|
21
|
+
open: t,
|
|
22
|
+
onClose: a,
|
|
23
23
|
children: W,
|
|
24
|
-
disableDefaultClose:
|
|
24
|
+
disableDefaultClose: m = !1,
|
|
25
25
|
closeOnOverlayClick: M = !0,
|
|
26
|
-
size:
|
|
27
|
-
xs:
|
|
28
|
-
sm:
|
|
26
|
+
size: w,
|
|
27
|
+
xs: R,
|
|
28
|
+
sm: S,
|
|
29
29
|
md: N,
|
|
30
|
-
lg:
|
|
30
|
+
lg: f,
|
|
31
31
|
xl: b,
|
|
32
|
-
maxWidth:
|
|
33
|
-
padding:
|
|
34
|
-
noPadding:
|
|
35
|
-
showCloseButton:
|
|
36
|
-
ariaLabel:
|
|
37
|
-
className:
|
|
32
|
+
maxWidth: z,
|
|
33
|
+
padding: P,
|
|
34
|
+
noPadding: k = !1,
|
|
35
|
+
showCloseButton: C = !0,
|
|
36
|
+
ariaLabel: h,
|
|
37
|
+
className: v,
|
|
38
38
|
style: s,
|
|
39
|
-
initialFocus:
|
|
39
|
+
initialFocus: j = "first"
|
|
40
40
|
}, l) {
|
|
41
|
-
const
|
|
42
|
-
|
|
41
|
+
const x = w ?? (R ? "xs" : S ? "sm" : f ? "lg" : b ? "xl" : "md"), [g, i] = r.useState(t), [u, c] = r.useState(!1), [y, E] = r.useState(!1), V = r.useRef(null), T = F(), d = r.useRef(null), I = () => {
|
|
42
|
+
T || (E(!0), d.current != null && window.clearTimeout(d.current), d.current = window.setTimeout(() => {
|
|
43
|
+
d.current = null, E(!1);
|
|
44
|
+
}, 500));
|
|
43
45
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
r.useEffect(
|
|
47
|
+
() => () => {
|
|
48
|
+
d.current != null && window.clearTimeout(d.current);
|
|
49
|
+
},
|
|
50
|
+
[]
|
|
51
|
+
), r.useEffect(() => {
|
|
52
|
+
if (t) {
|
|
53
|
+
if (i(!0), T) {
|
|
54
|
+
c(!0);
|
|
48
55
|
return;
|
|
49
56
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
57
|
+
const o = setTimeout(() => {
|
|
58
|
+
c(!0);
|
|
52
59
|
}, 10);
|
|
53
|
-
return () => clearTimeout(
|
|
60
|
+
return () => clearTimeout(o);
|
|
54
61
|
}
|
|
55
|
-
|
|
56
|
-
}, [
|
|
57
|
-
const { ref:
|
|
58
|
-
open:
|
|
62
|
+
c(!1), T && i(!1);
|
|
63
|
+
}, [t, T]);
|
|
64
|
+
const { ref: D } = O({
|
|
65
|
+
open: t,
|
|
59
66
|
onEscape: () => {
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
62
|
-
|
|
67
|
+
if (m)
|
|
68
|
+
return I(), !1;
|
|
69
|
+
a();
|
|
63
70
|
},
|
|
64
|
-
initialFocus:
|
|
71
|
+
initialFocus: j
|
|
65
72
|
});
|
|
66
|
-
if (!
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
if (
|
|
70
|
-
|
|
73
|
+
if (!g && !u) return null;
|
|
74
|
+
const B = (o) => {
|
|
75
|
+
if (o.target === o.currentTarget) {
|
|
76
|
+
if (m || !M) {
|
|
77
|
+
I();
|
|
71
78
|
return;
|
|
72
79
|
}
|
|
73
|
-
|
|
80
|
+
a();
|
|
74
81
|
}
|
|
75
|
-
},
|
|
76
|
-
return /* @__PURE__ */ e(
|
|
82
|
+
}, L = Y[x], X = k ? "0" : P ?? Q[x];
|
|
83
|
+
return /* @__PURE__ */ e(J, { children: /* @__PURE__ */ e("div", { ref: D, children: /* @__PURE__ */ e(
|
|
77
84
|
"div",
|
|
78
85
|
{
|
|
79
86
|
className: "prui-modal-overlay fixed inset-0 z-[var(--prui-z-modal)] flex justify-center overflow-y-auto p-4",
|
|
@@ -82,55 +89,55 @@ const O = {
|
|
|
82
89
|
paddingTop: "10vh",
|
|
83
90
|
backgroundColor: "var(--prui-scrim)",
|
|
84
91
|
backdropFilter: "blur(4px)",
|
|
85
|
-
opacity:
|
|
92
|
+
opacity: u ? 1 : 0,
|
|
86
93
|
transition: "opacity var(--prui-duration-slow) var(--prui-ease-out)"
|
|
87
94
|
},
|
|
88
|
-
onClick:
|
|
89
|
-
onMouseDown: (
|
|
90
|
-
|
|
95
|
+
onClick: B,
|
|
96
|
+
onMouseDown: (o) => {
|
|
97
|
+
o.target === o.currentTarget && B(o);
|
|
91
98
|
},
|
|
92
|
-
children: /* @__PURE__ */
|
|
99
|
+
children: /* @__PURE__ */ n(
|
|
93
100
|
"div",
|
|
94
101
|
{
|
|
95
|
-
ref: (
|
|
96
|
-
|
|
102
|
+
ref: (o) => {
|
|
103
|
+
V.current = o, typeof l == "function" ? l(o) : l && (l.current = o);
|
|
97
104
|
},
|
|
98
105
|
role: "dialog",
|
|
99
106
|
"aria-modal": "true",
|
|
100
|
-
"aria-label":
|
|
101
|
-
className:
|
|
107
|
+
"aria-label": h,
|
|
108
|
+
className: H(
|
|
102
109
|
"prui-modal-content relative h-fit m-auto w-full",
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
y && "prui-modal-shake",
|
|
111
|
+
v
|
|
105
112
|
),
|
|
106
113
|
style: {
|
|
107
|
-
width:
|
|
108
|
-
minWidth:
|
|
109
|
-
maxWidth:
|
|
110
|
-
padding:
|
|
114
|
+
width: L.width,
|
|
115
|
+
minWidth: L.minWidth,
|
|
116
|
+
maxWidth: z ?? L.width,
|
|
117
|
+
padding: X,
|
|
111
118
|
backgroundColor: "var(--prui-surface)",
|
|
112
119
|
border: "1px solid var(--prui-line)",
|
|
113
120
|
borderRadius: "var(--prui-radius-3)",
|
|
114
121
|
boxShadow: "var(--prui-shadow-modal)",
|
|
115
122
|
color: "var(--prui-fg)",
|
|
116
|
-
transform:
|
|
117
|
-
opacity:
|
|
123
|
+
transform: u ? "scale(1) translateY(0)" : "scale(0.95) translateY(8px)",
|
|
124
|
+
opacity: u ? 1 : 0,
|
|
118
125
|
transition: "transform var(--prui-duration-slow) var(--prui-ease-out), opacity var(--prui-duration-slow) var(--prui-ease-out)",
|
|
119
126
|
...s
|
|
120
127
|
},
|
|
121
128
|
onTransitionEnd: () => {
|
|
122
|
-
|
|
129
|
+
t || i(!1);
|
|
123
130
|
},
|
|
124
131
|
children: [
|
|
125
132
|
W,
|
|
126
|
-
|
|
133
|
+
C && !m ? /* @__PURE__ */ e(
|
|
127
134
|
"button",
|
|
128
135
|
{
|
|
129
136
|
type: "button",
|
|
130
|
-
onClick:
|
|
137
|
+
onClick: a,
|
|
131
138
|
"aria-label": "Close modal",
|
|
132
139
|
className: "absolute right-4 top-4 flex h-10 w-10 cursor-pointer items-center justify-center rounded-[var(--prui-radius)] text-[var(--prui-dim)] transition-all hover:bg-[var(--prui-raise)] hover:text-[var(--prui-fg)]",
|
|
133
|
-
children: /* @__PURE__ */ e(
|
|
140
|
+
children: /* @__PURE__ */ e(G, { className: "h-4 w-4", "aria-hidden": !0 })
|
|
134
141
|
}
|
|
135
142
|
) : null
|
|
136
143
|
]
|
|
@@ -139,32 +146,32 @@ const O = {
|
|
|
139
146
|
}
|
|
140
147
|
) }) });
|
|
141
148
|
});
|
|
142
|
-
|
|
143
|
-
const
|
|
149
|
+
U.displayName = "Modal";
|
|
150
|
+
const A = {
|
|
144
151
|
success: "var(--prui-ok)",
|
|
145
152
|
warning: "var(--prui-warn)",
|
|
146
153
|
danger: "var(--prui-danger)",
|
|
147
154
|
error: "var(--prui-danger)",
|
|
148
155
|
info: "var(--prui-brand)",
|
|
149
156
|
default: "var(--prui-brand)"
|
|
150
|
-
},
|
|
151
|
-
const
|
|
152
|
-
switch (
|
|
157
|
+
}, Z = ({ type: p }) => {
|
|
158
|
+
const t = A[p ?? "default"];
|
|
159
|
+
switch (p) {
|
|
153
160
|
case "success":
|
|
154
|
-
return /* @__PURE__ */
|
|
161
|
+
return /* @__PURE__ */ n("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", style: { color: t }, "aria-hidden": !0, children: [
|
|
155
162
|
/* @__PURE__ */ e("path", { d: "M9 12l2 2 4-4", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }),
|
|
156
163
|
/* @__PURE__ */ e("circle", { cx: "12", cy: "12", r: "9", stroke: "currentColor", strokeWidth: "2" })
|
|
157
164
|
] });
|
|
158
165
|
case "warning":
|
|
159
|
-
return /* @__PURE__ */ e("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", style: { color:
|
|
166
|
+
return /* @__PURE__ */ e("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", style: { color: t }, "aria-hidden": !0, children: /* @__PURE__ */ e("path", { d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.694-.833-2.464 0L4.34 16.5c-.77.833.192 2.5 1.732 2.5z", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
160
167
|
case "danger":
|
|
161
168
|
case "error":
|
|
162
|
-
return /* @__PURE__ */
|
|
169
|
+
return /* @__PURE__ */ n("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", style: { color: t }, "aria-hidden": !0, children: [
|
|
163
170
|
/* @__PURE__ */ e("circle", { cx: "12", cy: "12", r: "9", stroke: "currentColor", strokeWidth: "2" }),
|
|
164
171
|
/* @__PURE__ */ e("path", { d: "M15 9l-6 6m0-6l6 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })
|
|
165
172
|
] });
|
|
166
173
|
case "info":
|
|
167
|
-
return /* @__PURE__ */
|
|
174
|
+
return /* @__PURE__ */ n("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", style: { color: t }, "aria-hidden": !0, children: [
|
|
168
175
|
/* @__PURE__ */ e("circle", { cx: "12", cy: "12", r: "9", stroke: "currentColor", strokeWidth: "2" }),
|
|
169
176
|
/* @__PURE__ */ e("path", { d: "M12 8v4m0 4h.01", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })
|
|
170
177
|
] });
|
|
@@ -172,39 +179,39 @@ const Y = {
|
|
|
172
179
|
return null;
|
|
173
180
|
}
|
|
174
181
|
};
|
|
175
|
-
function
|
|
176
|
-
const
|
|
182
|
+
function ne(p) {
|
|
183
|
+
const t = K(), { title: a, message: W, confirmText: m = t.confirm, cancelText: M = t.cancel, type: w, size: R = "sm" } = p, S = A[w ?? "default"];
|
|
177
184
|
return new Promise((N) => {
|
|
178
|
-
const
|
|
179
|
-
document.body.appendChild(
|
|
180
|
-
const b =
|
|
185
|
+
const f = document.createElement("div");
|
|
186
|
+
document.body.appendChild(f);
|
|
187
|
+
const b = q(f), z = () => {
|
|
181
188
|
setTimeout(() => {
|
|
182
|
-
b.unmount(),
|
|
189
|
+
b.unmount(), f.remove();
|
|
183
190
|
}, 320);
|
|
184
|
-
},
|
|
185
|
-
const [
|
|
186
|
-
|
|
187
|
-
if (
|
|
188
|
-
|
|
191
|
+
}, P = () => {
|
|
192
|
+
const [k, C] = r.useState(!1), [h, v] = r.useState(!1), [s, j] = r.useState(!1), l = r.useRef(null), x = r.useRef(null), g = F();
|
|
193
|
+
r.useEffect(() => {
|
|
194
|
+
if (g) {
|
|
195
|
+
C(!0), v(!0);
|
|
189
196
|
return;
|
|
190
197
|
}
|
|
191
|
-
const
|
|
192
|
-
|
|
198
|
+
const y = setTimeout(() => {
|
|
199
|
+
C(!0), v(!0);
|
|
193
200
|
}, 10);
|
|
194
|
-
return () => clearTimeout(
|
|
195
|
-
}, [
|
|
196
|
-
const i = (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
},
|
|
200
|
-
}, { ref:
|
|
201
|
-
open:
|
|
201
|
+
return () => clearTimeout(y);
|
|
202
|
+
}, [g]);
|
|
203
|
+
const i = (y) => {
|
|
204
|
+
j(!0), v(!1), setTimeout(() => {
|
|
205
|
+
z(), N(y);
|
|
206
|
+
}, g ? 0 : 300);
|
|
207
|
+
}, { ref: u } = O({
|
|
208
|
+
open: k && !s,
|
|
202
209
|
onEscape: () => (s || i(!1), !1),
|
|
203
|
-
initialFocus:
|
|
210
|
+
initialFocus: x
|
|
204
211
|
});
|
|
205
|
-
if (!
|
|
206
|
-
const
|
|
207
|
-
return /* @__PURE__ */ e("div", { ref:
|
|
212
|
+
if (!k) return null;
|
|
213
|
+
const c = Y[R];
|
|
214
|
+
return /* @__PURE__ */ e("div", { ref: u, children: /* @__PURE__ */ e(
|
|
208
215
|
"div",
|
|
209
216
|
{
|
|
210
217
|
className: "prui-modal-overlay fixed inset-0 z-[var(--prui-z-confirm)] flex justify-center overflow-y-auto p-4",
|
|
@@ -213,37 +220,37 @@ function oe(c) {
|
|
|
213
220
|
paddingTop: "12vh",
|
|
214
221
|
backgroundColor: "var(--prui-scrim)",
|
|
215
222
|
backdropFilter: "blur(4px)",
|
|
216
|
-
opacity:
|
|
223
|
+
opacity: h ? 1 : 0,
|
|
217
224
|
transition: "opacity var(--prui-duration-slow) var(--prui-ease-out)"
|
|
218
225
|
},
|
|
219
|
-
children: /* @__PURE__ */
|
|
226
|
+
children: /* @__PURE__ */ n(
|
|
220
227
|
"div",
|
|
221
228
|
{
|
|
222
229
|
role: "alertdialog",
|
|
223
230
|
"aria-modal": "true",
|
|
224
|
-
"aria-label":
|
|
231
|
+
"aria-label": a,
|
|
225
232
|
className: "prui-modal-content relative m-auto w-full",
|
|
226
233
|
style: {
|
|
227
|
-
width:
|
|
228
|
-
minWidth:
|
|
234
|
+
width: c.width,
|
|
235
|
+
minWidth: c.minWidth,
|
|
229
236
|
backgroundColor: "var(--prui-surface)",
|
|
230
237
|
border: "1px solid var(--prui-line)",
|
|
231
238
|
borderRadius: "var(--prui-radius-3)",
|
|
232
239
|
boxShadow: "var(--prui-shadow-modal)",
|
|
233
240
|
color: "var(--prui-fg)",
|
|
234
|
-
transform:
|
|
235
|
-
opacity:
|
|
241
|
+
transform: h ? "scale(1) translateY(0)" : "scale(0.95) translateY(8px)",
|
|
242
|
+
opacity: h ? 1 : 0,
|
|
236
243
|
transition: "transform var(--prui-duration-slow) var(--prui-ease-out), opacity var(--prui-duration-slow) var(--prui-ease-out)"
|
|
237
244
|
},
|
|
238
245
|
children: [
|
|
239
|
-
/* @__PURE__ */
|
|
240
|
-
/* @__PURE__ */ e(
|
|
241
|
-
/* @__PURE__ */
|
|
242
|
-
/* @__PURE__ */ e("h2", { className: "m-0 text-lg font-semibold leading-normal", style: { color: "var(--prui-fg)" }, children:
|
|
246
|
+
/* @__PURE__ */ n("div", { className: "flex items-start gap-3 p-4 pb-2", children: [
|
|
247
|
+
/* @__PURE__ */ e(Z, { type: w }),
|
|
248
|
+
/* @__PURE__ */ n("div", { className: "min-w-0", children: [
|
|
249
|
+
/* @__PURE__ */ e("h2", { className: "m-0 text-lg font-semibold leading-normal", style: { color: "var(--prui-fg)" }, children: a }),
|
|
243
250
|
/* @__PURE__ */ e("p", { className: "mt-2 text-sm leading-normal", style: { color: "var(--prui-dim)" }, children: W })
|
|
244
251
|
] })
|
|
245
252
|
] }),
|
|
246
|
-
/* @__PURE__ */
|
|
253
|
+
/* @__PURE__ */ n("div", { className: "flex items-center justify-end gap-3 px-4 pb-4", children: [
|
|
247
254
|
/* @__PURE__ */ e(
|
|
248
255
|
"button",
|
|
249
256
|
{
|
|
@@ -260,12 +267,12 @@ function oe(c) {
|
|
|
260
267
|
"button",
|
|
261
268
|
{
|
|
262
269
|
type: "button",
|
|
263
|
-
ref:
|
|
270
|
+
ref: x,
|
|
264
271
|
disabled: s,
|
|
265
272
|
onClick: () => i(!0),
|
|
266
273
|
className: "cursor-pointer rounded-[var(--prui-radius)] border border-transparent px-4 py-2 text-sm font-medium text-white transition-all disabled:opacity-60",
|
|
267
|
-
style: { backgroundColor:
|
|
268
|
-
children:
|
|
274
|
+
style: { backgroundColor: S },
|
|
275
|
+
children: m
|
|
269
276
|
}
|
|
270
277
|
)
|
|
271
278
|
] })
|
|
@@ -275,10 +282,10 @@ function oe(c) {
|
|
|
275
282
|
}
|
|
276
283
|
) });
|
|
277
284
|
};
|
|
278
|
-
b.render(/* @__PURE__ */ e(
|
|
285
|
+
b.render(/* @__PURE__ */ e(P, {}));
|
|
279
286
|
});
|
|
280
287
|
}
|
|
281
|
-
const
|
|
288
|
+
const ie = {
|
|
282
289
|
name: "Modal",
|
|
283
290
|
props: [
|
|
284
291
|
{ name: "open", type: "boolean", default: null, control: "boolean" },
|
|
@@ -292,7 +299,7 @@ const ae = {
|
|
|
292
299
|
{ name: "maxWidth", type: "string (CSS)", default: "per-size", control: "text" },
|
|
293
300
|
{ name: "initialFocus", type: 'ref | "first" | "container" | false', default: '"first"', control: "none" }
|
|
294
301
|
]
|
|
295
|
-
},
|
|
302
|
+
}, ae = {
|
|
296
303
|
name: "confirmModal",
|
|
297
304
|
props: [
|
|
298
305
|
{ name: "title", type: "string", default: null, control: "text" },
|
|
@@ -303,8 +310,8 @@ const ae = {
|
|
|
303
310
|
]
|
|
304
311
|
};
|
|
305
312
|
export {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
313
|
+
U as Modal,
|
|
314
|
+
ne as confirmModal,
|
|
315
|
+
ae as confirmModalPropsMeta,
|
|
316
|
+
ie as modalPropsMeta
|
|
310
317
|
};
|
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
|
};
|