tekivex-ui 2.5.7 → 2.5.8
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/TkxForm-2tGLCPH6.js +326 -0
- package/dist/TkxForm-C2VqR2wC.cjs +12 -0
- package/dist/charts.cjs +1 -1
- package/dist/charts.js +264 -251
- package/dist/headless.cjs +1 -1
- package/dist/headless.js +21 -20
- package/dist/index-BgHMZe4Z.js +66 -0
- package/dist/index-Bt5y50Qa.cjs +1 -0
- package/dist/index-DnqXtpwV.cjs +2 -0
- package/dist/{index-CAXjeKoK.js → index-iUUHRxqJ.js} +77 -75
- package/dist/index.cjs +21 -21
- package/dist/index.js +24 -25
- package/dist/quantum.cjs +2 -2
- package/dist/quantum.js +4 -4
- package/dist/realtime.cjs +8 -4
- package/dist/realtime.js +391 -377
- package/dist/{security-loRa1HyV.js → security-C-ZPGoyG.js} +1 -1
- package/dist/{security-DMqZVW5d.cjs → security-Uf0mjv8o.cjs} +1 -1
- package/dist/src/charts/TkxDonutChart.d.ts.map +1 -1
- package/dist/src/charts/TkxPieChart.d.ts.map +1 -1
- package/dist/src/components/TkxForm.d.ts +17 -16
- package/dist/src/components/TkxForm.d.ts.map +1 -1
- package/dist/src/components/TkxLiveMetrics.d.ts.map +1 -1
- package/dist/src/components/TkxPlayground.d.ts.map +1 -1
- package/dist/src/components/TkxProgress.d.ts.map +1 -1
- package/dist/src/themes/index.d.ts.map +1 -1
- package/dist/{tkx-C_AlpMt4.js → tkx-BtHzWKTl.js} +1 -1
- package/dist/{tkx-69KQ0myA.cjs → tkx-C7GvVUE9.cjs} +1 -1
- package/package.json +5 -5
- package/src/charts/TkxDonutChart.tsx +6 -2
- package/src/charts/TkxPieChart.tsx +7 -3
- package/src/charts/shared.ts +4 -4
- package/src/components/TkxForm.tsx +35 -32
- package/src/components/TkxLiveMetrics.tsx +24 -2
- package/src/components/TkxPlayground.tsx +40 -5
- package/src/components/TkxProgress.tsx +0 -2
- package/src/themes/index.ts +8 -1
- package/dist/TkxForm-BK5Sq7oj.cjs +0 -12
- package/dist/TkxForm-br3i_vo8.js +0 -388
- package/dist/index-DB_m7X7e.cjs +0 -2
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { jsx as j, jsxs as R, Fragment as V } from "react/jsx-runtime";
|
|
2
|
+
import { useState as X, useRef as v, useCallback as m, useMemo as $, cloneElement as Z, useContext as J, createContext as O } from "react";
|
|
3
|
+
import { u as K } from "./index-iUUHRxqJ.js";
|
|
4
|
+
import { s as L } from "./security-C-ZPGoyG.js";
|
|
5
|
+
import { t as F, c as Y } from "./tkx-BtHzWKTl.js";
|
|
6
|
+
const W = O(null);
|
|
7
|
+
function ee() {
|
|
8
|
+
const e = J(W);
|
|
9
|
+
if (!e)
|
|
10
|
+
throw new Error("TkxFormField must be used inside a <TkxForm>. Wrap your fields in a TkxForm component.");
|
|
11
|
+
return e;
|
|
12
|
+
}
|
|
13
|
+
async function _(e, s) {
|
|
14
|
+
for (const t of s) {
|
|
15
|
+
if (t.required && (e == null || e === "" || Array.isArray(e) && e.length === 0))
|
|
16
|
+
return t.message ?? "This field is required";
|
|
17
|
+
if (!(e == null || e === "")) {
|
|
18
|
+
if (t.min !== void 0) {
|
|
19
|
+
if (typeof e == "string" && e.length < t.min)
|
|
20
|
+
return t.message ?? `Must be at least ${t.min} characters`;
|
|
21
|
+
if (typeof e == "number" && e < t.min)
|
|
22
|
+
return t.message ?? `Must be at least ${t.min}`;
|
|
23
|
+
}
|
|
24
|
+
if (t.max !== void 0) {
|
|
25
|
+
if (typeof e == "string" && e.length > t.max)
|
|
26
|
+
return t.message ?? `Must be no more than ${t.max} characters`;
|
|
27
|
+
if (typeof e == "number" && e > t.max)
|
|
28
|
+
return t.message ?? `Must be no more than ${t.max}`;
|
|
29
|
+
}
|
|
30
|
+
if (t.pattern && typeof e == "string" && !t.pattern.test(e))
|
|
31
|
+
return t.message ?? "Invalid format";
|
|
32
|
+
if (t.validator) {
|
|
33
|
+
const i = await t.validator(e);
|
|
34
|
+
if (i)
|
|
35
|
+
return i;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
function te(e, s) {
|
|
42
|
+
const t = e ? [...e] : [];
|
|
43
|
+
return s && !t.some((i) => i.required) && t.unshift({ required: !0, message: "This field is required" }), t;
|
|
44
|
+
}
|
|
45
|
+
function re(e) {
|
|
46
|
+
return e.some((s) => s.required);
|
|
47
|
+
}
|
|
48
|
+
function de() {
|
|
49
|
+
const e = J(W), s = v({}), t = v({}), i = v({}), b = $(() => ({
|
|
50
|
+
getFieldValue: (c) => s.current[c],
|
|
51
|
+
setFieldValue: (c, k) => {
|
|
52
|
+
s.current[c] = k;
|
|
53
|
+
},
|
|
54
|
+
getFieldsValue: () => ({ ...s.current }),
|
|
55
|
+
setFieldsValue: (c) => {
|
|
56
|
+
Object.assign(s.current, c);
|
|
57
|
+
},
|
|
58
|
+
validateFields: () => Promise.resolve({ ...s.current }),
|
|
59
|
+
validateField: (c) => Promise.resolve(!0),
|
|
60
|
+
resetFields: () => {
|
|
61
|
+
s.current = {}, t.current = {}, i.current = {};
|
|
62
|
+
},
|
|
63
|
+
getFieldError: (c) => t.current[c] ?? null,
|
|
64
|
+
isFieldTouched: (c) => i.current[c] ?? !1
|
|
65
|
+
}), []);
|
|
66
|
+
return e ? e.instance : b;
|
|
67
|
+
}
|
|
68
|
+
function se({
|
|
69
|
+
onSubmit: e,
|
|
70
|
+
onValuesChange: s,
|
|
71
|
+
initialValues: t = {},
|
|
72
|
+
layout: i = "vertical",
|
|
73
|
+
disabled: b = !1,
|
|
74
|
+
children: c,
|
|
75
|
+
className: k,
|
|
76
|
+
style: q,
|
|
77
|
+
form: E
|
|
78
|
+
}) {
|
|
79
|
+
const u = K(), [g, x] = X({
|
|
80
|
+
values: { ...t },
|
|
81
|
+
errors: {},
|
|
82
|
+
touched: {}
|
|
83
|
+
}), A = v(t), d = v({}), f = v(g);
|
|
84
|
+
f.current = g;
|
|
85
|
+
const M = m((r, n) => {
|
|
86
|
+
d.current[r] = n;
|
|
87
|
+
}, []), I = m((r) => {
|
|
88
|
+
delete d.current[r];
|
|
89
|
+
}, []), N = m((r, n) => {
|
|
90
|
+
x((o) => {
|
|
91
|
+
const l = {
|
|
92
|
+
...o,
|
|
93
|
+
values: { ...o.values, [r]: n }
|
|
94
|
+
};
|
|
95
|
+
return s == null || s({ [r]: n }, l.values), l;
|
|
96
|
+
});
|
|
97
|
+
}, [s]), z = m((r, n) => {
|
|
98
|
+
x((o) => ({
|
|
99
|
+
...o,
|
|
100
|
+
errors: { ...o.errors, [r]: n }
|
|
101
|
+
}));
|
|
102
|
+
}, []), y = m((r) => {
|
|
103
|
+
x((n) => ({
|
|
104
|
+
...n,
|
|
105
|
+
touched: { ...n.touched, [r]: !0 }
|
|
106
|
+
}));
|
|
107
|
+
}, []), w = m(async (r) => {
|
|
108
|
+
const n = d.current[r];
|
|
109
|
+
if (!n) return !0;
|
|
110
|
+
const o = f.current.values[r], l = await _(o, n.rules);
|
|
111
|
+
return x((h) => ({
|
|
112
|
+
...h,
|
|
113
|
+
errors: { ...h.errors, [r]: l },
|
|
114
|
+
touched: { ...h.touched, [r]: !0 }
|
|
115
|
+
})), l === null;
|
|
116
|
+
}, []), T = m(async () => {
|
|
117
|
+
const r = Object.keys(d.current), n = await Promise.all(
|
|
118
|
+
r.map(async (a) => {
|
|
119
|
+
const p = d.current[a], Q = f.current.values[a], U = await _(Q, p.rules);
|
|
120
|
+
return { name: a, error: U };
|
|
121
|
+
})
|
|
122
|
+
), o = {}, l = {};
|
|
123
|
+
let h = !1;
|
|
124
|
+
for (const { name: a, error: p } of n)
|
|
125
|
+
o[a] = p, l[a] = !0, p && (h = !0);
|
|
126
|
+
if (x((a) => ({
|
|
127
|
+
...a,
|
|
128
|
+
errors: { ...a.errors, ...o },
|
|
129
|
+
touched: { ...a.touched, ...l }
|
|
130
|
+
})), h) {
|
|
131
|
+
const a = Object.fromEntries(
|
|
132
|
+
n.filter((p) => p.error).map((p) => [p.name, p.error])
|
|
133
|
+
);
|
|
134
|
+
return Promise.reject(a);
|
|
135
|
+
}
|
|
136
|
+
return { ...f.current.values };
|
|
137
|
+
}, []), B = m(() => {
|
|
138
|
+
x({
|
|
139
|
+
values: { ...A.current },
|
|
140
|
+
errors: {},
|
|
141
|
+
touched: {}
|
|
142
|
+
});
|
|
143
|
+
}, []), C = $(() => ({
|
|
144
|
+
getFieldValue: (r) => f.current.values[r],
|
|
145
|
+
setFieldValue: N,
|
|
146
|
+
getFieldsValue: () => ({ ...f.current.values }),
|
|
147
|
+
setFieldsValue: (r) => {
|
|
148
|
+
x((n) => {
|
|
149
|
+
const o = { ...n.values, ...r };
|
|
150
|
+
return s == null || s(r, o), { ...n, values: o };
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
validateFields: T,
|
|
154
|
+
validateField: w,
|
|
155
|
+
resetFields: B,
|
|
156
|
+
getFieldError: (r) => f.current.errors[r] ?? null,
|
|
157
|
+
isFieldTouched: (r) => !!f.current.touched[r]
|
|
158
|
+
}), [N, T, w, B, s]), P = m(async (r) => {
|
|
159
|
+
r.preventDefault();
|
|
160
|
+
try {
|
|
161
|
+
const n = await T();
|
|
162
|
+
await (e == null ? void 0 : e(n));
|
|
163
|
+
} catch {
|
|
164
|
+
}
|
|
165
|
+
}, [T, e]), H = i === "inline" ? F("flex flex-row flex-wrap items-end gap-4") : F("flex flex-col gap-5"), S = E ?? C, D = $(() => ({
|
|
166
|
+
state: g,
|
|
167
|
+
initialValues: A.current,
|
|
168
|
+
layout: i,
|
|
169
|
+
disabled: b,
|
|
170
|
+
fieldMeta: d,
|
|
171
|
+
setFieldValue: N,
|
|
172
|
+
setFieldError: z,
|
|
173
|
+
setFieldTouched: y,
|
|
174
|
+
registerField: M,
|
|
175
|
+
unregisterField: I,
|
|
176
|
+
validateField: w,
|
|
177
|
+
instance: S
|
|
178
|
+
}), [g, i, b, N, z, y, M, I, w, S]);
|
|
179
|
+
return /* @__PURE__ */ j(W.Provider, { value: D, children: /* @__PURE__ */ j(
|
|
180
|
+
"form",
|
|
181
|
+
{
|
|
182
|
+
noValidate: !0,
|
|
183
|
+
role: "form",
|
|
184
|
+
"aria-label": "Form",
|
|
185
|
+
onSubmit: P,
|
|
186
|
+
className: Y(H, k),
|
|
187
|
+
style: {
|
|
188
|
+
color: u.text,
|
|
189
|
+
...q
|
|
190
|
+
},
|
|
191
|
+
children: c
|
|
192
|
+
}
|
|
193
|
+
) });
|
|
194
|
+
}
|
|
195
|
+
se.displayName = "TkxForm";
|
|
196
|
+
function ne({
|
|
197
|
+
name: e,
|
|
198
|
+
label: s,
|
|
199
|
+
rules: t,
|
|
200
|
+
help: i,
|
|
201
|
+
required: b,
|
|
202
|
+
children: c,
|
|
203
|
+
className: k,
|
|
204
|
+
style: q
|
|
205
|
+
}) {
|
|
206
|
+
const E = K(), u = ee(), { state: g, layout: x, disabled: A } = u, d = $(() => te(t, b), [t, b]), f = re(d), M = v({ rules: d });
|
|
207
|
+
M.current.rules = d;
|
|
208
|
+
const I = v(!1);
|
|
209
|
+
I.current || (u.registerField(e, M.current), I.current = !0), $(() => {
|
|
210
|
+
u.registerField(e, M.current);
|
|
211
|
+
}, [d, e, u]);
|
|
212
|
+
const N = g.values[e], z = g.touched[e] ? g.errors[e] ?? null : null, y = z ? L(z) : null, w = s ? L(s) : void 0, T = i ? L(i) : void 0, B = m(
|
|
213
|
+
(o) => {
|
|
214
|
+
let l;
|
|
215
|
+
if (o !== null && typeof o == "object" && "target" in o) {
|
|
216
|
+
const h = o.target;
|
|
217
|
+
l = h.type === "checkbox" ? h.checked : h.value;
|
|
218
|
+
} else
|
|
219
|
+
l = o;
|
|
220
|
+
u.setFieldValue(e, l);
|
|
221
|
+
},
|
|
222
|
+
[u, e]
|
|
223
|
+
), C = m(() => {
|
|
224
|
+
u.setFieldTouched(e), u.validateField(e);
|
|
225
|
+
}, [u, e]), P = Z(c, {
|
|
226
|
+
value: N ?? "",
|
|
227
|
+
onChange: B,
|
|
228
|
+
onBlur: C,
|
|
229
|
+
error: y ?? void 0,
|
|
230
|
+
isInvalid: !!y,
|
|
231
|
+
isRequired: f,
|
|
232
|
+
disabled: A || c.props.disabled,
|
|
233
|
+
name: e
|
|
234
|
+
}), H = x === "horizontal", S = x === "inline", D = /* @__PURE__ */ j("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ j("path", { d: "M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z" }) }), r = w ? /* @__PURE__ */ R(
|
|
235
|
+
"label",
|
|
236
|
+
{
|
|
237
|
+
className: F(
|
|
238
|
+
"text-sm font-medium font-sans",
|
|
239
|
+
H ? "min-w-[140px] pt-2.5" : ""
|
|
240
|
+
),
|
|
241
|
+
style: { color: E.text },
|
|
242
|
+
children: [
|
|
243
|
+
w,
|
|
244
|
+
f && /* @__PURE__ */ j("span", { "aria-hidden": "true", className: F("ml-1"), style: { color: E.danger }, children: "*" })
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
) : null, n = /* @__PURE__ */ R(V, { children: [
|
|
248
|
+
T && !y && /* @__PURE__ */ j("span", { className: F("text-xs mt-0.5"), style: { color: E.textMuted }, children: T }),
|
|
249
|
+
y && /* @__PURE__ */ R(
|
|
250
|
+
"span",
|
|
251
|
+
{
|
|
252
|
+
role: "alert",
|
|
253
|
+
className: F("text-xs flex items-center gap-1 mt-0.5"),
|
|
254
|
+
style: {
|
|
255
|
+
color: E.danger,
|
|
256
|
+
animation: "tkxFormErrorReveal 200ms ease-out"
|
|
257
|
+
},
|
|
258
|
+
children: [
|
|
259
|
+
D,
|
|
260
|
+
y
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
)
|
|
264
|
+
] });
|
|
265
|
+
return S ? /* @__PURE__ */ R(
|
|
266
|
+
"div",
|
|
267
|
+
{
|
|
268
|
+
className: Y(F("flex flex-col gap-1"), k),
|
|
269
|
+
style: q,
|
|
270
|
+
children: [
|
|
271
|
+
r,
|
|
272
|
+
P,
|
|
273
|
+
n
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
) : H ? /* @__PURE__ */ R(
|
|
277
|
+
"div",
|
|
278
|
+
{
|
|
279
|
+
className: Y(F("flex flex-row gap-4 items-start"), k),
|
|
280
|
+
style: q,
|
|
281
|
+
children: [
|
|
282
|
+
r,
|
|
283
|
+
/* @__PURE__ */ R("div", { className: F("flex flex-col gap-1 flex-1 min-w-0"), children: [
|
|
284
|
+
P,
|
|
285
|
+
n
|
|
286
|
+
] })
|
|
287
|
+
]
|
|
288
|
+
}
|
|
289
|
+
) : /* @__PURE__ */ R(
|
|
290
|
+
"div",
|
|
291
|
+
{
|
|
292
|
+
className: Y(F("flex flex-col gap-1"), k),
|
|
293
|
+
style: q,
|
|
294
|
+
children: [
|
|
295
|
+
r,
|
|
296
|
+
P,
|
|
297
|
+
n
|
|
298
|
+
]
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
ne.displayName = "TkxFormField";
|
|
303
|
+
let G = !1;
|
|
304
|
+
function oe() {
|
|
305
|
+
if (G || typeof document > "u") return;
|
|
306
|
+
G = !0;
|
|
307
|
+
const e = document.createElement("style");
|
|
308
|
+
e.setAttribute("data-tkx-form", ""), e.textContent = `
|
|
309
|
+
@keyframes tkxFormErrorReveal {
|
|
310
|
+
from {
|
|
311
|
+
opacity: 0;
|
|
312
|
+
transform: translateY(-4px);
|
|
313
|
+
}
|
|
314
|
+
to {
|
|
315
|
+
opacity: 1;
|
|
316
|
+
transform: translateY(0);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
`, document.head.appendChild(e);
|
|
320
|
+
}
|
|
321
|
+
oe();
|
|
322
|
+
export {
|
|
323
|
+
se as T,
|
|
324
|
+
ne as a,
|
|
325
|
+
de as u
|
|
326
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";const a=require("react/jsx-runtime"),s=require("react"),L=require("./index-DnqXtpwV.cjs"),B=require("./security-Uf0mjv8o.cjs"),u=require("./tkx-C7GvVUE9.cjs"),H=s.createContext(null);function K(){const e=s.useContext(H);if(!e)throw new Error("TkxFormField must be used inside a <TkxForm>. Wrap your fields in a TkxForm component.");return e}async function Y(e,n){for(const t of n){if(t.required&&(e==null||e===""||Array.isArray(e)&&e.length===0))return t.message??"This field is required";if(!(e==null||e==="")){if(t.min!==void 0){if(typeof e=="string"&&e.length<t.min)return t.message??`Must be at least ${t.min} characters`;if(typeof e=="number"&&e<t.min)return t.message??`Must be at least ${t.min}`}if(t.max!==void 0){if(typeof e=="string"&&e.length>t.max)return t.message??`Must be no more than ${t.max} characters`;if(typeof e=="number"&&e>t.max)return t.message??`Must be no more than ${t.max}`}if(t.pattern&&typeof e=="string"&&!t.pattern.test(e))return t.message??"Invalid format";if(t.validator){const i=await t.validator(e);if(i)return i}}}return null}function Q(e,n){const t=e?[...e]:[];return n&&!t.some(i=>i.required)&&t.unshift({required:!0,message:"This field is required"}),t}function U(e){return e.some(n=>n.required)}function V(){const e=s.useContext(H),n=s.useRef({}),t=s.useRef({}),i=s.useRef({}),b=s.useMemo(()=>({getFieldValue:l=>n.current[l],setFieldValue:(l,R)=>{n.current[l]=R},getFieldsValue:()=>({...n.current}),setFieldsValue:l=>{Object.assign(n.current,l)},validateFields:()=>Promise.resolve({...n.current}),validateField:l=>Promise.resolve(!0),resetFields:()=>{n.current={},t.current={},i.current={}},getFieldError:l=>t.current[l]??null,isFieldTouched:l=>i.current[l]??!1}),[]);return e?e.instance:b}function W({onSubmit:e,onValuesChange:n,initialValues:t={},layout:i="vertical",disabled:b=!1,children:l,className:R,style:M,form:T}){const m=L.useTheme(),[y,F]=s.useState({values:{...t},errors:{},touched:{}}),z=s.useRef(t),x=s.useRef({}),h=s.useRef(y);h.current=y;const w=s.useCallback((r,o)=>{x.current[r]=o},[]),q=s.useCallback(r=>{delete x.current[r]},[]),E=s.useCallback((r,o)=>{F(c=>{const d={...c,values:{...c.values,[r]:o}};return n==null||n({[r]:o},d.values),d})},[n]),C=s.useCallback((r,o)=>{F(c=>({...c,errors:{...c.errors,[r]:o}}))},[]),p=s.useCallback(r=>{F(o=>({...o,touched:{...o.touched,[r]:!0}}))},[]),v=s.useCallback(async r=>{const o=x.current[r];if(!o)return!0;const c=h.current.values[r],d=await Y(c,o.rules);return F(k=>({...k,errors:{...k.errors,[r]:d},touched:{...k.touched,[r]:!0}})),d===null},[]),j=s.useCallback(async()=>{const r=Object.keys(x.current),o=await Promise.all(r.map(async f=>{const g=x.current[f],G=h.current.values[f],J=await Y(G,g.rules);return{name:f,error:J}})),c={},d={};let k=!1;for(const{name:f,error:g}of o)c[f]=g,d[f]=!0,g&&(k=!0);if(F(f=>({...f,errors:{...f.errors,...c},touched:{...f.touched,...d}})),k){const f=Object.fromEntries(o.filter(g=>g.error).map(g=>[g.name,g.error]));return Promise.reject(f)}return{...h.current.values}},[]),I=s.useCallback(()=>{F({values:{...z.current},errors:{},touched:{}})},[]),$=s.useMemo(()=>({getFieldValue:r=>h.current.values[r],setFieldValue:E,getFieldsValue:()=>({...h.current.values}),setFieldsValue:r=>{F(o=>{const c={...o.values,...r};return n==null||n(r,c),{...o,values:c}})},validateFields:j,validateField:v,resetFields:I,getFieldError:r=>h.current.errors[r]??null,isFieldTouched:r=>!!h.current.touched[r]}),[E,j,v,I,n]),N=s.useCallback(async r=>{r.preventDefault();try{const o=await j();await(e==null?void 0:e(o))}catch{}},[j,e]),P=i==="inline"?u.tkx("flex flex-row flex-wrap items-end gap-4"):u.tkx("flex flex-col gap-5"),S=T??$,A=s.useMemo(()=>({state:y,initialValues:z.current,layout:i,disabled:b,fieldMeta:x,setFieldValue:E,setFieldError:C,setFieldTouched:p,registerField:w,unregisterField:q,validateField:v,instance:S}),[y,i,b,E,C,p,w,q,v,S]);return a.jsx(H.Provider,{value:A,children:a.jsx("form",{noValidate:!0,role:"form","aria-label":"Form",onSubmit:N,className:u.cx(P,R),style:{color:m.text,...M},children:l})})}W.displayName="TkxForm";function _({name:e,label:n,rules:t,help:i,required:b,children:l,className:R,style:M}){const T=L.useTheme(),m=K(),{state:y,layout:F,disabled:z}=m,x=s.useMemo(()=>Q(t,b),[t,b]),h=U(x),w=s.useRef({rules:x});w.current.rules=x;const q=s.useRef(!1);q.current||(m.registerField(e,w.current),q.current=!0),s.useMemo(()=>{m.registerField(e,w.current)},[x,e,m]);const E=y.values[e],C=y.touched[e]?y.errors[e]??null:null,p=C?B.sanitizeString(C):null,v=n?B.sanitizeString(n):void 0,j=i?B.sanitizeString(i):void 0,I=s.useCallback(c=>{let d;if(c!==null&&typeof c=="object"&&"target"in c){const k=c.target;d=k.type==="checkbox"?k.checked:k.value}else d=c;m.setFieldValue(e,d)},[m,e]),$=s.useCallback(()=>{m.setFieldTouched(e),m.validateField(e)},[m,e]),N=s.cloneElement(l,{value:E??"",onChange:I,onBlur:$,error:p??void 0,isInvalid:!!p,isRequired:h,disabled:z||l.props.disabled,name:e}),P=F==="horizontal",S=F==="inline",A=a.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:a.jsx("path",{d:"M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"})}),r=v?a.jsxs("label",{className:u.tkx("text-sm font-medium font-sans",P?"min-w-[140px] pt-2.5":""),style:{color:T.text},children:[v,h&&a.jsx("span",{"aria-hidden":"true",className:u.tkx("ml-1"),style:{color:T.danger},children:"*"})]}):null,o=a.jsxs(a.Fragment,{children:[j&&!p&&a.jsx("span",{className:u.tkx("text-xs mt-0.5"),style:{color:T.textMuted},children:j}),p&&a.jsxs("span",{role:"alert",className:u.tkx("text-xs flex items-center gap-1 mt-0.5"),style:{color:T.danger,animation:"tkxFormErrorReveal 200ms ease-out"},children:[A,p]})]});return S?a.jsxs("div",{className:u.cx(u.tkx("flex flex-col gap-1"),R),style:M,children:[r,N,o]}):P?a.jsxs("div",{className:u.cx(u.tkx("flex flex-row gap-4 items-start"),R),style:M,children:[r,a.jsxs("div",{className:u.tkx("flex flex-col gap-1 flex-1 min-w-0"),children:[N,o]})]}):a.jsxs("div",{className:u.cx(u.tkx("flex flex-col gap-1"),R),style:M,children:[r,N,o]})}_.displayName="TkxFormField";let D=!1;function X(){if(D||typeof document>"u")return;D=!0;const e=document.createElement("style");e.setAttribute("data-tkx-form",""),e.textContent=`
|
|
2
|
+
@keyframes tkxFormErrorReveal {
|
|
3
|
+
from {
|
|
4
|
+
opacity: 0;
|
|
5
|
+
transform: translateY(-4px);
|
|
6
|
+
}
|
|
7
|
+
to {
|
|
8
|
+
opacity: 1;
|
|
9
|
+
transform: translateY(0);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`,document.head.appendChild(e)}X();exports.TkxForm=W;exports.TkxFormField=_;exports.useTkxForm=V;
|
package/dist/charts.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("recharts"),g=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("recharts"),g=require("./index-DnqXtpwV.cjs"),L=require("react"),M=require("./index-Bt5y50Qa.cjs");function C(r){return[r.primary,r.secondary,r.info,r.success,r.warning,r.danger,r.primary+"aa",r.secondary+"aa",r.info+"aa",r.success+"aa"]}const A={top:10,right:30,bottom:10,left:0};function T(r){return{contentStyle:{backgroundColor:r.surface,border:`1px solid ${r.border}`,borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",color:r.text,fontSize:13},labelStyle:{color:r.textMuted,fontWeight:600,marginBottom:4},itemStyle:{color:r.text},cursor:{fill:`${r.primary}15`}}}function z({data:r,series:S,xKey:k,height:p=300,margin:d=A,showGrid:u=!0,showLegend:m=!0,showTooltip:j=!0,smooth:l=!0,xTickFormatter:y,yTickFormatter:a,yDomain:n,ariaLabel:h="Area chart"}){const i=g.useTheme(),s=C(i),o=T(i),f={fill:i.textMuted,fontSize:12};return e.jsx("div",{role:"img","aria-label":h,style:{width:"100%",height:p},children:e.jsx(t.ResponsiveContainer,{width:"100%",height:"100%",children:e.jsxs(t.AreaChart,{data:r,margin:d,children:[u&&e.jsx(t.CartesianGrid,{strokeDasharray:"3 3",stroke:i.border,vertical:!1}),e.jsx(t.XAxis,{dataKey:k,tick:f,axisLine:{stroke:i.border},tickLine:!1,tickFormatter:y}),e.jsx(t.YAxis,{tick:f,axisLine:!1,tickLine:!1,tickFormatter:a,domain:n}),j&&e.jsx(t.Tooltip,{contentStyle:o.contentStyle,labelStyle:o.labelStyle,itemStyle:o.itemStyle,cursor:o.cursor}),m&&e.jsx(t.Legend,{wrapperStyle:{fontSize:13,color:i.textMuted,paddingTop:8}}),S.map((x,b)=>{const c=x.color??s[b%s.length];return e.jsx(t.Area,{type:l?"monotone":"linear",dataKey:x.key,name:x.label??x.key,stroke:c,strokeWidth:2,fill:c,fillOpacity:x.fillOpacity??.2,stackId:x.stacked?"stack":void 0,dot:!1,activeDot:{r:5,strokeWidth:0}},x.key)})]})})})}function R({data:r,series:S,xKey:k,height:p=300,margin:d=A,showGrid:u=!0,showLegend:m=!0,showTooltip:j=!0,layout:l="horizontal",barSize:y,xTickFormatter:a,yTickFormatter:n,ariaLabel:h="Bar chart"}){const i=g.useTheme(),s=C(i),o=T(i),f={fill:i.textMuted,fontSize:12},x=l==="vertical";return e.jsx("div",{role:"img","aria-label":h,style:{width:"100%",height:p},children:e.jsx(t.ResponsiveContainer,{width:"100%",height:"100%",children:e.jsxs(t.BarChart,{data:r,margin:d,layout:l,children:[u&&e.jsx(t.CartesianGrid,{strokeDasharray:"3 3",stroke:i.border,vertical:x,horizontal:!x}),x?e.jsxs(e.Fragment,{children:[e.jsx(t.YAxis,{dataKey:k,type:"category",tick:f,axisLine:!1,tickLine:!1,tickFormatter:a,width:100}),e.jsx(t.XAxis,{type:"number",tick:f,axisLine:{stroke:i.border},tickLine:!1,tickFormatter:n})]}):e.jsxs(e.Fragment,{children:[e.jsx(t.XAxis,{dataKey:k,tick:f,axisLine:{stroke:i.border},tickLine:!1,tickFormatter:a}),e.jsx(t.YAxis,{tick:f,axisLine:!1,tickLine:!1,tickFormatter:n})]}),j&&e.jsx(t.Tooltip,{contentStyle:o.contentStyle,labelStyle:o.labelStyle,itemStyle:o.itemStyle,cursor:{fill:`${i.surfaceAlt}`}}),m&&e.jsx(t.Legend,{wrapperStyle:{fontSize:13,color:i.textMuted,paddingTop:8}}),S.map((b,c)=>{const v=b.color??s[c%s.length];return e.jsx(t.Bar,{dataKey:b.key,name:b.label??b.key,fill:v,stackId:b.stackId,maxBarSize:y??40,radius:b.radius??[4,4,0,0]},b.key)})]})})})}function F({data:r,series:S,xKey:k,height:p=300,margin:d=A,showGrid:u=!0,showLegend:m=!0,showTooltip:j=!0,smooth:l=!0,referenceLines:y=[],xTickFormatter:a,yTickFormatter:n,yDomain:h,connectNulls:i=!1,ariaLabel:s="Line chart"}){const o=g.useTheme(),f=C(o),x=T(o),b={fill:o.textMuted,fontSize:12};return e.jsx("div",{role:"img","aria-label":s,style:{width:"100%",height:p},children:e.jsx(t.ResponsiveContainer,{width:"100%",height:"100%",children:e.jsxs(t.LineChart,{data:r,margin:d,children:[u&&e.jsx(t.CartesianGrid,{strokeDasharray:"3 3",stroke:o.border,vertical:!1}),e.jsx(t.XAxis,{dataKey:k,tick:b,axisLine:{stroke:o.border},tickLine:!1,tickFormatter:a}),e.jsx(t.YAxis,{tick:b,axisLine:!1,tickLine:!1,tickFormatter:n,domain:h}),j&&e.jsx(t.Tooltip,{contentStyle:x.contentStyle,labelStyle:x.labelStyle,itemStyle:x.itemStyle,cursor:{stroke:o.border,strokeWidth:1}}),m&&e.jsx(t.Legend,{wrapperStyle:{fontSize:13,color:o.textMuted,paddingTop:8}}),y.map((c,v)=>e.jsx(t.ReferenceLine,{y:c.y,x:c.x,label:c.label?{value:c.label,fill:o.textMuted,fontSize:11}:void 0,stroke:c.color??o.border,strokeDasharray:c.dashed?"4 4":void 0},v)),S.map((c,v)=>{const w=c.color??f[v%f.length];return e.jsx(t.Line,{type:l?"monotone":"linear",dataKey:c.key,name:c.label??c.key,stroke:w,strokeWidth:c.strokeWidth??2,strokeDasharray:c.dashed?"6 3":void 0,dot:c.dot??!1,activeDot:{r:5,strokeWidth:0,fill:w},connectNulls:i},c.key)})]})})})}function D({data:r,height:S=300,showLegend:k=!0,showTooltip:p=!0,showLabels:d=!1,outerRadius:u="70%",startAngle:m=90,ariaLabel:j="Pie chart"}){const l=g.useTheme(),y=M.useReducedMotion(),a=C(l),n=T(l),[h,i]=L.useState(y);return L.useEffect(()=>{if(y){i(!0);return}const s=requestAnimationFrame(()=>i(!0));return()=>cancelAnimationFrame(s)},[y]),e.jsx("div",{role:"img","aria-label":j,style:{width:"100%",minWidth:240,height:S,position:"relative"},children:h&&e.jsx(t.ResponsiveContainer,{width:"100%",height:"100%",debounce:50,children:e.jsxs(t.PieChart,{children:[p&&e.jsx(t.Tooltip,{contentStyle:n.contentStyle,labelStyle:n.labelStyle,itemStyle:n.itemStyle}),k&&e.jsx(t.Legend,{wrapperStyle:{fontSize:13,color:l.textMuted}}),e.jsx(t.Pie,{data:r,dataKey:"value",nameKey:"name",outerRadius:u,startAngle:m,endAngle:m-360,label:d?({name:s,percent:o})=>`${s} (${(o*100).toFixed(0)}%)`:void 0,labelLine:d,strokeWidth:2,stroke:l.bg,children:r.map((s,o)=>e.jsx(t.Cell,{fill:s.color??a[o%a.length]},s.name))})]})})})}function K({data:r,height:S=300,showLegend:k=!0,showTooltip:p=!0,centerLabel:d,centerSublabel:u,innerRadius:m="55%",outerRadius:j="75%",startAngle:l=90,ariaLabel:y="Donut chart"}){const a=g.useTheme(),n=M.useReducedMotion(),h=C(a),i=T(a),[s,o]=L.useState(n);return L.useEffect(()=>{if(n){o(!0);return}const f=requestAnimationFrame(()=>o(!0));return()=>cancelAnimationFrame(f)},[n]),e.jsxs("div",{role:"img","aria-label":y,style:{width:"100%",minWidth:240,height:S,position:"relative"},children:[s&&e.jsx(t.ResponsiveContainer,{width:"100%",height:"100%",debounce:50,children:e.jsxs(t.PieChart,{children:[p&&e.jsx(t.Tooltip,{contentStyle:i.contentStyle,labelStyle:i.labelStyle,itemStyle:i.itemStyle}),k&&e.jsx(t.Legend,{wrapperStyle:{fontSize:13,color:a.textMuted}}),e.jsx(t.Pie,{data:r,dataKey:"value",nameKey:"name",innerRadius:m,outerRadius:j,startAngle:l,endAngle:l-360,strokeWidth:3,stroke:a.bg,label:!1,labelLine:!1,children:r.map((f,x)=>e.jsx(t.Cell,{fill:f.color??h[x%h.length]},f.name))}),(d||u)&&e.jsx("text",{})]})}),(d||u)&&e.jsxs("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",pointerEvents:"none",marginTop:k?-24:0},children:[d&&e.jsx("span",{style:{fontSize:22,fontWeight:700,color:a.text,lineHeight:1},children:d}),u&&e.jsx("span",{style:{fontSize:13,color:a.textMuted,marginTop:4},children:u})]})]})}function W({series:r,height:S=300,margin:k=A,showGrid:p=!0,showLegend:d=!0,showTooltip:u=!0,xTickFormatter:m,yTickFormatter:j,zRange:l=[20,400],ariaLabel:y="Scatter chart"}){const a=g.useTheme(),n=C(a),h=T(a),i={fill:a.textMuted,fontSize:12};return e.jsx("div",{role:"img","aria-label":y,style:{width:"100%",height:S},children:e.jsx(t.ResponsiveContainer,{width:"100%",height:"100%",children:e.jsxs(t.ScatterChart,{margin:k,children:[p&&e.jsx(t.CartesianGrid,{strokeDasharray:"3 3",stroke:a.border}),e.jsx(t.XAxis,{type:"number",dataKey:"x",tick:i,axisLine:{stroke:a.border},tickLine:!1,tickFormatter:m}),e.jsx(t.YAxis,{type:"number",dataKey:"y",tick:i,axisLine:!1,tickLine:!1,tickFormatter:j}),e.jsx(t.ZAxis,{type:"number",dataKey:"z",range:l}),u&&e.jsx(t.Tooltip,{contentStyle:h.contentStyle,labelStyle:h.labelStyle,itemStyle:h.itemStyle,cursor:{strokeDasharray:"3 3"}}),d&&e.jsx(t.Legend,{wrapperStyle:{fontSize:13,color:a.textMuted,paddingTop:8}}),r.map((s,o)=>e.jsx(t.Scatter,{name:s.name,data:s.data,fill:s.color??n[o%n.length],fillOpacity:.8},s.name??o))]})})})}function P({data:r,series:S,angleKey:k,height:p=300,showLegend:d=!0,showTooltip:u=!0,outerRadius:m="70%",ariaLabel:j="Radar chart"}){const l=g.useTheme(),y=C(l),a=T(l);return e.jsx("div",{role:"img","aria-label":j,style:{width:"100%",height:p},children:e.jsx(t.ResponsiveContainer,{width:"100%",height:"100%",children:e.jsxs(t.RadarChart,{data:r,outerRadius:m,children:[e.jsx(t.PolarGrid,{stroke:l.border}),e.jsx(t.PolarAngleAxis,{dataKey:k,tick:{fill:l.textMuted,fontSize:12}}),e.jsx(t.PolarRadiusAxis,{tick:{fill:l.textMuted,fontSize:10},axisLine:!1,tickLine:!1}),u&&e.jsx(t.Tooltip,{contentStyle:a.contentStyle,labelStyle:a.labelStyle,itemStyle:a.itemStyle}),d&&e.jsx(t.Legend,{wrapperStyle:{fontSize:13,color:l.textMuted}}),S.map((n,h)=>{const i=n.color??y[h%y.length];return e.jsx(t.Radar,{name:n.label??n.key,dataKey:n.key,stroke:i,fill:i,fillOpacity:n.fillOpacity??.2,strokeWidth:2},n.key)})]})})})}exports.TkxAreaChart=z;exports.TkxBarChart=R;exports.TkxDonutChart=K;exports.TkxLineChart=F;exports.TkxPieChart=D;exports.TkxRadarChart=P;exports.TkxScatterChart=W;
|