@nice2dev/ui 1.4.23 → 1.4.24

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,159 @@
1
+ import { jsx as f, jsxs as Q } from "react/jsx-runtime";
2
+ import { useNiceTranslation as V } from "@nice2dev/ui-core";
3
+ import { useRef as W, useState as Y, useEffect as Z } from "react";
4
+ const ot = ({
5
+ data: c,
6
+ min: s,
7
+ max: d,
8
+ start: o,
9
+ end: r,
10
+ onChange: g,
11
+ width: U = 500,
12
+ height: R = 100,
13
+ step: p = 1,
14
+ formatValue: k,
15
+ chartColor: y = "var(--nice-color-primary, #3b82f6)",
16
+ responsive: v = !0,
17
+ className: B,
18
+ style: E,
19
+ testId: F,
20
+ "data-testid": G
21
+ }) => {
22
+ const { t: D } = V(), _ = W(null), [$, H] = Y(null);
23
+ Z(() => {
24
+ const t = _.current;
25
+ if (!v || !t || typeof ResizeObserver > "u")
26
+ return;
27
+ const e = new ResizeObserver(([u]) => {
28
+ const i = Math.round(u.contentRect.width);
29
+ i > 0 && H(i);
30
+ });
31
+ return e.observe(t), () => e.disconnect();
32
+ }, [v]);
33
+ const A = v && $ ? $ : U, n = { top: 10, bottom: 30, left: 10, right: 10 }, x = Math.max(10, A - n.left - n.right), a = R - n.top - n.bottom, N = d - s || 1, h = (t) => Math.min(d, Math.max(s, Math.round((t - s) / p) * p + s)), l = (t) => n.left + (t - s) / N * x, M = (t) => k ? k(t) : String(t), S = (t, e) => {
34
+ e.preventDefault();
35
+ const i = (e.currentTarget.ownerSVGElement ?? e.currentTarget).getBoundingClientRect(), m = (b) => s + Math.max(0, Math.min(1, (b - i.left - n.left) / x)) * N, q = m(e.clientX), j = o, J = r, z = (b) => {
36
+ const w = m(b.clientX);
37
+ if (t === "start")
38
+ g(Math.min(h(w), r), r);
39
+ else if (t === "end")
40
+ g(o, Math.max(h(w), o));
41
+ else {
42
+ const X = J - j, O = Math.min(d - X, Math.max(s, h(j + (w - q))));
43
+ g(O, O + X);
44
+ }
45
+ }, T = () => {
46
+ document.removeEventListener("pointermove", z), document.removeEventListener("pointerup", T);
47
+ };
48
+ document.addEventListener("pointermove", z), document.addEventListener("pointerup", T);
49
+ }, I = (t) => (e) => {
50
+ const u = p * 10, i = t === "start" ? o : r, m = e.key === "ArrowLeft" || e.key === "ArrowDown" ? i - p : e.key === "ArrowRight" || e.key === "ArrowUp" ? i + p : e.key === "PageDown" ? i - u : e.key === "PageUp" ? i + u : e.key === "Home" ? t === "start" ? s : o : e.key === "End" ? t === "start" ? r : d : null;
51
+ m !== null && (e.preventDefault(), t === "start" ? g(Math.min(h(m), r), r) : g(o, Math.max(h(m), o)));
52
+ }, L = c && c.length ? Math.min(...c) : 0, K = (c && c.length ? Math.max(...c) : 1) - L || 1, P = (t) => {
53
+ const e = t === "start" ? o : r;
54
+ return /* @__PURE__ */ f(
55
+ "rect",
56
+ {
57
+ x: l(e) - 5,
58
+ y: n.top,
59
+ width: 10,
60
+ height: a,
61
+ fill: y,
62
+ rx: 2,
63
+ cursor: "ew-resize",
64
+ className: "nice-rangeselector__handle",
65
+ role: "slider",
66
+ tabIndex: 0,
67
+ "aria-label": t === "start" ? D("chartRangeSelector.start", "Range start") : D("chartRangeSelector.end", "Range end"),
68
+ "aria-valuemin": t === "start" ? s : o,
69
+ "aria-valuemax": t === "start" ? r : d,
70
+ "aria-valuenow": e,
71
+ "aria-valuetext": M(e),
72
+ onPointerDown: (u) => S(t, u),
73
+ onKeyDown: I(t)
74
+ }
75
+ );
76
+ };
77
+ return /* @__PURE__ */ f(
78
+ "div",
79
+ {
80
+ ref: _,
81
+ className: `nice-rangeselector ${B || ""}`,
82
+ style: v ? { width: "100%", ...E } : E,
83
+ "data-testid": G ?? F,
84
+ children: /* @__PURE__ */ Q("svg", { width: A, height: R, children: [
85
+ c && c.length > 1 && /* @__PURE__ */ f(
86
+ "polygon",
87
+ {
88
+ points: `${n.left},${n.top + a} ${c.map((t, e) => `${n.left + e / (c.length - 1) * x},${n.top + a - (t - L) / K * a}`).join(" ")} ${n.left + x},${n.top + a}`,
89
+ fill: y,
90
+ opacity: 0.15
91
+ }
92
+ ),
93
+ /* @__PURE__ */ f(
94
+ "rect",
95
+ {
96
+ x: l(o),
97
+ y: n.top,
98
+ width: Math.max(0, l(r) - l(o)),
99
+ height: a,
100
+ fill: y,
101
+ opacity: 0.12,
102
+ cursor: "grab",
103
+ className: "nice-rangeselector__window",
104
+ onPointerDown: (t) => S("window", t)
105
+ }
106
+ ),
107
+ /* @__PURE__ */ f(
108
+ "rect",
109
+ {
110
+ x: n.left,
111
+ y: n.top,
112
+ width: Math.max(0, l(o) - n.left),
113
+ height: a,
114
+ fill: "var(--nice-bg-secondary, #f5f5f5)",
115
+ opacity: 0.6,
116
+ pointerEvents: "none"
117
+ }
118
+ ),
119
+ /* @__PURE__ */ f(
120
+ "rect",
121
+ {
122
+ x: l(r),
123
+ y: n.top,
124
+ width: Math.max(0, n.left + x - l(r)),
125
+ height: a,
126
+ fill: "var(--nice-bg-secondary, #f5f5f5)",
127
+ opacity: 0.6,
128
+ pointerEvents: "none"
129
+ }
130
+ ),
131
+ P("start"),
132
+ P("end"),
133
+ /* @__PURE__ */ f(
134
+ "text",
135
+ {
136
+ x: l(o),
137
+ y: n.top + a + 18,
138
+ textAnchor: "middle",
139
+ className: "nice-chart__axis-label",
140
+ children: M(o)
141
+ }
142
+ ),
143
+ /* @__PURE__ */ f(
144
+ "text",
145
+ {
146
+ x: l(r),
147
+ y: n.top + a + 18,
148
+ textAnchor: "middle",
149
+ className: "nice-chart__axis-label",
150
+ children: M(r)
151
+ }
152
+ )
153
+ ] })
154
+ }
155
+ );
156
+ };
157
+ export {
158
+ ot as NiceChartRangeSelector
159
+ };
@@ -1,79 +1,149 @@
1
- import { jsx as c, jsxs as M } from "react/jsx-runtime";
2
- import { useControlId as I } from "@nice2dev/ui-core";
3
- import { forwardRef as w, useMemo as v, useCallback as V } from "react";
4
- const $ = [];
5
- function j(o, l, n) {
6
- const s = (x) => {
7
- const r = x.replace("#", "");
8
- return [
9
- parseInt(r.slice(0, 2), 16),
10
- parseInt(r.slice(2, 4), 16),
11
- parseInt(r.slice(4, 6), 16)
12
- ];
13
- }, [m, d, h] = s(o), [p, f, u] = s(l), g = Math.round(m + (p - m) * n), b = Math.round(d + (f - d) * n), _ = Math.round(h + (u - h) * n);
14
- return `rgb(${g},${b},${_})`;
1
+ import { jsxs as o, jsx as c } from "react/jsx-runtime";
2
+ import { useControlId as J } from "@nice2dev/ui-core";
3
+ import { forwardRef as K, useState as Q, useRef as W, useEffect as X, useMemo as Z } from "react";
4
+ const C = [], V = [
5
+ "var(--nice-primary-bg, #e0f2fe)",
6
+ "var(--nice-color-primary-active, #1d4ed8)"
7
+ ];
8
+ function z(t, s) {
9
+ const i = Math.max(0, Math.min(1, s));
10
+ return t.length === 3 ? i < 0.5 ? `color-mix(in srgb, ${t[1]} ${Math.round(i * 200)}%, ${t[0]})` : `color-mix(in srgb, ${t[2]} ${Math.round((i - 0.5) * 200)}%, ${t[1]})` : `color-mix(in srgb, ${t[1]} ${Math.round(i * 100)}%, ${t[0]})`;
15
11
  }
16
- const H = /* @__PURE__ */ Object.assign(
17
- /* @__PURE__ */ w(
12
+ const ae = /* @__PURE__ */ Object.assign(
13
+ /* @__PURE__ */ K(
18
14
  ({
19
- data: o = $,
20
- xLabels: l,
21
- yLabels: n,
22
- colors: s = ["var(--nice-primary-bg, #e0f2fe)", "var(--nice-color-primary-active, #1d4ed8)"],
23
- onCellClick: m,
24
- cellSize: d = 40,
25
- showValues: h = !0,
26
- className: p,
27
- style: f,
28
- id: u,
29
- testId: g,
30
- "data-testid": b
31
- }, _) => {
32
- const x = I(u), { minVal: r, maxVal: N } = v(() => {
33
- let e = 1 / 0, t = -1 / 0;
34
- for (const a of o)
35
- for (const i of a)
36
- i < e && (e = i), i > t && (t = i);
37
- return { minVal: e, maxVal: t };
38
- }, [o]), y = V(
39
- (e) => N === r ? 0.5 : (e - r) / (N - r),
40
- [r, N]
41
- );
42
- return /* @__PURE__ */ c(
15
+ data: t = C,
16
+ xLabels: s,
17
+ yLabels: i,
18
+ colors: v = V,
19
+ onCellClick: u,
20
+ cellSize: p = 32,
21
+ showValues: g = !1,
22
+ showLegend: A = !0,
23
+ showTooltip: F = !0,
24
+ responsive: H = !0,
25
+ min: $,
26
+ max: N,
27
+ cellGap: R = 2,
28
+ cellRadius: k = 3,
29
+ emptyColor: I = "var(--nice-bg-tertiary, #f1f5f9)",
30
+ formatValue: b,
31
+ xAxisLabel: x,
32
+ yAxisLabel: M,
33
+ className: D,
34
+ style: O,
35
+ id: P,
36
+ testId: S,
37
+ "data-testid": U
38
+ }, Y) => {
39
+ const q = J(P), [l, w] = Q(null), y = W(null);
40
+ X(() => {
41
+ const e = y.current;
42
+ if (!e)
43
+ return;
44
+ const n = (a) => {
45
+ const r = a.target.closest("[data-cell]");
46
+ r && w({ r: Number(r.dataset.r), c: Number(r.dataset.c) });
47
+ }, d = () => w(null);
48
+ return e.addEventListener("mouseover", n), e.addEventListener("focusin", n), e.addEventListener("mouseleave", d), () => {
49
+ e.removeEventListener("mouseover", n), e.removeEventListener("focusin", n), e.removeEventListener("mouseleave", d);
50
+ };
51
+ }, []);
52
+ const m = (e) => b ? b(e) : String(e), { lo: h, hi: _ } = Z(() => {
53
+ let e = 1 / 0, n = -1 / 0;
54
+ for (const d of t)
55
+ for (const a of d)
56
+ a == null || !Number.isFinite(a) || (e = Math.min(e, a), n = Math.max(n, a));
57
+ return { lo: $ ?? (Number.isFinite(e) ? e : 0), hi: N ?? (Number.isFinite(n) ? n : 1) };
58
+ }, [t, $, N]), B = (e) => _ === h ? 0.5 : (e - h) / (_ - h), f = t.reduce((e, n) => Math.max(e, n.length), 0), G = H ? `minmax(${p}px, 1fr)` : `${p}px`, E = l ? t[l.r]?.[l.c] ?? null : null;
59
+ return /* @__PURE__ */ o(
43
60
  "div",
44
61
  {
45
- ref: _,
46
- id: x,
47
- className: `nice-heatmap ${p || ""}`,
48
- style: f,
49
- "data-testid": b ?? g,
50
- children: /* @__PURE__ */ M("table", { className: "nice-heatmap__table", children: [
51
- l && /* @__PURE__ */ c("thead", { children: /* @__PURE__ */ M("tr", { children: [
52
- n && /* @__PURE__ */ c("th", {}),
53
- l.map((e, t) => /* @__PURE__ */ c("th", { className: "nice-heatmap__header", children: e }, t))
54
- ] }) }),
55
- /* @__PURE__ */ c("tbody", { children: o.map((e, t) => /* @__PURE__ */ M("tr", { children: [
56
- n && /* @__PURE__ */ c("th", { className: "nice-heatmap__row-label", children: n[t] }),
57
- e.map((a, i) => /* @__PURE__ */ c(
58
- "td",
62
+ ref: Y,
63
+ id: q,
64
+ className: `nice-heatmap ${D || ""}`,
65
+ style: O,
66
+ "data-testid": U ?? S,
67
+ children: [
68
+ x && /* @__PURE__ */ c("div", { className: "nice-heatmap__axis nice-heatmap__axis--x", children: x }),
69
+ /* @__PURE__ */ o("div", { className: "nice-heatmap__body", children: [
70
+ M && /* @__PURE__ */ c("div", { className: "nice-heatmap__axis nice-heatmap__axis--y", children: M }),
71
+ /* @__PURE__ */ o(
72
+ "div",
59
73
  {
60
- className: "nice-heatmap__cell",
74
+ ref: y,
75
+ className: "nice-heatmap__grid",
76
+ role: "table",
61
77
  style: {
62
- background: j(s[0], s[1], y(a)),
63
- width: d,
64
- height: d,
65
- textAlign: "center",
66
- color: y(a) > 0.6 ? "var(--nice-color-white, #fff)" : "var(--nice-text-primary, #333)",
67
- cursor: m ? "pointer" : void 0
78
+ gridTemplateColumns: `${i ? "auto " : ""}repeat(${f}, ${G})`,
79
+ gap: R
68
80
  },
69
- onClick: () => m?.(t, i, a),
70
- title: String(a),
71
- children: h ? a : ""
72
- },
73
- i
74
- ))
75
- ] }, t)) })
76
- ] })
81
+ children: [
82
+ s && /* @__PURE__ */ o("div", { role: "row", className: "nice-heatmap__row nice-heatmap__row--header", children: [
83
+ i && /* @__PURE__ */ c("span", {}),
84
+ Array.from({ length: f }, (e, n) => /* @__PURE__ */ c("span", { role: "columnheader", className: "nice-heatmap__header", children: s[n] ?? "" }, n))
85
+ ] }),
86
+ t.map((e, n) => /* @__PURE__ */ o("div", { role: "row", className: "nice-heatmap__row", children: [
87
+ i && /* @__PURE__ */ c("span", { role: "rowheader", className: "nice-heatmap__row-label", children: i[n] ?? "" }),
88
+ Array.from({ length: f }, (d, a) => {
89
+ const r = e[a] ?? null, T = r == null ? 0 : B(r), j = `${i?.[n] ?? `#${n + 1}`} × ${s?.[a] ?? `#${a + 1}`}: ${r == null ? "—" : m(r)}`;
90
+ return /* @__PURE__ */ c(
91
+ "span",
92
+ {
93
+ role: "cell",
94
+ "data-cell": "",
95
+ "data-r": n,
96
+ "data-c": a,
97
+ "aria-label": u ? void 0 : j,
98
+ className: `nice-heatmap__cell${l?.r === n && l?.c === a ? " nice-heatmap__cell--hover" : ""}`,
99
+ style: {
100
+ minHeight: p,
101
+ borderRadius: k,
102
+ background: r == null ? I : z(v, T),
103
+ color: T > 0.6 ? "var(--nice-color-white, #fff)" : "var(--nice-text-primary, #333)"
104
+ },
105
+ children: u ? /* @__PURE__ */ c(
106
+ "button",
107
+ {
108
+ type: "button",
109
+ className: "nice-heatmap__cell-btn",
110
+ "aria-label": j,
111
+ onClick: () => u(n, a, r),
112
+ children: g && r != null ? m(r) : ""
113
+ }
114
+ ) : g && r != null ? m(r) : ""
115
+ },
116
+ a
117
+ );
118
+ })
119
+ ] }, n))
120
+ ]
121
+ }
122
+ )
123
+ ] }),
124
+ F && l && /* @__PURE__ */ o("div", { className: "nice-heatmap__tooltip", role: "status", children: [
125
+ /* @__PURE__ */ o("strong", { children: [
126
+ i?.[l.r] ?? `#${l.r + 1}`,
127
+ " ×",
128
+ " ",
129
+ s?.[l.c] ?? `#${l.c + 1}`
130
+ ] }),
131
+ /* @__PURE__ */ c("span", { children: E == null ? "—" : m(E) })
132
+ ] }),
133
+ A && /* @__PURE__ */ o("div", { className: "nice-heatmap__legend", "aria-hidden": "true", children: [
134
+ /* @__PURE__ */ c("span", { children: m(h) }),
135
+ /* @__PURE__ */ c(
136
+ "span",
137
+ {
138
+ className: "nice-heatmap__legend-bar",
139
+ style: {
140
+ background: `linear-gradient(90deg, ${v.join(", ")})`
141
+ }
142
+ }
143
+ ),
144
+ /* @__PURE__ */ c("span", { children: m(_) })
145
+ ] })
146
+ ]
77
147
  }
78
148
  );
79
149
  }
@@ -81,5 +151,5 @@ const H = /* @__PURE__ */ Object.assign(
81
151
  { displayName: "NiceHeatMap" }
82
152
  );
83
153
  export {
84
- H as NiceHeatMap
154
+ ae as NiceHeatMap
85
155
  };