bmi-next-brokers 2.5.9 → 2.6.1

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.
@@ -11,21 +11,20 @@ export interface SearchableInputGroupField {
11
11
  }
12
12
  export interface SearchableInputGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onSelect"> {
13
13
  fields: SearchableInputGroupField[];
14
- /** Valores controlados que se muestran en los inputs. */
15
- values?: Record<string, string>;
16
- /** Resultados de búsqueda actuales, provistos por el padre. */
14
+ /** Opción seleccionada actualmente. Controlado por el padre. */
15
+ selectedItem?: Record<string, unknown> | null;
16
+ /** Opciones del dropdown. Si no se pasa onSearch, el filtrado es interno. */
17
17
  options?: Record<string, unknown>[];
18
- /** Se llama al cambiar cualquier input, con la clave del campo y el nuevo valor. */
19
- onSearch: (key: string, value: string) => void;
18
+ /** Búsqueda remota: el padre filtra las opciones. Si se omite, el filtrado es interno. */
19
+ onSearch?: (key: string, value: string) => void;
20
20
  /** Se llama al seleccionar una fila del dropdown. */
21
21
  onSelect?: (item: Record<string, unknown>) => void;
22
- /** Mensaje cuando no hay resultados (solo visible si loading es false). */
22
+ /** Se llama cuando selectedItem ya no está en las opciones filtradas. */
23
+ onReset?: () => void;
23
24
  noResultMessage?: string;
24
- /** Mientras loading=true no se muestra el mensaje de sin resultados. */
25
- loading?: boolean;
26
25
  disabled?: boolean;
27
26
  size?: SelectSize;
28
27
  btc?: boolean;
29
28
  containerClassName?: string;
30
29
  }
31
- export declare const SearchableInputGroup: ({ fields, values, options, onSearch, onSelect, noResultMessage, loading, disabled, btc, size, className, containerClassName, ...rest }: SearchableInputGroupProps) => import("react/jsx-runtime").JSX.Element;
30
+ export declare const SearchableInputGroup: ({ fields, selectedItem, options, onSearch, onSelect, onReset, noResultMessage, disabled, btc, size, className, containerClassName, ...rest }: SearchableInputGroupProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,112 +1,176 @@
1
- import { jsxs as v, jsx as o } from "react/jsx-runtime";
2
- import { useState as W, useRef as N, useEffect as y } from "react";
3
- import { createPortal as L } from "react-dom";
4
- import { Input as O } from "../Input/Input.js";
5
- import { s as n } from "../../Select.module-D_7bjq9u.js";
6
- import { useBTC as k } from "../../hooks/btcContext/useBtcContext.js";
7
- import { useDropdownPosition as F } from "../../hooks/useDropdownPosition.js";
8
- import '../../assets/index4.css';const G = "_container_1kajw_1", M = "_inputs_1kajw_7", V = "_inputWrapper_1kajw_13", p = {
9
- container: G,
10
- inputs: M,
11
- inputWrapper: V
12
- }, X = ({
13
- fields: m,
14
- values: _ = {},
1
+ import { jsxs as O, jsx as i } from "react/jsx-runtime";
2
+ import { useState as N, useRef as w, useMemo as Y, useEffect as _ } from "react";
3
+ import { createPortal as Z } from "react-dom";
4
+ import { Input as z } from "../Input/Input.js";
5
+ import { s as e } from "../../Select.module-D_7bjq9u.js";
6
+ import { useBTC as I } from "../../hooks/btcContext/useBtcContext.js";
7
+ import { useDropdownPosition as R } from "../../hooks/useDropdownPosition.js";
8
+ import '../../assets/index4.css';const rr = "_container_1kajw_1", nr = "_inputs_1kajw_7", tr = "_inputWrapper_1kajw_13", $ = {
9
+ container: rr,
10
+ inputs: nr,
11
+ inputWrapper: tr
12
+ }, lr = ({
13
+ fields: u,
14
+ selectedItem: c = null,
15
15
  options: a = [],
16
- onSearch: b,
17
- onSelect: u,
18
- noResultMessage: $ = "No se encontraron resultados",
19
- loading: j = !1,
20
- disabled: f = !1,
21
- btc: C = !1,
22
- size: s = "medium",
23
- className: h,
24
- containerClassName: I,
25
- ...R
16
+ onSearch: d,
17
+ onSelect: S,
18
+ onReset: s,
19
+ noResultMessage: W = "No se encontraron resultados",
20
+ disabled: C = !1,
21
+ btc: F = !1,
22
+ size: m = "medium",
23
+ className: E,
24
+ containerClassName: L,
25
+ ...P
26
26
  }) => {
27
- const { btc: x } = k(), B = C ?? x, [w, c] = W(!1), l = N(null), i = N(null), D = w && !f, E = F({
28
- isOpen: w,
29
- containerRef: l,
30
- dropdownRef: i,
31
- size: s,
27
+ const { btc: T } = I(), M = F ?? T, K = !!d, [x, g] = N(!1), [j, V] = N(
28
+ {}
29
+ ), [o, f] = N(null), h = w(null), v = w(null), b = w({}), D = w({}), q = x && !C, l = o ? j[o] ?? "" : "", A = R({
30
+ isOpen: x,
31
+ containerRef: h,
32
+ dropdownRef: v,
33
+ size: m,
32
34
  optionsLength: a.length,
33
35
  isSearchable: !0
34
- });
35
- y(() => {
36
- const e = (t) => {
37
- l.current && !l.current.contains(t.target) && i.current && !i.current.contains(t.target) && c(!1);
36
+ }), Q = (r) => typeof r == "string" ? r.normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/\s+/g, "").toLowerCase() : "", k = Y(() => {
37
+ if (!o || !l || K) return a;
38
+ const r = u.find((t) => t.key === o);
39
+ if (!r) return a;
40
+ const n = r.columnKey ?? r.key;
41
+ return a.filter(
42
+ (t) => Q(String(t[n] ?? "")).includes(Q(l))
43
+ );
44
+ }, [a, l, o, K]);
45
+ _(() => {
46
+ const r = (n) => {
47
+ h.current && !h.current.contains(n.target) && v.current && !v.current.contains(n.target) && (g(!1), f(null));
38
48
  };
39
- return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
40
- }, []);
41
- const P = (e, t) => {
42
- b(e, t), t.trim() ? c(!0) : c(!1);
43
- }, S = (e) => {
44
- u == null || u(e), c(!1);
45
- }, T = !j && a.length === 0;
46
- return /* @__PURE__ */ v(
49
+ return document.addEventListener("mousedown", r), () => document.removeEventListener("mousedown", r);
50
+ }, []), _(() => {
51
+ if (!o) return;
52
+ const r = l.trim(), n = (b.current[o] ?? "").trim();
53
+ c && r.length > 0 && (k.some(
54
+ (p) => u.every((y) => {
55
+ const B = y.columnKey ?? y.key;
56
+ return String(p[B] ?? "") === String(c[B] ?? "");
57
+ })
58
+ ) || s == null || s()), r === "" && n.length > 0 && c && (s == null || s()), b.current = {
59
+ ...b.current,
60
+ [o]: l
61
+ };
62
+ }, [l, o, c, k]), _(() => {
63
+ if (!c) return;
64
+ a.some(
65
+ (n) => u.every((t) => {
66
+ const p = t.columnKey ?? t.key;
67
+ return String(n[p] ?? "") === String(c[p] ?? "");
68
+ })
69
+ ) || s == null || s();
70
+ }, [a]);
71
+ const G = (r, n) => {
72
+ V((t) => ({ ...t, [r]: n })), f(r), g(!0), d == null || d(r, n);
73
+ }, H = (r) => {
74
+ f(r), x || g(!0);
75
+ }, J = (r) => {
76
+ var n, t;
77
+ S == null || S(r), g(!1), f(null), o && ((t = (n = D.current[o]) == null ? void 0 : n.querySelector("input")) == null || t.blur());
78
+ }, U = (r) => c ? u.every((n) => {
79
+ const t = n.columnKey ?? n.key;
80
+ return String(r[t] ?? "") === String(c[t] ?? "");
81
+ }) : !1, X = (r) => {
82
+ if (o === r.key)
83
+ return j[r.key] ?? "";
84
+ if (c) {
85
+ const n = r.columnKey ?? r.key;
86
+ return String(c[n] ?? "");
87
+ }
88
+ return "";
89
+ };
90
+ return /* @__PURE__ */ O(
47
91
  "div",
48
92
  {
49
- ref: l,
50
- className: [p.container, I].filter(Boolean).join(" "),
93
+ ref: h,
94
+ className: [$.container, L].filter(Boolean).join(" "),
51
95
  children: [
52
- /* @__PURE__ */ o(
96
+ /* @__PURE__ */ i(
53
97
  "div",
54
98
  {
55
- className: `${p.inputs} ${h || ""}`,
56
- ...R,
57
- children: m.map(({ key: e, label: t, placeholder: r }) => /* @__PURE__ */ o("div", { className: p.inputWrapper, children: /* @__PURE__ */ o(
58
- O,
99
+ className: `${$.inputs} ${E || ""}`,
100
+ ...P,
101
+ children: u.map((r) => /* @__PURE__ */ i(
102
+ "div",
59
103
  {
60
- label: t,
61
- placeholder: r,
62
- value: _[e] ?? "",
63
- onChange: (d) => P(e, d.target.value),
64
- icon: "SearchIcon",
65
- size: s,
66
- disabled: f,
67
- btc: B
68
- }
69
- ) }, e))
104
+ className: $.inputWrapper,
105
+ ref: (n) => {
106
+ D.current[r.key] = n;
107
+ },
108
+ children: /* @__PURE__ */ i(
109
+ z,
110
+ {
111
+ label: r.label,
112
+ placeholder: r.placeholder,
113
+ value: X(r),
114
+ onChange: (n) => G(r.key, n.target.value),
115
+ onFocus: () => H(r.key),
116
+ icon: "SearchIcon",
117
+ size: m,
118
+ disabled: C,
119
+ btc: M
120
+ }
121
+ )
122
+ },
123
+ r.key
124
+ ))
70
125
  }
71
126
  ),
72
- D && L(
73
- /* @__PURE__ */ o(
127
+ q && Z(
128
+ /* @__PURE__ */ i(
74
129
  "div",
75
130
  {
76
- ref: i,
131
+ ref: v,
77
132
  className: [
78
- n.dropdown,
79
- n[s],
80
- n.dropdownPortal,
81
- n.dropdownTable
133
+ e.dropdown,
134
+ e[m],
135
+ e.dropdownPortal,
136
+ e.dropdownTable
82
137
  ].join(" "),
83
- style: E,
84
- children: a.length > 0 ? a.map((e, t) => /* @__PURE__ */ o(
138
+ style: A,
139
+ children: k.length > 0 ? k.map((r, n) => /* @__PURE__ */ i(
85
140
  "div",
86
141
  {
87
- className: `${n.option} ${n.optionTable}`,
88
- onMouseDown: (r) => {
89
- r.preventDefault(), r.stopPropagation(), S(e);
142
+ className: `${e.option} ${e.optionTable} ${U(r) ? e.optionSelected : ""}`,
143
+ onMouseDown: (t) => {
144
+ t.preventDefault(), t.stopPropagation(), J(r);
90
145
  },
91
- children: m.map(({ key: r, columnKey: d, columnHeader: g }) => /* @__PURE__ */ v("div", { className: n.tableColumn, children: [
92
- g && /* @__PURE__ */ o(
93
- "div",
94
- {
95
- className: `${n.columnHeader} ${n[s]}`,
96
- children: g
97
- }
98
- ),
99
- /* @__PURE__ */ o(
100
- "div",
101
- {
102
- className: `${n.columnValue} ${n[s]}`,
103
- children: String(e[d ?? r] ?? "")
104
- }
105
- )
106
- ] }, r))
146
+ style: { padding: 0, gap: 0 },
147
+ children: u.map(({ key: t, columnKey: p, columnHeader: y }) => /* @__PURE__ */ O(
148
+ "div",
149
+ {
150
+ className: e.tableColumn,
151
+ style: { padding: "8px 12px 8px 18px" },
152
+ children: [
153
+ y && /* @__PURE__ */ i(
154
+ "div",
155
+ {
156
+ className: `${e.columnHeader} ${e[m]}`,
157
+ children: y
158
+ }
159
+ ),
160
+ /* @__PURE__ */ i(
161
+ "div",
162
+ {
163
+ className: `${e.columnValue} ${e[m]}`,
164
+ children: String(r[p ?? t] ?? "")
165
+ }
166
+ )
167
+ ]
168
+ },
169
+ t
170
+ ))
107
171
  },
108
- t
109
- )) : T && /* @__PURE__ */ o("span", { className: n.noResults, children: $ })
172
+ n
173
+ )) : /* @__PURE__ */ i("span", { className: e.noResults, children: W })
110
174
  }
111
175
  ),
112
176
  document.getElementById("root") || document.body
@@ -116,5 +180,5 @@ import '../../assets/index4.css';const G = "_container_1kajw_1", M = "_inputs_1k
116
180
  );
117
181
  };
118
182
  export {
119
- X as SearchableInputGroup
183
+ lr as SearchableInputGroup
120
184
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bmi-next-brokers",
3
3
  "description": "Componentes de UI para proyecto BMI Next Brokers",
4
- "version": "2.5.9",
4
+ "version": "2.6.1",
5
5
  "author": "BMI Ahorro España",
6
6
  "contributors": [
7
7
  "José Ramón Jiménez <jrjimenez@bmicos.com>",