@kapiuara/ui 0.3.1 → 0.5.0
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/components/inputs/KapiAutocomplete.js +1 -1
- package/dist/components/inputs/KapiFacetedSearch.d.ts +14 -1
- package/dist/components/inputs/KapiFacetedSearch.js +172 -110
- package/dist/components/inputs/KapiField.d.ts +10 -2
- package/dist/components/inputs/KapiField.js +39 -32
- package/dist/components/inputs/KapiSelect.d.ts +7 -0
- package/dist/components/inputs/KapiSelect.js +233 -229
- package/dist/components/inputs/facetedSearchLogic.d.ts +12 -2
- package/dist/components/inputs/facetedSearchLogic.js +10 -7
- package/dist/components/inputs/fieldLogic.d.ts +6 -0
- package/dist/components/inputs/fieldLogic.js +5 -2
- package/dist/components/navigation/KapiWizard.d.ts +9 -2
- package/dist/components/navigation/KapiWizard.js +75 -58
- package/dist/components/navigation/wizardLogic.d.ts +13 -3
- package/dist/components/navigation/wizardLogic.js +2 -5
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/package.json +1 -1
|
@@ -129,10 +129,10 @@ var u = {
|
|
|
129
129
|
"aria-expanded": $,
|
|
130
130
|
"aria-controls": N,
|
|
131
131
|
"aria-activedescendant": $ && Q >= 0 ? F(Q) : void 0,
|
|
132
|
-
"aria-busy": X || void 0,
|
|
133
132
|
...t(A ? null : je, {
|
|
134
133
|
id: M,
|
|
135
134
|
describedBy: n(P, O["aria-describedby"]),
|
|
135
|
+
busy: X || void 0,
|
|
136
136
|
invalid: x ? x === "err" : void 0
|
|
137
137
|
}),
|
|
138
138
|
required: C,
|
|
@@ -20,6 +20,10 @@ export type KapiFacetedSearchLabels = {
|
|
|
20
20
|
valueOf: string;
|
|
21
21
|
/** Botón que quita todos los filtros (con `onClearAll`). */
|
|
22
22
|
clearAll: string;
|
|
23
|
+
/** Mientras `loadOptions` de la faceta está resolviendo. */
|
|
24
|
+
loading: string;
|
|
25
|
+
/** Cuando `loadOptions` falla: el menú lo dice en vez de quedar vacío, que parece "sin datos". */
|
|
26
|
+
loadError: string;
|
|
23
27
|
};
|
|
24
28
|
export declare const DEFAULT_FACETED_SEARCH_LABELS: KapiFacetedSearchLabels;
|
|
25
29
|
/** Atributos nativos (`id`, `style`, `data-*`…) van a la región `role="search"` (el rol es propio). */
|
|
@@ -30,6 +34,15 @@ export type KapiFacetedSearchProps = Omit<HTMLAttributes<HTMLDivElement>, "child
|
|
|
30
34
|
chips: ReadonlyArray<KapiFacetChip>;
|
|
31
35
|
/** Texto libre confirmado con Enter. */
|
|
32
36
|
onText: (text: string) => void;
|
|
37
|
+
/** Espera tras la última tecla antes de llamar a `loadOptions` de la faceta, en ms. @default 300 */
|
|
38
|
+
loadDelay?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Cambiar este valor tira el resultado cacheado y vuelve a pedir. Es la única forma de refrescar
|
|
41
|
+
* lo que cargó `loadOptions`, porque ese estado vive adentro del componente y el consumidor no
|
|
42
|
+
* lo puede alcanzar. Los datos que el consumidor YA tiene (filas, opciones estáticas) se
|
|
43
|
+
* refrescan pasando props nuevas: para eso no hace falta esto.
|
|
44
|
+
*/
|
|
45
|
+
reloadKey?: unknown;
|
|
33
46
|
/**
|
|
34
47
|
* Con esta prop, la barra muestra "Limpiar todo" mientras haya algún chip; al tocarlo se llama una
|
|
35
48
|
* sola vez (la pantalla vacía sus filtros de una, sin quitar chip por chip).
|
|
@@ -45,4 +58,4 @@ export type KapiFacetedSearchProps = Omit<HTMLAttributes<HTMLDivElement>, "child
|
|
|
45
58
|
* Teclado: flechas y Enter en el desplegable, Backspace con el campo vacío suelta la faceta pendiente
|
|
46
59
|
* y después el último chip, Escape cancela la faceta pendiente.
|
|
47
60
|
*/
|
|
48
|
-
export declare function KapiFacetedSearch({ facets, chips, onText, onClearAll, labels, className, onMouseDown, "aria-label": ariaLabel, ...rest }: KapiFacetedSearchProps): import("react").JSX.Element;
|
|
61
|
+
export declare function KapiFacetedSearch({ facets, chips, onText, onClearAll, loadDelay, reloadKey, labels, className, onMouseDown, "aria-label": ariaLabel, ...rest }: KapiFacetedSearchProps): import("react").JSX.Element;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { createLoadSequencer as t } from "./asyncSelectLogic.js";
|
|
4
|
+
import { joinClasses as n } from "../rootProps.js";
|
|
5
|
+
import { KapiDatePicker as r } from "./KapiDatePicker.js";
|
|
6
|
+
import { KapiDateRangePicker as i } from "./KapiDateRangePicker.js";
|
|
7
|
+
import { KapiTag as a } from "../display/KapiTag.js";
|
|
8
|
+
import { KapiPopover as o } from "../overlays/KapiPopover.js";
|
|
9
|
+
import { facetKeyAction as ee, facetMenuItems as te, facetOptionName as ne, isDateFacet as s, moveActive as re, toDateRangeValue as c, toDateValue as l } from "./facetedSearchLogic.js";
|
|
9
10
|
/* empty css */
|
|
10
|
-
import { Fragment as
|
|
11
|
-
import { useId as
|
|
12
|
-
import { Search as
|
|
11
|
+
import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
12
|
+
import { useEffect as p, useId as m, useRef as h, useState as g } from "react";
|
|
13
|
+
import { Search as ie } from "lucide-react";
|
|
13
14
|
//#region src/components/inputs/KapiFacetedSearch.tsx
|
|
14
|
-
var
|
|
15
|
+
var _ = {
|
|
15
16
|
input: "Buscar o filtrar",
|
|
16
17
|
region: "Búsqueda",
|
|
17
18
|
placeholder: "Buscar o filtrar…",
|
|
@@ -20,171 +21,232 @@ var b = {
|
|
|
20
21
|
empty: "Sin opciones",
|
|
21
22
|
remove: "Quitar",
|
|
22
23
|
valueOf: "Valor de",
|
|
23
|
-
clearAll: "Limpiar todo"
|
|
24
|
+
clearAll: "Limpiar todo",
|
|
25
|
+
loading: "Buscando…",
|
|
26
|
+
loadError: "No se pudieron cargar los valores"
|
|
24
27
|
};
|
|
25
|
-
function
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
function v({ facets: v, chips: y, onText: b, onClearAll: x, loadDelay: S = 300, reloadKey: C, labels: ae, className: oe, onMouseDown: se, "aria-label": ce, ...le }) {
|
|
29
|
+
let w = e("facetedSearch", _, ae), T = m(), E = `${T}-list`, D = h(null), O = h(null), k = h(null), [A, j] = g(""), [M, N] = g(null), [ue, P] = g(!1), [F, I] = g(-1), [L, R] = g(null), [z] = g(t), B = h(C);
|
|
30
|
+
p(() => {
|
|
31
|
+
Object.is(B.current, C) || (B.current = C, z.cancel(), R(null));
|
|
32
|
+
}, [C, z]);
|
|
33
|
+
let V = A.trim(), H = typeof M?.loadOptions == "function", U = H && L?.key === M?.key && L?.query === V ? L : null, W = H && !U, G = te(v, M, A, U && !U.error ? U.options : void 0), K = s(M), q = ue && !K, J = h(M?.loadOptions);
|
|
34
|
+
p(() => {
|
|
35
|
+
J.current = M?.loadOptions;
|
|
36
|
+
}), p(() => {
|
|
37
|
+
if (!H || !q || U) return;
|
|
38
|
+
let e = M?.key ?? "", t = setTimeout(() => {
|
|
39
|
+
let t = J.current;
|
|
40
|
+
if (!t) return;
|
|
41
|
+
let n = z.start(), r;
|
|
42
|
+
try {
|
|
43
|
+
r = t(V, { signal: n.signal });
|
|
44
|
+
} catch (e) {
|
|
45
|
+
r = Promise.reject(e);
|
|
46
|
+
}
|
|
47
|
+
r.then((t) => {
|
|
48
|
+
n.isCurrent() && (R({
|
|
49
|
+
key: e,
|
|
50
|
+
query: V,
|
|
51
|
+
options: t,
|
|
52
|
+
error: !1
|
|
53
|
+
}), I(-1));
|
|
54
|
+
}, () => {
|
|
55
|
+
n.isCurrent() && R({
|
|
56
|
+
key: e,
|
|
57
|
+
query: V,
|
|
58
|
+
options: [],
|
|
59
|
+
error: !0
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}, S);
|
|
63
|
+
return () => clearTimeout(t);
|
|
64
|
+
}, [
|
|
65
|
+
H,
|
|
66
|
+
q,
|
|
67
|
+
U,
|
|
68
|
+
V,
|
|
69
|
+
S,
|
|
70
|
+
M?.key,
|
|
71
|
+
z
|
|
72
|
+
]), p(() => ((!q || !M) && (z.cancel(), R((e) => e?.error ? null : e)), () => z.cancel()), [
|
|
73
|
+
q,
|
|
74
|
+
M,
|
|
75
|
+
z
|
|
76
|
+
]);
|
|
77
|
+
let Y = () => requestAnimationFrame(() => O.current?.focus()), X = () => {
|
|
78
|
+
j(""), N(null), I(-1);
|
|
79
|
+
}, Z = () => {
|
|
80
|
+
X(), P(!1), Y();
|
|
81
|
+
}, Q = (e) => {
|
|
82
|
+
e.type === "text" ? (b(e.text), Z()) : e.type === "option" ? (M?.apply(e.option.value), Z()) : e.facet.kind === "flag" ? (e.facet.apply("true"), Z()) : (N(e.facet), j(""), I(-1), P(!0), s(e.facet) ? requestAnimationFrame(() => k.current?.focus()) : Y());
|
|
83
|
+
}, de = (e) => {
|
|
84
|
+
let t = ee(e.key, {
|
|
85
|
+
input: A,
|
|
86
|
+
pending: !!M,
|
|
87
|
+
active: F,
|
|
88
|
+
open: q,
|
|
89
|
+
chips: y.length
|
|
39
90
|
});
|
|
40
91
|
if (t) switch (e.preventDefault(), t) {
|
|
41
92
|
case "next":
|
|
42
93
|
case "prev":
|
|
43
|
-
|
|
94
|
+
P(!0), I((e) => re(q ? e : -1, G.length, t === "next" ? 1 : -1));
|
|
44
95
|
break;
|
|
45
96
|
case "select": {
|
|
46
|
-
let e =
|
|
47
|
-
e &&
|
|
97
|
+
let e = G[F];
|
|
98
|
+
e && Q(e);
|
|
48
99
|
break;
|
|
49
100
|
}
|
|
50
101
|
case "text":
|
|
51
|
-
|
|
102
|
+
b(A.trim()), Z();
|
|
52
103
|
break;
|
|
53
104
|
case "cancel":
|
|
54
|
-
|
|
105
|
+
X();
|
|
55
106
|
break;
|
|
56
107
|
case "close":
|
|
57
|
-
|
|
108
|
+
P(!1), I(-1);
|
|
58
109
|
break;
|
|
59
110
|
case "dropPending":
|
|
60
|
-
|
|
111
|
+
N(null), I(-1);
|
|
61
112
|
break;
|
|
62
|
-
case "removeLast":
|
|
113
|
+
case "removeLast": y[y.length - 1]?.onRemove();
|
|
63
114
|
}
|
|
64
|
-
},
|
|
115
|
+
}, fe = (e) => {
|
|
65
116
|
let t = e.target.value === "";
|
|
66
|
-
(e.key === "Escape" || e.key === "Backspace" && t) && (e.preventDefault(),
|
|
67
|
-
}, $ = (e) => `${
|
|
68
|
-
return /* @__PURE__ */
|
|
69
|
-
...
|
|
70
|
-
ref:
|
|
71
|
-
className:
|
|
117
|
+
(e.key === "Escape" || e.key === "Backspace" && t) && (e.preventDefault(), X(), Y());
|
|
118
|
+
}, $ = (e) => `${T}-opt-${e}`;
|
|
119
|
+
return /* @__PURE__ */ f("div", {
|
|
120
|
+
...le,
|
|
121
|
+
ref: D,
|
|
122
|
+
className: n("kapi-facets", oe),
|
|
72
123
|
role: "search",
|
|
73
|
-
"aria-label":
|
|
124
|
+
"aria-label": ce ?? w.region,
|
|
74
125
|
onMouseDown: (e) => {
|
|
75
|
-
|
|
126
|
+
se?.(e), !e.defaultPrevented && e.target === e.currentTarget && (e.preventDefault(), O.current?.focus(), P(!0));
|
|
76
127
|
},
|
|
77
128
|
children: [
|
|
78
|
-
/* @__PURE__ */
|
|
129
|
+
/* @__PURE__ */ d(ie, {
|
|
79
130
|
className: "kapi-facets__icon",
|
|
80
131
|
size: 15,
|
|
81
132
|
"aria-hidden": !0
|
|
82
133
|
}),
|
|
83
|
-
|
|
134
|
+
y.map((e) => /* @__PURE__ */ d(a, {
|
|
84
135
|
size: "sm",
|
|
85
136
|
onRemove: () => {
|
|
86
|
-
e.onRemove(),
|
|
137
|
+
e.onRemove(), Y();
|
|
87
138
|
},
|
|
88
|
-
removeLabel: `${
|
|
139
|
+
removeLabel: `${w.remove} ${e.label}`,
|
|
89
140
|
children: e.label
|
|
90
141
|
}, e.key)),
|
|
91
|
-
|
|
142
|
+
M && /* @__PURE__ */ f(a, {
|
|
92
143
|
size: "sm",
|
|
93
144
|
tone: "primary",
|
|
94
145
|
className: "kapi-facets__pending",
|
|
95
|
-
children: [
|
|
146
|
+
children: [M.label, ":"]
|
|
96
147
|
}),
|
|
97
|
-
|
|
148
|
+
K && M ? /* @__PURE__ */ d("span", {
|
|
98
149
|
className: "kapi-facets__date",
|
|
99
|
-
onKeyDown:
|
|
100
|
-
children:
|
|
101
|
-
ref:
|
|
102
|
-
"aria-label": `${
|
|
150
|
+
onKeyDown: fe,
|
|
151
|
+
children: M.kind === "dateRange" ? /* @__PURE__ */ d(i, {
|
|
152
|
+
ref: k,
|
|
153
|
+
"aria-label": `${w.valueOf} ${M.label}`,
|
|
103
154
|
onChange: ({ from: e, to: t }) => {
|
|
104
|
-
e && t && (
|
|
155
|
+
e && t && (M.apply(c(e, t)), Z());
|
|
105
156
|
}
|
|
106
|
-
}) : /* @__PURE__ */
|
|
107
|
-
ref:
|
|
108
|
-
"aria-label": `${
|
|
157
|
+
}) : /* @__PURE__ */ d(r, {
|
|
158
|
+
ref: k,
|
|
159
|
+
"aria-label": `${w.valueOf} ${M.label}`,
|
|
109
160
|
onChange: (e) => {
|
|
110
|
-
e && (
|
|
161
|
+
e && (M.apply(l(e)), Z());
|
|
111
162
|
}
|
|
112
163
|
})
|
|
113
|
-
}) : /* @__PURE__ */
|
|
114
|
-
ref:
|
|
164
|
+
}) : /* @__PURE__ */ d("input", {
|
|
165
|
+
ref: O,
|
|
115
166
|
className: "kapi-facets__input",
|
|
116
167
|
type: "text",
|
|
117
168
|
role: "combobox",
|
|
118
169
|
autoComplete: "off",
|
|
119
|
-
"aria-label":
|
|
120
|
-
"aria-expanded":
|
|
121
|
-
"aria-controls":
|
|
170
|
+
"aria-label": w.input,
|
|
171
|
+
"aria-expanded": q,
|
|
172
|
+
"aria-controls": E,
|
|
122
173
|
"aria-autocomplete": "list",
|
|
123
|
-
"aria-activedescendant":
|
|
124
|
-
placeholder:
|
|
125
|
-
value:
|
|
126
|
-
onFocus: () =>
|
|
127
|
-
onClick: () =>
|
|
174
|
+
"aria-activedescendant": q && F >= 0 ? $(F) : void 0,
|
|
175
|
+
placeholder: y.length === 0 && !M ? w.placeholder : void 0,
|
|
176
|
+
value: A,
|
|
177
|
+
onFocus: () => P(!0),
|
|
178
|
+
onClick: () => P(!0),
|
|
128
179
|
onBlur: (e) => {
|
|
129
180
|
let t = e.relatedTarget;
|
|
130
|
-
(!t || !
|
|
181
|
+
(!t || !D.current?.contains(t)) && P(!1);
|
|
131
182
|
},
|
|
132
183
|
onChange: (e) => {
|
|
133
|
-
|
|
184
|
+
j(e.target.value), P(!0), I(-1);
|
|
134
185
|
},
|
|
135
|
-
onKeyDown:
|
|
186
|
+
onKeyDown: de
|
|
136
187
|
}),
|
|
137
|
-
|
|
188
|
+
x && y.length > 0 && /* @__PURE__ */ d("button", {
|
|
138
189
|
type: "button",
|
|
139
190
|
className: "kapi-facets__clear",
|
|
140
191
|
onClick: () => {
|
|
141
|
-
|
|
192
|
+
x(), X(), Y();
|
|
142
193
|
},
|
|
143
|
-
children:
|
|
194
|
+
children: w.clearAll
|
|
144
195
|
}),
|
|
145
|
-
/* @__PURE__ */
|
|
146
|
-
open:
|
|
147
|
-
anchorRef:
|
|
148
|
-
onClose: () =>
|
|
196
|
+
/* @__PURE__ */ f(o, {
|
|
197
|
+
open: q,
|
|
198
|
+
anchorRef: D,
|
|
199
|
+
onClose: () => P(!1),
|
|
149
200
|
matchAnchorWidth: !0,
|
|
150
201
|
role: "listbox",
|
|
151
|
-
id:
|
|
152
|
-
"aria-label":
|
|
202
|
+
id: E,
|
|
203
|
+
"aria-label": M ? M.label : w.input,
|
|
153
204
|
closeOnEscape: !1,
|
|
154
205
|
restoreFocus: !1,
|
|
155
206
|
className: "kapi-facets__menu",
|
|
156
|
-
children: [
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
"
|
|
173
|
-
|
|
174
|
-
className: "kapi-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
207
|
+
children: [
|
|
208
|
+
W && /* @__PURE__ */ d("div", {
|
|
209
|
+
className: "kapi-facets__empty",
|
|
210
|
+
children: w.loading
|
|
211
|
+
}),
|
|
212
|
+
!W && U?.error && /* @__PURE__ */ d("div", {
|
|
213
|
+
className: "kapi-facets__empty kapi-facets__empty--err",
|
|
214
|
+
children: w.loadError
|
|
215
|
+
}),
|
|
216
|
+
!W && !U?.error && G.length === 0 && /* @__PURE__ */ d("div", {
|
|
217
|
+
className: "kapi-facets__empty",
|
|
218
|
+
children: w.empty
|
|
219
|
+
}),
|
|
220
|
+
!W && !U?.error && G.map((e, t) => /* @__PURE__ */ d("div", {
|
|
221
|
+
id: $(t),
|
|
222
|
+
role: "option",
|
|
223
|
+
"aria-selected": t === F,
|
|
224
|
+
"aria-label": e.type === "option" ? ne(e.option) : void 0,
|
|
225
|
+
className: `kapi-facets__opt${t === F ? " kapi-facets__opt--active" : ""}`,
|
|
226
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
227
|
+
onMouseEnter: () => I(t),
|
|
228
|
+
onClick: () => Q(e),
|
|
229
|
+
children: e.type === "text" ? /* @__PURE__ */ f("span", { children: [
|
|
230
|
+
w.searchFor,
|
|
231
|
+
" “",
|
|
232
|
+
e.text,
|
|
233
|
+
"”"
|
|
234
|
+
] }) : e.type === "option" ? /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("span", { children: e.option.label }), e.option.count !== void 0 && /* @__PURE__ */ d("span", {
|
|
235
|
+
className: "kapi-facets__count",
|
|
236
|
+
"aria-hidden": "true",
|
|
237
|
+
children: e.option.count
|
|
238
|
+
})] }) : /* @__PURE__ */ f("span", { children: [/* @__PURE__ */ d("span", {
|
|
239
|
+
className: "kapi-facets__facet",
|
|
240
|
+
children: e.facet.label
|
|
241
|
+
}), e.facet.kind !== "flag" && /* @__PURE__ */ f("span", {
|
|
242
|
+
className: "kapi-facets__hint",
|
|
243
|
+
children: [" · ", w.pickValue]
|
|
244
|
+
})] })
|
|
245
|
+
}, e.type === "facet" ? `f-${e.facet.key}` : e.type === "option" ? `o-${e.option.value}` : "t"))
|
|
246
|
+
]
|
|
185
247
|
})
|
|
186
248
|
]
|
|
187
249
|
});
|
|
188
250
|
}
|
|
189
251
|
//#endregion
|
|
190
|
-
export {
|
|
252
|
+
export { _ as DEFAULT_FACETED_SEARCH_LABELS, v as KapiFacetedSearch };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type HTMLAttributes, type ReactNode } from "react";
|
|
2
2
|
import { type KapiFieldContextValue } from "./fieldLogic";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* `pending` es para mientras una validación asíncrona resuelve: el campo se marca ocupado pero NO
|
|
5
|
+
* inválido, porque pintarlo en rojo antes de saber el resultado le miente a quien lo está usando.
|
|
6
|
+
*/
|
|
7
|
+
export type KapiFieldStatus = "ok" | "err" | "pending";
|
|
4
8
|
export type { KapiFieldContextValue };
|
|
5
9
|
/** Atributos nativos (`id`, `style`, `data-*`…) van al contenedor; el `id` del control es `htmlFor`. */
|
|
6
10
|
export type KapiFieldProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
@@ -14,7 +18,11 @@ export type KapiFieldProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> &
|
|
|
14
18
|
help?: ReactNode | undefined;
|
|
15
19
|
/** `id` del texto de ayuda. Opcional: sin él se deriva del id del control. */
|
|
16
20
|
helpId?: string | undefined;
|
|
17
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Estado de validación: pinta la ayuda y le pone ícono. Con `err` el control queda `aria-invalid`
|
|
23
|
+
* y la ayuda interrumpe (`role="alert"`); con `pending` queda `aria-busy` y la ayuda se anuncia
|
|
24
|
+
* sin interrumpir (`aria-live="polite"`), que es lo que corresponde cuando todavía no pasó nada.
|
|
25
|
+
*/
|
|
18
26
|
status?: KapiFieldStatus | undefined;
|
|
19
27
|
/** El control del campo (input, select…); recibe `id`, `aria-describedby` y estado del contexto. */
|
|
20
28
|
children: ReactNode;
|
|
@@ -2,54 +2,61 @@
|
|
|
2
2
|
import { fieldIds as e } from "./fieldLogic.js";
|
|
3
3
|
import { jsx as t, jsxs as n } from "react/jsx-runtime";
|
|
4
4
|
import { createContext as r, useContext as i, useId as a, useMemo as o } from "react";
|
|
5
|
-
import { AlertTriangle as s, CheckCircle2 as c } from "lucide-react";
|
|
5
|
+
import { AlertTriangle as s, CheckCircle2 as c, LoaderCircle as l } from "lucide-react";
|
|
6
6
|
//#region src/components/inputs/KapiField.tsx
|
|
7
|
-
var
|
|
8
|
-
let
|
|
7
|
+
var u = r(null), d = () => i(u), f = (e = "") => ["kapi-field", e].filter(Boolean).join(" "), p = (e) => ["kapi-help", e && `kapi-help--${e}`].filter(Boolean).join(" "), m = ({ label: r, htmlFor: i, required: d = !1, help: m, helpId: h, status: g, className: _, children: v, ...y }) => {
|
|
8
|
+
let b = a(), x = !!m, { controlId: S, labelId: C, helpId: w } = e({
|
|
9
9
|
htmlFor: i,
|
|
10
|
-
autoId:
|
|
11
|
-
helpId:
|
|
12
|
-
hasHelp:
|
|
13
|
-
}),
|
|
14
|
-
controlId:
|
|
15
|
-
labelId: r == null ? void 0 :
|
|
16
|
-
helpId:
|
|
17
|
-
required:
|
|
18
|
-
invalid:
|
|
10
|
+
autoId: b,
|
|
11
|
+
helpId: h,
|
|
12
|
+
hasHelp: x
|
|
13
|
+
}), T = o(() => ({
|
|
14
|
+
controlId: S,
|
|
15
|
+
labelId: r == null ? void 0 : C,
|
|
16
|
+
helpId: w,
|
|
17
|
+
required: d,
|
|
18
|
+
invalid: g === "err",
|
|
19
|
+
busy: g === "pending"
|
|
19
20
|
}), [
|
|
20
|
-
x,
|
|
21
21
|
S,
|
|
22
|
-
r,
|
|
23
22
|
C,
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
r,
|
|
24
|
+
w,
|
|
25
|
+
d,
|
|
26
|
+
g
|
|
26
27
|
]);
|
|
27
|
-
return /* @__PURE__ */ t(
|
|
28
|
-
value:
|
|
28
|
+
return /* @__PURE__ */ t(u.Provider, {
|
|
29
|
+
value: T,
|
|
29
30
|
children: /* @__PURE__ */ n("div", {
|
|
30
|
-
...
|
|
31
|
-
className:
|
|
31
|
+
...y,
|
|
32
|
+
className: f(_),
|
|
32
33
|
children: [
|
|
33
34
|
r != null && /* @__PURE__ */ n("label", {
|
|
34
|
-
id: S,
|
|
35
|
-
htmlFor: x,
|
|
36
|
-
children: [r, u && " *"]
|
|
37
|
-
}),
|
|
38
|
-
_,
|
|
39
|
-
b ? /* @__PURE__ */ n("span", {
|
|
40
35
|
id: C,
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
htmlFor: S,
|
|
37
|
+
children: [r, d && " *"]
|
|
38
|
+
}),
|
|
39
|
+
v,
|
|
40
|
+
x ? /* @__PURE__ */ n("span", {
|
|
41
|
+
id: w,
|
|
42
|
+
className: p(g),
|
|
43
|
+
role: g === "err" ? "alert" : void 0,
|
|
44
|
+
"aria-live": g === "pending" ? "polite" : void 0,
|
|
43
45
|
children: [
|
|
44
|
-
|
|
46
|
+
g === "ok" && /* @__PURE__ */ t(c, {
|
|
45
47
|
size: 13,
|
|
46
48
|
strokeWidth: 2.2
|
|
47
49
|
}),
|
|
48
|
-
|
|
50
|
+
g === "err" && /* @__PURE__ */ t(s, {
|
|
49
51
|
size: 13,
|
|
50
52
|
strokeWidth: 2.2
|
|
51
53
|
}),
|
|
52
|
-
|
|
54
|
+
g === "pending" && /* @__PURE__ */ t(l, {
|
|
55
|
+
size: 13,
|
|
56
|
+
strokeWidth: 2.2,
|
|
57
|
+
className: "kapi-spinner"
|
|
58
|
+
}),
|
|
59
|
+
m
|
|
53
60
|
]
|
|
54
61
|
}) : null
|
|
55
62
|
]
|
|
@@ -57,4 +64,4 @@ var l = r(null), u = () => i(l), d = (e = "") => ["kapi-field", e].filter(Boolea
|
|
|
57
64
|
});
|
|
58
65
|
};
|
|
59
66
|
//#endregion
|
|
60
|
-
export {
|
|
67
|
+
export { m as KapiField, f as fieldClasses, p as helpClasses, d as useKapiField };
|
|
@@ -40,6 +40,13 @@ export interface KapiSelectBaseProps<T = unknown> {
|
|
|
40
40
|
}) => Promise<KapiSelectEntry<T>[]>;
|
|
41
41
|
/** Espera tras la última tecla antes de llamar a `loadOptions`, en ms. @default 300 */
|
|
42
42
|
loadDelay?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Cambiar este valor tira el resultado cacheado y vuelve a pedir. Es la única forma de refrescar
|
|
45
|
+
* lo que cargó `loadOptions`, porque ese estado vive adentro del componente y el consumidor no
|
|
46
|
+
* lo puede alcanzar. Los datos que el consumidor YA tiene (filas, opciones estáticas) se
|
|
47
|
+
* refrescan pasando props nuevas: para eso no hace falta esto.
|
|
48
|
+
*/
|
|
49
|
+
reloadKey?: unknown;
|
|
43
50
|
/** Ofrece "Crear “texto”" si ninguna opción coincide exacto; si devuelve una opción, se elige. Una promesa debe terminar (resolver o rechazar): mientras está pendiente no se puede crear otra. */
|
|
44
51
|
onCreate?: (text: string) => KapiSelectOption<T> | void | Promise<KapiSelectOption<T> | void>;
|
|
45
52
|
/** Filtrar tipeando. Default `true`. */
|