@nice2dev/ui 1.4.21 → 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,83 +1,112 @@
1
- import { jsx as t, jsxs as E } from "react/jsx-runtime";
2
- const R = ({
3
- value: n,
4
- min: a = 0,
5
- max: N = 100,
6
- width: d = 200,
7
- height: l = 200,
8
- startAngle: i = 225,
9
- endAngle: x = -45,
10
- color: _ = "var(--nice-color-primary, #3b82f6)",
11
- trackColor: A,
12
- label: h,
13
- formatValue: p,
14
- ranges: y,
1
+ import { jsx as c, jsxs as q } from "react/jsx-runtime";
2
+ const J = ({
3
+ value: a,
4
+ min: x = 0,
5
+ max: _ = 100,
6
+ width: s = 200,
7
+ height: i = 200,
8
+ startAngle: r = 225,
9
+ endAngle: h = -45,
10
+ color: A,
11
+ trackColor: C,
12
+ label: m,
13
+ formatValue: y,
14
+ ranges: M,
15
15
  className: L,
16
- style: W,
17
- testId: j,
18
- "data-testid": C
16
+ style: j,
17
+ testId: P,
18
+ "data-testid": R
19
19
  }) => {
20
- const c = d / 2, r = l / 2, o = Math.min(c, r) - 20, k = Math.max(0, Math.min(1, (n - a) / (N - a || 1))), m = (e) => e * Math.PI / 180, P = (i - x + 360) % 360 || 360, s = (e) => ({
21
- x: c + o * Math.cos(m(e)),
22
- y: r - o * Math.sin(m(e))
23
- }), f = (e, b) => {
24
- const g = s(e), v = s(b), w = (e - b + 360) % 360 > 180 ? 1 : 0;
25
- return `M${g.x},${g.y} A${o},${o} 0 ${w},1 ${v.x},${v.y}`;
26
- }, u = i - k * P, $ = s(u);
27
- let M = _;
28
- if (y) {
29
- for (const e of y)
30
- if (n >= e.start && n <= e.end) {
31
- M = e.color;
20
+ const w = A || "var(--nice-color-primary, #3b82f6)", o = s / 2, n = i / 2, p = Math.min(o, n), l = Math.max(4, p * 0.12), e = Math.max(8, p - l / 2 - 4), B = Math.max(2.5, e * 0.05), E = Math.max(3, e * 0.08), f = Math.min(40, Math.max(10, e * 0.34)), u = Math.min(18, Math.max(8, e * 0.17)), k = Math.max(0, Math.min(1, (a - x) / (_ - x || 1))), $ = (t) => t * Math.PI / 180, G = (r - h + 360) % 360 || 360, d = (t) => ({
21
+ x: o + e * Math.cos($(t)),
22
+ y: n - e * Math.sin($(t))
23
+ }), b = (t, z) => {
24
+ const N = d(t), S = d(z), I = (t - z + 360) % 360 > 180 ? 1 : 0;
25
+ return `M${N.x},${N.y} A${e},${e} 0 ${I},1 ${S.x},${S.y}`;
26
+ }, v = r - k * G, W = d(v);
27
+ let g = w;
28
+ if (M) {
29
+ for (const t of M)
30
+ if (a >= t.start && a <= t.end) {
31
+ g = t.color;
32
32
  break;
33
33
  }
34
34
  }
35
- return /* @__PURE__ */ t(
35
+ return /* @__PURE__ */ c(
36
36
  "div",
37
37
  {
38
38
  className: `nice-gauge nice-gauge--circular ${L || ""}`,
39
- style: W,
40
- "data-testid": C ?? j,
41
- children: /* @__PURE__ */ E("svg", { width: d, height: l, children: [
42
- /* @__PURE__ */ t(
43
- "path",
44
- {
45
- d: f(i, x),
46
- fill: "none",
47
- stroke: A || "var(--nice-border-color, #e2e8f0)",
48
- strokeWidth: 12,
49
- strokeLinecap: "round"
50
- }
51
- ),
52
- k > 0 && /* @__PURE__ */ t(
53
- "path",
54
- {
55
- d: f(i, u),
56
- fill: "none",
57
- stroke: M,
58
- strokeWidth: 12,
59
- strokeLinecap: "round"
60
- }
61
- ),
62
- /* @__PURE__ */ t(
63
- "line",
64
- {
65
- x1: c,
66
- y1: r,
67
- x2: $.x,
68
- y2: $.y,
69
- stroke: "var(--nice-text-primary, #333)",
70
- strokeWidth: 2,
71
- strokeLinecap: "round"
72
- }
73
- ),
74
- /* @__PURE__ */ t("circle", { cx: c, cy: r, r: 4, fill: "var(--nice-text-primary, #333)" }),
75
- /* @__PURE__ */ t("text", { x: c, y: r + o * 0.6, textAnchor: "middle", className: "nice-gauge__value", children: p ? p(n) : n }),
76
- h && /* @__PURE__ */ t("text", { x: c, y: r + o * 0.95, textAnchor: "middle", className: "nice-gauge__label", children: h })
77
- ] })
39
+ style: j,
40
+ "data-testid": R ?? P,
41
+ children: /* @__PURE__ */ q(
42
+ "svg",
43
+ {
44
+ width: s,
45
+ height: i,
46
+ viewBox: `0 0 ${s} ${i}`,
47
+ style: { maxWidth: "100%", height: "auto" },
48
+ children: [
49
+ /* @__PURE__ */ c(
50
+ "path",
51
+ {
52
+ d: b(r, h),
53
+ fill: "none",
54
+ stroke: C || "var(--nice-border-color, #e2e8f0)",
55
+ strokeWidth: l,
56
+ strokeLinecap: "round"
57
+ }
58
+ ),
59
+ k > 0 && /* @__PURE__ */ c(
60
+ "path",
61
+ {
62
+ d: b(r, v),
63
+ fill: "none",
64
+ stroke: g,
65
+ strokeWidth: l,
66
+ strokeLinecap: "round"
67
+ }
68
+ ),
69
+ /* @__PURE__ */ c(
70
+ "line",
71
+ {
72
+ x1: o,
73
+ y1: n,
74
+ x2: W.x,
75
+ y2: W.y,
76
+ stroke: "var(--nice-text-primary, #333)",
77
+ strokeWidth: B,
78
+ strokeLinecap: "round"
79
+ }
80
+ ),
81
+ /* @__PURE__ */ c("circle", { cx: o, cy: n, r: E, fill: "var(--nice-text-primary, #333)" }),
82
+ /* @__PURE__ */ c(
83
+ "text",
84
+ {
85
+ x: o,
86
+ y: n + e * 0.58,
87
+ textAnchor: "middle",
88
+ className: "nice-gauge__value",
89
+ style: { fontSize: f },
90
+ children: y ? y(a) : a
91
+ }
92
+ ),
93
+ m && /* @__PURE__ */ c(
94
+ "text",
95
+ {
96
+ x: o,
97
+ y: n + e * 0.58 + f * 0.5 + u * 1.1,
98
+ textAnchor: "middle",
99
+ className: "nice-gauge__label",
100
+ style: { fontSize: u },
101
+ children: m
102
+ }
103
+ )
104
+ ]
105
+ }
106
+ )
78
107
  }
79
108
  );
80
109
  };
81
110
  export {
82
- R as NiceCircularGauge
111
+ J as NiceCircularGauge
83
112
  };
@@ -1,147 +1,196 @@
1
- import { jsx as r, jsxs as N } from "react/jsx-runtime";
2
- const L = ({
3
- value: i,
4
- min: o = 0,
5
- max: g = 100,
6
- width: n = 300,
7
- height: c = 60,
8
- orientation: A = "horizontal",
9
- color: k = "var(--nice-color-primary, #3b82f6)",
10
- label: s,
11
- formatValue: x,
12
- ranges: y,
13
- showTicks: v = !0,
14
- tickCount: _ = 5,
15
- className: m,
16
- style: p,
17
- testId: $,
18
- "data-testid": h
1
+ import { jsx as t, jsxs as D } from "react/jsx-runtime";
2
+ const A = 16, I = 7, P = ({
3
+ value: x,
4
+ min: i = 0,
5
+ max: y = 100,
6
+ width: a = 300,
7
+ height: k = 60,
8
+ orientation: F = "horizontal",
9
+ color: J,
10
+ label: e,
11
+ labelPlacement: d = "bottom",
12
+ showValueLabel: f = !1,
13
+ formatValue: b,
14
+ ranges: H,
15
+ showTicks: _ = !0,
16
+ tickCount: K = 5,
17
+ className: L,
18
+ style: S,
19
+ testId: j,
20
+ "data-testid": C
19
21
  }) => {
20
- const u = A === "horizontal", t = u ? n - 40 : c - 40, a = Math.max(0, Math.min(1, (i - o) / (g - o || 1))), e = 10;
21
- let f = k;
22
- if (y) {
23
- for (const l of y)
24
- if (i >= l.start && i <= l.end) {
25
- f = l.color;
22
+ const Q = F === "horizontal", p = Math.max(0, Math.min(1, (x - i) / (y - i || 1))), n = 10, $ = b ? b(x) : String(x);
23
+ let B = J || "var(--nice-color-primary, #3b82f6)";
24
+ if (H) {
25
+ for (const c of H)
26
+ if (x >= c.start && x <= c.end) {
27
+ B = c.color;
26
28
  break;
27
29
  }
28
30
  }
29
- const z = Array.from(
30
- { length: _ },
31
- (l, d) => o + (g - o) * (d / (_ - 1))
32
- );
33
- if (u) {
34
- const l = s ? 14 : 0;
35
- return /* @__PURE__ */ r(
31
+ const R = Math.max(2, K), Y = Array.from({ length: R }, (c, s) => i + (y - i) * (s / (R - 1)));
32
+ if (Q) {
33
+ const c = e && d === "left", s = e && d === "top", O = e && d === "bottom", W = c ? Math.min(a * 0.35, e.length * I + 12) : 0, Z = (s ? A : 0) + (f ? 16 : 6), l = 20 + W, m = Math.max(20, a - 40 - W), o = Z + 8, X = o + n + 12, z = Math.max(k, X + (_ ? 4 : -8) + (O ? A + 4 : 4)), N = l + m * p;
34
+ return /* @__PURE__ */ t(
36
35
  "div",
37
36
  {
38
- className: `nice-gauge nice-gauge--linear ${m || ""}`,
39
- style: p,
40
- "data-testid": h ?? $,
41
- children: /* @__PURE__ */ N("svg", { width: n, height: c + l, children: [
42
- /* @__PURE__ */ r(
43
- "text",
44
- {
45
- x: 20 + t * a,
46
- y: 14,
47
- textAnchor: "middle",
48
- className: "nice-gauge__value",
49
- style: { fontSize: 12 },
50
- children: x ? x(i) : i
51
- }
52
- ),
53
- /* @__PURE__ */ r(
54
- "rect",
55
- {
56
- x: 20,
57
- y: c / 2 - e / 2,
58
- width: t,
59
- height: e,
60
- rx: 5,
61
- fill: "var(--nice-border-color, #e2e8f0)"
62
- }
63
- ),
64
- /* @__PURE__ */ r(
65
- "rect",
66
- {
67
- x: 20,
68
- y: c / 2 - e / 2,
69
- width: t * a,
70
- height: e,
71
- rx: 5,
72
- fill: f
73
- }
74
- ),
75
- /* @__PURE__ */ r(
76
- "polygon",
77
- {
78
- points: `${20 + t * a},${c / 2 - e / 2 - 2} ${20 + t * a - 5},${c / 2 - e / 2 - 8} ${20 + t * a + 5},${c / 2 - e / 2 - 8}`,
79
- fill: "var(--nice-text-primary, #333)"
80
- }
81
- ),
82
- v && z.map((d, b) => {
83
- const j = 20 + (d - o) / (g - o) * t;
84
- return /* @__PURE__ */ r(
85
- "text",
86
- {
87
- x: j,
88
- y: c / 2 + e / 2 + 12,
89
- textAnchor: "middle",
90
- className: "nice-gauge__tick",
91
- children: d
92
- },
93
- b
94
- );
95
- }),
96
- s && /* @__PURE__ */ r(
97
- "text",
98
- {
99
- x: n / 2,
100
- y: c + l - 2,
101
- textAnchor: "middle",
102
- className: "nice-gauge__label",
103
- children: s
104
- }
105
- )
106
- ] })
37
+ className: `nice-gauge nice-gauge--linear ${L || ""}`,
38
+ style: S,
39
+ "data-testid": C ?? j,
40
+ children: /* @__PURE__ */ D(
41
+ "svg",
42
+ {
43
+ width: a,
44
+ height: z,
45
+ viewBox: `0 0 ${a} ${z}`,
46
+ style: { maxWidth: "100%" },
47
+ children: [
48
+ s && /* @__PURE__ */ t("text", { x: l, y: 12, className: "nice-gauge__label", children: e }),
49
+ c && /* @__PURE__ */ t(
50
+ "text",
51
+ {
52
+ x: W + 8,
53
+ y: o + n / 2,
54
+ textAnchor: "end",
55
+ dominantBaseline: "middle",
56
+ className: "nice-gauge__label",
57
+ children: e
58
+ }
59
+ ),
60
+ f && /* @__PURE__ */ t(
61
+ "text",
62
+ {
63
+ x: N,
64
+ y: o - 10,
65
+ textAnchor: "middle",
66
+ className: "nice-gauge__value",
67
+ style: { fontSize: 12 },
68
+ children: $
69
+ }
70
+ ),
71
+ /* @__PURE__ */ t(
72
+ "rect",
73
+ {
74
+ x: l,
75
+ y: o,
76
+ width: m,
77
+ height: n,
78
+ rx: 5,
79
+ fill: "var(--nice-border-color, #e2e8f0)"
80
+ }
81
+ ),
82
+ /* @__PURE__ */ t(
83
+ "rect",
84
+ {
85
+ x: l,
86
+ y: o,
87
+ width: m * p,
88
+ height: n,
89
+ rx: 5,
90
+ fill: B
91
+ }
92
+ ),
93
+ /* @__PURE__ */ t(
94
+ "polygon",
95
+ {
96
+ points: `${N},${o - 2} ${N - 5},${o - 8} ${N + 5},${o - 8}`,
97
+ fill: "var(--nice-text-primary, #333)",
98
+ children: /* @__PURE__ */ t("title", { children: $ })
99
+ }
100
+ ),
101
+ _ && Y.map((q, T) => /* @__PURE__ */ t(
102
+ "text",
103
+ {
104
+ x: l + (q - i) / (y - i || 1) * m,
105
+ y: X,
106
+ textAnchor: "middle",
107
+ className: "nice-gauge__tick",
108
+ children: Math.round(q * 100) / 100
109
+ },
110
+ T
111
+ )),
112
+ O && /* @__PURE__ */ t(
113
+ "text",
114
+ {
115
+ x: l + m / 2,
116
+ y: z - 4,
117
+ textAnchor: "middle",
118
+ className: "nice-gauge__label",
119
+ children: e
120
+ }
121
+ )
122
+ ]
123
+ }
124
+ )
107
125
  }
108
126
  );
109
127
  }
110
- return /* @__PURE__ */ r(
128
+ const u = Math.max(a, k), h = Math.max(72, Math.min(a, k, 140)), E = e && d !== "bottom", G = e && d === "bottom", g = (E ? A + 4 : 0) + (f ? 18 : 8), U = G ? A + 8 : 8, v = Math.max(20, u - g - U), r = h / 2 - n / 2 - (_ ? 10 : 0), M = g + v * (1 - p);
129
+ return /* @__PURE__ */ t(
111
130
  "div",
112
131
  {
113
- className: `nice-gauge nice-gauge--linear nice-gauge--vertical ${m || ""}`,
114
- style: p,
115
- "data-testid": h ?? $,
116
- children: /* @__PURE__ */ N("svg", { width: n, height: c, children: [
117
- /* @__PURE__ */ r(
132
+ className: `nice-gauge nice-gauge--linear nice-gauge--vertical ${L || ""}`,
133
+ style: S,
134
+ "data-testid": C ?? j,
135
+ children: /* @__PURE__ */ D("svg", { width: h, height: u, viewBox: `0 0 ${h} ${u}`, style: { maxWidth: "100%" }, children: [
136
+ E && /* @__PURE__ */ t("text", { x: h / 2, y: 12, textAnchor: "middle", className: "nice-gauge__label", children: e }),
137
+ f && /* @__PURE__ */ t(
138
+ "text",
139
+ {
140
+ x: r + n / 2,
141
+ y: g - 6,
142
+ textAnchor: "middle",
143
+ className: "nice-gauge__value",
144
+ style: { fontSize: 12 },
145
+ children: $
146
+ }
147
+ ),
148
+ /* @__PURE__ */ t(
118
149
  "rect",
119
150
  {
120
- x: n / 2 - e / 2,
121
- y: 20,
122
- width: e,
123
- height: t,
151
+ x: r,
152
+ y: g,
153
+ width: n,
154
+ height: v,
124
155
  rx: 5,
125
156
  fill: "var(--nice-border-color, #e2e8f0)"
126
157
  }
127
158
  ),
128
- /* @__PURE__ */ r(
159
+ /* @__PURE__ */ t(
129
160
  "rect",
130
161
  {
131
- x: n / 2 - e / 2,
132
- y: 20 + t * (1 - a),
133
- width: e,
134
- height: t * a,
162
+ x: r,
163
+ y: M,
164
+ width: n,
165
+ height: v * p,
135
166
  rx: 5,
136
- fill: f
167
+ fill: B
137
168
  }
138
169
  ),
139
- /* @__PURE__ */ r("text", { x: n / 2, y: 14, textAnchor: "middle", className: "nice-gauge__value", children: x ? x(i) : i }),
140
- s && /* @__PURE__ */ r("text", { x: n / 2, y: c - 4, textAnchor: "middle", className: "nice-gauge__label", children: s })
170
+ /* @__PURE__ */ t(
171
+ "polygon",
172
+ {
173
+ points: `${r - 2},${M} ${r - 8},${M - 5} ${r - 8},${M + 5}`,
174
+ fill: "var(--nice-text-primary, #333)",
175
+ children: /* @__PURE__ */ t("title", { children: $ })
176
+ }
177
+ ),
178
+ _ && Y.map((c, s) => /* @__PURE__ */ t(
179
+ "text",
180
+ {
181
+ x: r + n + 6,
182
+ y: g + v * (1 - (c - i) / (y - i || 1)),
183
+ dominantBaseline: "middle",
184
+ className: "nice-gauge__tick",
185
+ children: Math.round(c * 100) / 100
186
+ },
187
+ s
188
+ )),
189
+ G && /* @__PURE__ */ t("text", { x: h / 2, y: u - 6, textAnchor: "middle", className: "nice-gauge__label", children: e })
141
190
  ] })
142
191
  }
143
192
  );
144
193
  };
145
194
  export {
146
- L as NiceLinearGauge
195
+ P as NiceLinearGauge
147
196
  };