@zauru-sdk/components 6.14.0 → 6.14.2
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/CHANGELOG.md +16 -0
- package/dist/Table/ZauruTable.d.ts +2 -0
- package/dist/esm/Table/ZauruTable.js +57 -23
- package/package.json +17 -17
- package/src/Table/ZauruTable.tsx +68 -21
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [6.14.2](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.14.1...@zauru-sdk/components@6.14.2) (2026-10-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* alinear encabezados y celdas de ZauruTable ([46783d1](https://github.com/intuitiva/zauru-typescript-sdk/commit/46783d1f))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [6.14.1](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.14.0...@zauru-sdk/components@6.14.1) (2026-10-26)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @zauru-sdk/components
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
# [6.14.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.13.3...@zauru-sdk/components@6.14.0) (2026-10-26)
|
|
7
23
|
|
|
8
24
|
|
|
@@ -21,5 +21,7 @@ type Props = TableProps<any> & {
|
|
|
21
21
|
theme?: "solarized" | "subTable";
|
|
22
22
|
className?: string;
|
|
23
23
|
};
|
|
24
|
+
export declare const normalizeZauruTableColumns: (columns: any) => any;
|
|
25
|
+
export declare const zauruTableFlexBasisCss: (tableClassName: string, columns: any) => string;
|
|
24
26
|
export declare const ZauruTable: (props: Props) => import("react/jsx-runtime").JSX.Element;
|
|
25
27
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useSearchParams } from "@remix-run/react";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
3
|
+
import { useEffect, useId, useMemo, useState } from "react";
|
|
4
4
|
import { createTheme } from "react-data-table-component";
|
|
5
5
|
import { SearchSVG } from "@zauru-sdk/icons";
|
|
6
6
|
import * as ReactDataTableComponent from "react-data-table-component";
|
|
@@ -160,6 +160,56 @@ createTheme("subTable", {
|
|
|
160
160
|
background: "black",
|
|
161
161
|
},
|
|
162
162
|
});
|
|
163
|
+
export const normalizeZauruTableColumns = (columns) => {
|
|
164
|
+
if (!Array.isArray(columns)) {
|
|
165
|
+
return columns;
|
|
166
|
+
}
|
|
167
|
+
return columns.map((column, index) => {
|
|
168
|
+
if (!column || typeof column !== "object") {
|
|
169
|
+
return column;
|
|
170
|
+
}
|
|
171
|
+
const next = { wrap: true, ...column };
|
|
172
|
+
if (next.id == null) {
|
|
173
|
+
next.id = index + 1;
|
|
174
|
+
}
|
|
175
|
+
// RDT `width` sets both min-width and max-width, wiping a px floor.
|
|
176
|
+
// Keep % as flex-basis so minWidth/maxWidth/grow still apply.
|
|
177
|
+
if (typeof next.width === "string" && next.width.endsWith("%")) {
|
|
178
|
+
const pct = next.width;
|
|
179
|
+
delete next.width;
|
|
180
|
+
next.style = {
|
|
181
|
+
flexBasis: pct,
|
|
182
|
+
...next.style,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return next;
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
export const zauruTableFlexBasisCss = (tableClassName, columns) => {
|
|
189
|
+
if (!tableClassName || !Array.isArray(columns)) {
|
|
190
|
+
return "";
|
|
191
|
+
}
|
|
192
|
+
const safeClass = tableClassName.replace(/[^a-zA-Z0-9_-]/g, "");
|
|
193
|
+
if (!safeClass) {
|
|
194
|
+
return "";
|
|
195
|
+
}
|
|
196
|
+
return columns
|
|
197
|
+
.flatMap((column) => {
|
|
198
|
+
const basis = column?.style?.flexBasis;
|
|
199
|
+
if (basis == null || column?.id == null) {
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
const id = String(column.id).replace(/[^a-zA-Z0-9_-]/g, "");
|
|
203
|
+
const safeBasis = String(basis).replace(/[^\d.%]/g, "");
|
|
204
|
+
if (!id || !safeBasis) {
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
return [
|
|
208
|
+
`.${safeClass} [data-column-id="${id}"] { flex-basis: ${safeBasis} !important; }`,
|
|
209
|
+
];
|
|
210
|
+
})
|
|
211
|
+
.join("\n");
|
|
212
|
+
};
|
|
163
213
|
//Documentación de la tabla https://react-data-table-component.netlify.app/?path=/docs/getting-started-intro--docs
|
|
164
214
|
export const ZauruTable = (props) => {
|
|
165
215
|
const { columns, conditionalRowStyles, data, loading = false, pagination, search, expandable, theme, className, offlineSearch = [], whitOutPagination = false, ...others } = props;
|
|
@@ -176,6 +226,9 @@ export const ZauruTable = (props) => {
|
|
|
176
226
|
useEffect(() => {
|
|
177
227
|
setFilteredData(data);
|
|
178
228
|
}, [data]);
|
|
229
|
+
const tableInstanceClass = `zauru-table-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
230
|
+
const normalizedColumns = useMemo(() => normalizeZauruTableColumns(columns), [columns]);
|
|
231
|
+
const flexBasisCss = useMemo(() => zauruTableFlexBasisCss(tableInstanceClass, normalizedColumns), [tableInstanceClass, normalizedColumns]);
|
|
179
232
|
const subHeaderComponentMemo = (_jsxs(_Fragment, { children: [_jsx("input", { name: "search", type: "text", placeholder: search?.placeholderSearch ?? "Filtrar", "aria-label": "Search Input", className: "bg-gray-50 border border-gray-300 text-gray-900 rounded-lg px-2", onChange: (event) => {
|
|
180
233
|
const searchTerm = event.target.value;
|
|
181
234
|
if (offlineSearch.length > 0) {
|
|
@@ -228,26 +281,7 @@ export const ZauruTable = (props) => {
|
|
|
228
281
|
};
|
|
229
282
|
const loadSubHeader = !!(search || offlineSearch.length > 0);
|
|
230
283
|
const subHeaderComponent = loadSubHeader ? subHeaderComponentMemo : undefined;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return column;
|
|
235
|
-
}
|
|
236
|
-
const next = { wrap: true, ...column };
|
|
237
|
-
// RDT `width` sets both min-width and max-width, wiping a px floor.
|
|
238
|
-
// Keep % as flex-basis so minWidth/maxWidth/grow still apply.
|
|
239
|
-
if (typeof next.width === "string" && next.width.endsWith("%")) {
|
|
240
|
-
const pct = next.width;
|
|
241
|
-
delete next.width;
|
|
242
|
-
next.style = {
|
|
243
|
-
flexBasis: pct,
|
|
244
|
-
...next.style,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
return next;
|
|
248
|
-
})
|
|
249
|
-
: columns;
|
|
250
|
-
return (_jsx("div", { className: "w-full min-w-0 max-w-full overflow-x-auto", children: _jsx(DataTable, { className: className, subHeaderWrap: true, theme: theme ?? "solarized", columns: normalizedColumns, conditionalRowStyles: conditionalRowStyles, data: filteredData, customStyles: customStyles, progressPending: loading, highlightOnHover: true, pointerOnHover: true, dense: true, striped: true, pagination: !whitOutPagination, persistTableHead: true, responsive: true, noHeader: true, expandableRows: !!expandable, expandOnRowClicked: !!expandable, expandableRowExpanded: expandable ? expandable.expandableRowExpanded : undefined, expandableRowsComponent: expandable ? expandable.expandableRowsComponent : undefined, subHeader: loadSubHeader, subHeaderComponent: subHeaderComponent, paginationServer: !!pagination, paginationTotalRows: pagination?.totalRows ?? undefined, onChangeRowsPerPage: pagination ? handlePerRowsChange : undefined, onChangePage: pagination ? handlePageChange : undefined, paginationComponentOptions: paginationComponentOptions, paginationRowsPerPageOptions: pagination?.rowsPerPageOptions
|
|
251
|
-
? pagination.rowsPerPageOptions
|
|
252
|
-
: [10, 50, 100], ...others }) }));
|
|
284
|
+
return (_jsxs("div", { className: `w-full min-w-0 max-w-full overflow-x-auto ${tableInstanceClass}`, children: [flexBasisCss ? _jsx("style", { children: flexBasisCss }) : null, _jsx(DataTable, { className: className, subHeaderWrap: true, theme: theme ?? "solarized", columns: normalizedColumns, conditionalRowStyles: conditionalRowStyles, data: filteredData, customStyles: customStyles, progressPending: loading, highlightOnHover: true, pointerOnHover: true, dense: true, striped: true, pagination: !whitOutPagination, persistTableHead: true, responsive: true, noHeader: true, expandableRows: !!expandable, expandOnRowClicked: !!expandable, expandableRowExpanded: expandable ? expandable.expandableRowExpanded : undefined, expandableRowsComponent: expandable ? expandable.expandableRowsComponent : undefined, subHeader: loadSubHeader, subHeaderComponent: subHeaderComponent, paginationServer: !!pagination, paginationTotalRows: pagination?.totalRows ?? undefined, onChangeRowsPerPage: pagination ? handlePerRowsChange : undefined, onChangePage: pagination ? handlePageChange : undefined, paginationComponentOptions: paginationComponentOptions, paginationRowsPerPageOptions: pagination?.rowsPerPageOptions
|
|
285
|
+
? pagination.rowsPerPageOptions
|
|
286
|
+
: [10, 50, 100], ...others })] }));
|
|
253
287
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/components",
|
|
3
|
-
"version": "6.14.
|
|
3
|
+
"version": "6.14.2",
|
|
4
4
|
"description": "Componentes reutilizables en las WebApps de Zauru.",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -10,13 +10,6 @@
|
|
|
10
10
|
"access": "public",
|
|
11
11
|
"registry": "https://registry.npmjs.org/"
|
|
12
12
|
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "npm run build:esm",
|
|
15
|
-
"build:esm": "tsc -p tsconfig.esm.json",
|
|
16
|
-
"play": "ladle serve --port 61000",
|
|
17
|
-
"play:build": "ladle build",
|
|
18
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
|
-
},
|
|
20
13
|
"author": {
|
|
21
14
|
"name": "Oscar Cuellar",
|
|
22
15
|
"email": "usackoka@gmail.com"
|
|
@@ -44,12 +37,6 @@
|
|
|
44
37
|
"@reduxjs/toolkit": "^2.2.1",
|
|
45
38
|
"@remix-run/node": "^2.8.1",
|
|
46
39
|
"@remix-run/react": "^2.8.1",
|
|
47
|
-
"@zauru-sdk/common": "^6.11.1",
|
|
48
|
-
"@zauru-sdk/hooks": "^6.3.22",
|
|
49
|
-
"@zauru-sdk/icons": "^6.1.0",
|
|
50
|
-
"@zauru-sdk/redux": "^6.7.1",
|
|
51
|
-
"@zauru-sdk/types": "^6.27.0",
|
|
52
|
-
"@zauru-sdk/utils": "^6.25.0",
|
|
53
40
|
"browser-image-compression": "^2.0.2",
|
|
54
41
|
"framer-motion": "^12.0.0",
|
|
55
42
|
"jsonwebtoken": "^9.0.2",
|
|
@@ -60,7 +47,20 @@
|
|
|
60
47
|
"react-is": "^18.2.0",
|
|
61
48
|
"react-select": "^5.8.0",
|
|
62
49
|
"styled-components": "^5.3.5",
|
|
63
|
-
"zod": "^3.23.8"
|
|
50
|
+
"zod": "^3.23.8",
|
|
51
|
+
"@zauru-sdk/common": "^6.12.0",
|
|
52
|
+
"@zauru-sdk/icons": "^6.1.0",
|
|
53
|
+
"@zauru-sdk/hooks": "^6.3.23",
|
|
54
|
+
"@zauru-sdk/redux": "^6.7.2",
|
|
55
|
+
"@zauru-sdk/types": "^6.28.0",
|
|
56
|
+
"@zauru-sdk/utils": "^6.26.1"
|
|
64
57
|
},
|
|
65
|
-
"gitHead": "
|
|
66
|
-
|
|
58
|
+
"gitHead": "57c966c16b47b52c32e72d40ccd7c76d9aaba247",
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "npm run build:esm",
|
|
61
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
62
|
+
"play": "ladle serve --port 61000",
|
|
63
|
+
"play:build": "ladle build",
|
|
64
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/Table/ZauruTable.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useSearchParams } from "@remix-run/react";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
2
|
+
import { useEffect, useId, useMemo, useState } from "react";
|
|
3
3
|
import type {
|
|
4
4
|
PaginationOptions,
|
|
5
5
|
TableProps,
|
|
@@ -193,6 +193,61 @@ type Props = TableProps<any> & {
|
|
|
193
193
|
className?: string;
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
+
export const normalizeZauruTableColumns = (columns: any): any => {
|
|
197
|
+
if (!Array.isArray(columns)) {
|
|
198
|
+
return columns;
|
|
199
|
+
}
|
|
200
|
+
return columns.map((column: any, index: number) => {
|
|
201
|
+
if (!column || typeof column !== "object") {
|
|
202
|
+
return column;
|
|
203
|
+
}
|
|
204
|
+
const next = { wrap: true, ...column };
|
|
205
|
+
if (next.id == null) {
|
|
206
|
+
next.id = index + 1;
|
|
207
|
+
}
|
|
208
|
+
// RDT `width` sets both min-width and max-width, wiping a px floor.
|
|
209
|
+
// Keep % as flex-basis so minWidth/maxWidth/grow still apply.
|
|
210
|
+
if (typeof next.width === "string" && next.width.endsWith("%")) {
|
|
211
|
+
const pct = next.width;
|
|
212
|
+
delete next.width;
|
|
213
|
+
next.style = {
|
|
214
|
+
flexBasis: pct,
|
|
215
|
+
...next.style,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return next;
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export const zauruTableFlexBasisCss = (
|
|
223
|
+
tableClassName: string,
|
|
224
|
+
columns: any
|
|
225
|
+
): string => {
|
|
226
|
+
if (!tableClassName || !Array.isArray(columns)) {
|
|
227
|
+
return "";
|
|
228
|
+
}
|
|
229
|
+
const safeClass = tableClassName.replace(/[^a-zA-Z0-9_-]/g, "");
|
|
230
|
+
if (!safeClass) {
|
|
231
|
+
return "";
|
|
232
|
+
}
|
|
233
|
+
return columns
|
|
234
|
+
.flatMap((column: any) => {
|
|
235
|
+
const basis = column?.style?.flexBasis;
|
|
236
|
+
if (basis == null || column?.id == null) {
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
const id = String(column.id).replace(/[^a-zA-Z0-9_-]/g, "");
|
|
240
|
+
const safeBasis = String(basis).replace(/[^\d.%]/g, "");
|
|
241
|
+
if (!id || !safeBasis) {
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
return [
|
|
245
|
+
`.${safeClass} [data-column-id="${id}"] { flex-basis: ${safeBasis} !important; }`,
|
|
246
|
+
];
|
|
247
|
+
})
|
|
248
|
+
.join("\n");
|
|
249
|
+
};
|
|
250
|
+
|
|
196
251
|
//Documentación de la tabla https://react-data-table-component.netlify.app/?path=/docs/getting-started-intro--docs
|
|
197
252
|
export const ZauruTable = (props: Props) => {
|
|
198
253
|
const {
|
|
@@ -227,6 +282,16 @@ export const ZauruTable = (props: Props) => {
|
|
|
227
282
|
setFilteredData(data);
|
|
228
283
|
}, [data]);
|
|
229
284
|
|
|
285
|
+
const tableInstanceClass = `zauru-table-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
286
|
+
const normalizedColumns = useMemo(
|
|
287
|
+
() => normalizeZauruTableColumns(columns),
|
|
288
|
+
[columns]
|
|
289
|
+
);
|
|
290
|
+
const flexBasisCss = useMemo(
|
|
291
|
+
() => zauruTableFlexBasisCss(tableInstanceClass, normalizedColumns),
|
|
292
|
+
[tableInstanceClass, normalizedColumns]
|
|
293
|
+
);
|
|
294
|
+
|
|
230
295
|
const subHeaderComponentMemo = (
|
|
231
296
|
<>
|
|
232
297
|
<input
|
|
@@ -307,28 +372,10 @@ export const ZauruTable = (props: Props) => {
|
|
|
307
372
|
|
|
308
373
|
const loadSubHeader = !!(search || offlineSearch.length > 0);
|
|
309
374
|
const subHeaderComponent = loadSubHeader ? subHeaderComponentMemo : undefined;
|
|
310
|
-
const normalizedColumns = Array.isArray(columns)
|
|
311
|
-
? columns.map((column: any) => {
|
|
312
|
-
if (!column || typeof column !== "object") {
|
|
313
|
-
return column;
|
|
314
|
-
}
|
|
315
|
-
const next = { wrap: true, ...column };
|
|
316
|
-
// RDT `width` sets both min-width and max-width, wiping a px floor.
|
|
317
|
-
// Keep % as flex-basis so minWidth/maxWidth/grow still apply.
|
|
318
|
-
if (typeof next.width === "string" && next.width.endsWith("%")) {
|
|
319
|
-
const pct = next.width;
|
|
320
|
-
delete next.width;
|
|
321
|
-
next.style = {
|
|
322
|
-
flexBasis: pct,
|
|
323
|
-
...next.style,
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
return next;
|
|
327
|
-
})
|
|
328
|
-
: columns;
|
|
329
375
|
|
|
330
376
|
return (
|
|
331
|
-
<div className=
|
|
377
|
+
<div className={`w-full min-w-0 max-w-full overflow-x-auto ${tableInstanceClass}`}>
|
|
378
|
+
{flexBasisCss ? <style>{flexBasisCss}</style> : null}
|
|
332
379
|
<DataTable
|
|
333
380
|
className={className}
|
|
334
381
|
subHeaderWrap
|