@alea-design/ui 0.3.1 → 0.5.0
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/components/command/CommandPalette.js +53 -42
- package/dist/components/field/Field.d.ts +7 -1
- package/dist/components/field/Field.js +82 -82
- package/dist/components/media/Media.d.ts +4 -0
- package/dist/components/media/Media.js +76 -76
- package/dist/components/notification/NotificationCenter.d.ts +86 -0
- package/dist/components/notification/NotificationCenter.js +185 -0
- package/dist/components/theme/Theme.js +141 -98
- package/dist/css/command.css +1 -1
- package/dist/css/groups.json +12 -2
- package/dist/css/media.css +1 -1
- package/dist/css/notification.css +1 -0
- package/dist/i18n/strings.d.ts +16 -0
- package/dist/i18n/strings.js +24 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +150 -148
- package/dist/styles.css +1 -1
- package/package.json +3 -3
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsxs as h, jsx as e, Fragment as B } from "react/jsx-runtime";
|
|
3
|
-
import { useRef as H, useState as C, useId as U, useCallback as X, useEffect as
|
|
3
|
+
import { useRef as H, useState as C, useId as U, useCallback as X, useEffect as L, forwardRef as F, useMemo as O, useLayoutEffect as _ } from "react";
|
|
4
4
|
import { Pause as G, Play as J, ChevronLeft as K, ChevronRight as Y, ImageOff as V, ZoomOut as ee, ZoomIn as ae, X as te } from "lucide-react";
|
|
5
|
-
import { cx as
|
|
6
|
-
import { IconButton as
|
|
5
|
+
import { cx as z } from "../../utils/cx.js";
|
|
6
|
+
import { IconButton as P, Button as S } from "../button/Button.js";
|
|
7
7
|
import { DialogModal as W, Dialog as j } from "../overlay/Overlay.js";
|
|
8
8
|
import { useStrings as R } from "../../i18n/strings.js";
|
|
9
|
-
import { DotField as
|
|
10
|
-
import { inertProps as
|
|
11
|
-
function ve({ items: f, pending: r, mode: s = "start", reverse: d, size: b, className:
|
|
9
|
+
import { DotField as le } from "../../utils/DotField.js";
|
|
10
|
+
import { inertProps as re } from "../../utils/inert.js";
|
|
11
|
+
function ve({ items: f, pending: r, mode: s = "start", reverse: d, size: b, className: k }) {
|
|
12
12
|
const u = d ? [...f].reverse() : f;
|
|
13
|
-
return /* @__PURE__ */ h("ol", { className:
|
|
14
|
-
u.map((
|
|
15
|
-
/* @__PURE__ */ e("span", { className: "alea-tl-dot", "aria-hidden": "true", children:
|
|
13
|
+
return /* @__PURE__ */ h("ol", { className: z("alea-timeline", k), "data-mode": s !== "start" ? s : void 0, "data-size": b, children: [
|
|
14
|
+
u.map((t) => /* @__PURE__ */ h("li", { className: "alea-tl-item", "data-tone": t.tone || "neutral", "data-active": t.isActive || void 0, children: [
|
|
15
|
+
/* @__PURE__ */ e("span", { className: "alea-tl-dot", "aria-hidden": "true", children: t.dot }),
|
|
16
16
|
/* @__PURE__ */ h("div", { className: "alea-tl-body", children: [
|
|
17
|
-
|
|
18
|
-
/* @__PURE__ */ e("p", { className: "alea-tl-title", children:
|
|
19
|
-
|
|
17
|
+
t.time && (t.dateTime ? /* @__PURE__ */ e("time", { className: "alea-tl-time", dateTime: t.dateTime, children: t.time }) : /* @__PURE__ */ e("span", { className: "alea-tl-time", children: t.time })),
|
|
18
|
+
t.href ? /* @__PURE__ */ e("p", { className: "alea-tl-title", children: /* @__PURE__ */ e("a", { className: "alea-tl-link alea-focus-ring", href: t.href, children: t.title }) }) : t.onPress ? /* @__PURE__ */ e("p", { className: "alea-tl-title", children: /* @__PURE__ */ e("button", { type: "button", className: "alea-tl-link alea-focus-ring", onClick: t.onPress, children: t.title }) }) : /* @__PURE__ */ e("p", { className: "alea-tl-title", children: t.title }),
|
|
19
|
+
t.description && /* @__PURE__ */ e("div", { className: "alea-tl-desc", children: t.description })
|
|
20
20
|
] })
|
|
21
|
-
] },
|
|
21
|
+
] }, t.id)),
|
|
22
22
|
r && /* @__PURE__ */ h("li", { className: "alea-tl-item", "data-pending": !0, children: [
|
|
23
23
|
/* @__PURE__ */ e("span", { className: "alea-tl-dot", "aria-hidden": "true" }),
|
|
24
24
|
/* @__PURE__ */ e("div", { className: "alea-tl-body", children: /* @__PURE__ */ e("p", { className: "alea-tl-title alea-tl-pending", children: r }) })
|
|
25
25
|
] })
|
|
26
26
|
] });
|
|
27
27
|
}
|
|
28
|
-
function pe({ children: f, "aria-label": r, autoplay: s, perView: d = 1, showDots: b = !0, className:
|
|
29
|
-
const u = R(),
|
|
30
|
-
var
|
|
31
|
-
const a =
|
|
28
|
+
function pe({ children: f, "aria-label": r, autoplay: s, perView: d = 1, showDots: b = !0, className: k }) {
|
|
29
|
+
const u = R(), t = H(null), [i, v] = C(0), [g, p] = C(!!s), [y, o] = C(!1), N = f.length, m = Math.max(1, Math.ceil(N - d + 1)), n = U(), l = X((c) => {
|
|
30
|
+
var E;
|
|
31
|
+
const a = t.current;
|
|
32
32
|
if (!a) return;
|
|
33
|
-
const w = (c + m) % m,
|
|
34
|
-
typeof a.scrollTo == "function" ? a.scrollTo({ left: M, behavior:
|
|
33
|
+
const w = (c + m) % m, x = a.children[w], I = getComputedStyle(a).direction === "rtl", M = x ? a.scrollLeft + (I ? x.getBoundingClientRect().right - a.getBoundingClientRect().right : x.getBoundingClientRect().left - a.getBoundingClientRect().left) : 0, $ = ((E = window.matchMedia) == null ? void 0 : E.call(window, "(prefers-reduced-motion: reduce)").matches) && document.documentElement.getAttribute("data-alea-reduced") !== "never" || ["off", "reduced"].includes(document.documentElement.getAttribute("data-alea-motion") || "");
|
|
34
|
+
typeof a.scrollTo == "function" ? a.scrollTo({ left: M, behavior: $ ? "auto" : "smooth" }) : a.scrollLeft = M, v(w);
|
|
35
35
|
}, [m]);
|
|
36
|
-
return
|
|
37
|
-
const c =
|
|
36
|
+
return L(() => {
|
|
37
|
+
const c = t.current;
|
|
38
38
|
if (!c) return;
|
|
39
39
|
const a = () => {
|
|
40
40
|
const w = c.clientWidth / d;
|
|
41
41
|
v(Math.min(m - 1, Math.round(Math.abs(c.scrollLeft) / Math.max(1, w))));
|
|
42
42
|
};
|
|
43
43
|
return c.addEventListener("scroll", a, { passive: !0 }), () => c.removeEventListener("scroll", a);
|
|
44
|
-
}, [d, m]),
|
|
44
|
+
}, [d, m]), L(() => {
|
|
45
45
|
var a;
|
|
46
46
|
if (!s || !g || y || typeof window < "u" && ((a = window.matchMedia) != null && a.call(window, "(prefers-reduced-motion: reduce)").matches)) return;
|
|
47
|
-
const c = setInterval(() =>
|
|
47
|
+
const c = setInterval(() => l(i + 1), s);
|
|
48
48
|
return () => clearInterval(c);
|
|
49
|
-
}, [s, g, y, i,
|
|
49
|
+
}, [s, g, y, i, l]), /* @__PURE__ */ h(
|
|
50
50
|
"section",
|
|
51
51
|
{
|
|
52
|
-
className:
|
|
52
|
+
className: z("alea-carousel", k),
|
|
53
53
|
"aria-roledescription": "carousel",
|
|
54
54
|
"aria-label": r,
|
|
55
55
|
onMouseEnter: () => o(!0),
|
|
@@ -58,40 +58,40 @@ function pe({ children: f, "aria-label": r, autoplay: s, perView: d = 1, showDot
|
|
|
58
58
|
onBlurCapture: () => o(!1),
|
|
59
59
|
children: [
|
|
60
60
|
/* @__PURE__ */ h("div", { className: "alea-carousel-controls", children: [
|
|
61
|
-
s && /* @__PURE__ */ e(
|
|
62
|
-
/* @__PURE__ */ e(
|
|
63
|
-
/* @__PURE__ */ e(
|
|
61
|
+
s && /* @__PURE__ */ e(P, { size: "sm", "aria-label": g ? u.stopSlides : u.playSlides, onPress: () => p((c) => !c), children: g ? /* @__PURE__ */ e(G, {}) : /* @__PURE__ */ e(J, {}) }),
|
|
62
|
+
/* @__PURE__ */ e(P, { size: "sm", "aria-label": u.previousSlide, "aria-controls": `${n}-track`, onPress: () => l(i - 1), children: /* @__PURE__ */ e(K, {}) }),
|
|
63
|
+
/* @__PURE__ */ e(P, { size: "sm", "aria-label": u.nextSlide, "aria-controls": `${n}-track`, onPress: () => l(i + 1), children: /* @__PURE__ */ e(Y, {}) })
|
|
64
64
|
] }),
|
|
65
|
-
/* @__PURE__ */ e("div", { ref:
|
|
66
|
-
b && m > 1 && /* @__PURE__ */ e("div", { className: "alea-carousel-dots", role: "group", "aria-label": u.chooseSlide, children: Array.from({ length: m }, (c, a) => /* @__PURE__ */ e("button", { type: "button", className: "alea-carousel-dot alea-focus-ring", "aria-label": u.slideN(a + 1), "aria-current": a === i ? "true" : void 0, onClick: () =>
|
|
65
|
+
/* @__PURE__ */ e("div", { ref: t, id: `${n}-track`, className: "alea-carousel-track alea-focus-ring", tabIndex: 0, "aria-label": u.slides, "aria-live": g && !y ? "off" : "polite", style: { "--alea-per-view": d }, children: f.map((c, a) => /* @__PURE__ */ e("div", { className: "alea-carousel-slide", role: "group", "aria-roledescription": "slide", "aria-label": u.nOfTotal(a + 1, N), "aria-hidden": a < i || a >= i + d ? !0 : void 0, ...re(a < i || a >= i + d), children: c }, a)) }),
|
|
66
|
+
b && m > 1 && /* @__PURE__ */ e("div", { className: "alea-carousel-dots", role: "group", "aria-label": u.chooseSlide, children: Array.from({ length: m }, (c, a) => /* @__PURE__ */ e("button", { type: "button", className: "alea-carousel-dot alea-focus-ring", "aria-label": u.slideN(a + 1), "aria-current": a === i ? "true" : void 0, onClick: () => l(a) }, a)) })
|
|
67
67
|
]
|
|
68
68
|
}
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
|
-
function be({ src: f, alt: r, width: s, height: d, preview: b = !0, fallback:
|
|
72
|
-
const
|
|
73
|
-
M &&
|
|
74
|
-
M && /* @__PURE__ */ e("span", { role: "status", className: "alea-visually-hidden", children:
|
|
75
|
-
|
|
71
|
+
function be({ src: f, alt: r, width: s, height: d, preview: b = !0, fallback: k, fit: u = "cover", radius: t = "md", srcSet: i, sizes: v, ratio: g, priority: p, placeholder: y, loadingEffect: o = "shimmer", isLoading: N, className: m }) {
|
|
72
|
+
const n = R(), [l, c] = C("loading"), [a, w] = C(!1), [x, I] = C(1), M = o === "matrix", $ = !!N || l === "loading", E = N ? "loading" : l, Q = f ? /* @__PURE__ */ e("img", { src: f, srcSet: i, sizes: v, alt: r, loading: p ? "eager" : "lazy", decoding: p ? "sync" : "async", fetchPriority: p ? "high" : void 0, onLoad: () => c("ok"), onError: () => c("error"), style: { objectFit: u } }) : null, T = y ? /^(data:|https?:|\/)/.test(y) ? { backgroundImage: `url(${y})`, backgroundSize: "cover" } : { background: y } : null, A = /* @__PURE__ */ h("span", { className: z("alea-image", m), "data-state": E, "data-effect": M ? "matrix" : void 0, "aria-busy": $ || void 0, "data-radius": t, "data-placeholder": T ? !0 : void 0, style: { width: s, height: d, aspectRatio: g ? String(g) : void 0, ...l === "loading" && T ? T : {} }, children: [
|
|
73
|
+
M && l !== "error" && /* @__PURE__ */ e(le, {}),
|
|
74
|
+
M && /* @__PURE__ */ e("span", { role: "status", className: "alea-visually-hidden", children: $ ? n.loading : "" }),
|
|
75
|
+
l === "error" ? k ?? /* @__PURE__ */ h("span", { className: "alea-image-fallback", children: [
|
|
76
76
|
/* @__PURE__ */ e(V, { size: 22, "aria-hidden": "true" }),
|
|
77
|
-
/* @__PURE__ */ e("span", { children:
|
|
77
|
+
/* @__PURE__ */ e("span", { children: n.imageFailed(r || "") })
|
|
78
78
|
] }) : Q
|
|
79
79
|
] });
|
|
80
|
-
return !b ||
|
|
80
|
+
return !b || l === "error" || N || !f ? A : /* @__PURE__ */ h(B, { children: [
|
|
81
81
|
/* @__PURE__ */ e("button", { type: "button", className: "alea-image-button alea-focus-ring", onClick: () => {
|
|
82
|
-
|
|
83
|
-
}, "aria-label":
|
|
84
|
-
/* @__PURE__ */ e(W, { isOpen: a, onOpenChange: w, size: "full", className: "alea-image-overlay", children: /* @__PURE__ */ e(j, { "aria-label": r ||
|
|
82
|
+
I(1), w(!0);
|
|
83
|
+
}, "aria-label": n.viewLarger(r || n.image.toLowerCase()), style: { width: s, height: d }, children: A }),
|
|
84
|
+
/* @__PURE__ */ e(W, { isOpen: a, onOpenChange: w, size: "full", className: "alea-image-overlay", children: /* @__PURE__ */ e(j, { "aria-label": r || n.imagePreview, hideClose: !0, className: "alea-image-dialog", children: ({ close: Z }) => /* @__PURE__ */ h(B, { children: [
|
|
85
85
|
/* @__PURE__ */ h("div", { className: "alea-image-tools", children: [
|
|
86
|
-
/* @__PURE__ */ e(
|
|
86
|
+
/* @__PURE__ */ e(P, { "aria-label": n.zoomOut, variant: "secondary", isDisabled: x <= 0.5, onPress: () => I((q) => Math.max(0.5, q - 0.25)), children: /* @__PURE__ */ e(ee, {}) }),
|
|
87
87
|
/* @__PURE__ */ h("span", { className: "alea-image-zoom", "aria-live": "polite", children: [
|
|
88
|
-
Math.round(
|
|
88
|
+
Math.round(x * 100),
|
|
89
89
|
"%"
|
|
90
90
|
] }),
|
|
91
|
-
/* @__PURE__ */ e(
|
|
92
|
-
/* @__PURE__ */ e(
|
|
91
|
+
/* @__PURE__ */ e(P, { "aria-label": n.zoomIn, variant: "secondary", isDisabled: x >= 3, onPress: () => I((q) => Math.min(3, q + 0.25)), children: /* @__PURE__ */ e(ae, {}) }),
|
|
92
|
+
/* @__PURE__ */ e(P, { "aria-label": n.close, variant: "secondary", onPress: Z, children: /* @__PURE__ */ e(te, {}) })
|
|
93
93
|
] }),
|
|
94
|
-
/* @__PURE__ */ e("div", { className: "alea-image-stage", children: /* @__PURE__ */ e("img", { src: f, alt: r, style: { transform: `scale(${
|
|
94
|
+
/* @__PURE__ */ e("div", { className: "alea-image-stage", children: /* @__PURE__ */ e("img", { src: f, alt: r, style: { transform: `scale(${x})` } }) })
|
|
95
95
|
] }) }) })
|
|
96
96
|
] });
|
|
97
97
|
}
|
|
@@ -102,77 +102,77 @@ function se() {
|
|
|
102
102
|
return r.stringToBytes = r.stringToBytesFuncs["UTF-8"], D = r;
|
|
103
103
|
}));
|
|
104
104
|
}
|
|
105
|
-
const Ne = F(function({ value: r, size: s = 160, level: d = "M", logo: b, label:
|
|
105
|
+
const Ne = F(function({ value: r, size: s = 160, level: d = "M", logo: b, label: k, color: u = "#111011", background: t = "#ffffff", className: i, style: v, ...g }, p) {
|
|
106
106
|
const y = R(), [o, N] = C(D ? { qrcode: D } : null);
|
|
107
|
-
|
|
107
|
+
L(() => {
|
|
108
108
|
if (o) return;
|
|
109
|
-
let
|
|
110
|
-
return se().then((
|
|
111
|
-
|
|
109
|
+
let n = !0;
|
|
110
|
+
return se().then((l) => {
|
|
111
|
+
n && N({ qrcode: l });
|
|
112
112
|
}, () => {
|
|
113
113
|
}), () => {
|
|
114
|
-
|
|
114
|
+
n = !1;
|
|
115
115
|
};
|
|
116
116
|
}, [o]);
|
|
117
117
|
const m = O(() => {
|
|
118
118
|
if (!o) return null;
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
const
|
|
119
|
+
const n = o.qrcode(0, d);
|
|
120
|
+
n.addData(r), n.make();
|
|
121
|
+
const l = n.getModuleCount();
|
|
122
122
|
let c = "";
|
|
123
|
-
for (let a = 0; a <
|
|
124
|
-
return { d: c, n:
|
|
123
|
+
for (let a = 0; a < l; a++) for (let w = 0; w < l; w++) n.isDark(a, w) && (c += `M${w + 4} ${a + 4}h1v1h-1z`);
|
|
124
|
+
return { d: c, n: l + 8 };
|
|
125
125
|
}, [o, r, d]);
|
|
126
|
-
return /* @__PURE__ */ h("span", { ref: p, ...g, className:
|
|
126
|
+
return /* @__PURE__ */ h("span", { ref: p, ...g, className: z("alea-qr", i), style: { width: s, height: s, ...v }, role: "img", "aria-label": k ?? g["aria-label"] ?? y.qrCode(r), children: [
|
|
127
127
|
m && /* @__PURE__ */ h("svg", { viewBox: `0 0 ${m.n} ${m.n}`, width: s, height: s, shapeRendering: "crispEdges", "aria-hidden": "true", children: [
|
|
128
|
-
/* @__PURE__ */ e("rect", { width: m.n, height: m.n, fill:
|
|
128
|
+
/* @__PURE__ */ e("rect", { width: m.n, height: m.n, fill: t, rx: m.n * 0.06 }),
|
|
129
129
|
/* @__PURE__ */ e("path", { d: m.d, fill: u })
|
|
130
130
|
] }),
|
|
131
|
-
b && m && /* @__PURE__ */ e("span", { className: "alea-qr-logo", "aria-hidden": "true", style: { background:
|
|
131
|
+
b && m && /* @__PURE__ */ e("span", { className: "alea-qr-logo", "aria-hidden": "true", style: { background: t }, children: b })
|
|
132
132
|
] });
|
|
133
133
|
});
|
|
134
|
-
function ye({ children: f, text: r, rotate: s = -22, gap: d = 120, opacity: b = 0.08, className:
|
|
134
|
+
function ye({ children: f, text: r, rotate: s = -22, gap: d = 120, opacity: b = 0.08, className: k }) {
|
|
135
135
|
const u = O(() => {
|
|
136
|
-
const
|
|
136
|
+
const t = d + r.length * 7.5, i = d, v = `<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${i}"><text x="50%" y="50%" fill="currentColor" font-family="Inter, sans-serif" font-size="14" font-weight="600" text-anchor="middle" dominant-baseline="middle" transform="rotate(${s} ${t / 2} ${i / 2})">${r.replace(/[<&>"]/g, (g) => ({ "<": "<", "&": "&", ">": ">", '"': """ })[g])}</text></svg>`;
|
|
137
137
|
return `url("data:image/svg+xml,${encodeURIComponent(v)}")`;
|
|
138
138
|
}, [r, s, d]);
|
|
139
|
-
return /* @__PURE__ */ h("div", { className:
|
|
139
|
+
return /* @__PURE__ */ h("div", { className: z("alea-watermark", k), children: [
|
|
140
140
|
f,
|
|
141
141
|
/* @__PURE__ */ e("span", { className: "alea-watermark-layer", "aria-hidden": "true", style: { WebkitMaskImage: u, maskImage: u, opacity: b } })
|
|
142
142
|
] });
|
|
143
143
|
}
|
|
144
|
-
const we = F(function({ steps: r, isOpen: s, onOpenChange: d, onFinish: b, className:
|
|
144
|
+
const we = F(function({ steps: r, isOpen: s, onOpenChange: d, onFinish: b, className: k, style: u }, t) {
|
|
145
145
|
const i = R(), [v, g] = C(0), [p, y] = C(null), o = r[v];
|
|
146
|
-
if (
|
|
146
|
+
if (L(() => {
|
|
147
147
|
s && g(0);
|
|
148
148
|
}, [s]), _(() => {
|
|
149
149
|
if (!s || !o) return;
|
|
150
|
-
const
|
|
151
|
-
if (!
|
|
150
|
+
const n = typeof o.target == "string" ? document.querySelector(o.target) : o.target || null;
|
|
151
|
+
if (!n) {
|
|
152
152
|
y(null);
|
|
153
153
|
return;
|
|
154
154
|
}
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
const c = setTimeout(
|
|
159
|
-
return window.addEventListener("resize",
|
|
160
|
-
clearTimeout(c), window.removeEventListener("resize",
|
|
155
|
+
n.scrollIntoView({ block: "center", behavior: "smooth" });
|
|
156
|
+
const l = () => y(n.getBoundingClientRect());
|
|
157
|
+
l();
|
|
158
|
+
const c = setTimeout(l, 350);
|
|
159
|
+
return window.addEventListener("resize", l), window.addEventListener("scroll", l, !0), () => {
|
|
160
|
+
clearTimeout(c), window.removeEventListener("resize", l), window.removeEventListener("scroll", l, !0);
|
|
161
161
|
};
|
|
162
162
|
}, [s, v, o]), !o) return null;
|
|
163
163
|
const N = 8, m = p ? { top: Math.min(window.innerHeight - 220, p.bottom + N + 12), left: Math.max(16, Math.min(window.innerWidth - 336, p.left)) } : { top: "50%", left: "50%", transform: "translate(-50%, -50%)" };
|
|
164
|
-
return /* @__PURE__ */ e(W, { isOpen: s, onOpenChange: d, isDismissable: !1, className: "alea-tour-overlay", children: /* @__PURE__ */ e(j, { ref:
|
|
164
|
+
return /* @__PURE__ */ e(W, { isOpen: s, onOpenChange: d, isDismissable: !1, className: "alea-tour-overlay", children: /* @__PURE__ */ e(j, { ref: t, style: u, "aria-label": typeof o.title == "string" ? o.title : i.stepN(v + 1), hideClose: !0, className: z("alea-tour", k), children: ({ close: n }) => /* @__PURE__ */ h(B, { children: [
|
|
165
165
|
p && /* @__PURE__ */ e("span", { className: "alea-tour-spot", "aria-hidden": "true", style: { top: p.top - N, left: p.left - N, width: p.width + N * 2, height: p.height + N * 2 } }),
|
|
166
166
|
/* @__PURE__ */ h("div", { className: "alea-tour-card", style: m, children: [
|
|
167
167
|
/* @__PURE__ */ e("p", { className: "alea-tour-count", children: i.stepNOfTotal(v + 1, r.length) }),
|
|
168
168
|
/* @__PURE__ */ e("h2", { className: "alea-tour-title", children: o.title }),
|
|
169
169
|
o.content && /* @__PURE__ */ e("div", { className: "alea-tour-text", children: o.content }),
|
|
170
170
|
/* @__PURE__ */ h("div", { className: "alea-tour-actions", children: [
|
|
171
|
-
/* @__PURE__ */ e(S, { size: "sm", variant: "ghost", onPress:
|
|
171
|
+
/* @__PURE__ */ e(S, { size: "sm", variant: "ghost", onPress: n, children: i.skip }),
|
|
172
172
|
/* @__PURE__ */ e("span", { className: "alea-tour-spacer" }),
|
|
173
|
-
v > 0 && /* @__PURE__ */ e(S, { size: "sm", variant: "ghost", onPress: () => g((
|
|
173
|
+
v > 0 && /* @__PURE__ */ e(S, { size: "sm", variant: "ghost", onPress: () => g((l) => l - 1), children: i.back }),
|
|
174
174
|
/* @__PURE__ */ e(S, { size: "sm", autoFocus: !0, onPress: () => {
|
|
175
|
-
v < r.length - 1 ? g((
|
|
175
|
+
v < r.length - 1 ? g((l) => l + 1) : (b == null || b(), n());
|
|
176
176
|
}, children: v < r.length - 1 ? i.next : i.done })
|
|
177
177
|
] })
|
|
178
178
|
] })
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type MotionProp } from '@alea-design/motion';
|
|
2
|
+
export type NotificationTone = 'info' | 'success' | 'warning' | 'danger';
|
|
3
|
+
export interface NotificationAction {
|
|
4
|
+
/** The text of the action: "View invoice". */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Makes the action a link. */
|
|
7
|
+
href?: string;
|
|
8
|
+
/** Called when the action is pressed (with or without href). */
|
|
9
|
+
onPress?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface NotificationItem {
|
|
12
|
+
/** Stable id of the notification. */
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
/** A line of detail under the title. */
|
|
16
|
+
description?: string;
|
|
17
|
+
/** When it happened; shown as a relative time ("5 minutes ago"). */
|
|
18
|
+
time: Date;
|
|
19
|
+
/** info, success, warning or danger: sets the icon and the color. */
|
|
20
|
+
tone: NotificationTone;
|
|
21
|
+
/** Read notifications are quieter and do not count in the badge. */
|
|
22
|
+
read: boolean;
|
|
23
|
+
/** One action that goes somewhere or does something. */
|
|
24
|
+
action?: NotificationAction;
|
|
25
|
+
}
|
|
26
|
+
/** Every text the component writes. All are optional; the defaults follow the locale (English and Spanish ship with the kit). */
|
|
27
|
+
export interface NotificationLabels {
|
|
28
|
+
/** The panel's title. */
|
|
29
|
+
title: string;
|
|
30
|
+
/** The bell's name; gets the unread count. Default "Notifications, 3 unread". */
|
|
31
|
+
bell: (unread: number) => string;
|
|
32
|
+
/** The button that marks one notification as read. */
|
|
33
|
+
markRead: string;
|
|
34
|
+
/** The button that marks all of them as read. */
|
|
35
|
+
markAllRead: string;
|
|
36
|
+
/** The button that dismisses one notification. */
|
|
37
|
+
dismiss: string;
|
|
38
|
+
/** The empty state's title. */
|
|
39
|
+
emptyTitle: string;
|
|
40
|
+
/** The empty state's line under the title. */
|
|
41
|
+
emptyDescription: string;
|
|
42
|
+
/** What screen readers hear when a new notification arrives. */
|
|
43
|
+
newNotification: (title: string) => string;
|
|
44
|
+
/** Said before the title of an unread notification, for screen readers. */
|
|
45
|
+
unread: string;
|
|
46
|
+
/** Said before the title, for screen readers, per tone. */
|
|
47
|
+
tones: Record<NotificationTone, string>;
|
|
48
|
+
}
|
|
49
|
+
export interface NotificationCenterProps {
|
|
50
|
+
/** The notifications, newest first. The component never changes them: it reports every change. */
|
|
51
|
+
items: NotificationItem[];
|
|
52
|
+
/** Called with the next list after any change (read, read all, dismiss). */
|
|
53
|
+
onChange?: (items: NotificationItem[]) => void;
|
|
54
|
+
/** Called with the notification that was marked as read. */
|
|
55
|
+
onMarkRead?: (item: NotificationItem) => void;
|
|
56
|
+
/** Called when "mark all as read" is pressed, with the notifications that were unread. */
|
|
57
|
+
onMarkAllRead?: (items: NotificationItem[]) => void;
|
|
58
|
+
/** Called with the notification that was dismissed. */
|
|
59
|
+
onDismiss?: (item: NotificationItem) => void;
|
|
60
|
+
/** Called when a notification's action is pressed. */
|
|
61
|
+
onAction?: (item: NotificationItem) => void;
|
|
62
|
+
/** Text overrides: the bell, the buttons, the empty state and the announcements. */
|
|
63
|
+
labels?: Partial<NotificationLabels>;
|
|
64
|
+
/** popover (a panel under the bell), drawer (a sheet from the bottom) or auto: a drawer on small screens. Default auto. */
|
|
65
|
+
presentation?: 'auto' | 'popover' | 'drawer';
|
|
66
|
+
/** Where the popover opens. Default bottom end. */
|
|
67
|
+
placement?: 'bottom' | 'bottom start' | 'bottom end' | 'top' | 'top start' | 'top end';
|
|
68
|
+
/** Opens or closes the panel (controlled). */
|
|
69
|
+
isOpen?: boolean;
|
|
70
|
+
/** Starts open (uncontrolled). */
|
|
71
|
+
defaultOpen?: boolean;
|
|
72
|
+
/** Called when the panel opens or closes. */
|
|
73
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
74
|
+
/** The badge shows max+ above this. Default 99. */
|
|
75
|
+
max?: number;
|
|
76
|
+
/** Announces new unread notifications to screen readers. Default true. */
|
|
77
|
+
announce?: boolean;
|
|
78
|
+
/** How the panel enters and leaves: a preset, false for none, or options. */
|
|
79
|
+
motion?: MotionProp;
|
|
80
|
+
className?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A bell with an unread count that opens the list of notifications: read one or all, dismiss, go to the action. A panel under the bell, or a drawer on small screens.
|
|
84
|
+
* You own the list; every change comes back through onChange. Arrow keys move between notifications, Escape closes and focus returns to the bell, and new unread notifications are announced.
|
|
85
|
+
*/
|
|
86
|
+
export declare function NotificationCenter({ items, onChange, onMarkRead, onMarkAllRead, onDismiss, onAction, labels, presentation, placement, isOpen, defaultOpen, onOpenChange, max, announce, motion, className, }: NotificationCenterProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as c, jsx as a, Fragment as ue } from "react/jsx-runtime";
|
|
3
|
+
import { useId as fe, useState as N, useRef as S, useEffect as V, useMemo as he, useLayoutEffect as me, useCallback as pe, useSyncExternalStore as we } from "react";
|
|
4
|
+
import { useLocale as Ne, DialogTrigger as xe, Dialog as ye, Heading as ve } from "react-aria-components";
|
|
5
|
+
import { Bell as U, CheckCheck as ge, X, CircleAlert as Se, TriangleAlert as be, CircleCheck as Ie, Info as Te, Check as Ee } from "lucide-react";
|
|
6
|
+
import { Presence as ke, Reveal as ze } from "@alea-design/motion";
|
|
7
|
+
import { cx as De } from "../../utils/cx.js";
|
|
8
|
+
import { useStrings as Le } from "../../i18n/strings.js";
|
|
9
|
+
import { IconButton as b, Button as _ } from "../button/Button.js";
|
|
10
|
+
import { Badge as J } from "../display/Display.js";
|
|
11
|
+
import { EmptyState as Pe } from "../data/Data.js";
|
|
12
|
+
import { Popover as $e } from "../overlay/Overlay.js";
|
|
13
|
+
import { Drawer as Me } from "../overlay/Drawer.js";
|
|
14
|
+
const Ae = { info: Te, success: Ie, warning: be, danger: Se }, Q = "(max-width: 639.98px)";
|
|
15
|
+
function Fe() {
|
|
16
|
+
const r = pe((d) => {
|
|
17
|
+
var s;
|
|
18
|
+
if (typeof window > "u" || !window.matchMedia) return () => {
|
|
19
|
+
};
|
|
20
|
+
const o = window.matchMedia(Q);
|
|
21
|
+
return (s = o.addEventListener) == null || s.call(o, "change", d), () => {
|
|
22
|
+
var l;
|
|
23
|
+
return (l = o.removeEventListener) == null ? void 0 : l.call(o, "change", d);
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
return we(r, () => typeof window < "u" && window.matchMedia ? window.matchMedia(Q).matches : !1, () => !1);
|
|
27
|
+
}
|
|
28
|
+
function Be(r, d = 3e4) {
|
|
29
|
+
const [o, s] = N(() => Date.now());
|
|
30
|
+
return V(() => {
|
|
31
|
+
if (!r) return;
|
|
32
|
+
s(Date.now());
|
|
33
|
+
const l = window.setInterval(() => s(Date.now()), d);
|
|
34
|
+
return () => window.clearInterval(l);
|
|
35
|
+
}, [r, d]), o;
|
|
36
|
+
}
|
|
37
|
+
function Oe(r, d, o) {
|
|
38
|
+
const s = Math.round((r.getTime() - d) / 1e3), l = Math.abs(s), h = new Intl.RelativeTimeFormat(o, { numeric: "auto" });
|
|
39
|
+
return l < 45 ? h.format(0, "second") : l < 3600 ? h.format(Math.round(s / 60), "minute") : l < 86400 ? h.format(Math.round(s / 3600), "hour") : h.format(Math.round(s / 86400), "day");
|
|
40
|
+
}
|
|
41
|
+
function We({
|
|
42
|
+
items: r,
|
|
43
|
+
onChange: d,
|
|
44
|
+
onMarkRead: o,
|
|
45
|
+
onMarkAllRead: s,
|
|
46
|
+
onDismiss: l,
|
|
47
|
+
onAction: h,
|
|
48
|
+
labels: x,
|
|
49
|
+
presentation: k = "auto",
|
|
50
|
+
placement: W = "bottom end",
|
|
51
|
+
isOpen: z,
|
|
52
|
+
defaultOpen: Y,
|
|
53
|
+
onOpenChange: I,
|
|
54
|
+
max: y = 99,
|
|
55
|
+
announce: Z = !0,
|
|
56
|
+
motion: D,
|
|
57
|
+
className: q
|
|
58
|
+
}) {
|
|
59
|
+
var K;
|
|
60
|
+
const u = Le(), { locale: L } = Ne(), f = {
|
|
61
|
+
title: u.notifications,
|
|
62
|
+
bell: u.notificationBell,
|
|
63
|
+
markRead: u.markRead,
|
|
64
|
+
markAllRead: u.markAllRead,
|
|
65
|
+
dismiss: u.dismissNotification,
|
|
66
|
+
emptyTitle: u.notificationsEmpty,
|
|
67
|
+
emptyDescription: u.notificationsEmptyHint,
|
|
68
|
+
newNotification: u.newNotification,
|
|
69
|
+
unread: u.unreadNotification,
|
|
70
|
+
...x,
|
|
71
|
+
tones: { ...u.notificationTones, ...x == null ? void 0 : x.tones }
|
|
72
|
+
}, P = fe(), ee = Fe(), $ = k === "drawer" || k === "auto" && ee, [te, ne] = N(Y ?? !1), M = z ?? te, ae = (t) => {
|
|
73
|
+
z === void 0 && ne(t), I == null || I(t);
|
|
74
|
+
}, re = Be(M), m = r.filter((t) => !t.read).length, A = S(null), [ie, F] = N({ text: "", n: 0 });
|
|
75
|
+
V(() => {
|
|
76
|
+
const t = A.current;
|
|
77
|
+
if (A.current = new Set(r.map((i) => i.id)), !t || !Z) return;
|
|
78
|
+
const e = r.filter((i) => !i.read && !t.has(i.id));
|
|
79
|
+
if (!e.length) return;
|
|
80
|
+
F((i) => ({ text: e.map((p) => f.newNotification(p.title)).join(". "), n: i.n + 1 }));
|
|
81
|
+
const n = window.setTimeout(() => F((i) => ({ ...i, text: "" })), 6e3);
|
|
82
|
+
return () => window.clearTimeout(n);
|
|
83
|
+
}, [r]);
|
|
84
|
+
const [B, O] = N([]), C = he(() => {
|
|
85
|
+
const t = r.map((n) => ({ item: n, leaving: !1 })), e = new Set(r.map((n) => n.id));
|
|
86
|
+
for (const n of B) e.has(n.item.id) || t.splice(Math.min(n.index, t.length), 0, { item: n.item, leaving: !0 });
|
|
87
|
+
return t;
|
|
88
|
+
}, [r, B]), T = S(null), H = S(null), [R, v] = N(null), oe = r.some((t) => t.id === R) ? R : ((K = r[0]) == null ? void 0 : K.id) ?? null, g = S(null);
|
|
89
|
+
me(() => {
|
|
90
|
+
var n;
|
|
91
|
+
const t = g.current;
|
|
92
|
+
if (!t) return;
|
|
93
|
+
const e = t === "empty" ? H.current : (n = T.current) == null ? void 0 : n.querySelector(`[data-nid="${CSS.escape(t)}"]`);
|
|
94
|
+
e && (g.current = null, e.focus());
|
|
95
|
+
});
|
|
96
|
+
const E = (t) => d == null ? void 0 : d(t), j = (t) => {
|
|
97
|
+
g.current = t.id, v(t.id), o == null || o(t), E(r.map((e) => e.id === t.id ? { ...e, read: !0 } : e));
|
|
98
|
+
}, se = () => {
|
|
99
|
+
const t = r.filter((e) => !e.read);
|
|
100
|
+
t.length && (s == null || s(t), E(r.map((e) => e.read ? e : { ...e, read: !0 })));
|
|
101
|
+
}, le = (t) => {
|
|
102
|
+
const e = r.findIndex((i) => i.id === t.id), n = r[e + 1] ?? r[e - 1];
|
|
103
|
+
g.current = n ? n.id : "empty", n && v(n.id), O((i) => [...i, { item: t, index: e }]), window.setTimeout(() => O((i) => i.filter((p) => p.item.id !== t.id)), 400), l == null || l(t), E(r.filter((i) => i.id !== t.id));
|
|
104
|
+
}, ce = (t) => {
|
|
105
|
+
var e, n;
|
|
106
|
+
(n = (e = t.action) == null ? void 0 : e.onPress) == null || n.call(e), h == null || h(t), t.read || j(t);
|
|
107
|
+
}, de = (t) => {
|
|
108
|
+
var p;
|
|
109
|
+
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(t.key)) return;
|
|
110
|
+
const e = [...((p = T.current) == null ? void 0 : p.querySelectorAll("[data-nid]:not([data-leaving])")) ?? []];
|
|
111
|
+
if (!e.length) return;
|
|
112
|
+
const n = e.findIndex((w) => w.contains(t.target)), i = t.key === "Home" ? 0 : t.key === "End" ? e.length - 1 : t.key === "ArrowDown" ? Math.min(n + 1, e.length - 1) : Math.max(n - 1, 0);
|
|
113
|
+
t.preventDefault(), v(e[i].dataset.nid ?? null), e[i].focus();
|
|
114
|
+
}, G = /* @__PURE__ */ a(ye, { className: "alea-notifs", "aria-labelledby": P, children: ({ close: t }) => /* @__PURE__ */ c(ue, { children: [
|
|
115
|
+
/* @__PURE__ */ c("div", { className: "alea-notifs-head", children: [
|
|
116
|
+
/* @__PURE__ */ c(ve, { slot: "title", id: P, className: "alea-notifs-title", children: [
|
|
117
|
+
f.title,
|
|
118
|
+
m > 0 && /* @__PURE__ */ a(J, { tone: "accent", size: "sm", "aria-hidden": "true", children: m > y ? `${y}+` : m })
|
|
119
|
+
] }),
|
|
120
|
+
/* @__PURE__ */ a(_, { variant: "text", size: "xs", iconStart: /* @__PURE__ */ a(ge, {}), isDisabled: m === 0, onPress: se, children: f.markAllRead }),
|
|
121
|
+
$ && /* @__PURE__ */ a(b, { "aria-label": u.close, size: "xs", onPress: t, children: /* @__PURE__ */ a(X, {}) })
|
|
122
|
+
] }),
|
|
123
|
+
C.length === 0 ? /* @__PURE__ */ a("div", { className: "alea-notifs-empty", ref: H, tabIndex: -1, children: /* @__PURE__ */ a(Pe, { size: "sm", title: f.emptyTitle, description: f.emptyDescription, icon: /* @__PURE__ */ a(U, {}) }) }) : /* @__PURE__ */ a("ul", { className: "alea-notifs-list", ref: T, onKeyDown: de, children: C.map(({ item: e, leaving: n }, i) => {
|
|
124
|
+
const p = Ae[e.tone], w = !n && e.id === oe;
|
|
125
|
+
return /* @__PURE__ */ a(ke, { show: !n, exitClassName: "alea-notif-out", children: /* @__PURE__ */ a(
|
|
126
|
+
"li",
|
|
127
|
+
{
|
|
128
|
+
className: "alea-notif",
|
|
129
|
+
"data-nid": e.id,
|
|
130
|
+
"data-tone": e.tone,
|
|
131
|
+
"data-unread": e.read ? void 0 : !0,
|
|
132
|
+
"data-leaving": n || void 0,
|
|
133
|
+
tabIndex: w ? 0 : -1,
|
|
134
|
+
onFocus: () => !n && v(e.id),
|
|
135
|
+
children: /* @__PURE__ */ c(ze, { className: "alea-notif-inner", motion: "rise", delay: Math.min(i, 6) * 30, children: [
|
|
136
|
+
/* @__PURE__ */ a("span", { className: "alea-notif-icon", "aria-hidden": "true", children: /* @__PURE__ */ a(p, {}) }),
|
|
137
|
+
/* @__PURE__ */ c("div", { className: "alea-notif-body", children: [
|
|
138
|
+
/* @__PURE__ */ c("p", { className: "alea-notif-title", children: [
|
|
139
|
+
/* @__PURE__ */ c("span", { className: "alea-visually-hidden", children: [
|
|
140
|
+
e.read ? "" : `${f.unread}. `,
|
|
141
|
+
f.tones[e.tone],
|
|
142
|
+
": "
|
|
143
|
+
] }),
|
|
144
|
+
e.title
|
|
145
|
+
] }),
|
|
146
|
+
e.description && /* @__PURE__ */ a("p", { className: "alea-notif-text", children: e.description }),
|
|
147
|
+
/* @__PURE__ */ c("p", { className: "alea-notif-meta", children: [
|
|
148
|
+
/* @__PURE__ */ a("time", { dateTime: e.time.toISOString(), title: e.time.toLocaleString(L), children: Oe(e.time, re, L) }),
|
|
149
|
+
e.action && /* @__PURE__ */ a(
|
|
150
|
+
_,
|
|
151
|
+
{
|
|
152
|
+
variant: "link",
|
|
153
|
+
size: "xs",
|
|
154
|
+
href: e.action.href,
|
|
155
|
+
excludeFromTabOrder: !w,
|
|
156
|
+
className: "alea-notif-action",
|
|
157
|
+
onPress: () => ce(e),
|
|
158
|
+
children: e.action.label
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
] })
|
|
162
|
+
] }),
|
|
163
|
+
/* @__PURE__ */ c("div", { className: "alea-notif-tools", children: [
|
|
164
|
+
!e.read && /* @__PURE__ */ a(b, { "aria-label": `${f.markRead}: ${e.title}`, size: "xs", excludeFromTabOrder: !w, onPress: () => j(e), children: /* @__PURE__ */ a(Ee, {}) }),
|
|
165
|
+
/* @__PURE__ */ a(b, { "aria-label": `${f.dismiss}: ${e.title}`, size: "xs", excludeFromTabOrder: !w, onPress: () => le(e), children: /* @__PURE__ */ a(X, {}) })
|
|
166
|
+
] })
|
|
167
|
+
] })
|
|
168
|
+
}
|
|
169
|
+
) }, e.id);
|
|
170
|
+
}) })
|
|
171
|
+
] }) });
|
|
172
|
+
return /* @__PURE__ */ c("span", { className: De("alea-notifs-root", q), children: [
|
|
173
|
+
/* @__PURE__ */ c(xe, { isOpen: M, onOpenChange: ae, children: [
|
|
174
|
+
/* @__PURE__ */ c("span", { className: "alea-notifs-bell", children: [
|
|
175
|
+
/* @__PURE__ */ a(b, { "aria-label": f.bell(m), variant: "ghost", children: /* @__PURE__ */ a(U, {}) }),
|
|
176
|
+
m > 0 && /* @__PURE__ */ a(J, { className: "alea-notifs-count", tone: "danger", appearance: "solid", size: "sm", "aria-hidden": "true", children: m > y ? `${y}+` : m })
|
|
177
|
+
] }),
|
|
178
|
+
$ ? /* @__PURE__ */ a(Me, { placement: "bottom", size: 640, motion: D, className: "alea-notifs-drawer", children: G }) : /* @__PURE__ */ a($e, { placement: W, size: "lg", motion: D, className: "alea-notifs-popover", children: G })
|
|
179
|
+
] }),
|
|
180
|
+
/* @__PURE__ */ a("span", { className: "alea-visually-hidden", role: "status", "aria-live": "polite", "aria-atomic": "true", children: ie.text })
|
|
181
|
+
] });
|
|
182
|
+
}
|
|
183
|
+
export {
|
|
184
|
+
We as NotificationCenter
|
|
185
|
+
};
|