@nivaro/react 0.3.133 → 0.3.134

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.
@@ -0,0 +1,157 @@
1
+ import { jsxs as b, jsx as r } from "react/jsx-runtime";
2
+ import { useContext as N, useMemo as g, useState as S, useEffect as C } from "react";
3
+ import { RechartsGate as E } from "../charts/RechartsGate.js";
4
+ import { COLOR_ROLES as R } from "../QueryTable.js";
5
+ import { Skeleton as $ } from "../ui/skeleton.js";
6
+ import { DrillContext as D } from "./ui.js";
7
+ import { bucketLabel as f, fmtInt as y } from "./url.js";
8
+ const h = () => typeof document < "u" && document.documentElement.classList.contains("dark");
9
+ function O() {
10
+ const [a, n] = S(h);
11
+ return C(() => {
12
+ if (typeof document > "u") return;
13
+ const d = new MutationObserver(() => n(h()));
14
+ return d.observe(document.documentElement, { attributes: !0, attributeFilter: ["class"] }), () => d.disconnect();
15
+ }, []), a;
16
+ }
17
+ const v = (a, n) => R[a][n ? 1 : 0];
18
+ function T({
19
+ summary: a,
20
+ kind: n,
21
+ height: d = 168
22
+ }) {
23
+ const l = O(), w = N(D), o = a.window.bucket, s = g(() => {
24
+ const t = a.series;
25
+ return n === "notifications" ? [
26
+ {
27
+ key: "read",
28
+ label: "Read",
29
+ color: "rgb(var(--nvr-cyan-rgb))",
30
+ cells: t.map((e) => e.read),
31
+ drillLabel: (e) => `Read · ${f(e, o)}`
32
+ },
33
+ {
34
+ key: "unread",
35
+ label: "Not read",
36
+ color: l ? "rgb(var(--nvr-cyan-rgb) / 0.32)" : "rgb(var(--nvr-cyan-rgb) / 0.3)",
37
+ // Unread = sent minus read: the read dimension splits every row in two.
38
+ cells: t.map((e) => ({
39
+ n: e.sent.n - e.read.n,
40
+ s: "n",
41
+ w: [...e.sent.w, ["read", ["unread"]]]
42
+ })),
43
+ drillLabel: (e) => `Not read · ${f(e, o)}`
44
+ }
45
+ ] : [
46
+ {
47
+ key: "delivered",
48
+ label: "Sent",
49
+ color: v("info", l),
50
+ cells: t.map((e) => e.email_delivered),
51
+ drillLabel: (e) => `Emails sent · ${f(e, o)}`
52
+ },
53
+ {
54
+ key: "failed",
55
+ label: "Failed",
56
+ color: v("negative", l),
57
+ cells: t.map((e) => e.email_failed),
58
+ drillLabel: (e) => `Emails failed · ${f(e, o)}`
59
+ }
60
+ ];
61
+ }, [a.series, n, l, o]), p = g(
62
+ () => a.series.map((t, e) => ({
63
+ bucket: t.bucket,
64
+ label: f(t.bucket, o),
65
+ ...Object.fromEntries(s.map((i) => {
66
+ var c;
67
+ return [i.key, ((c = i.cells[e]) == null ? void 0 : c.n) ?? 0];
68
+ }))
69
+ })),
70
+ [a.series, s, o]
71
+ ), L = p.every((t) => s.every((e) => t[e.key] === 0)), k = l ? "#94a3b8" : "#64748b";
72
+ return /* @__PURE__ */ b("div", { children: [
73
+ /* @__PURE__ */ r("ul", { className: "mb-1.5 flex flex-wrap gap-x-4 gap-y-1 text-[11.5px] text-slate-600 dark:text-muted-foreground", children: s.map((t) => /* @__PURE__ */ b("li", { className: "inline-flex items-center gap-1.5", children: [
74
+ /* @__PURE__ */ r("span", { className: "h-2 w-2 rounded-sm", style: { background: t.color }, "aria-hidden": !0 }),
75
+ t.label,
76
+ /* @__PURE__ */ r("span", { className: "tabular-nums text-slate-400 dark:text-muted-foreground/70", children: y(t.cells.reduce((e, i) => e + i.n, 0)) })
77
+ ] }, t.key)) }),
78
+ L ? /* @__PURE__ */ r(
79
+ "p",
80
+ {
81
+ className: "flex items-center justify-center text-[12px] text-slate-500 dark:text-muted-foreground",
82
+ style: { height: d },
83
+ children: n === "notifications" ? "No notifications in this window." : "No email in this window."
84
+ }
85
+ ) : /* @__PURE__ */ r("div", { style: { height: d }, role: "img", "aria-label": `${n} per ${o}`, children: /* @__PURE__ */ r(E, { fallback: /* @__PURE__ */ r($, { className: "h-full w-full", "aria-busy": "true" }), children: (t) => /* @__PURE__ */ r(t.ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ b(
86
+ t.BarChart,
87
+ {
88
+ data: p,
89
+ margin: { top: 4, right: 4, left: 0, bottom: 0 },
90
+ barCategoryGap: "18%",
91
+ children: [
92
+ /* @__PURE__ */ r(t.CartesianGrid, { vertical: !1, stroke: l ? "#1e293b" : "#eef2f6" }),
93
+ /* @__PURE__ */ r(
94
+ t.XAxis,
95
+ {
96
+ dataKey: "label",
97
+ tick: { fontSize: 10.5, fill: k },
98
+ tickLine: !1,
99
+ axisLine: !1,
100
+ interval: "preserveStartEnd",
101
+ minTickGap: 18
102
+ }
103
+ ),
104
+ /* @__PURE__ */ r(
105
+ t.YAxis,
106
+ {
107
+ tick: { fontSize: 10.5, fill: k },
108
+ tickLine: !1,
109
+ axisLine: !1,
110
+ allowDecimals: !1,
111
+ width: 44
112
+ }
113
+ ),
114
+ /* @__PURE__ */ r(
115
+ t.Tooltip,
116
+ {
117
+ cursor: { fill: l ? "rgba(148,163,184,0.08)" : "rgba(15,23,42,0.04)" },
118
+ contentStyle: {
119
+ fontSize: 12,
120
+ borderRadius: 6,
121
+ border: `1px solid ${l ? "#334155" : "#e2e8f0"}`,
122
+ background: l ? "#0f172a" : "#ffffff",
123
+ color: l ? "#e2e8f0" : "#0f172a"
124
+ },
125
+ formatter: (e, i) => {
126
+ var c;
127
+ return [
128
+ y(Number(e)),
129
+ ((c = s.find((u) => u.key === i)) == null ? void 0 : c.label) ?? String(i)
130
+ ];
131
+ }
132
+ }
133
+ ),
134
+ s.map((e, i) => /* @__PURE__ */ r(
135
+ t.Bar,
136
+ {
137
+ dataKey: e.key,
138
+ stackId: "a",
139
+ fill: e.color,
140
+ radius: i === s.length - 1 ? [2, 2, 0, 0] : 0,
141
+ cursor: "pointer",
142
+ isAnimationActive: !1,
143
+ onClick: (c, u) => {
144
+ const m = e.cells[u], x = a.series[u];
145
+ m && m.n > 0 && x && w(m, e.drillLabel(x.bucket));
146
+ }
147
+ },
148
+ e.key
149
+ ))
150
+ ]
151
+ }
152
+ ) }) }) })
153
+ ] });
154
+ }
155
+ export {
156
+ T as TrendBars
157
+ };