next-recomponents 2.0.57 → 2.0.58

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/index.d.mts CHANGED
@@ -275,6 +275,7 @@ interface TableProps {
275
275
  flex?: number;
276
276
  sortBy?: Record<string, "DESC" | "ASC">;
277
277
  onCloseModal?: (data: GridValidRowModel) => Promise<boolean>;
278
+ disabled?: boolean;
278
279
  [key: string]: any;
279
280
  }
280
281
 
package/dist/index.d.ts CHANGED
@@ -275,6 +275,7 @@ interface TableProps {
275
275
  flex?: number;
276
276
  sortBy?: Record<string, "DESC" | "ASC">;
277
277
  onCloseModal?: (data: GridValidRowModel) => Promise<boolean>;
278
+ disabled?: boolean;
278
279
  [key: string]: any;
279
280
  }
280
281
 
package/dist/index.js CHANGED
@@ -38766,7 +38766,9 @@ function Header({
38766
38766
  header,
38767
38767
  context,
38768
38768
  drag,
38769
- padding
38769
+ padding,
38770
+ index,
38771
+ length
38770
38772
  }) {
38771
38773
  const [visible, setVisible] = (0, import_react18.useState)(false);
38772
38774
  const [hovered, setHovered] = (0, import_react18.useState)(false);
@@ -38776,14 +38778,17 @@ function Header({
38776
38778
  const [coords, setCoords] = (0, import_react18.useState)(
38777
38779
  null
38778
38780
  );
38779
- const filteredValues = [
38780
- ...new Set(context.data.map((d) => d[header]))
38781
- ].filter((d) => {
38782
- if (text == "") return true;
38783
- return `${d}`.toLowerCase().includes(text.toLowerCase());
38784
- });
38785
- const [selected, setSelected] = (0, import_react18.useState)([...filteredValues]);
38781
+ const filteredValues = (0, import_react18.useMemo)(() => {
38782
+ return [...new Set(context.data.map((d) => d[header]))].filter((d) => {
38783
+ if (text == "") return true;
38784
+ return `${d}`.toLowerCase().includes(text.toLowerCase());
38785
+ });
38786
+ }, [context.data, header, text]);
38787
+ const [selected, setSelected] = (0, import_react18.useState)([]);
38786
38788
  const hasFilter = context.filters.find((b) => b.field == header);
38789
+ (0, import_react18.useEffect)(() => {
38790
+ setSelected(filteredValues);
38791
+ }, [filteredValues]);
38787
38792
  (0, import_react18.useEffect)(() => {
38788
38793
  if (visible) {
38789
38794
  context.setCurrentHeader(header);
@@ -38850,13 +38855,13 @@ function Header({
38850
38855
  "div",
38851
38856
  {
38852
38857
  ref: cellRef,
38853
- className: " border-r ",
38858
+ className: index < length - 1 ? "border-r" : "",
38854
38859
  onMouseEnter: (e) => setHovered(true),
38855
38860
  onMouseLeave: (e) => setHovered(false),
38856
38861
  style: { zIndex: 10, height: `${padding}px`, maxHeight: "100px" },
38857
38862
  children: [
38858
38863
  /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex justify-between items-center ", children: [
38859
- /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex gap-2", children: [
38864
+ !context.disabled ? /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex gap-2", children: [
38860
38865
  hasFilter ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38861
38866
  "div",
38862
38867
  {
@@ -38879,7 +38884,7 @@ function Header({
38879
38884
  children: sortIndex >= 0 ? context.sort[sortIndex].type === "ASC" ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ArrowUPIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ArrowDownIcon2, {}) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", {})
38880
38885
  }
38881
38886
  )
38882
- ] }),
38887
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", {}),
38883
38888
  /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38884
38889
  "div",
38885
38890
  {
@@ -38893,7 +38898,7 @@ function Header({
38893
38898
  children: header
38894
38899
  }
38895
38900
  ),
38896
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38901
+ !context.disabled ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38897
38902
  "div",
38898
38903
  {
38899
38904
  style: { zIndex: 10 },
@@ -38901,9 +38906,9 @@ function Header({
38901
38906
  onClick: (e) => setVisible(true),
38902
38907
  children: hovered ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(DropIcon, {}) : ""
38903
38908
  }
38904
- )
38909
+ ) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", {})
38905
38910
  ] }),
38906
- context.currentHeader != header && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38911
+ !context.disabled && context.currentHeader != header && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38907
38912
  "div",
38908
38913
  {
38909
38914
  onMouseDown: (e) => drag.startDrag(e, header),
@@ -39029,9 +39034,9 @@ function Header({
39029
39034
  type: "checkbox",
39030
39035
  onChange: (e) => {
39031
39036
  const ns = [...selected];
39032
- const index = ns.findIndex((n) => n == d);
39033
- if (index >= 0) {
39034
- ns.splice(index, 1);
39037
+ const index2 = ns.findIndex((n) => n == d);
39038
+ if (index2 >= 0) {
39039
+ ns.splice(index2, 1);
39035
39040
  } else {
39036
39041
  ns.push(d);
39037
39042
  }
@@ -39040,7 +39045,7 @@ function Header({
39040
39045
  checked: text != "" || selected.includes(d)
39041
39046
  }
39042
39047
  ),
39043
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "truncate", children: d })
39048
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "truncate", children: d == "" ? "Vacias" : !Boolean(d) ? "null" : d })
39044
39049
  ] }, d);
39045
39050
  })
39046
39051
  ]
@@ -39135,7 +39140,9 @@ function usePaginacion({
39135
39140
  tamanioPagina = 100,
39136
39141
  paginaInicial = 1
39137
39142
  }) {
39138
- const totalPaginas = Math.max(1, Math.ceil(total / tamanioPagina));
39143
+ const [totalPaginas, setTotalPaginas] = (0, import_react19.useState)(
39144
+ Math.max(1, Math.ceil(total / tamanioPagina))
39145
+ );
39139
39146
  const [pagina, setPagina] = (0, import_react19.useState)(
39140
39147
  Math.min(Math.max(paginaInicial, 1), totalPaginas)
39141
39148
  );
@@ -39159,6 +39166,10 @@ function usePaginacion({
39159
39166
  },
39160
39167
  [totalPaginas]
39161
39168
  );
39169
+ (0, import_react19.useEffect)(() => {
39170
+ setTotalPaginas(Math.max(1, Math.ceil(total / tamanioPagina)));
39171
+ setPagina(1);
39172
+ }, [total]);
39162
39173
  return {
39163
39174
  rango,
39164
39175
  inicio,
@@ -39265,12 +39276,14 @@ function HTable({
39265
39276
  observer.observe(tableRef.current);
39266
39277
  return () => observer.disconnect();
39267
39278
  }, [headers.length]);
39268
- const searchedData = context.filteredData.filter((row) => {
39269
- if (context.searchBy === "") return true;
39270
- return Object.values(row).some(
39271
- (value) => String(value).toLowerCase().includes(context.searchBy.toLowerCase())
39272
- );
39273
- });
39279
+ const searchedData = (0, import_react20.useMemo)(() => {
39280
+ return context.filteredData.filter((row) => {
39281
+ if (context.searchBy === "") return true;
39282
+ return Object.values(row).some(
39283
+ (value) => String(value).toLowerCase().includes(context.searchBy.toLowerCase())
39284
+ );
39285
+ });
39286
+ }, [context.filteredData]);
39274
39287
  const pagination = use_pagination_default({ total: searchedData.length });
39275
39288
  return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
39276
39289
  "div",
@@ -39366,6 +39379,8 @@ function HTable({
39366
39379
  children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39367
39380
  Header,
39368
39381
  {
39382
+ length: headers.length,
39383
+ index: i,
39369
39384
  padding,
39370
39385
  header,
39371
39386
  context,
@@ -39386,7 +39401,8 @@ function HTable({
39386
39401
  width: Object.values(widths).reduce((acc, i) => acc + i, 0)
39387
39402
  },
39388
39403
  className: [
39389
- "grid max-h-[500px] overflow-hidden overflow-y-scroll "
39404
+ "grid max-h-[500px] ",
39405
+ context.filteredData.length >= 5 ? "overflow-hidden overflow-y-scroll " : ""
39390
39406
  ].join(" "),
39391
39407
  children: searchedData.slice(pagination.inicio - 1, pagination.fin).map((row, rowIndex) => {
39392
39408
  const items = Object.entries(row);
@@ -39541,7 +39557,7 @@ function HTable({
39541
39557
  },
39542
39558
  className: ["grid border-b bg-white"].join(" "),
39543
39559
  children: Object.keys((context == null ? void 0 : context.footer) || {}).length > 0 && headers.map((header) => {
39544
- var _a, _b, _c, _d;
39560
+ var _a, _b, _c, _d, _e;
39545
39561
  if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
39546
39562
  if (header.startsWith("_") && !header.startsWith("__"))
39547
39563
  return null;
@@ -39553,10 +39569,10 @@ function HTable({
39553
39569
  maxHeight: "100px"
39554
39570
  },
39555
39571
  title: ((_c = context.footer) == null ? void 0 : _c[header]) + " de " + header,
39556
- className: " cursor-default font-bold bg-white flex items-center justify-center border-r text-xs my-5 ",
39572
+ className: " cursor-default font-bold bg-white flex items-center justify-center text-xs my-5 " + (((_d = context.footer) == null ? void 0 : _d[header]) ? " border-r border-l " : ""),
39557
39573
  children: valueFormatter({
39558
39574
  currentCoin: context.currentCoin,
39559
- value: ((_d = context.footer) == null ? void 0 : _d[header]) ? context.footer[header] == "sum" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) : context.footer[header] == "count" ? context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : context.footer[header] == "avg" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) / context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : "" : ""
39575
+ value: ((_e = context.footer) == null ? void 0 : _e[header]) ? context.footer[header] == "sum" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) : context.footer[header] == "count" ? context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : context.footer[header] == "avg" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) / context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : "" : ""
39560
39576
  })
39561
39577
  },
39562
39578
  header
@@ -39564,7 +39580,7 @@ function HTable({
39564
39580
  })
39565
39581
  }
39566
39582
  ),
39567
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex justify-end p-2", children: [
39583
+ searchedData.length > 100 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex justify-end p-2", children: [
39568
39584
  pagination.rango,
39569
39585
  " de ",
39570
39586
  pagination.total,
package/dist/index.mjs CHANGED
@@ -38501,18 +38501,19 @@ function Table3({
38501
38501
  }
38502
38502
 
38503
38503
  // src/table-advanced/index.tsx
38504
- import { useEffect as useEffect13 } from "react";
38504
+ import { useEffect as useEffect14 } from "react";
38505
38505
 
38506
38506
  // src/table-advanced/h.table.tsx
38507
38507
  import React10, {
38508
38508
  useCallback as useCallback3,
38509
- useEffect as useEffect11,
38509
+ useEffect as useEffect12,
38510
+ useMemo as useMemo10,
38510
38511
  useRef as useRef7,
38511
38512
  useState as useState16
38512
38513
  } from "react";
38513
38514
 
38514
38515
  // src/table-advanced/header.tsx
38515
- import { useEffect as useEffect10, useRef as useRef6, useState as useState14 } from "react";
38516
+ import { useEffect as useEffect10, useMemo as useMemo8, useRef as useRef6, useState as useState14 } from "react";
38516
38517
  import { createPortal } from "react-dom";
38517
38518
 
38518
38519
  // src/table-advanced/icons.tsx
@@ -38762,7 +38763,9 @@ function Header({
38762
38763
  header,
38763
38764
  context,
38764
38765
  drag,
38765
- padding
38766
+ padding,
38767
+ index,
38768
+ length
38766
38769
  }) {
38767
38770
  const [visible, setVisible] = useState14(false);
38768
38771
  const [hovered, setHovered] = useState14(false);
@@ -38772,14 +38775,17 @@ function Header({
38772
38775
  const [coords, setCoords] = useState14(
38773
38776
  null
38774
38777
  );
38775
- const filteredValues = [
38776
- ...new Set(context.data.map((d) => d[header]))
38777
- ].filter((d) => {
38778
- if (text == "") return true;
38779
- return `${d}`.toLowerCase().includes(text.toLowerCase());
38780
- });
38781
- const [selected, setSelected] = useState14([...filteredValues]);
38778
+ const filteredValues = useMemo8(() => {
38779
+ return [...new Set(context.data.map((d) => d[header]))].filter((d) => {
38780
+ if (text == "") return true;
38781
+ return `${d}`.toLowerCase().includes(text.toLowerCase());
38782
+ });
38783
+ }, [context.data, header, text]);
38784
+ const [selected, setSelected] = useState14([]);
38782
38785
  const hasFilter = context.filters.find((b) => b.field == header);
38786
+ useEffect10(() => {
38787
+ setSelected(filteredValues);
38788
+ }, [filteredValues]);
38783
38789
  useEffect10(() => {
38784
38790
  if (visible) {
38785
38791
  context.setCurrentHeader(header);
@@ -38846,13 +38852,13 @@ function Header({
38846
38852
  "div",
38847
38853
  {
38848
38854
  ref: cellRef,
38849
- className: " border-r ",
38855
+ className: index < length - 1 ? "border-r" : "",
38850
38856
  onMouseEnter: (e) => setHovered(true),
38851
38857
  onMouseLeave: (e) => setHovered(false),
38852
38858
  style: { zIndex: 10, height: `${padding}px`, maxHeight: "100px" },
38853
38859
  children: [
38854
38860
  /* @__PURE__ */ jsxs23("div", { className: "flex justify-between items-center ", children: [
38855
- /* @__PURE__ */ jsxs23("div", { className: "flex gap-2", children: [
38861
+ !context.disabled ? /* @__PURE__ */ jsxs23("div", { className: "flex gap-2", children: [
38856
38862
  hasFilter ? /* @__PURE__ */ jsx31(
38857
38863
  "div",
38858
38864
  {
@@ -38875,7 +38881,7 @@ function Header({
38875
38881
  children: sortIndex >= 0 ? context.sort[sortIndex].type === "ASC" ? /* @__PURE__ */ jsx31(ArrowUPIcon, {}) : /* @__PURE__ */ jsx31(ArrowDownIcon2, {}) : /* @__PURE__ */ jsx31("div", {})
38876
38882
  }
38877
38883
  )
38878
- ] }),
38884
+ ] }) : /* @__PURE__ */ jsx31("div", {}),
38879
38885
  /* @__PURE__ */ jsx31(
38880
38886
  "div",
38881
38887
  {
@@ -38889,7 +38895,7 @@ function Header({
38889
38895
  children: header
38890
38896
  }
38891
38897
  ),
38892
- /* @__PURE__ */ jsx31(
38898
+ !context.disabled ? /* @__PURE__ */ jsx31(
38893
38899
  "div",
38894
38900
  {
38895
38901
  style: { zIndex: 10 },
@@ -38897,9 +38903,9 @@ function Header({
38897
38903
  onClick: (e) => setVisible(true),
38898
38904
  children: hovered ? /* @__PURE__ */ jsx31(DropIcon, {}) : ""
38899
38905
  }
38900
- )
38906
+ ) : /* @__PURE__ */ jsx31("div", {})
38901
38907
  ] }),
38902
- context.currentHeader != header && /* @__PURE__ */ jsx31(
38908
+ !context.disabled && context.currentHeader != header && /* @__PURE__ */ jsx31(
38903
38909
  "div",
38904
38910
  {
38905
38911
  onMouseDown: (e) => drag.startDrag(e, header),
@@ -39025,9 +39031,9 @@ function Header({
39025
39031
  type: "checkbox",
39026
39032
  onChange: (e) => {
39027
39033
  const ns = [...selected];
39028
- const index = ns.findIndex((n) => n == d);
39029
- if (index >= 0) {
39030
- ns.splice(index, 1);
39034
+ const index2 = ns.findIndex((n) => n == d);
39035
+ if (index2 >= 0) {
39036
+ ns.splice(index2, 1);
39031
39037
  } else {
39032
39038
  ns.push(d);
39033
39039
  }
@@ -39036,7 +39042,7 @@ function Header({
39036
39042
  checked: text != "" || selected.includes(d)
39037
39043
  }
39038
39044
  ),
39039
- /* @__PURE__ */ jsx31("div", { className: "truncate", children: d })
39045
+ /* @__PURE__ */ jsx31("div", { className: "truncate", children: d == "" ? "Vacias" : !Boolean(d) ? "null" : d })
39040
39046
  ] }, d);
39041
39047
  })
39042
39048
  ]
@@ -39125,19 +39131,21 @@ function valueFormatter({
39125
39131
  }
39126
39132
 
39127
39133
  // src/table-advanced/use.pagination.tsx
39128
- import { useState as useState15, useMemo as useMemo8, useCallback as useCallback2 } from "react";
39134
+ import { useState as useState15, useMemo as useMemo9, useCallback as useCallback2, useEffect as useEffect11 } from "react";
39129
39135
  function usePaginacion({
39130
39136
  total,
39131
39137
  tamanioPagina = 100,
39132
39138
  paginaInicial = 1
39133
39139
  }) {
39134
- const totalPaginas = Math.max(1, Math.ceil(total / tamanioPagina));
39140
+ const [totalPaginas, setTotalPaginas] = useState15(
39141
+ Math.max(1, Math.ceil(total / tamanioPagina))
39142
+ );
39135
39143
  const [pagina, setPagina] = useState15(
39136
39144
  Math.min(Math.max(paginaInicial, 1), totalPaginas)
39137
39145
  );
39138
39146
  const inicio = total === 0 ? 0 : (pagina - 1) * tamanioPagina + 1;
39139
39147
  const fin = Math.min(pagina * tamanioPagina, total);
39140
- const rango = useMemo8(() => {
39148
+ const rango = useMemo9(() => {
39141
39149
  if (total === 0) return "0 a 0";
39142
39150
  return `${inicio} a ${fin}`;
39143
39151
  }, [inicio, fin, total]);
@@ -39155,6 +39163,10 @@ function usePaginacion({
39155
39163
  },
39156
39164
  [totalPaginas]
39157
39165
  );
39166
+ useEffect11(() => {
39167
+ setTotalPaginas(Math.max(1, Math.ceil(total / tamanioPagina)));
39168
+ setPagina(1);
39169
+ }, [total]);
39158
39170
  return {
39159
39171
  rango,
39160
39172
  inicio,
@@ -39230,7 +39242,7 @@ function HTable({
39230
39242
  return { widths: widths2, gridTemplateColumns: gridTemplateColumns2, startDrag: startDrag2, setWidths: setWidths2 };
39231
39243
  }
39232
39244
  const { gridTemplateColumns, startDrag, widths, setWidths } = useResizableColumns(headers);
39233
- useEffect11(() => {
39245
+ useEffect12(() => {
39234
39246
  if (!tableRef.current) return;
39235
39247
  const observer = new ResizeObserver(([entry]) => {
39236
39248
  const ocultos = headers.filter(
@@ -39261,12 +39273,14 @@ function HTable({
39261
39273
  observer.observe(tableRef.current);
39262
39274
  return () => observer.disconnect();
39263
39275
  }, [headers.length]);
39264
- const searchedData = context.filteredData.filter((row) => {
39265
- if (context.searchBy === "") return true;
39266
- return Object.values(row).some(
39267
- (value) => String(value).toLowerCase().includes(context.searchBy.toLowerCase())
39268
- );
39269
- });
39276
+ const searchedData = useMemo10(() => {
39277
+ return context.filteredData.filter((row) => {
39278
+ if (context.searchBy === "") return true;
39279
+ return Object.values(row).some(
39280
+ (value) => String(value).toLowerCase().includes(context.searchBy.toLowerCase())
39281
+ );
39282
+ });
39283
+ }, [context.filteredData]);
39270
39284
  const pagination = use_pagination_default({ total: searchedData.length });
39271
39285
  return /* @__PURE__ */ jsxs25(
39272
39286
  "div",
@@ -39362,6 +39376,8 @@ function HTable({
39362
39376
  children: /* @__PURE__ */ jsx33(
39363
39377
  Header,
39364
39378
  {
39379
+ length: headers.length,
39380
+ index: i,
39365
39381
  padding,
39366
39382
  header,
39367
39383
  context,
@@ -39382,7 +39398,8 @@ function HTable({
39382
39398
  width: Object.values(widths).reduce((acc, i) => acc + i, 0)
39383
39399
  },
39384
39400
  className: [
39385
- "grid max-h-[500px] overflow-hidden overflow-y-scroll "
39401
+ "grid max-h-[500px] ",
39402
+ context.filteredData.length >= 5 ? "overflow-hidden overflow-y-scroll " : ""
39386
39403
  ].join(" "),
39387
39404
  children: searchedData.slice(pagination.inicio - 1, pagination.fin).map((row, rowIndex) => {
39388
39405
  const items = Object.entries(row);
@@ -39537,7 +39554,7 @@ function HTable({
39537
39554
  },
39538
39555
  className: ["grid border-b bg-white"].join(" "),
39539
39556
  children: Object.keys((context == null ? void 0 : context.footer) || {}).length > 0 && headers.map((header) => {
39540
- var _a, _b, _c, _d;
39557
+ var _a, _b, _c, _d, _e;
39541
39558
  if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
39542
39559
  if (header.startsWith("_") && !header.startsWith("__"))
39543
39560
  return null;
@@ -39549,10 +39566,10 @@ function HTable({
39549
39566
  maxHeight: "100px"
39550
39567
  },
39551
39568
  title: ((_c = context.footer) == null ? void 0 : _c[header]) + " de " + header,
39552
- className: " cursor-default font-bold bg-white flex items-center justify-center border-r text-xs my-5 ",
39569
+ className: " cursor-default font-bold bg-white flex items-center justify-center text-xs my-5 " + (((_d = context.footer) == null ? void 0 : _d[header]) ? " border-r border-l " : ""),
39553
39570
  children: valueFormatter({
39554
39571
  currentCoin: context.currentCoin,
39555
- value: ((_d = context.footer) == null ? void 0 : _d[header]) ? context.footer[header] == "sum" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) : context.footer[header] == "count" ? context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : context.footer[header] == "avg" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) / context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : "" : ""
39572
+ value: ((_e = context.footer) == null ? void 0 : _e[header]) ? context.footer[header] == "sum" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) : context.footer[header] == "count" ? context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : context.footer[header] == "avg" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) / context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : "" : ""
39556
39573
  })
39557
39574
  },
39558
39575
  header
@@ -39560,7 +39577,7 @@ function HTable({
39560
39577
  })
39561
39578
  }
39562
39579
  ),
39563
- /* @__PURE__ */ jsxs25("div", { className: "flex justify-end p-2", children: [
39580
+ searchedData.length > 100 && /* @__PURE__ */ jsxs25("div", { className: "flex justify-end p-2", children: [
39564
39581
  pagination.rango,
39565
39582
  " de ",
39566
39583
  pagination.total,
@@ -39663,7 +39680,7 @@ function ModalContent({
39663
39680
  }
39664
39681
 
39665
39682
  // src/table-advanced/context.ts
39666
- import { useEffect as useEffect12, useMemo as useMemo10, useReducer as useReducer3, useState as useState17 } from "react";
39683
+ import { useEffect as useEffect13, useMemo as useMemo11, useReducer as useReducer3, useState as useState17 } from "react";
39667
39684
 
39668
39685
  // src/table-advanced/filter.reducer.ts
39669
39686
  var filterReducer = (acc, b) => {
@@ -39703,7 +39720,7 @@ function useContext({ onSelect }) {
39703
39720
  );
39704
39721
  const [searchBy, setSearchBy] = useState17("");
39705
39722
  const [sort, setSort] = useReducer3(sortReducer, new Array());
39706
- const sortedData = useMemo10(() => {
39723
+ const sortedData = useMemo11(() => {
39707
39724
  return [...data].sort((a, b) => {
39708
39725
  for (const { field, type } of sort.reverse()) {
39709
39726
  const av = a[field];
@@ -39733,7 +39750,7 @@ function useContext({ onSelect }) {
39733
39750
  }
39734
39751
  return true;
39735
39752
  });
39736
- useEffect12(() => {
39753
+ useEffect13(() => {
39737
39754
  if (filters.length == 0) {
39738
39755
  setEditions([]);
39739
39756
  }
@@ -39766,7 +39783,7 @@ import { jsx as jsx34 } from "react/jsx-runtime";
39766
39783
  function TableAdvanced(tableProps) {
39767
39784
  const { data, ...props } = tableProps;
39768
39785
  const context = useContext({ onSelect: Boolean(tableProps.onSelect) });
39769
- useEffect13(() => {
39786
+ useEffect14(() => {
39770
39787
  context.setData(
39771
39788
  Array.isArray(data) ? data.map((d) => {
39772
39789
  return {
@@ -39777,7 +39794,7 @@ function TableAdvanced(tableProps) {
39777
39794
  }) : data
39778
39795
  );
39779
39796
  }, [data]);
39780
- useEffect13(() => {
39797
+ useEffect14(() => {
39781
39798
  if (tableProps == null ? void 0 : tableProps.sortBy) {
39782
39799
  const [k, v] = Object.entries(tableProps.sortBy)[0];
39783
39800
  context.setSort({ [k]: v });
@@ -39796,7 +39813,7 @@ function TableAdvanced(tableProps) {
39796
39813
  }
39797
39814
 
39798
39815
  // src/tabs/index.tsx
39799
- import React11, { useEffect as useEffect14, useState as useState19 } from "react";
39816
+ import React11, { useEffect as useEffect15, useState as useState19 } from "react";
39800
39817
  import { Fragment as Fragment3, jsx as jsx35, jsxs as jsxs26 } from "react/jsx-runtime";
39801
39818
  function TabContainer({
39802
39819
  children,
@@ -39813,7 +39830,7 @@ function TabContainer({
39813
39830
  if (e.key === "ArrowLeft")
39814
39831
  setIndex((k - 1 + labels.length) % labels.length);
39815
39832
  };
39816
- useEffect14(() => {
39833
+ useEffect15(() => {
39817
39834
  setIndex(currentIndex);
39818
39835
  }, [currentIndex]);
39819
39836
  return /* @__PURE__ */ jsxs26("div", { className: "w-full bg-white", children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "2.0.57",
3
+ "version": "2.0.58",
4
4
  "description": "description nueva",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -138,13 +138,17 @@ export default function HTable({
138
138
  observer.observe(tableRef.current);
139
139
  return () => observer.disconnect();
140
140
  }, [headers.length]);
141
- const searchedData = context.filteredData.filter((row) => {
142
- if (context.searchBy === "") return true;
143
141
 
144
- return Object.values(row).some((value) =>
145
- String(value).toLowerCase().includes(context.searchBy.toLowerCase()),
146
- );
147
- });
142
+ const searchedData = useMemo(() => {
143
+ return context.filteredData.filter((row) => {
144
+ if (context.searchBy === "") return true;
145
+
146
+ return Object.values(row).some((value) =>
147
+ String(value).toLowerCase().includes(context.searchBy.toLowerCase()),
148
+ );
149
+ });
150
+ }, [context.filteredData]);
151
+
148
152
  const pagination = usePaginacion({ total: searchedData.length });
149
153
  return (
150
154
  <div
@@ -247,6 +251,8 @@ export default function HTable({
247
251
  // style={{ position: "relative" }}
248
252
  >
249
253
  <Header
254
+ length={headers.length}
255
+ index={i}
250
256
  padding={padding}
251
257
  header={header}
252
258
  context={context}
@@ -284,7 +290,10 @@ export default function HTable({
284
290
  width: Object.values(widths).reduce((acc, i) => acc + i, 0),
285
291
  }}
286
292
  className={[
287
- "grid max-h-[500px] overflow-hidden overflow-y-scroll ",
293
+ "grid max-h-[500px] ",
294
+ context.filteredData.length >= 5
295
+ ? "overflow-hidden overflow-y-scroll "
296
+ : "",
288
297
  ].join(" ")}
289
298
  >
290
299
  {searchedData
@@ -515,7 +524,8 @@ export default function HTable({
515
524
  className={
516
525
  " cursor-default font-bold " +
517
526
  " bg-white flex items-center justify-center" +
518
- " border-r text-xs my-5 "
527
+ " text-xs my-5 " +
528
+ (context.footer?.[header] ? " border-r border-l " : "")
519
529
  }
520
530
  >
521
531
  {valueFormatter({
@@ -543,23 +553,25 @@ export default function HTable({
543
553
  );
544
554
  })}
545
555
  </div>
546
- <div className="flex justify-end p-2">
547
- {pagination.rango} de {pagination.total}
548
- <div className="flex items-center gap-5 mx-5">
549
- <button
550
- onClick={(e) => pagination.hasPrev && pagination.prev()}
551
- className={pagination.hasPrev ? "" : "text-gray-300"}
552
- >
553
- <PrevIcon />
554
- </button>
555
- <button
556
- onClick={(e) => pagination.hasNext && pagination.next()}
557
- className={pagination.hasNext ? "" : "text-gray-300"}
558
- >
559
- <NextIcon />
560
- </button>
556
+ {searchedData.length > 100 && (
557
+ <div className="flex justify-end p-2">
558
+ {pagination.rango} de {pagination.total}
559
+ <div className="flex items-center gap-5 mx-5">
560
+ <button
561
+ onClick={(e) => pagination.hasPrev && pagination.prev()}
562
+ className={pagination.hasPrev ? "" : "text-gray-300"}
563
+ >
564
+ <PrevIcon />
565
+ </button>
566
+ <button
567
+ onClick={(e) => pagination.hasNext && pagination.next()}
568
+ className={pagination.hasNext ? "" : "text-gray-300"}
569
+ >
570
+ <NextIcon />
571
+ </button>
572
+ </div>
561
573
  </div>
562
- </div>
574
+ )}
563
575
  </div>
564
576
 
565
577
  {context.modal && (
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef, useState } from "react";
1
+ import { useEffect, useMemo, useRef, useState } from "react";
2
2
  import { createPortal } from "react-dom";
3
3
  import DropIcon, {
4
4
  ArrowDownIcon,
@@ -17,14 +17,18 @@ export function Header({
17
17
  context,
18
18
  drag,
19
19
  padding,
20
+ index,
21
+ length,
20
22
  }: {
21
23
  header: string;
22
24
  context: ContextType & Omit<TableProps, "data">;
25
+ index: number;
23
26
  drag: {
24
27
  widths: Record<string, number>;
25
28
  gridTemplateColumns: string;
26
29
  startDrag: (e: React.MouseEvent, headerKey: string) => void;
27
30
  };
31
+ length: number;
28
32
  padding: string;
29
33
  }) {
30
34
  const [visible, setVisible] = useState(false);
@@ -36,17 +40,21 @@ export function Header({
36
40
  null,
37
41
  );
38
42
 
39
- const filteredValues = [
40
- ...new Set(context.data.map((d) => d[header])),
41
- ].filter((d) => {
42
- if (text == "") return true;
43
- return `${d}`.toLowerCase().includes(text.toLowerCase());
44
- });
43
+ const filteredValues = useMemo(() => {
44
+ return [...new Set(context.data.map((d) => d[header]))].filter((d) => {
45
+ if (text == "") return true;
46
+ return `${d}`.toLowerCase().includes(text.toLowerCase());
47
+ });
48
+ }, [context.data, header, text]);
45
49
 
46
- const [selected, setSelected] = useState([...filteredValues]);
50
+ const [selected, setSelected] = useState<any[]>([]);
47
51
 
48
52
  const hasFilter = context.filters.find((b) => b.field == header);
49
53
 
54
+ useEffect(() => {
55
+ setSelected(filteredValues);
56
+ }, [filteredValues]);
57
+
50
58
  useEffect(() => {
51
59
  if (visible) {
52
60
  context.setCurrentHeader(header);
@@ -121,44 +129,49 @@ export function Header({
121
129
  <div className=" ">
122
130
  <div
123
131
  ref={cellRef}
124
- className={" border-r "}
132
+ className={index < length - 1 ? "border-r" : ""}
125
133
  onMouseEnter={(e) => setHovered(true)}
126
134
  onMouseLeave={(e) => setHovered(false)}
127
135
  style={{ zIndex: 10, height: `${padding}px`, maxHeight: "100px" }}
128
136
  >
129
137
  <div className="flex justify-between items-center ">
130
- <div className="flex gap-2">
131
- {hasFilter ? (
138
+ {!context.disabled ? (
139
+ <div className="flex gap-2">
140
+ {hasFilter ? (
141
+ <div
142
+ className="cursor-pointer"
143
+ onClick={(e) => {
144
+ context.setFilters(null);
145
+ setSelected(filteredValues);
146
+ }}
147
+ >
148
+ <FilterIcon />
149
+ </div>
150
+ ) : (
151
+ <div></div>
152
+ )}
153
+
132
154
  <div
133
- className="cursor-pointer"
134
155
  onClick={(e) => {
135
- context.setFilters(null);
136
- setSelected(filteredValues);
156
+ context.setSort({
157
+ [header]: "TOGGLE",
158
+ });
137
159
  }}
138
160
  >
139
- <FilterIcon />
140
- </div>
141
- ) : (
142
- <div></div>
143
- )}
144
- <div
145
- onClick={(e) => {
146
- context.setSort({
147
- [header]: "TOGGLE",
148
- });
149
- }}
150
- >
151
- {sortIndex >= 0 ? (
152
- context.sort[sortIndex].type === "ASC" ? (
153
- <ArrowUPIcon />
161
+ {sortIndex >= 0 ? (
162
+ context.sort[sortIndex].type === "ASC" ? (
163
+ <ArrowUPIcon />
164
+ ) : (
165
+ <ArrowDownIcon />
166
+ )
154
167
  ) : (
155
- <ArrowDownIcon />
156
- )
157
- ) : (
158
- <div></div>
159
- )}
168
+ <div></div>
169
+ )}
170
+ </div>
160
171
  </div>
161
- </div>
172
+ ) : (
173
+ <div></div>
174
+ )}
162
175
  <div
163
176
  className="font-bold flex truncate text-xs items-center "
164
177
  style={{ height: `${padding}px` }}
@@ -170,16 +183,20 @@ export function Header({
170
183
  >
171
184
  {header}
172
185
  </div>
173
- <div
174
- style={{ zIndex: 10 }}
175
- className="icon font-bold p-1 cursor-pointer pr-3 "
176
- onClick={(e) => setVisible(true)}
177
- >
178
- {hovered ? <DropIcon /> : ""}
179
- </div>
186
+ {!context.disabled ? (
187
+ <div
188
+ style={{ zIndex: 10 }}
189
+ className="icon font-bold p-1 cursor-pointer pr-3 "
190
+ onClick={(e) => setVisible(true)}
191
+ >
192
+ {hovered ? <DropIcon /> : ""}
193
+ </div>
194
+ ) : (
195
+ <div></div>
196
+ )}
180
197
  </div>
181
198
 
182
- {context.currentHeader != header && (
199
+ {!context.disabled && context.currentHeader != header && (
183
200
  <div
184
201
  onMouseDown={(e) => drag.startDrag(e, header)}
185
202
  className="absolute top-0 h-full cursor-col-resize hover:bg-blue-300 "
@@ -304,7 +321,13 @@ export function Header({
304
321
  }}
305
322
  checked={text != "" || selected.includes(d)}
306
323
  />
307
- <div className="truncate">{d}</div>
324
+ <div className="truncate">
325
+ {d == ""
326
+ ? "Vacias"
327
+ : !Boolean(d)
328
+ ? "null"
329
+ : d}
330
+ </div>
308
331
  </div>
309
332
  );
310
333
  })}
@@ -52,6 +52,7 @@ export interface TableProps {
52
52
  flex?: number;
53
53
  sortBy?: Record<string, "DESC" | "ASC">;
54
54
  onCloseModal?: (data: GridValidRowModel) => Promise<boolean>;
55
+ disabled?: boolean;
55
56
  [key: string]: any;
56
57
  }
57
58
 
@@ -1,4 +1,4 @@
1
- import { useState, useMemo, useCallback } from "react";
1
+ import { useState, useMemo, useCallback, useEffect } from "react";
2
2
 
3
3
  function usePaginacion({
4
4
  total,
@@ -9,7 +9,9 @@ function usePaginacion({
9
9
  tamanioPagina?: number;
10
10
  paginaInicial?: number;
11
11
  }) {
12
- const totalPaginas = Math.max(1, Math.ceil(total / tamanioPagina));
12
+ const [totalPaginas, setTotalPaginas] = useState(
13
+ Math.max(1, Math.ceil(total / tamanioPagina)),
14
+ );
13
15
 
14
16
  const [pagina, setPagina] = useState(
15
17
  Math.min(Math.max(paginaInicial, 1), totalPaginas),
@@ -41,6 +43,10 @@ function usePaginacion({
41
43
  [totalPaginas],
42
44
  );
43
45
 
46
+ useEffect(() => {
47
+ setTotalPaginas(Math.max(1, Math.ceil(total / tamanioPagina)));
48
+ setPagina(1);
49
+ }, [total]);
44
50
  return {
45
51
  rango,
46
52
  inicio,