@zauru-sdk/components 1.0.26 → 1.0.28

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 (89) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/Alerts/index.d.ts +2 -2
  3. package/dist/Alerts/index.js +2 -2
  4. package/dist/BlockUI/index.d.ts +1 -1
  5. package/dist/BlockUI/index.js +1 -1
  6. package/dist/Buttons/index.d.ts +1 -1
  7. package/dist/Buttons/index.js +1 -1
  8. package/dist/Card/index.d.ts +1 -1
  9. package/dist/Card/index.js +1 -1
  10. package/dist/Chat/index.d.ts +2 -2
  11. package/dist/Chat/index.js +2 -2
  12. package/dist/ConnectionState/index.d.ts +1 -1
  13. package/dist/ConnectionState/index.js +1 -1
  14. package/dist/Containers/index.d.ts +7 -7
  15. package/dist/Containers/index.js +7 -7
  16. package/dist/DynamicTable/DynamicPrintTable.d.ts +2 -2
  17. package/dist/DynamicTable/DynamicPrintTable.js +1 -2
  18. package/dist/DynamicTable/DynamicTable.d.ts +24 -0
  19. package/dist/DynamicTable/DynamicTable.js +192 -0
  20. package/dist/DynamicTable/index.d.ts +4 -24
  21. package/dist/DynamicTable/index.js +4 -193
  22. package/dist/Footer/index.d.ts +1 -1
  23. package/dist/Footer/index.js +1 -1
  24. package/dist/Form/FieldContainer/index.d.ts +3 -3
  25. package/dist/Form/FieldContainer/index.js +3 -3
  26. package/dist/Form/index.d.ts +13 -13
  27. package/dist/Form/index.js +13 -13
  28. package/dist/Labels/index.d.ts +1 -1
  29. package/dist/Labels/index.js +1 -1
  30. package/dist/Layouts/index.d.ts +1 -1
  31. package/dist/Layouts/index.js +1 -1
  32. package/dist/LineSeparator/index.d.ts +1 -1
  33. package/dist/LineSeparator/index.js +1 -1
  34. package/dist/Modal/index.d.ts +1 -1
  35. package/dist/Modal/index.js +1 -1
  36. package/dist/NavBar/index.d.ts +3 -3
  37. package/dist/NavBar/index.js +3 -3
  38. package/dist/ProgressBar/index.d.ts +2 -2
  39. package/dist/ProgressBar/index.js +2 -2
  40. package/dist/Skeletons/index.d.ts +1 -1
  41. package/dist/Skeletons/index.js +1 -1
  42. package/dist/Tab/index.d.ts +1 -1
  43. package/dist/Tab/index.js +1 -1
  44. package/dist/Table/index.d.ts +1 -1
  45. package/dist/Table/index.js +1 -1
  46. package/dist/TaskList/index.d.ts +1 -1
  47. package/dist/TaskList/index.js +1 -1
  48. package/dist/Titles/index.d.ts +5 -5
  49. package/dist/Titles/index.js +5 -5
  50. package/dist/Tooltip/index.d.ts +1 -1
  51. package/dist/Tooltip/index.js +1 -1
  52. package/dist/WithTooltip/index.d.ts +1 -1
  53. package/dist/WithTooltip/index.js +1 -1
  54. package/dist/Wizards/index.d.ts +1 -1
  55. package/dist/Wizards/index.js +1 -1
  56. package/dist/Zendesk/index.d.ts +2 -2
  57. package/dist/Zendesk/index.js +2 -2
  58. package/dist/index.d.ts +24 -23
  59. package/dist/index.js +24 -23
  60. package/package.json +3 -3
  61. package/src/Alerts/index.ts +2 -2
  62. package/src/BlockUI/index.tsx +1 -1
  63. package/src/Buttons/index.ts +1 -1
  64. package/src/Card/index.ts +1 -1
  65. package/src/Chat/index.ts +2 -2
  66. package/src/ConnectionState/index.tsx +1 -1
  67. package/src/Containers/index.ts +7 -7
  68. package/src/DynamicTable/DynamicPrintTable.tsx +1 -3
  69. package/src/DynamicTable/DynamicTable.tsx +405 -0
  70. package/src/DynamicTable/index.tsx +4 -407
  71. package/src/Footer/index.tsx +1 -1
  72. package/src/Form/FieldContainer/index.ts +3 -3
  73. package/src/Form/index.ts +13 -13
  74. package/src/Labels/index.tsx +1 -1
  75. package/src/Layouts/index.ts +1 -1
  76. package/src/LineSeparator/index.tsx +1 -1
  77. package/src/Modal/index.tsx +1 -1
  78. package/src/NavBar/index.tsx +3 -3
  79. package/src/ProgressBar/index.tsx +2 -2
  80. package/src/Skeletons/index.ts +1 -1
  81. package/src/Tab/index.ts +1 -1
  82. package/src/Table/index.tsx +1 -1
  83. package/src/TaskList/index.ts +1 -1
  84. package/src/Titles/index.ts +5 -5
  85. package/src/Tooltip/index.ts +1 -1
  86. package/src/WithTooltip/index.tsx +1 -1
  87. package/src/Wizards/index.ts +1 -1
  88. package/src/Zendesk/index.ts +2 -2
  89. package/src/index.ts +24 -23
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
+ ## [1.0.28](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.27...v1.0.28) (2024-03-25)
7
+
8
+ **Note:** Version bump only for package @zauru-sdk/components
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.0.27](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.26...v1.0.27) (2024-03-25)
15
+
16
+ **Note:** Version bump only for package @zauru-sdk/components
17
+
18
+
19
+
20
+
21
+
6
22
  ## [1.0.26](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.25...v1.0.26) (2024-03-25)
7
23
 
8
24
  **Note:** Version bump only for package @zauru-sdk/components
@@ -1,2 +1,2 @@
1
- export * from "./ErrorBoundaryAlert/ErrorBoundaryAlert";
2
- export * from "./StaticAlert";
1
+ export * from "./ErrorBoundaryAlert/ErrorBoundaryAlert.js";
2
+ export * from "./StaticAlert.js";
@@ -1,2 +1,2 @@
1
- export * from "./ErrorBoundaryAlert/ErrorBoundaryAlert";
2
- export * from "./StaticAlert";
1
+ export * from "./ErrorBoundaryAlert/ErrorBoundaryAlert.js";
2
+ export * from "./StaticAlert.js";
@@ -1 +1 @@
1
- export * from "./BlockUI";
1
+ export * from "./BlockUI.js";
@@ -1 +1 @@
1
- export * from "./BlockUI";
1
+ export * from "./BlockUI.js";
@@ -1 +1 @@
1
- export * from "./Button";
1
+ export * from "./Button.js";
@@ -1 +1 @@
1
- export * from "./Button";
1
+ export * from "./Button.js";
@@ -1 +1 @@
1
- export * from "./Card";
1
+ export * from "./Card.js";
@@ -1 +1 @@
1
- export * from "./Card";
1
+ export * from "./Card.js";
@@ -1,2 +1,2 @@
1
- export * from "./ChatLayout";
2
- export * from "./ChatMessageHistory";
1
+ export * from "./ChatLayout.js";
2
+ export * from "./ChatMessageHistory.js";
@@ -1,2 +1,2 @@
1
- export * from "./ChatLayout";
2
- export * from "./ChatMessageHistory";
1
+ export * from "./ChatLayout.js";
2
+ export * from "./ChatMessageHistory.js";
@@ -1 +1 @@
1
- export * from "./ConnectionState";
1
+ export * from "./ConnectionState.js";
@@ -1 +1 @@
1
- export * from "./ConnectionState";
1
+ export * from "./ConnectionState.js";
@@ -1,7 +1,7 @@
1
- export * from "./BodyContainer";
2
- export * from "./ButtonSectionContainer";
3
- export * from "./Container";
4
- export * from "./DoubleContainer";
5
- export * from "./MainContainer";
6
- export * from "./OutletContainer";
7
- export * from "./SubContainer";
1
+ export * from "./BodyContainer.js";
2
+ export * from "./ButtonSectionContainer.js";
3
+ export * from "./Container.js";
4
+ export * from "./DoubleContainer.js";
5
+ export * from "./MainContainer.js";
6
+ export * from "./OutletContainer.js";
7
+ export * from "./SubContainer.js";
@@ -1,7 +1,7 @@
1
- export * from "./BodyContainer";
2
- export * from "./ButtonSectionContainer";
3
- export * from "./Container";
4
- export * from "./DoubleContainer";
5
- export * from "./MainContainer";
6
- export * from "./OutletContainer";
7
- export * from "./SubContainer";
1
+ export * from "./BodyContainer.js";
2
+ export * from "./ButtonSectionContainer.js";
3
+ export * from "./Container.js";
4
+ export * from "./DoubleContainer.js";
5
+ export * from "./MainContainer.js";
6
+ export * from "./OutletContainer.js";
7
+ export * from "./SubContainer.js";
@@ -19,5 +19,5 @@ type Props = {
19
19
  getTableState: (updatedData?: ReactNode[][]) => TableStateItem[] | undefined;
20
20
  }>;
21
21
  };
22
- declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<unknown>>;
23
- export default _default;
22
+ export declare const DynamicPrintTable: ({ forwardedRef, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
23
+ export {};
@@ -7,7 +7,7 @@ const errorAnimation = {
7
7
  hidden: { opacity: 0, y: -10 },
8
8
  visible: { opacity: 1, y: 0 },
9
9
  };
10
- const DynamicPrintTable = ({ forwardedRef, ...props }) => {
10
+ export const DynamicPrintTable = ({ forwardedRef, ...props }) => {
11
11
  const { items, onChange, className } = props;
12
12
  const { formValidations } = useAppSelector((state) => state.formValidation);
13
13
  const createItemSelect = (rowIndex, defaultValue) => (_jsx(SelectFieldWithoutValidation, { name: "item_select", isClearable: true, onChange: (value) => {
@@ -129,4 +129,3 @@ const DynamicPrintTable = ({ forwardedRef, ...props }) => {
129
129
  return sum + val;
130
130
  }, 0)] })] }) })] })] }));
131
131
  };
132
- export default React.forwardRef(DynamicPrintTable);
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ type Props = {
3
+ cellInputs?: boolean;
4
+ intersectionTitle?: string;
5
+ className?: string;
6
+ onChange?: (data: string) => void;
7
+ defaultValue?: string;
8
+ onValidate?: (headerValue: string, rowValue: string) => boolean;
9
+ onRemove?: () => void;
10
+ margins?: {
11
+ marginLeft?: number;
12
+ marginTop?: number;
13
+ verticalGap?: number;
14
+ horizontalGap?: number;
15
+ };
16
+ forwardedRef?: React.RefObject<{
17
+ getTotalForRows: () => number;
18
+ getTotalForColumns: () => number;
19
+ getColumnsCount: () => number;
20
+ getRowsCount: () => number;
21
+ }>;
22
+ };
23
+ export declare const DynamicTable: ({ forwardedRef, ...props }: Props, ref: React.ForwardedRef<any>) => import("react/jsx-runtime").JSX.Element;
24
+ export {};
@@ -0,0 +1,192 @@
1
+ import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { useEffect, useState } from "react";
3
+ import { TextAreaWithoutValidation } from "../Form/TextArea";
4
+ import { TextFieldWithoutValidation } from "../Form/TextField";
5
+ import { CheckboxWithoutValidation } from "../Form/Checkbox";
6
+ export const DynamicTable = ({ forwardedRef, ...props }, ref) => {
7
+ const [tableData, setTableData] = useState({});
8
+ const { cellInputs, intersectionTitle, className, onChange, defaultValue, margins, } = props;
9
+ useEffect(() => {
10
+ if (onChange) {
11
+ onChange(JSON.stringify(tableData));
12
+ }
13
+ // eslint-disable-next-line react-hooks/exhaustive-deps
14
+ }, [tableData]);
15
+ useEffect(() => {
16
+ if (defaultValue) {
17
+ initializeTable(defaultValue);
18
+ }
19
+ else {
20
+ initializeTableWithDefaults();
21
+ }
22
+ }, [defaultValue]);
23
+ const getRows = () => {
24
+ const rowsIds = Object.keys(tableData)
25
+ .filter((key) => key.startsWith("row"))
26
+ .map((key) => parseInt(key.slice(3)));
27
+ return rowsIds.sort().map((id) => ({ id }));
28
+ };
29
+ const getCols = () => {
30
+ const colsIds = Object.keys(tableData)
31
+ .filter((key) => key.startsWith("column"))
32
+ .map((key) => parseInt(key.slice(6)));
33
+ return colsIds.sort().map((id) => ({ id }));
34
+ };
35
+ const addRow = (event) => {
36
+ event.stopPropagation();
37
+ event.preventDefault();
38
+ const rows = getRows();
39
+ const lastId = rows[rows.length - 1].id;
40
+ handleInputChange(`row${lastId + 1}`, 1);
41
+ };
42
+ const addCol = (event) => {
43
+ event.stopPropagation();
44
+ event.preventDefault();
45
+ const cols = getCols();
46
+ const lastId = cols[cols.length - 1].id;
47
+ handleInputChange(`column${lastId + 1}`, 1);
48
+ };
49
+ const removeRow = (rowId) => {
50
+ const newRowData = { ...tableData };
51
+ for (const key in newRowData) {
52
+ if (key.startsWith(`row${rowId}`) || key.startsWith(`cell-${rowId}-`)) {
53
+ delete newRowData[key];
54
+ }
55
+ }
56
+ setTableData(newRowData);
57
+ };
58
+ const removeCol = (colId) => {
59
+ const newRowData = { ...tableData };
60
+ for (const key in newRowData) {
61
+ if (key.startsWith(`column${colId}`) || key.endsWith(`-${colId}`)) {
62
+ delete newRowData[key];
63
+ }
64
+ }
65
+ setTableData(newRowData);
66
+ };
67
+ const getTotalForRow = (rowId) => {
68
+ return Number(tableData[`row${rowId}`] ?? 0) ?? 0;
69
+ };
70
+ const getTotalForColumn = (colId) => {
71
+ return Number(tableData[`column${colId}`] ?? 0) ?? 0;
72
+ };
73
+ const getTotalForRows = () => {
74
+ return getRows()
75
+ .map((row) => getTotalForRow(row.id))
76
+ .reduce((a, b) => a + b, 0);
77
+ };
78
+ const getTotalForColumns = () => {
79
+ return getCols()
80
+ .map((col) => getTotalForColumn(col.id))
81
+ .reduce((a, b) => a + b, 0);
82
+ };
83
+ const getRowsCount = () => {
84
+ return getRows().length;
85
+ };
86
+ const getColumnsCount = () => {
87
+ return getCols().length;
88
+ };
89
+ const handleInputChange = (name, value) => {
90
+ setTableData((prevData) => ({ ...prevData, [name]: value }));
91
+ };
92
+ const handleValidation = (cellId, colId, rowId) => {
93
+ const headerValue = tableData[`column${colId}`];
94
+ const rowValue = tableData[`row${rowId}`];
95
+ if (props.onValidate && props.onValidate(headerValue, rowValue)) {
96
+ return handleInputChange(cellId, true);
97
+ }
98
+ return { stopUIChange: true };
99
+ };
100
+ const handleRemoveValidation = (cellId) => {
101
+ handleInputChange(cellId, false);
102
+ };
103
+ const initializeTableWithDefaults = () => {
104
+ const initialData = { row0: 1, column0: 1 };
105
+ setTableData(initialData);
106
+ };
107
+ const initializeTable = (tableJson) => {
108
+ try {
109
+ const initialData = JSON.parse(tableJson);
110
+ setTableData(initialData);
111
+ }
112
+ catch (error) {
113
+ console.error("Error al inicializar la tabla:", error);
114
+ }
115
+ };
116
+ const cellBordered = {
117
+ border: "1px solid #ccc",
118
+ };
119
+ const pastelGrayBackground = {
120
+ backgroundColor: "#B69E99",
121
+ };
122
+ const cellCenteredContent = {
123
+ textAlign: "center",
124
+ verticalAlign: "middle",
125
+ };
126
+ const renderTotalHeight = () => {
127
+ const sumaFilas = getRows()
128
+ .map((row) => getTotalForRow(row.id))
129
+ .reduce((a, b) => a + b, 0);
130
+ const sumTotalFilas = sumaFilas +
131
+ (margins?.marginTop ?? 0) +
132
+ (getRows().length - 1) * (margins?.verticalGap ?? 0);
133
+ return (_jsxs("div", { className: "ml-4 inline-block", children: [_jsxs("strong", { children: ["Total alto: ", sumTotalFilas, " "] }), margins && (_jsxs(_Fragment, { children: ["(Celdas: ", sumaFilas, " + M\u00E1rgen superior: ", margins?.marginTop ?? 0, " +", " ", getRows().length - 1, " Brechas verticales:", " ", Math.round((getRows().length - 1) * (margins?.verticalGap ?? 0)), ")"] }))] }));
134
+ };
135
+ const renderTotalWidth = () => {
136
+ const cols = getCols();
137
+ const sumaColumnas = cols
138
+ .map((col) => getTotalForColumn(col.id))
139
+ .reduce((a, b) => a + b, 0);
140
+ const sumaTotal = sumaColumnas +
141
+ (margins?.marginLeft ?? 0) +
142
+ (getCols().length - 1) * (margins?.horizontalGap ?? 0);
143
+ return (_jsxs("div", { className: "ml-4 inline-block", children: [_jsxs("strong", { children: ["Total ancho: ", sumaTotal, " "] }), margins && (_jsxs(_Fragment, { children: ["(Celdas: ", sumaColumnas, " + M\u00E1rgen izquierdo:", " ", margins?.marginLeft ?? 0, " + ", getCols().length - 1, " Brechas horizontales:", " ", Math.round((getCols().length - 1) * (margins?.horizontalGap ?? 0)), ")"] }))] }));
144
+ };
145
+ const renderHeader = () => {
146
+ const cols = getCols();
147
+ return (_jsxs("tr", { children: [_jsx("th", { className: "align-middle py-2 text-center", style: {
148
+ ...cellBordered,
149
+ ...pastelGrayBackground,
150
+ }, children: intersectionTitle ?? "" }), cols.map((col) => (_jsx("th", { className: "align-middle py-2 text-center", style: { ...cellBordered, ...pastelGrayBackground }, children: _jsxs("div", { className: "inline-flex", children: [_jsx(TextFieldWithoutValidation, { style: { maxWidth: "45%", minWidth: "45%" }, name: `column${col.id}`, defaultValue: tableData[`column${col.id}`] || 1, type: "number", onChange: (value) => handleInputChange(`column${col.id}`, value) }), col.id > 0 && (_jsx("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: () => removeCol(col.id), children: "x" }))] }) }, col.id))), _jsx("th", { children: _jsx("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: addCol, children: "+" }) })] }));
151
+ };
152
+ const renderRow = (rowId) => {
153
+ const cols = getCols();
154
+ return (_jsxs("tr", { children: [_jsx("td", { className: "align-middle", style: {
155
+ ...cellBordered,
156
+ ...pastelGrayBackground,
157
+ textOverflow: "ellipsis",
158
+ msTextOverflow: "ellipsis",
159
+ maxWidth: "200px",
160
+ }, children: _jsxs("div", { className: "inline-flex", children: [_jsx(TextFieldWithoutValidation, { style: { maxWidth: "45%", minWidth: "45%" }, name: `row${rowId}`, defaultValue: tableData[`row${rowId}`] || 1, type: "number", onChange: (value) => handleInputChange(`row${rowId}`, value) }), rowId > 0 && (_jsx("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: () => {
161
+ removeRow(rowId);
162
+ }, children: "x" }))] }) }), cols.map((col) => {
163
+ const cellId = `cell-${rowId}-${col.id}`;
164
+ const cellValidation = tableData[cellId] === true;
165
+ if (!cellInputs)
166
+ tableData[cellId] = cellValidation;
167
+ return (_jsx("td", { id: cellId, style: { ...cellBordered, ...cellCenteredContent }, children: cellInputs ? (_jsx(TextAreaWithoutValidation, { name: cellId, defaultValue: tableData[cellId] || "", onChange: (value) => handleInputChange(cellId, value) })) : (_jsx(CheckboxWithoutValidation, { name: cellId, defaultValue: cellValidation, onChange: (value) => {
168
+ if (value) {
169
+ return handleValidation(cellId, col.id, rowId);
170
+ }
171
+ else {
172
+ handleRemoveValidation(cellId);
173
+ }
174
+ } })) }, col.id));
175
+ }), rowId === 0 && (_jsx("td", { rowSpan: getRows().length, style: { maxWidth: "100px" }, children: renderTotalHeight() }))] }, rowId));
176
+ };
177
+ const renderRows = () => {
178
+ const rows = getRows();
179
+ return rows.map((row) => renderRow(row.id));
180
+ };
181
+ // Use el "useImperativeHandle" para que el componente padre pueda acceder a los métodos deseados
182
+ React.useImperativeHandle(forwardedRef, () => ({
183
+ getTotalForRows,
184
+ getTotalForColumns,
185
+ getColumnsCount,
186
+ getRowsCount,
187
+ }));
188
+ return (_jsx("div", { className: `${className}`, children: _jsxs("table", { className: "border-collapse", children: [_jsx("thead", { children: renderHeader() }), _jsx("tbody", { children: renderRows() }), _jsx("tfoot", { children: _jsxs("tr", { children: [_jsx("td", { children: _jsx("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: addRow, children: "+" }) }), _jsx("td", { colSpan: getCols().length + 1, className: "text-left align-middle", style: {
189
+ textOverflow: "ellipsis",
190
+ msTextOverflow: "ellipsis",
191
+ }, children: renderTotalWidth() })] }) })] }) }));
192
+ };
@@ -1,24 +1,4 @@
1
- import React from "react";
2
- type Props = {
3
- cellInputs?: boolean;
4
- intersectionTitle?: string;
5
- className?: string;
6
- onChange?: (data: string) => void;
7
- defaultValue?: string;
8
- onValidate?: (headerValue: string, rowValue: string) => boolean;
9
- onRemove?: () => void;
10
- margins?: {
11
- marginLeft?: number;
12
- marginTop?: number;
13
- verticalGap?: number;
14
- horizontalGap?: number;
15
- };
16
- forwardedRef?: React.RefObject<{
17
- getTotalForRows: () => number;
18
- getTotalForColumns: () => number;
19
- getColumnsCount: () => number;
20
- getRowsCount: () => number;
21
- }>;
22
- };
23
- declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<any>>;
24
- export default _default;
1
+ export * from "./BasicPrintDynamicTable.js";
2
+ export * from "./DynamicPrintTable.js";
3
+ export * from "./DynamicTable.js";
4
+ export * from "./GenericDynamicTable.js";
@@ -1,193 +1,4 @@
1
- import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useEffect, useState } from "react";
3
- import { TextAreaWithoutValidation } from "../Form/TextArea";
4
- import { TextFieldWithoutValidation } from "../Form/TextField";
5
- import { CheckboxWithoutValidation } from "../Form/Checkbox";
6
- const DynamicTable = ({ forwardedRef, ...props }, ref) => {
7
- const [tableData, setTableData] = useState({});
8
- const { cellInputs, intersectionTitle, className, onChange, defaultValue, margins, } = props;
9
- useEffect(() => {
10
- if (onChange) {
11
- onChange(JSON.stringify(tableData));
12
- }
13
- // eslint-disable-next-line react-hooks/exhaustive-deps
14
- }, [tableData]);
15
- useEffect(() => {
16
- if (defaultValue) {
17
- initializeTable(defaultValue);
18
- }
19
- else {
20
- initializeTableWithDefaults();
21
- }
22
- }, [defaultValue]);
23
- const getRows = () => {
24
- const rowsIds = Object.keys(tableData)
25
- .filter((key) => key.startsWith("row"))
26
- .map((key) => parseInt(key.slice(3)));
27
- return rowsIds.sort().map((id) => ({ id }));
28
- };
29
- const getCols = () => {
30
- const colsIds = Object.keys(tableData)
31
- .filter((key) => key.startsWith("column"))
32
- .map((key) => parseInt(key.slice(6)));
33
- return colsIds.sort().map((id) => ({ id }));
34
- };
35
- const addRow = (event) => {
36
- event.stopPropagation();
37
- event.preventDefault();
38
- const rows = getRows();
39
- const lastId = rows[rows.length - 1].id;
40
- handleInputChange(`row${lastId + 1}`, 1);
41
- };
42
- const addCol = (event) => {
43
- event.stopPropagation();
44
- event.preventDefault();
45
- const cols = getCols();
46
- const lastId = cols[cols.length - 1].id;
47
- handleInputChange(`column${lastId + 1}`, 1);
48
- };
49
- const removeRow = (rowId) => {
50
- const newRowData = { ...tableData };
51
- for (const key in newRowData) {
52
- if (key.startsWith(`row${rowId}`) || key.startsWith(`cell-${rowId}-`)) {
53
- delete newRowData[key];
54
- }
55
- }
56
- setTableData(newRowData);
57
- };
58
- const removeCol = (colId) => {
59
- const newRowData = { ...tableData };
60
- for (const key in newRowData) {
61
- if (key.startsWith(`column${colId}`) || key.endsWith(`-${colId}`)) {
62
- delete newRowData[key];
63
- }
64
- }
65
- setTableData(newRowData);
66
- };
67
- const getTotalForRow = (rowId) => {
68
- return Number(tableData[`row${rowId}`] ?? 0) ?? 0;
69
- };
70
- const getTotalForColumn = (colId) => {
71
- return Number(tableData[`column${colId}`] ?? 0) ?? 0;
72
- };
73
- const getTotalForRows = () => {
74
- return getRows()
75
- .map((row) => getTotalForRow(row.id))
76
- .reduce((a, b) => a + b, 0);
77
- };
78
- const getTotalForColumns = () => {
79
- return getCols()
80
- .map((col) => getTotalForColumn(col.id))
81
- .reduce((a, b) => a + b, 0);
82
- };
83
- const getRowsCount = () => {
84
- return getRows().length;
85
- };
86
- const getColumnsCount = () => {
87
- return getCols().length;
88
- };
89
- const handleInputChange = (name, value) => {
90
- setTableData((prevData) => ({ ...prevData, [name]: value }));
91
- };
92
- const handleValidation = (cellId, colId, rowId) => {
93
- const headerValue = tableData[`column${colId}`];
94
- const rowValue = tableData[`row${rowId}`];
95
- if (props.onValidate && props.onValidate(headerValue, rowValue)) {
96
- return handleInputChange(cellId, true);
97
- }
98
- return { stopUIChange: true };
99
- };
100
- const handleRemoveValidation = (cellId) => {
101
- handleInputChange(cellId, false);
102
- };
103
- const initializeTableWithDefaults = () => {
104
- const initialData = { row0: 1, column0: 1 };
105
- setTableData(initialData);
106
- };
107
- const initializeTable = (tableJson) => {
108
- try {
109
- const initialData = JSON.parse(tableJson);
110
- setTableData(initialData);
111
- }
112
- catch (error) {
113
- console.error("Error al inicializar la tabla:", error);
114
- }
115
- };
116
- const cellBordered = {
117
- border: "1px solid #ccc",
118
- };
119
- const pastelGrayBackground = {
120
- backgroundColor: "#B69E99",
121
- };
122
- const cellCenteredContent = {
123
- textAlign: "center",
124
- verticalAlign: "middle",
125
- };
126
- const renderTotalHeight = () => {
127
- const sumaFilas = getRows()
128
- .map((row) => getTotalForRow(row.id))
129
- .reduce((a, b) => a + b, 0);
130
- const sumTotalFilas = sumaFilas +
131
- (margins?.marginTop ?? 0) +
132
- (getRows().length - 1) * (margins?.verticalGap ?? 0);
133
- return (_jsxs("div", { className: "ml-4 inline-block", children: [_jsxs("strong", { children: ["Total alto: ", sumTotalFilas, " "] }), margins && (_jsxs(_Fragment, { children: ["(Celdas: ", sumaFilas, " + M\u00E1rgen superior: ", margins?.marginTop ?? 0, " +", " ", getRows().length - 1, " Brechas verticales:", " ", Math.round((getRows().length - 1) * (margins?.verticalGap ?? 0)), ")"] }))] }));
134
- };
135
- const renderTotalWidth = () => {
136
- const cols = getCols();
137
- const sumaColumnas = cols
138
- .map((col) => getTotalForColumn(col.id))
139
- .reduce((a, b) => a + b, 0);
140
- const sumaTotal = sumaColumnas +
141
- (margins?.marginLeft ?? 0) +
142
- (getCols().length - 1) * (margins?.horizontalGap ?? 0);
143
- return (_jsxs("div", { className: "ml-4 inline-block", children: [_jsxs("strong", { children: ["Total ancho: ", sumaTotal, " "] }), margins && (_jsxs(_Fragment, { children: ["(Celdas: ", sumaColumnas, " + M\u00E1rgen izquierdo:", " ", margins?.marginLeft ?? 0, " + ", getCols().length - 1, " Brechas horizontales:", " ", Math.round((getCols().length - 1) * (margins?.horizontalGap ?? 0)), ")"] }))] }));
144
- };
145
- const renderHeader = () => {
146
- const cols = getCols();
147
- return (_jsxs("tr", { children: [_jsx("th", { className: "align-middle py-2 text-center", style: {
148
- ...cellBordered,
149
- ...pastelGrayBackground,
150
- }, children: intersectionTitle ?? "" }), cols.map((col) => (_jsx("th", { className: "align-middle py-2 text-center", style: { ...cellBordered, ...pastelGrayBackground }, children: _jsxs("div", { className: "inline-flex", children: [_jsx(TextFieldWithoutValidation, { style: { maxWidth: "45%", minWidth: "45%" }, name: `column${col.id}`, defaultValue: tableData[`column${col.id}`] || 1, type: "number", onChange: (value) => handleInputChange(`column${col.id}`, value) }), col.id > 0 && (_jsx("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: () => removeCol(col.id), children: "x" }))] }) }, col.id))), _jsx("th", { children: _jsx("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: addCol, children: "+" }) })] }));
151
- };
152
- const renderRow = (rowId) => {
153
- const cols = getCols();
154
- return (_jsxs("tr", { children: [_jsx("td", { className: "align-middle", style: {
155
- ...cellBordered,
156
- ...pastelGrayBackground,
157
- textOverflow: "ellipsis",
158
- msTextOverflow: "ellipsis",
159
- maxWidth: "200px",
160
- }, children: _jsxs("div", { className: "inline-flex", children: [_jsx(TextFieldWithoutValidation, { style: { maxWidth: "45%", minWidth: "45%" }, name: `row${rowId}`, defaultValue: tableData[`row${rowId}`] || 1, type: "number", onChange: (value) => handleInputChange(`row${rowId}`, value) }), rowId > 0 && (_jsx("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: () => {
161
- removeRow(rowId);
162
- }, children: "x" }))] }) }), cols.map((col) => {
163
- const cellId = `cell-${rowId}-${col.id}`;
164
- const cellValidation = tableData[cellId] === true;
165
- if (!cellInputs)
166
- tableData[cellId] = cellValidation;
167
- return (_jsx("td", { id: cellId, style: { ...cellBordered, ...cellCenteredContent }, children: cellInputs ? (_jsx(TextAreaWithoutValidation, { name: cellId, defaultValue: tableData[cellId] || "", onChange: (value) => handleInputChange(cellId, value) })) : (_jsx(CheckboxWithoutValidation, { name: cellId, defaultValue: cellValidation, onChange: (value) => {
168
- if (value) {
169
- return handleValidation(cellId, col.id, rowId);
170
- }
171
- else {
172
- handleRemoveValidation(cellId);
173
- }
174
- } })) }, col.id));
175
- }), rowId === 0 && (_jsx("td", { rowSpan: getRows().length, style: { maxWidth: "100px" }, children: renderTotalHeight() }))] }, rowId));
176
- };
177
- const renderRows = () => {
178
- const rows = getRows();
179
- return rows.map((row) => renderRow(row.id));
180
- };
181
- // Use el "useImperativeHandle" para que el componente padre pueda acceder a los métodos deseados
182
- React.useImperativeHandle(forwardedRef, () => ({
183
- getTotalForRows,
184
- getTotalForColumns,
185
- getColumnsCount,
186
- getRowsCount,
187
- }));
188
- return (_jsx("div", { className: `${className}`, children: _jsxs("table", { className: "border-collapse", children: [_jsx("thead", { children: renderHeader() }), _jsx("tbody", { children: renderRows() }), _jsx("tfoot", { children: _jsxs("tr", { children: [_jsx("td", { children: _jsx("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: addRow, children: "+" }) }), _jsx("td", { colSpan: getCols().length + 1, className: "text-left align-middle", style: {
189
- textOverflow: "ellipsis",
190
- msTextOverflow: "ellipsis",
191
- }, children: renderTotalWidth() })] }) })] }) }));
192
- };
193
- export default React.forwardRef(DynamicTable);
1
+ export * from "./BasicPrintDynamicTable.js";
2
+ export * from "./DynamicPrintTable.js";
3
+ export * from "./DynamicTable.js";
4
+ export * from "./GenericDynamicTable.js";
@@ -1 +1 @@
1
- export * from "./Footer";
1
+ export * from "./Footer.js";
@@ -1 +1 @@
1
- export * from "./Footer";
1
+ export * from "./Footer.js";
@@ -1,3 +1,3 @@
1
- export * from "./DoubleFieldContainer";
2
- export * from "./QuadrupleFieldContainer";
3
- export * from "./TripleFieldContainer";
1
+ export * from "./DoubleFieldContainer.js";
2
+ export * from "./QuadrupleFieldContainer.js";
3
+ export * from "./TripleFieldContainer.js";
@@ -1,3 +1,3 @@
1
- export * from "./DoubleFieldContainer";
2
- export * from "./QuadrupleFieldContainer";
3
- export * from "./TripleFieldContainer";
1
+ export * from "./DoubleFieldContainer.js";
2
+ export * from "./QuadrupleFieldContainer.js";
3
+ export * from "./TripleFieldContainer.js";
@@ -1,13 +1,13 @@
1
- export * from "./Checkbox";
2
- export * from "./Checklist";
3
- export * from "./DatePicker";
4
- export * from "./DynamicBaculoForm";
5
- export * from "./FieldContainer";
6
- export * from "./FileUpload";
7
- export * from "./FormButtons";
8
- export * from "./FormLayout";
9
- export * from "./SelectField";
10
- export * from "./TextArea";
11
- export * from "./TextField";
12
- export * from "./TimePicker";
13
- export * from "./YesNo";
1
+ export * from "./Checkbox/index.js";
2
+ export * from "./Checklist/index.js";
3
+ export * from "./DatePicker/index.js";
4
+ export * from "./DynamicBaculoForm/index.js";
5
+ export * from "./FieldContainer/index.js";
6
+ export * from "./FileUpload/index.js";
7
+ export * from "./FormButtons/index.js";
8
+ export * from "./FormLayout/index.js";
9
+ export * from "./SelectField/index.js";
10
+ export * from "./TextArea/index.js";
11
+ export * from "./TextField/index.js";
12
+ export * from "./TimePicker/index.js";
13
+ export * from "./YesNo/index.js";