@kapiuara/ui 0.6.0 → 0.8.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.
Files changed (53) hide show
  1. package/README.md +115 -5
  2. package/dist/components/chat/KapiComposer.d.ts +2 -2
  3. package/dist/components/chat/KapiComposer.js +47 -45
  4. package/dist/components/data/KapiTable.d.ts +58 -1
  5. package/dist/components/data/KapiTable.js +399 -358
  6. package/dist/components/data/datasetSelectionLogic.d.ts +22 -0
  7. package/dist/components/data/datasetSelectionLogic.js +5 -0
  8. package/dist/components/data/index.d.ts +2 -1
  9. package/dist/components/data/tableLogic.d.ts +7 -0
  10. package/dist/components/data/tableLogic.js +21 -16
  11. package/dist/components/display/KapiTruncate.d.ts +32 -0
  12. package/dist/components/display/KapiTruncate.js +43 -0
  13. package/dist/components/display/index.d.ts +3 -0
  14. package/dist/components/display/truncateLogic.d.ts +6 -0
  15. package/dist/components/display/truncateLogic.js +4 -0
  16. package/dist/components/inputs/KapiButton.d.ts +9 -2
  17. package/dist/components/inputs/KapiButton.js +25 -15
  18. package/dist/components/inputs/KapiFacetedSearch.d.ts +29 -5
  19. package/dist/components/inputs/KapiFacetedSearch.js +161 -119
  20. package/dist/components/inputs/KapiSegmented.d.ts +9 -2
  21. package/dist/components/inputs/KapiSegmented.js +46 -44
  22. package/dist/components/inputs/facetedSearchLogic.d.ts +40 -9
  23. package/dist/components/inputs/facetedSearchLogic.js +38 -20
  24. package/dist/components/inputs/index.d.ts +2 -2
  25. package/dist/components/layout/KapiRail.d.ts +1 -1
  26. package/dist/components/layout/KapiRail.js +57 -50
  27. package/dist/components/layout/KapiShell.d.ts +27 -4
  28. package/dist/components/layout/KapiShell.js +23 -22
  29. package/dist/components/navigation/KapiTabs.d.ts +3 -1
  30. package/dist/components/navigation/KapiTabs.js +47 -46
  31. package/dist/components/overlays/KapiCanvasForm.js +2 -6
  32. package/dist/components/overlays/KapiConfirm.js +1 -6
  33. package/dist/hooks/colorLogic.d.ts +26 -0
  34. package/dist/hooks/colorLogic.js +53 -0
  35. package/dist/hooks/index.d.ts +6 -0
  36. package/dist/hooks/numberFormatLogic.d.ts +6 -0
  37. package/dist/hooks/numberFormatLogic.js +7 -0
  38. package/dist/hooks/rightClick.d.ts +10 -0
  39. package/dist/hooks/rightClick.js +10 -4
  40. package/dist/hooks/themeColorsLogic.d.ts +11 -0
  41. package/dist/hooks/themeColorsLogic.js +37 -0
  42. package/dist/hooks/themeContrastLogic.d.ts +23 -0
  43. package/dist/hooks/themeContrastLogic.js +46 -0
  44. package/dist/hooks/themeDeriveLogic.d.ts +52 -0
  45. package/dist/hooks/themeDeriveLogic.js +103 -0
  46. package/dist/hooks/useDragScroll.js +26 -23
  47. package/dist/hooks/useGlobalRightClick.js +28 -25
  48. package/dist/hooks/useKapiTheme.d.ts +28 -4
  49. package/dist/hooks/useKapiTheme.js +82 -50
  50. package/dist/index.js +132 -126
  51. package/dist/kapi.css +1 -1
  52. package/dist/kapi.layered.css +1 -1
  53. package/package.json +3 -3
@@ -3,250 +3,292 @@ import { useLabels as e } from "../locale/KapiLocaleProvider.js";
3
3
  import { createLoadSequencer as t } from "./asyncSelectLogic.js";
4
4
  import { joinClasses as n } from "../rootProps.js";
5
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";
6
+ import { KapiDateRangePicker as ee } from "./KapiDateRangePicker.js";
7
+ import { KapiTag as i } from "../display/KapiTag.js";
8
+ import { KapiPopover as te } from "../overlays/KapiPopover.js";
9
+ import { facetChipText as ne, facetKeyAction as re, facetMenuItems as ie, facetOperators as a, facetOptionName as ae, isDateFacet as o, moveActive as oe, toDateRangeValue as se, toDateValue as ce } from "./facetedSearchLogic.js";
10
10
  /* empty css */
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";
11
+ import { Fragment as le, jsx as s, jsxs as c } from "react/jsx-runtime";
12
+ import { useEffect as l, useId as ue, useRef as u, useState as d } from "react";
13
+ import { Search as de } from "lucide-react";
14
14
  //#region src/components/inputs/KapiFacetedSearch.tsx
15
- var _ = {
15
+ var f = {
16
16
  input: "Buscar o filtrar",
17
17
  region: "Búsqueda",
18
18
  placeholder: "Buscar o filtrar…",
19
19
  searchFor: "Buscar",
20
20
  pickValue: "elegir valor…",
21
+ typeValue: "escribir texto…",
21
22
  empty: "Sin opciones",
22
23
  remove: "Quitar",
23
24
  valueOf: "Valor de",
24
25
  clearAll: "Limpiar todo",
25
26
  loading: "Buscando…",
26
- loadError: "No se pudieron cargar los valores"
27
+ loadError: "No se pudieron cargar los valores",
28
+ pickOperator: "Cómo comparar",
29
+ operatorEq: "es",
30
+ operatorNe: "no es",
31
+ operatorContains: "contiene",
32
+ operatorStartsWith: "empieza con",
33
+ operatorEndsWith: "termina con",
34
+ operatorGt: "mayor que",
35
+ operatorGte: "mayor o igual que",
36
+ operatorLt: "menor que",
37
+ operatorLte: "menor o igual que"
27
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
+ function p({ facets: p, chips: m, onText: fe, onClearAll: h, loadDelay: g = 300, reloadKey: _, labels: pe, className: me, onMouseDown: he, "aria-label": ge, ..._e }) {
40
+ let v = e("facetedSearch", f, pe), y = ue(), b = `${y}-list`, x = u(null), S = u(null), C = u(null), [w, T] = d(""), [E, D] = d(null), [O, k] = d(null), [ve, A] = d(!1), [j, M] = d(-1), [N, P] = d(null), [F] = d(t), I = u(_);
41
+ l(() => {
42
+ Object.is(I.current, _) || (I.current = _, F.cancel(), P(null));
43
+ }, [_, F]);
44
+ let L = w.trim(), R = !!E && a(E).length >= 2 && O === null, z = E?.kind === "text" && !R, B = typeof E?.loadOptions == "function" && E.kind !== "text" && !R, V = {
45
+ eq: v.operatorEq,
46
+ ne: v.operatorNe,
47
+ contains: v.operatorContains,
48
+ startsWith: v.operatorStartsWith,
49
+ endsWith: v.operatorEndsWith,
50
+ gt: v.operatorGt,
51
+ gte: v.operatorGte,
52
+ lt: v.operatorLt,
53
+ lte: v.operatorLte
54
+ }, H = (e) => ne(e, e.operator ? V[e.operator] : void 0), U = B && N?.key === E?.key && N?.query === L ? N : null, W = B && !U, G = ie(p, E, w, U && !U.error ? U.options : void 0, O), K = o(E) && !R, q = ve && !K && !(z && G.length === 0), J = u(E?.loadOptions);
55
+ l(() => {
56
+ J.current = E?.loadOptions;
57
+ }), l(() => {
58
+ if (!B || !q || U) return;
59
+ let e = E?.key ?? "", t = setTimeout(() => {
39
60
  let t = J.current;
40
61
  if (!t) return;
41
- let n = z.start(), r;
62
+ let n = F.start(), r;
42
63
  try {
43
- r = t(V, { signal: n.signal });
64
+ r = t(L, { signal: n.signal });
44
65
  } catch (e) {
45
66
  r = Promise.reject(e);
46
67
  }
47
68
  r.then((t) => {
48
- n.isCurrent() && (R({
69
+ n.isCurrent() && (P({
49
70
  key: e,
50
- query: V,
71
+ query: L,
51
72
  options: t,
52
73
  error: !1
53
- }), I(-1));
74
+ }), M(-1));
54
75
  }, () => {
55
- n.isCurrent() && R({
76
+ n.isCurrent() && P({
56
77
  key: e,
57
- query: V,
78
+ query: L,
58
79
  options: [],
59
80
  error: !0
60
81
  });
61
82
  });
62
- }, S);
83
+ }, g);
63
84
  return () => clearTimeout(t);
64
85
  }, [
65
- H,
86
+ B,
66
87
  q,
67
88
  U,
68
- V,
69
- S,
70
- M?.key,
71
- z
72
- ]), p(() => ((!q || !M) && (z.cancel(), R((e) => e?.error ? null : e)), () => z.cancel()), [
89
+ L,
90
+ g,
91
+ E?.key,
92
+ F
93
+ ]), l(() => ((!q || !E) && (F.cancel(), P((e) => e?.error ? null : e)), () => F.cancel()), [
73
94
  q,
74
- M,
75
- z
95
+ E,
96
+ F
76
97
  ]);
77
- let Y = () => requestAnimationFrame(() => O.current?.focus()), X = () => {
78
- j(""), N(null), I(-1);
98
+ let Y = () => requestAnimationFrame(() => S.current?.focus()), X = () => {
99
+ T(""), D(null), k(null), M(-1);
79
100
  }, 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,
101
+ X(), A(!1), Y();
102
+ }, Q = (e, t) => {
103
+ e.kind === "flag" ? (e.apply("true", t), Z()) : (D(e), k(t), T(""), M(-1), A(!0), o(e) ? requestAnimationFrame(() => C.current?.focus()) : Y());
104
+ }, ye = () => {
105
+ O !== null && E && a(E).length >= 2 || D(null), k(null), M(-1), Y();
106
+ }, be = (e) => {
107
+ E?.kind === "text" ? E.apply(e, O ?? "eq") : fe(e), Z();
108
+ }, xe = (e) => {
109
+ if (e.type === "text") be(e.text);
110
+ else if (e.type === "option") E?.apply(e.option.value, O ?? "eq"), Z();
111
+ else if (e.type === "operator") Q(e.facet, e.operator);
112
+ else {
113
+ let t = a(e.facet);
114
+ t.length >= 2 ? (D(e.facet), k(null), T(""), M(-1), A(!0), Y()) : Q(e.facet, t[0] ?? "eq");
115
+ }
116
+ }, Se = (e) => {
117
+ let t = re(e.key, {
118
+ input: w,
119
+ pending: !!E,
120
+ pendingText: z,
121
+ active: j,
88
122
  open: q,
89
- chips: y.length
123
+ chips: m.length
90
124
  });
91
125
  if (t) switch (e.preventDefault(), t) {
92
126
  case "next":
93
127
  case "prev":
94
- P(!0), I((e) => re(q ? e : -1, G.length, t === "next" ? 1 : -1));
128
+ A(!0), M((e) => oe(q ? e : -1, G.length, t === "next" ? 1 : -1));
95
129
  break;
96
130
  case "select": {
97
- let e = G[F];
98
- e && Q(e);
131
+ let e = G[j];
132
+ e && xe(e);
99
133
  break;
100
134
  }
101
135
  case "text":
102
- b(A.trim()), Z();
136
+ be(w.trim());
103
137
  break;
104
138
  case "cancel":
105
139
  X();
106
140
  break;
107
141
  case "close":
108
- P(!1), I(-1);
142
+ A(!1), M(-1);
109
143
  break;
110
144
  case "dropPending":
111
- N(null), I(-1);
145
+ ye();
112
146
  break;
113
- case "removeLast": y[y.length - 1]?.onRemove();
147
+ case "removeLast": m[m.length - 1]?.onRemove();
114
148
  }
115
- }, fe = (e) => {
149
+ }, Ce = (e) => {
116
150
  let t = e.target.value === "";
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),
151
+ e.key === "Escape" ? (e.preventDefault(), X(), Y()) : e.key === "Backspace" && t && (e.preventDefault(), ye());
152
+ }, $ = (e) => `${y}-opt-${e}`;
153
+ return /* @__PURE__ */ c("div", {
154
+ ..._e,
155
+ ref: x,
156
+ className: n("kapi-facets", me),
123
157
  role: "search",
124
- "aria-label": ce ?? w.region,
158
+ "aria-label": ge ?? v.region,
125
159
  onMouseDown: (e) => {
126
- se?.(e), !e.defaultPrevented && e.target === e.currentTarget && (e.preventDefault(), O.current?.focus(), P(!0));
160
+ he?.(e), !e.defaultPrevented && e.target === e.currentTarget && (e.preventDefault(), S.current?.focus(), A(!0));
127
161
  },
128
162
  children: [
129
- /* @__PURE__ */ d(ie, {
163
+ /* @__PURE__ */ s(de, {
130
164
  className: "kapi-facets__icon",
131
165
  size: 15,
132
166
  "aria-hidden": !0
133
167
  }),
134
- y.map((e) => /* @__PURE__ */ d(a, {
168
+ m.map((e) => /* @__PURE__ */ s(i, {
135
169
  size: "sm",
136
170
  onRemove: () => {
137
171
  e.onRemove(), Y();
138
172
  },
139
- removeLabel: `${w.remove} ${e.label}`,
140
- children: e.label
173
+ removeLabel: `${v.remove} ${H(e)}`,
174
+ children: H(e)
141
175
  }, e.key)),
142
- M && /* @__PURE__ */ f(a, {
176
+ E && /* @__PURE__ */ c(i, {
143
177
  size: "sm",
144
178
  tone: "primary",
145
179
  className: "kapi-facets__pending",
146
- children: [M.label, ":"]
180
+ children: [
181
+ E.label,
182
+ O && O !== "eq" ? ` ${V[O]}` : "",
183
+ ":"
184
+ ]
147
185
  }),
148
- K && M ? /* @__PURE__ */ d("span", {
186
+ K && E ? /* @__PURE__ */ s("span", {
149
187
  className: "kapi-facets__date",
150
- onKeyDown: fe,
151
- children: M.kind === "dateRange" ? /* @__PURE__ */ d(i, {
152
- ref: k,
153
- "aria-label": `${w.valueOf} ${M.label}`,
188
+ onKeyDown: Ce,
189
+ children: E.kind === "dateRange" ? /* @__PURE__ */ s(ee, {
190
+ ref: C,
191
+ "aria-label": `${v.valueOf} ${E.label}`,
154
192
  onChange: ({ from: e, to: t }) => {
155
- e && t && (M.apply(c(e, t)), Z());
193
+ e && t && (E.apply(se(e, t), O ?? "eq"), Z());
156
194
  }
157
- }) : /* @__PURE__ */ d(r, {
158
- ref: k,
159
- "aria-label": `${w.valueOf} ${M.label}`,
195
+ }) : /* @__PURE__ */ s(r, {
196
+ ref: C,
197
+ "aria-label": `${v.valueOf} ${E.label}`,
160
198
  onChange: (e) => {
161
- e && (M.apply(l(e)), Z());
199
+ e && (E.apply(ce(e), O ?? "eq"), Z());
162
200
  }
163
201
  })
164
- }) : /* @__PURE__ */ d("input", {
165
- ref: O,
202
+ }) : /* @__PURE__ */ s("input", {
203
+ ref: S,
166
204
  className: "kapi-facets__input",
167
205
  type: "text",
168
206
  role: "combobox",
169
207
  autoComplete: "off",
170
- "aria-label": w.input,
208
+ "aria-label": v.input,
171
209
  "aria-expanded": q,
172
- "aria-controls": E,
210
+ "aria-controls": b,
173
211
  "aria-autocomplete": "list",
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),
212
+ "aria-activedescendant": q && j >= 0 ? $(j) : void 0,
213
+ placeholder: z ? v.typeValue : m.length === 0 && !E ? v.placeholder : void 0,
214
+ value: w,
215
+ onFocus: () => A(!0),
216
+ onClick: () => A(!0),
179
217
  onBlur: (e) => {
180
218
  let t = e.relatedTarget;
181
- (!t || !D.current?.contains(t)) && P(!1);
219
+ (!t || !x.current?.contains(t)) && A(!1);
182
220
  },
183
221
  onChange: (e) => {
184
- j(e.target.value), P(!0), I(-1);
222
+ T(e.target.value), A(!0), M(-1);
185
223
  },
186
- onKeyDown: de
224
+ onKeyDown: Se
187
225
  }),
188
- x && y.length > 0 && /* @__PURE__ */ d("button", {
226
+ h && m.length > 0 && /* @__PURE__ */ s("button", {
189
227
  type: "button",
190
228
  className: "kapi-facets__clear",
191
229
  onClick: () => {
192
- x(), X(), Y();
230
+ h(), X(), Y();
193
231
  },
194
- children: w.clearAll
232
+ children: v.clearAll
195
233
  }),
196
- /* @__PURE__ */ f(o, {
234
+ /* @__PURE__ */ c(te, {
197
235
  open: q,
198
- anchorRef: D,
199
- onClose: () => P(!1),
236
+ anchorRef: x,
237
+ onClose: () => A(!1),
200
238
  matchAnchorWidth: !0,
201
239
  role: "listbox",
202
- id: E,
203
- "aria-label": M ? M.label : w.input,
240
+ id: b,
241
+ "aria-label": E ? R ? `${E.label}: ${v.pickOperator}` : E.label : v.input,
204
242
  closeOnEscape: !1,
205
243
  restoreFocus: !1,
206
244
  className: "kapi-facets__menu",
207
245
  children: [
208
- W && /* @__PURE__ */ d("div", {
246
+ W && /* @__PURE__ */ s("div", {
209
247
  className: "kapi-facets__empty",
210
- children: w.loading
248
+ children: v.loading
211
249
  }),
212
- !W && U?.error && /* @__PURE__ */ d("div", {
250
+ !W && U?.error && /* @__PURE__ */ s("div", {
213
251
  className: "kapi-facets__empty kapi-facets__empty--err",
214
- children: w.loadError
252
+ children: v.loadError
215
253
  }),
216
- !W && !U?.error && G.length === 0 && /* @__PURE__ */ d("div", {
254
+ !W && !U?.error && G.length === 0 && /* @__PURE__ */ s("div", {
217
255
  className: "kapi-facets__empty",
218
- children: w.empty
256
+ children: v.empty
219
257
  }),
220
- !W && !U?.error && G.map((e, t) => /* @__PURE__ */ d("div", {
258
+ !W && !U?.error && G.map((e, t) => /* @__PURE__ */ s("div", {
221
259
  id: $(t),
222
260
  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" : ""}`,
261
+ "aria-selected": t === j,
262
+ "aria-label": e.type === "option" ? ae(e.option) : void 0,
263
+ className: `kapi-facets__opt${t === j ? " kapi-facets__opt--active" : ""}`,
226
264
  onMouseDown: (e) => e.preventDefault(),
227
- onMouseEnter: () => I(t),
228
- onClick: () => Q(e),
229
- children: e.type === "text" ? /* @__PURE__ */ f("span", { children: [
230
- w.searchFor,
265
+ onMouseEnter: () => M(t),
266
+ onClick: () => xe(e),
267
+ children: e.type === "text" ? /* @__PURE__ */ c("span", { children: [
268
+ v.searchFor,
231
269
  " “",
232
270
  e.text,
233
271
  "”"
234
- ] }) : e.type === "option" ? /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("span", { children: e.option.label }), e.option.count !== void 0 && /* @__PURE__ */ d("span", {
272
+ ] }) : e.type === "operator" ? /* @__PURE__ */ s("span", { children: V[e.operator] }) : e.type === "option" ? /* @__PURE__ */ c(le, { children: [/* @__PURE__ */ s("span", { children: e.option.label }), e.option.count !== void 0 && /* @__PURE__ */ s("span", {
235
273
  className: "kapi-facets__count",
236
274
  "aria-hidden": "true",
237
275
  children: e.option.count
238
- })] }) : /* @__PURE__ */ f("span", { children: [/* @__PURE__ */ d("span", {
276
+ })] }) : /* @__PURE__ */ c("span", { children: [/* @__PURE__ */ s("span", {
239
277
  className: "kapi-facets__facet",
240
278
  children: e.facet.label
241
- }), e.facet.kind !== "flag" && /* @__PURE__ */ f("span", {
279
+ }), e.facet.kind !== "flag" && /* @__PURE__ */ c("span", {
242
280
  className: "kapi-facets__hint",
243
- children: [" · ", w.pickValue]
281
+ children: [
282
+ " ",
283
+ "· ",
284
+ e.facet.kind === "text" ? v.typeValue : v.pickValue
285
+ ]
244
286
  })] })
245
- }, e.type === "facet" ? `f-${e.facet.key}` : e.type === "option" ? `o-${e.option.value}` : "t"))
287
+ }, e.type === "facet" ? `f-${e.facet.key}` : e.type === "option" ? `o-${e.option.value}` : e.type === "operator" ? `op-${e.operator}` : "t"))
246
288
  ]
247
289
  })
248
290
  ]
249
291
  });
250
292
  }
251
293
  //#endregion
252
- export { _ as DEFAULT_FACETED_SEARCH_LABELS, v as KapiFacetedSearch };
294
+ export { f as DEFAULT_FACETED_SEARCH_LABELS, p as KapiFacetedSearch };
@@ -6,10 +6,17 @@ export type KapiSegmentedItem<Id extends string | number = string> = {
6
6
  label: string;
7
7
  /** Ícono (lucide-react). Se muestra en las variantes `icon` y `both`. */
8
8
  icon?: ReactNode;
9
- /** Contador en píldora a la derecha. */
9
+ /** Contador en píldora a la derecha, con separadores de miles del español, que agrupa desde
10
+ * cinco cifras (`14760` → «14.760»; `4760` queda «4760»). */
10
11
  count?: number;
11
- /** Color del ítem cuando está activo (en vez del primario). */
12
+ /** Color del ítem cuando está activo (en vez del primario); sin activar no se ve. */
12
13
  color?: KapiSegmentedColor;
14
+ /**
15
+ * Estado permanente del ítem: tiñe el label y el contador **siempre**, sin tocar el fondo, para que una
16
+ * opción que necesita atención («Demorados 41») se vea sin tener que elegirla. Si además está activa, el
17
+ * tratamiento de `color` gana.
18
+ */
19
+ tone?: KapiSegmentedColor;
13
20
  };
14
21
  /** Atributos nativos (`id`, `style`, `data-*`…) van al `radiogroup`; el rol y el teclado son propios. */
15
22
  export type KapiSegmentedProps<Id extends string | number = string> = Omit<HTMLAttributes<HTMLDivElement>, "children" | "onChange" | "defaultValue" | "role" | "onKeyDown"> & {
@@ -3,81 +3,83 @@ import { assignRef as e, fieldControlProps as t } from "./fieldLogic.js";
3
3
  import { useKapiField as n } from "./KapiField.js";
4
4
  import { joinClasses as r } from "../rootProps.js";
5
5
  import { useSlidingIndicator as i } from "../../hooks/useSlidingIndicator.js";
6
- import { KapiTooltip as a } from "../overlays/KapiTooltip.js";
7
- import { nextRadioIndex as o } from "./segmentedLogic.js";
8
- import { jsx as s, jsxs as c } from "react/jsx-runtime";
6
+ import { formatCount as a } from "../../hooks/numberFormatLogic.js";
7
+ import { KapiTooltip as o } from "../overlays/KapiTooltip.js";
8
+ import { nextRadioIndex as s } from "./segmentedLogic.js";
9
+ import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
9
10
  //#region src/components/inputs/KapiSegmented.tsx
10
- var l = ({ items: l, value: u, onChange: d, variant: f = "text", "aria-label": p, className: m, name: h, onBlur: g, invalid: _, required: v, id: y, "aria-describedby": b, ref: x, ...S }) => {
11
- let C = t(n(), {
12
- id: y,
13
- describedBy: b,
14
- invalid: _,
15
- required: v,
11
+ var d = ({ items: d, value: f, onChange: p, variant: m = "text", "aria-label": h, className: g, name: _, onBlur: v, invalid: y, required: b, id: x, "aria-describedby": S, ref: C, ...w }) => {
12
+ let T = t(n(), {
13
+ id: x,
14
+ describedBy: S,
15
+ invalid: y,
16
+ required: b,
16
17
  labelable: !1,
17
- ariaLabel: p
18
- }), w = l.find((e) => e.id === u), { containerRef: T, indicatorRef: E } = i({
19
- active: u,
20
- deps: [l, f],
18
+ ariaLabel: h
19
+ }), E = d.find((e) => e.id === f), { containerRef: D, indicatorRef: O } = i({
20
+ active: f,
21
+ deps: [d, m],
21
22
  findActive: (e) => e.querySelector("[role=\"radio\"][aria-checked=\"true\"]")
22
- }), D = l.findIndex((e) => e.id === u), O = (e) => {
23
- let t = o(l.length, D, e.key), n = t === void 0 ? void 0 : l[t];
24
- t !== void 0 && n && (e.preventDefault(), d(n.id), T.current?.querySelectorAll("[role=\"radio\"]")[t]?.focus());
25
- }, k = (e) => {
26
- e.currentTarget.contains(e.relatedTarget) || g?.(e);
23
+ }), k = d.findIndex((e) => e.id === f), A = (e) => {
24
+ let t = s(d.length, k, e.key), n = t === void 0 ? void 0 : d[t];
25
+ t !== void 0 && n && (e.preventDefault(), p(n.id), D.current?.querySelectorAll("[role=\"radio\"]")[t]?.focus());
26
+ }, j = (e) => {
27
+ e.currentTarget.contains(e.relatedTarget) || v?.(e);
27
28
  };
28
- return /* @__PURE__ */ c("div", {
29
- ...S,
30
- ...C,
29
+ return /* @__PURE__ */ u("div", {
30
+ ...w,
31
+ ...T,
31
32
  ref: (t) => {
32
- T.current = t, e(x, t);
33
+ D.current = t, e(C, t);
33
34
  },
34
- className: r("kapi-seg", m),
35
+ className: r("kapi-seg", g),
35
36
  role: "radiogroup",
36
- "aria-label": p,
37
- onKeyDown: O,
38
- onBlur: k,
37
+ "aria-label": h,
38
+ onKeyDown: A,
39
+ onBlur: j,
39
40
  children: [
40
- /* @__PURE__ */ s("span", {
41
- ref: E,
41
+ /* @__PURE__ */ l("span", {
42
+ ref: O,
42
43
  className: "kapi-seg__indicator",
43
- "data-color": w?.color,
44
+ "data-color": E?.color,
44
45
  "aria-hidden": "true"
45
46
  }),
46
- l.map((e, t) => {
47
- let n = u === e.id, r = /* @__PURE__ */ c("button", {
47
+ d.map((e, t) => {
48
+ let n = f === e.id, r = /* @__PURE__ */ u("button", {
48
49
  type: "button",
49
50
  role: "radio",
50
51
  "aria-checked": n,
51
- tabIndex: n || D === -1 && t === 0 ? 0 : -1,
52
- "aria-label": f === "icon" ? e.label : void 0,
52
+ tabIndex: n || k === -1 && t === 0 ? 0 : -1,
53
+ "aria-label": m === "icon" ? e.label : void 0,
53
54
  className: `kapi-seg__btn${n ? " is-on" : ""}`,
54
55
  "data-color": n && e.color ? e.color : void 0,
55
- onClick: () => d(e.id),
56
+ "data-tone": e.tone,
57
+ onClick: () => p(e.id),
56
58
  children: [
57
- (f === "icon" || f === "both") && e.icon && /* @__PURE__ */ s("span", {
59
+ (m === "icon" || m === "both") && e.icon && /* @__PURE__ */ l("span", {
58
60
  className: "kapi-seg__ico",
59
61
  children: e.icon
60
62
  }),
61
- f !== "icon" && /* @__PURE__ */ s("span", { children: e.label }),
62
- e.count != null && /* @__PURE__ */ s("span", {
63
+ m !== "icon" && /* @__PURE__ */ l("span", { children: e.label }),
64
+ e.count != null && /* @__PURE__ */ u(c, { children: [" ", /* @__PURE__ */ l("span", {
63
65
  className: "kapi-seg__n",
64
- children: e.count
65
- })
66
+ children: a(e.count)
67
+ })] })
66
68
  ]
67
69
  }, e.id);
68
- return f === "icon" && e.label ? /* @__PURE__ */ s(a, {
70
+ return m === "icon" && e.label ? /* @__PURE__ */ l(o, {
69
71
  label: e.label,
70
72
  prefer: "top",
71
73
  children: r
72
74
  }, e.id) : r;
73
75
  }),
74
- h && /* @__PURE__ */ s("input", {
76
+ _ && /* @__PURE__ */ l("input", {
75
77
  type: "hidden",
76
- name: h,
77
- value: String(u)
78
+ name: _,
79
+ value: String(f)
78
80
  })
79
81
  ]
80
82
  });
81
83
  };
82
84
  //#endregion
83
- export { l as KapiSegmented };
85
+ export { d as KapiSegmented };