@nice2dev/ui 1.4.22 → 1.4.23

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.
@@ -1,77 +1,112 @@
1
- import { jsx as e, jsxs as k } from "react/jsx-runtime";
2
- import { CHART_COLORS as E } from "./colors.mjs";
3
- const Y = [], G = 20, q = 10, w = 32, K = ({
4
- items: h = Y,
5
- min: y = 0,
6
- max: S = 100,
7
- width: M = 300,
8
- height: R = 300,
9
- startAngle: c = 225,
10
- endAngle: p = -45,
11
- formatValue: I,
12
- title: x,
13
- className: j,
1
+ import { jsx as e, jsxs as R, Fragment as w } from "react/jsx-runtime";
2
+ import { CHART_COLORS as r } from "./colors.mjs";
3
+ const J = [], H = 20, K = 10, Q = 32, V = ({
4
+ items: s = J,
5
+ min: f = 0,
6
+ max: j = 100,
7
+ width: x = 300,
8
+ height: p = 300,
9
+ startAngle: l = 225,
10
+ endAngle: g = -45,
11
+ formatValue: k,
12
+ title: _,
13
+ className: z,
14
14
  style: C,
15
- testId: H,
16
- "data-testid": O
15
+ testId: O,
16
+ "data-testid": P
17
17
  }) => {
18
- const o = (t) => t * Math.PI / 180, T = (c - p + 360) % 360 || 360, d = [o(c), o(p)], l = (t) => (c - t + 720) % 360 <= T, m = l(90) ? 1 : Math.max(0, ...d.map((t) => Math.sin(t))), f = l(270) ? 1 : Math.max(0, ...d.map((t) => -Math.sin(t))), u = l(180) ? 1 : Math.max(0, ...d.map((t) => -Math.cos(t))), g = l(0) ? 1 : Math.max(0, ...d.map((t) => Math.cos(t))), L = x ? w : 0, r = q + G / 2, W = M - 2 * r, A = R - L - 2 * r, s = Math.max(0, Math.min(W / (u + g || 1), A / (m + f || 1))), $ = r + u * s + (W - (u + g) * s) / 2, b = L + r + m * s + (A - (m + f) * s) / 2, v = Math.min(G, s / (h.length + 1)), P = 4, B = (t, n, a) => {
19
- const i = $ + t * Math.cos(o(n)), _ = b - t * Math.sin(o(n)), N = $ + t * Math.cos(o(a)), z = b - t * Math.sin(o(a)), X = (n - a + 360) % 360;
20
- return `M${i},${_} A${t},${t} 0 ${X > 180 ? 1 : 0},1 ${N},${z}`;
18
+ const h = (t) => t * Math.PI / 180, B = (l - g + 360) % 360 || 360, M = [h(l), h(g)], u = (t) => (l - t + 720) % 360 <= B, b = u(90) ? 1 : Math.max(0, ...M.map((t) => Math.sin(t))), A = u(270) ? 1 : Math.max(0, ...M.map((t) => -Math.sin(t))), v = u(180) ? 1 : Math.max(0, ...M.map((t) => -Math.cos(t))), I = u(0) ? 1 : Math.max(0, ...M.map((t) => Math.cos(t))), T = _ ? Q : 0, m = K + H / 2, W = x - 2 * m, L = p - T - 2 * m, c = Math.max(0, Math.min(W / (v + I || 1), L / (b + A || 1))), i = m + v * c + (W - (v + I) * c) / 2, $ = T + m + b * c + (L - (b + A) * c) / 2, d = Math.min(H, c / (s.length + 1)), S = 4, F = Math.max(
19
+ 0,
20
+ c - (s.length - 1) * (d + S) - d / 2 - 2
21
+ ), E = Math.min(20, Math.max(9, F * 1.5 / Math.max(1, s.length))), X = E / 1.3, G = (t, n, a) => {
22
+ const o = i + t * Math.cos(h(n)), y = $ - t * Math.sin(h(n)), N = i + t * Math.cos(h(a)), Y = $ - t * Math.sin(h(a)), q = (n - a + 360) % 360;
23
+ return `M${o},${y} A${t},${t} 0 ${q > 180 ? 1 : 0},1 ${N},${Y}`;
21
24
  };
22
25
  return /* @__PURE__ */ e(
23
26
  "div",
24
27
  {
25
- className: `nice-bargauge ${j || ""}`,
28
+ className: `nice-bargauge ${z || ""}`,
26
29
  style: C,
27
- "data-testid": O ?? H,
28
- children: /* @__PURE__ */ k("svg", { width: M, height: R, children: [
29
- x && /* @__PURE__ */ e("text", { x: M / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: x }),
30
- h.map((t, n) => {
31
- const a = s - n * (v + P), i = Math.max(0, Math.min(1, (t.value - y) / (S - y || 1))), _ = c - i * T, N = t.color || E[n % E.length];
32
- return /* @__PURE__ */ k("g", { children: [
33
- /* @__PURE__ */ e(
34
- "path",
35
- {
36
- d: B(a, c, p),
37
- fill: "none",
38
- stroke: "var(--nice-border-color, #e2e8f0)",
39
- strokeWidth: v,
40
- strokeLinecap: "round"
41
- }
42
- ),
43
- i > 0 && /* @__PURE__ */ e(
44
- "path",
45
- {
46
- d: B(a, c, _),
47
- fill: "none",
48
- stroke: N,
49
- strokeWidth: v,
50
- strokeLinecap: "round"
51
- }
52
- )
53
- ] }, n);
54
- }),
55
- /* @__PURE__ */ e("g", { children: h.map((t, n) => /* @__PURE__ */ k(
56
- "text",
57
- {
58
- x: $,
59
- y: b - ((h.length - 1) / 2 - n) * 16,
60
- textAnchor: "middle",
61
- dominantBaseline: "middle",
62
- className: "nice-gauge__value",
63
- style: { fontSize: 12 },
64
- children: [
65
- t.label ? `${t.label}: ` : "",
66
- I ? I(t.value) : t.value
67
- ]
68
- },
69
- n
70
- )) })
71
- ] })
30
+ "data-testid": P ?? O,
31
+ children: /* @__PURE__ */ R(
32
+ "svg",
33
+ {
34
+ width: x,
35
+ height: p,
36
+ viewBox: `0 0 ${x} ${p}`,
37
+ style: { maxWidth: "100%", height: "auto" },
38
+ children: [
39
+ _ && /* @__PURE__ */ e("text", { x: x / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: _ }),
40
+ s.map((t, n) => {
41
+ const a = c - n * (d + S), o = Math.max(0, Math.min(1, (t.value - f) / (j - f || 1))), y = l - o * B, N = t.color || r[n % r.length];
42
+ return /* @__PURE__ */ R("g", { children: [
43
+ /* @__PURE__ */ e(
44
+ "path",
45
+ {
46
+ d: G(a, l, g),
47
+ fill: "none",
48
+ stroke: "var(--nice-border-color, #e2e8f0)",
49
+ strokeWidth: d,
50
+ strokeLinecap: "round"
51
+ }
52
+ ),
53
+ o > 0 && /* @__PURE__ */ e(
54
+ "path",
55
+ {
56
+ d: G(a, l, y),
57
+ fill: "none",
58
+ stroke: N,
59
+ strokeWidth: d,
60
+ strokeLinecap: "round"
61
+ }
62
+ )
63
+ ] }, n);
64
+ }),
65
+ /* @__PURE__ */ e("g", { children: s.map((t, n) => {
66
+ const a = $ - ((s.length - 1) / 2 - n) * E, o = k ? k(t.value) : t.value;
67
+ return /* @__PURE__ */ e("g", { style: { fontSize: X }, children: t.label ? /* @__PURE__ */ R(w, { children: [
68
+ /* @__PURE__ */ e(
69
+ "text",
70
+ {
71
+ x: i - 3,
72
+ y: a,
73
+ textAnchor: "end",
74
+ dominantBaseline: "middle",
75
+ className: "nice-bargauge__label",
76
+ children: t.label
77
+ }
78
+ ),
79
+ /* @__PURE__ */ e(
80
+ "text",
81
+ {
82
+ x: i + 3,
83
+ y: a,
84
+ textAnchor: "start",
85
+ dominantBaseline: "middle",
86
+ className: "nice-gauge__value nice-bargauge__value",
87
+ style: { fill: t.color || r[n % r.length] },
88
+ children: o
89
+ }
90
+ )
91
+ ] }) : /* @__PURE__ */ e(
92
+ "text",
93
+ {
94
+ x: i,
95
+ y: a,
96
+ textAnchor: "middle",
97
+ dominantBaseline: "middle",
98
+ className: "nice-gauge__value nice-bargauge__value",
99
+ style: { fill: t.color || r[n % r.length] },
100
+ children: o
101
+ }
102
+ ) }, n);
103
+ }) })
104
+ ]
105
+ }
106
+ )
72
107
  }
73
108
  );
74
109
  };
75
110
  export {
76
- K as NiceBarGauge
111
+ V as NiceBarGauge
77
112
  };
@@ -1,4 +1,4 @@
1
- import { jsxs as y, jsx as r } from "react/jsx-runtime";
1
+ import { jsxs as y, jsx as e } from "react/jsx-runtime";
2
2
  import { useNiceTranslation as D } from "@nice2dev/ui-core";
3
3
  const F = {
4
4
  sm: { width: 160, height: 22, fontSize: 11 },
@@ -6,19 +6,19 @@ const F = {
6
6
  lg: { width: 320, height: 44, fontSize: 14 }
7
7
  }, T = ({
8
8
  value: b,
9
- target: o,
10
- min: h = 0,
9
+ target: c,
10
+ min: f = 0,
11
11
  max: v = 100,
12
- width: W,
13
- height: j,
14
- color: A = "var(--nice-color-primary, #3b82f6)",
12
+ width: $,
13
+ height: L,
14
+ color: j = "var(--nice-color-primary, #3b82f6)",
15
15
  targetColor: S = "var(--nice-color-error, #ef4444)",
16
- size: $ = "md",
17
- label: a,
16
+ size: A = "md",
17
+ label: g,
18
18
  labelPlacement: i = "top",
19
19
  showValue: C = !1,
20
20
  showTarget: x = !1,
21
- formatValue: w = (f) => String(f),
21
+ formatValue: w = (u) => String(u),
22
22
  state: E = "normal",
23
23
  errorMessage: I,
24
24
  className: k,
@@ -26,111 +26,116 @@ const F = {
26
26
  testId: _,
27
27
  "data-testid": M
28
28
  }) => {
29
- const { t: f } = D(), m = F[$], g = W ?? m.width, N = j ?? m.height, c = m.fontSize, t = 4, e = g - t * 2, n = x && o != null ? c + 4 : t, u = x && o != null ? N + (n - t) : N, s = u - n - t, l = Math.max(0, Math.min(1, (b - h) / (v - h || 1))), d = o != null ? Math.max(0, Math.min(1, (o - h) / (v - h || 1))) : null, R = () => E === "error" ? /* @__PURE__ */ r(
29
+ const { t: u } = D(), m = F[A], s = $ ?? m.width, N = L ?? m.height, o = m.fontSize, t = 4, r = s - t * 2, n = x && c != null ? o + 4 : t, l = x && c != null ? N + (n - t) : N, d = l - n - t, h = Math.max(0, Math.min(1, (b - f) / (v - f || 1))), a = c != null ? Math.max(0, Math.min(1, (c - f) / (v - f || 1))) : null, B = () => E === "error" ? /* @__PURE__ */ e(
30
30
  "div",
31
31
  {
32
32
  role: "alert",
33
33
  style: {
34
- width: g,
35
- height: u,
34
+ width: s,
35
+ height: l,
36
36
  display: "flex",
37
37
  alignItems: "center",
38
38
  justifyContent: "center",
39
39
  border: "1px dashed var(--nice-color-error, #ef4444)",
40
40
  borderRadius: 4,
41
41
  color: "var(--nice-color-error, #ef4444)",
42
- fontSize: c,
42
+ fontSize: o,
43
43
  padding: "0 8px",
44
44
  boxSizing: "border-box"
45
45
  },
46
- children: I ?? f("bullet.error", "Error")
46
+ children: I ?? u("bullet.error", "Error")
47
47
  }
48
- ) : E === "loading" ? /* @__PURE__ */ r(
48
+ ) : E === "loading" ? /* @__PURE__ */ e(
49
49
  "div",
50
50
  {
51
51
  role: "status",
52
- "aria-label": f("bullet.loading", "Loading"),
52
+ "aria-label": u("bullet.loading", "Loading"),
53
53
  className: "nice-bullet__skeleton",
54
54
  style: {
55
- width: g,
56
- height: u,
55
+ width: s,
56
+ height: l,
57
57
  borderRadius: 4,
58
58
  background: "linear-gradient(90deg, var(--nice-bg-tertiary, #e5e7eb) 25%, var(--nice-bg-secondary, #f3f4f6) 50%, var(--nice-bg-tertiary, #e5e7eb) 75%)",
59
59
  backgroundSize: "200% 100%",
60
60
  animation: "nice-bullet-shimmer 1.4s linear infinite"
61
61
  }
62
62
  }
63
- ) : /* @__PURE__ */ y(
64
- "svg",
65
- {
66
- width: g,
67
- height: u,
68
- role: "img",
69
- "aria-label": typeof a == "string" ? a : void 0,
70
- children: [
71
- /* @__PURE__ */ r(
72
- "rect",
73
- {
74
- x: t,
75
- y: n,
76
- width: e,
77
- height: s,
78
- rx: 3,
79
- fill: "var(--nice-border-color, #e2e8f0)"
80
- }
81
- ),
82
- /* @__PURE__ */ r(
83
- "rect",
84
- {
85
- x: t,
86
- y: n + s * 0.2,
87
- width: e * l,
88
- height: s * 0.6,
89
- rx: 2,
90
- fill: A
91
- }
92
- ),
93
- d != null && /* @__PURE__ */ r(
94
- "line",
95
- {
96
- x1: t + e * d,
97
- y1: n + 2,
98
- x2: t + e * d,
99
- y2: n + s - 2,
100
- stroke: S,
101
- strokeWidth: 2
102
- }
103
- ),
104
- C && /* @__PURE__ */ r(
105
- "text",
106
- {
107
- x: t + Math.max(e * l, 4),
108
- y: n + s / 2,
109
- dx: e * l > 24 ? -4 : 4,
110
- textAnchor: e * l > 24 ? "end" : "start",
111
- dominantBaseline: "middle",
112
- fontSize: c,
113
- fill: e * l > 24 ? "var(--nice-color-white, #ffffff)" : "var(--nice-text-primary)",
114
- fontWeight: 600,
115
- children: w(b)
116
- }
117
- ),
118
- x && d != null && /* @__PURE__ */ r(
119
- "text",
120
- {
121
- x: t + e * d,
122
- y: n - 2,
123
- textAnchor: "middle",
124
- fontSize: c - 1,
125
- fill: S,
126
- fontWeight: 600,
127
- children: w(o)
128
- }
129
- )
130
- ]
131
- }
63
+ ) : (
64
+ // 1.4.23 ("nieco bardziej responsywnym"): the drawing scales down with a narrow container
65
+ /* @__PURE__ */ y(
66
+ "svg",
67
+ {
68
+ width: s,
69
+ height: l,
70
+ viewBox: `0 0 ${s} ${l}`,
71
+ style: { maxWidth: "100%", height: "auto" },
72
+ role: "img",
73
+ "aria-label": typeof g == "string" ? g : void 0,
74
+ children: [
75
+ /* @__PURE__ */ e(
76
+ "rect",
77
+ {
78
+ x: t,
79
+ y: n,
80
+ width: r,
81
+ height: d,
82
+ rx: 3,
83
+ fill: "var(--nice-border-color, #e2e8f0)"
84
+ }
85
+ ),
86
+ /* @__PURE__ */ e(
87
+ "rect",
88
+ {
89
+ x: t,
90
+ y: n + d * 0.2,
91
+ width: r * h,
92
+ height: d * 0.6,
93
+ rx: 2,
94
+ fill: j
95
+ }
96
+ ),
97
+ a != null && /* @__PURE__ */ e(
98
+ "line",
99
+ {
100
+ x1: t + r * a,
101
+ y1: n + 2,
102
+ x2: t + r * a,
103
+ y2: n + d - 2,
104
+ stroke: S,
105
+ strokeWidth: 2
106
+ }
107
+ ),
108
+ C && /* @__PURE__ */ e(
109
+ "text",
110
+ {
111
+ x: t + Math.max(r * h, 4),
112
+ y: n + d / 2 + o * 0.08,
113
+ dx: r * h > 24 ? -4 : 4,
114
+ textAnchor: r * h > 24 ? "end" : "start",
115
+ dominantBaseline: "middle",
116
+ fontSize: o,
117
+ fill: r * h > 24 ? "var(--nice-color-white, #ffffff)" : "var(--nice-text-primary)",
118
+ fontWeight: 600,
119
+ children: w(b)
120
+ }
121
+ ),
122
+ x && a != null && /* @__PURE__ */ e(
123
+ "text",
124
+ {
125
+ x: t + r * a,
126
+ y: n - 2,
127
+ textAnchor: "middle",
128
+ fontSize: o - 1,
129
+ fill: S,
130
+ fontWeight: 600,
131
+ children: w(c)
132
+ }
133
+ )
134
+ ]
135
+ }
136
+ )
132
137
  );
133
- if (i === "none" || !a)
138
+ if (i === "none" || !g)
134
139
  return /* @__PURE__ */ y(
135
140
  "div",
136
141
  {
@@ -138,17 +143,17 @@ const F = {
138
143
  style: z,
139
144
  "data-testid": M ?? _,
140
145
  children: [
141
- R(),
142
- /* @__PURE__ */ r("style", { children: L })
146
+ B(),
147
+ /* @__PURE__ */ e("style", { children: W })
143
148
  ]
144
149
  }
145
150
  );
146
- const p = i === "top" || i === "bottom", B = /* @__PURE__ */ r(
151
+ const p = i === "top" || i === "bottom", R = /* @__PURE__ */ e(
147
152
  "span",
148
153
  {
149
154
  className: "nice-bullet__label",
150
155
  style: {
151
- fontSize: c,
156
+ fontSize: o,
152
157
  fontWeight: 600,
153
158
  color: "var(--nice-text-primary)",
154
159
  ...p ? {
@@ -158,7 +163,7 @@ const F = {
158
163
  ...i === "left" ? { marginRight: 8 } : {},
159
164
  ...i === "right" ? { marginLeft: 8 } : {}
160
165
  },
161
- children: a
166
+ children: g
162
167
  }
163
168
  );
164
169
  return /* @__PURE__ */ y(
@@ -173,14 +178,14 @@ const F = {
173
178
  },
174
179
  "data-testid": M ?? _,
175
180
  children: [
176
- (i === "top" || i === "left") && B,
177
- R(),
178
- (i === "bottom" || i === "right") && B,
179
- /* @__PURE__ */ r("style", { children: L })
181
+ (i === "top" || i === "left") && R,
182
+ B(),
183
+ (i === "bottom" || i === "right") && R,
184
+ /* @__PURE__ */ e("style", { children: W })
180
185
  ]
181
186
  }
182
187
  );
183
- }, L = `
188
+ }, W = `
184
189
  @keyframes nice-bullet-shimmer {
185
190
  0% { background-position: 200% 0; }
186
191
  100% { background-position: -200% 0; }