bmi-next-brokers 2.5.9 → 2.6.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.
@@ -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,157 @@
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: _ = {},
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
1
+ import { jsxs as Q, jsx as c } from "react/jsx-runtime";
2
+ import { useState as N, useRef as S, useMemo as U, useEffect as B } from "react";
3
+ import { createPortal as X } from "react-dom";
4
+ import { Input as Y } from "../Input/Input.js";
5
+ import { s as t } from "../../Select.module-D_7bjq9u.js";
6
+ import { useBTC as Z } from "../../hooks/btcContext/useBtcContext.js";
7
+ import { useDropdownPosition as z } from "../../hooks/useDropdownPosition.js";
8
+ import '../../assets/index4.css';const R = "_container_1kajw_1", nn = "_inputs_1kajw_7", rn = "_inputWrapper_1kajw_13", _ = {
9
+ container: R,
10
+ inputs: nn,
11
+ inputWrapper: rn
12
+ }, ln = ({
13
+ fields: u,
14
+ selectedItem: s = null,
15
+ options: l = [],
16
+ onSearch: d,
17
+ onSelect: k,
18
+ onReset: a,
19
+ noResultMessage: O = "No se encontraron resultados",
20
+ disabled: $ = !1,
21
+ btc: F = !1,
22
+ size: p = "medium",
23
+ className: C,
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({
27
+ const { btc: T } = Z(), W = F ?? T, j = !!d, [w, y] = N(!1), [K, M] = N(
28
+ {}
29
+ ), [o, g] = N(null), f = S(null), h = S(null), b = S({}), V = w && !$, i = o ? K[o] ?? "" : "", A = z({
28
30
  isOpen: w,
29
- containerRef: l,
30
- dropdownRef: i,
31
- size: s,
32
- optionsLength: a.length,
31
+ containerRef: f,
32
+ dropdownRef: h,
33
+ size: p,
34
+ optionsLength: l.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
+ }), D = (n) => typeof n == "string" ? n.normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/\s+/g, "").toLowerCase() : "", v = U(() => {
37
+ if (!o || !i || j) return l;
38
+ const n = u.find((e) => e.key === o);
39
+ if (!n) return l;
40
+ const r = n.columnKey ?? n.key;
41
+ return l.filter(
42
+ (e) => D(String(e[r] ?? "")).includes(D(i))
43
+ );
44
+ }, [l, i, o, j]);
45
+ B(() => {
46
+ const n = (r) => {
47
+ f.current && !f.current.contains(r.target) && h.current && !h.current.contains(r.target) && (y(!1), g(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", n), () => document.removeEventListener("mousedown", n);
50
+ }, []), B(() => {
51
+ if (!o) return;
52
+ const n = i.trim(), r = (b.current[o] ?? "").trim();
53
+ s && n.length > 0 && (v.some(
54
+ (x) => u.every((m) => {
55
+ const E = m.columnKey ?? m.key;
56
+ return String(x[E] ?? "") === String(s[E] ?? "");
57
+ })
58
+ ) || a == null || a()), n === "" && r.length > 0 && s && (a == null || a()), b.current = {
59
+ ...b.current,
60
+ [o]: i
61
+ };
62
+ }, [i, o, s, v]);
63
+ const G = (n, r) => {
64
+ M((e) => ({ ...e, [n]: r })), g(n), y(!0), d == null || d(n, r);
65
+ }, q = (n) => {
66
+ g(n), w || y(!0);
67
+ }, H = (n) => {
68
+ k == null || k(n), y(!1), g(null);
69
+ }, I = (n) => s ? u.every((r) => {
70
+ const e = r.columnKey ?? r.key;
71
+ return String(n[e] ?? "") === String(s[e] ?? "");
72
+ }) : !1, J = (n) => {
73
+ if (o === n.key)
74
+ return K[n.key] ?? "";
75
+ if (s) {
76
+ const r = n.columnKey ?? n.key;
77
+ return String(s[r] ?? "");
78
+ }
79
+ return "";
80
+ };
81
+ return /* @__PURE__ */ Q(
47
82
  "div",
48
83
  {
49
- ref: l,
50
- className: [p.container, I].filter(Boolean).join(" "),
84
+ ref: f,
85
+ className: [_.container, L].filter(Boolean).join(" "),
51
86
  children: [
52
- /* @__PURE__ */ o(
87
+ /* @__PURE__ */ c(
53
88
  "div",
54
89
  {
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,
90
+ className: `${_.inputs} ${C || ""}`,
91
+ ...P,
92
+ children: u.map((n) => /* @__PURE__ */ c("div", { className: _.inputWrapper, children: /* @__PURE__ */ c(
93
+ Y,
59
94
  {
60
- label: t,
61
- placeholder: r,
62
- value: _[e] ?? "",
63
- onChange: (d) => P(e, d.target.value),
95
+ label: n.label,
96
+ placeholder: n.placeholder,
97
+ value: J(n),
98
+ onChange: (r) => G(n.key, r.target.value),
99
+ onFocus: () => q(n.key),
64
100
  icon: "SearchIcon",
65
- size: s,
66
- disabled: f,
67
- btc: B
101
+ size: p,
102
+ disabled: $,
103
+ btc: W
68
104
  }
69
- ) }, e))
105
+ ) }, n.key))
70
106
  }
71
107
  ),
72
- D && L(
73
- /* @__PURE__ */ o(
108
+ V && X(
109
+ /* @__PURE__ */ c(
74
110
  "div",
75
111
  {
76
- ref: i,
112
+ ref: h,
77
113
  className: [
78
- n.dropdown,
79
- n[s],
80
- n.dropdownPortal,
81
- n.dropdownTable
114
+ t.dropdown,
115
+ t[p],
116
+ t.dropdownPortal,
117
+ t.dropdownTable
82
118
  ].join(" "),
83
- style: E,
84
- children: a.length > 0 ? a.map((e, t) => /* @__PURE__ */ o(
119
+ style: A,
120
+ children: v.length > 0 ? v.map((n, r) => /* @__PURE__ */ c(
85
121
  "div",
86
122
  {
87
- className: `${n.option} ${n.optionTable}`,
88
- onMouseDown: (r) => {
89
- r.preventDefault(), r.stopPropagation(), S(e);
123
+ className: `${t.option} ${t.optionTable} ${I(n) ? t.optionSelected : ""}`,
124
+ onMouseDown: (e) => {
125
+ e.preventDefault(), e.stopPropagation(), H(n);
90
126
  },
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))
127
+ style: { padding: 0, gap: 0 },
128
+ children: u.map(({ key: e, columnKey: x, columnHeader: m }) => /* @__PURE__ */ Q(
129
+ "div",
130
+ {
131
+ className: t.tableColumn,
132
+ style: { padding: "8px 12px 8px 18px" },
133
+ children: [
134
+ m && /* @__PURE__ */ c(
135
+ "div",
136
+ {
137
+ className: `${t.columnHeader} ${t[p]}`,
138
+ children: m
139
+ }
140
+ ),
141
+ /* @__PURE__ */ c(
142
+ "div",
143
+ {
144
+ className: `${t.columnValue} ${t[p]}`,
145
+ children: String(n[x ?? e] ?? "")
146
+ }
147
+ )
148
+ ]
149
+ },
150
+ e
151
+ ))
107
152
  },
108
- t
109
- )) : T && /* @__PURE__ */ o("span", { className: n.noResults, children: $ })
153
+ r
154
+ )) : /* @__PURE__ */ c("span", { className: t.noResults, children: O })
110
155
  }
111
156
  ),
112
157
  document.getElementById("root") || document.body
@@ -116,5 +161,5 @@ import '../../assets/index4.css';const G = "_container_1kajw_1", M = "_inputs_1k
116
161
  );
117
162
  };
118
163
  export {
119
- X as SearchableInputGroup
164
+ ln as SearchableInputGroup
120
165
  };
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.0",
5
5
  "author": "BMI Ahorro España",
6
6
  "contributors": [
7
7
  "José Ramón Jiménez <jrjimenez@bmicos.com>",