@zauru-sdk/components 1.0.51 → 1.0.52

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 (177) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +10 -17
  3. package/tsconfig.cjs.json +8 -0
  4. package/tsconfig.esm.json +11 -0
  5. package/tsconfig.json +6 -15
  6. package/dist/Alerts/ErrorBoundaryAlert/ErrorBoundaryAlert.d.ts +0 -6
  7. package/dist/Alerts/ErrorBoundaryAlert/ErrorBoundaryAlert.js +0 -5
  8. package/dist/Alerts/StaticAlert.d.ts +0 -11
  9. package/dist/Alerts/StaticAlert.js +0 -28
  10. package/dist/Alerts/index.d.ts +0 -2
  11. package/dist/Alerts/index.js +0 -2
  12. package/dist/BlockUI/BlockUI.d.ts +0 -8
  13. package/dist/BlockUI/BlockUI.js +0 -8
  14. package/dist/BlockUI/index.d.ts +0 -1
  15. package/dist/BlockUI/index.js +0 -1
  16. package/dist/Buttons/Button.d.ts +0 -15
  17. package/dist/Buttons/Button.js +0 -43
  18. package/dist/Buttons/index.d.ts +0 -1
  19. package/dist/Buttons/index.js +0 -1
  20. package/dist/Card/Card.d.ts +0 -8
  21. package/dist/Card/Card.js +0 -5
  22. package/dist/Card/index.d.ts +0 -1
  23. package/dist/Card/index.js +0 -1
  24. package/dist/Chat/ChatLayout.d.ts +0 -17
  25. package/dist/Chat/ChatLayout.js +0 -27
  26. package/dist/Chat/ChatMessageHistory.d.ts +0 -12
  27. package/dist/Chat/ChatMessageHistory.js +0 -53
  28. package/dist/Chat/index.d.ts +0 -2
  29. package/dist/Chat/index.js +0 -2
  30. package/dist/ConnectionState/ConnectionState.d.ts +0 -1
  31. package/dist/ConnectionState/ConnectionState.js +0 -21
  32. package/dist/ConnectionState/index.d.ts +0 -1
  33. package/dist/ConnectionState/index.js +0 -1
  34. package/dist/Containers/BodyContainer.d.ts +0 -6
  35. package/dist/Containers/BodyContainer.js +0 -5
  36. package/dist/Containers/ButtonSectionContainer.d.ts +0 -8
  37. package/dist/Containers/ButtonSectionContainer.js +0 -5
  38. package/dist/Containers/Container.d.ts +0 -10
  39. package/dist/Containers/Container.js +0 -6
  40. package/dist/Containers/DoubleContainer.d.ts +0 -9
  41. package/dist/Containers/DoubleContainer.js +0 -14
  42. package/dist/Containers/MainContainer.d.ts +0 -6
  43. package/dist/Containers/MainContainer.js +0 -5
  44. package/dist/Containers/OutletContainer.d.ts +0 -6
  45. package/dist/Containers/OutletContainer.js +0 -5
  46. package/dist/Containers/SubContainer.d.ts +0 -10
  47. package/dist/Containers/SubContainer.js +0 -6
  48. package/dist/Containers/index.d.ts +0 -7
  49. package/dist/Containers/index.js +0 -7
  50. package/dist/DynamicTable/BasicPrintDynamicTable.d.ts +0 -10
  51. package/dist/DynamicTable/BasicPrintDynamicTable.js +0 -27
  52. package/dist/DynamicTable/DynamicPrintTable.d.ts +0 -23
  53. package/dist/DynamicTable/DynamicPrintTable.js +0 -131
  54. package/dist/DynamicTable/DynamicTable.d.ts +0 -24
  55. package/dist/DynamicTable/DynamicTable.js +0 -192
  56. package/dist/DynamicTable/GenericDynamicTable.d.ts +0 -21
  57. package/dist/DynamicTable/GenericDynamicTable.js +0 -196
  58. package/dist/DynamicTable/index.d.ts +0 -4
  59. package/dist/DynamicTable/index.js +0 -4
  60. package/dist/Footer/Footer.d.ts +0 -7
  61. package/dist/Footer/Footer.js +0 -16
  62. package/dist/Footer/index.d.ts +0 -1
  63. package/dist/Footer/index.js +0 -1
  64. package/dist/Form/Checkbox/index.d.ts +0 -17
  65. package/dist/Form/Checkbox/index.js +0 -34
  66. package/dist/Form/Checklist/index.d.ts +0 -14
  67. package/dist/Form/Checklist/index.js +0 -10
  68. package/dist/Form/DatePicker/index.d.ts +0 -18
  69. package/dist/Form/DatePicker/index.js +0 -31
  70. package/dist/Form/DynamicBaculoForm/index.d.ts +0 -18
  71. package/dist/Form/DynamicBaculoForm/index.js +0 -140
  72. package/dist/Form/FieldContainer/DoubleFieldContainer.d.ts +0 -8
  73. package/dist/Form/FieldContainer/DoubleFieldContainer.js +0 -14
  74. package/dist/Form/FieldContainer/QuadrupleFieldContainer.d.ts +0 -7
  75. package/dist/Form/FieldContainer/QuadrupleFieldContainer.js +0 -14
  76. package/dist/Form/FieldContainer/TripleFieldContainer.d.ts +0 -7
  77. package/dist/Form/FieldContainer/TripleFieldContainer.js +0 -14
  78. package/dist/Form/FieldContainer/index.d.ts +0 -3
  79. package/dist/Form/FieldContainer/index.js +0 -3
  80. package/dist/Form/FileUpload/index.d.ts +0 -21
  81. package/dist/Form/FileUpload/index.js +0 -54
  82. package/dist/Form/FormButtons/index.d.ts +0 -16
  83. package/dist/Form/FormButtons/index.js +0 -5
  84. package/dist/Form/FormLayout/index.d.ts +0 -11
  85. package/dist/Form/FormLayout/index.js +0 -7
  86. package/dist/Form/SelectField/index.d.ts +0 -27
  87. package/dist/Form/SelectField/index.js +0 -74
  88. package/dist/Form/TextArea/index.d.ts +0 -23
  89. package/dist/Form/TextArea/index.js +0 -36
  90. package/dist/Form/TextField/index.d.ts +0 -25
  91. package/dist/Form/TextField/index.js +0 -70
  92. package/dist/Form/TimePicker/index.d.ts +0 -16
  93. package/dist/Form/TimePicker/index.js +0 -31
  94. package/dist/Form/YesNo/index.d.ts +0 -12
  95. package/dist/Form/YesNo/index.js +0 -18
  96. package/dist/Form/index.d.ts +0 -13
  97. package/dist/Form/index.js +0 -13
  98. package/dist/Labels/InfoLabel/index.d.ts +0 -7
  99. package/dist/Labels/InfoLabel/index.js +0 -5
  100. package/dist/Labels/index.d.ts +0 -1
  101. package/dist/Labels/index.js +0 -1
  102. package/dist/Layouts/homeLayout/index.d.ts +0 -6
  103. package/dist/Layouts/homeLayout/index.js +0 -10
  104. package/dist/Layouts/index.d.ts +0 -1
  105. package/dist/Layouts/index.js +0 -1
  106. package/dist/LineSeparator/LineSeparator.d.ts +0 -1
  107. package/dist/LineSeparator/LineSeparator.js +0 -4
  108. package/dist/LineSeparator/index.d.ts +0 -1
  109. package/dist/LineSeparator/index.js +0 -1
  110. package/dist/Modal/Modal.d.ts +0 -10
  111. package/dist/Modal/Modal.js +0 -32
  112. package/dist/Modal/index.d.ts +0 -1
  113. package/dist/Modal/index.js +0 -1
  114. package/dist/NavBar/NavBar.d.ts +0 -2
  115. package/dist/NavBar/NavBar.js +0 -32
  116. package/dist/NavBar/NavBar.types.d.ts +0 -50
  117. package/dist/NavBar/NavBar.types.js +0 -1
  118. package/dist/NavBar/NavBar.utils.d.ts +0 -58
  119. package/dist/NavBar/NavBar.utils.js +0 -58
  120. package/dist/NavBar/index.d.ts +0 -3
  121. package/dist/NavBar/index.js +0 -3
  122. package/dist/ProgressBar/ProgressBar.d.ts +0 -6
  123. package/dist/ProgressBar/ProgressBar.js +0 -5
  124. package/dist/ProgressBar/ProgressCircle.d.ts +0 -6
  125. package/dist/ProgressBar/ProgressCircle.js +0 -22
  126. package/dist/ProgressBar/index.d.ts +0 -2
  127. package/dist/ProgressBar/index.js +0 -2
  128. package/dist/Skeletons/LoadingInputSkeleton.d.ts +0 -1
  129. package/dist/Skeletons/LoadingInputSkeleton.js +0 -8
  130. package/dist/Skeletons/index.d.ts +0 -1
  131. package/dist/Skeletons/index.js +0 -1
  132. package/dist/Tab/Tab.d.ts +0 -9
  133. package/dist/Tab/Tab.js +0 -19
  134. package/dist/Tab/index.d.ts +0 -1
  135. package/dist/Tab/index.js +0 -1
  136. package/dist/Table/ZauruTable.d.ts +0 -25
  137. package/dist/Table/ZauruTable.js +0 -148
  138. package/dist/Table/index.d.ts +0 -1
  139. package/dist/Table/index.js +0 -1
  140. package/dist/TaskList/TaskList.d.ts +0 -14
  141. package/dist/TaskList/TaskList.js +0 -35
  142. package/dist/TaskList/index.d.ts +0 -1
  143. package/dist/TaskList/index.js +0 -1
  144. package/dist/Titles/LabelArray.d.ts +0 -4
  145. package/dist/Titles/LabelArray.js +0 -7
  146. package/dist/Titles/TableColumnTitle.d.ts +0 -4
  147. package/dist/Titles/TableColumnTitle.js +0 -5
  148. package/dist/Titles/TitleH1.d.ts +0 -1
  149. package/dist/Titles/TitleH1.js +0 -5
  150. package/dist/Titles/TitleH2.d.ts +0 -1
  151. package/dist/Titles/TitleH2.js +0 -5
  152. package/dist/Titles/TitleH3.d.ts +0 -1
  153. package/dist/Titles/TitleH3.js +0 -5
  154. package/dist/Titles/index.d.ts +0 -5
  155. package/dist/Titles/index.js +0 -5
  156. package/dist/Tooltip/Tooltip.d.ts +0 -7
  157. package/dist/Tooltip/Tooltip.js +0 -14
  158. package/dist/Tooltip/index.d.ts +0 -1
  159. package/dist/Tooltip/index.js +0 -1
  160. package/dist/WithTooltip/WithTooltip.d.ts +0 -7
  161. package/dist/WithTooltip/WithTooltip.js +0 -5
  162. package/dist/WithTooltip/index.d.ts +0 -1
  163. package/dist/WithTooltip/index.js +0 -1
  164. package/dist/Wizards/StepWizard.d.ts +0 -14
  165. package/dist/Wizards/StepWizard.js +0 -14
  166. package/dist/Wizards/index.d.ts +0 -1
  167. package/dist/Wizards/index.js +0 -1
  168. package/dist/Zendesk/Chat.d.ts +0 -14
  169. package/dist/Zendesk/Chat.js +0 -63
  170. package/dist/Zendesk/index.d.ts +0 -2
  171. package/dist/Zendesk/index.js +0 -2
  172. package/dist/Zendesk/zendesk.config.d.ts +0 -9
  173. package/dist/Zendesk/zendesk.config.js +0 -24
  174. package/dist/index.d.ts +0 -24
  175. package/dist/index.js +0 -24
  176. package/dist/tailwind.config.d.ts +0 -1
  177. package/dist/tailwind.config.js +0 -8
@@ -1,7 +0,0 @@
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,10 +0,0 @@
1
- import { GenericDynamicTableColumn } from "@zauru-sdk/types";
2
- export declare const BasicTableHTML: (props: {
3
- data: {
4
- [key: string]: string;
5
- }[];
6
- headers: GenericDynamicTableColumn[];
7
- footer: {
8
- [key: string]: string;
9
- };
10
- }) => import("react/jsx-runtime").JSX.Element;
@@ -1,27 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { isNumeric } from "@zauru-sdk/common";
3
- //TABLA PARA LA IMPRESION:
4
- export const BasicTableHTML = (props) => {
5
- const { data, footer, headers } = props;
6
- return (_jsxs("table", { style: { borderCollapse: "collapse", width: "100%" }, children: [_jsx("thead", { children: _jsx("tr", { children: headers?.map((titulo, index) => (_jsx("th", { style: {
7
- border: "1px solid black",
8
- padding: "10px",
9
- textAlign: "center",
10
- whiteSpace: "normal",
11
- }, children: titulo.label }, index))) }) }), _jsx("tbody", { children: data?.map((fila, index) => (_jsx("tr", { children: headers?.map((titulo, index) => (_jsx("td", { style: {
12
- border: "1px solid black",
13
- padding: "1px",
14
- textAlign: "center",
15
- whiteSpace: "normal",
16
- fontSize: isNumeric(fila[titulo.name])
17
- ? "2em"
18
- : "1em",
19
- }, children: fila[titulo.name] }, index))) }, index))) }), _jsx("tfoot", { children: _jsx("tr", { children: headers?.map((titulo, index) => (_jsx("td", { style: {
20
- padding: "10px",
21
- textAlign: "center",
22
- whiteSpace: "normal",
23
- fontSize: isNumeric(footer[titulo.name])
24
- ? "2em"
25
- : "1em",
26
- }, children: footer[titulo.name] }, index))) }) })] }));
27
- };
@@ -1,23 +0,0 @@
1
- import React, { type ReactNode } from "react";
2
- export type TableStateItem = {
3
- item_id: string | undefined;
4
- quantity: number | undefined;
5
- };
6
- export type FormatedItem = {
7
- label: string;
8
- value: number;
9
- template: string;
10
- };
11
- type Props = {
12
- name: string;
13
- formName?: string;
14
- className?: string;
15
- items: FormatedItem[];
16
- onChange?: (tableState?: TableStateItem[]) => void;
17
- forwardedRef?: React.RefObject<{
18
- insertItems: (items: FormatedItem[]) => void;
19
- getTableState: (updatedData?: ReactNode[][]) => TableStateItem[] | undefined;
20
- }>;
21
- };
22
- export declare const DynamicPrintTable: ({ forwardedRef, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
23
- export {};
@@ -1,131 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useEffect, useCallback, useState } from "react";
3
- import { TextFieldWithoutValidation } from "../Form/TextField/index.js";
4
- import { SelectFieldWithoutValidation } from "../Form/SelectField/index.js";
5
- import { useAppSelector } from "@zauru-sdk/redux";
6
- const errorAnimation = {
7
- hidden: { opacity: 0, y: -10 },
8
- visible: { opacity: 1, y: 0 },
9
- };
10
- export const DynamicPrintTable = ({ forwardedRef, ...props }) => {
11
- const { items, onChange, className } = props;
12
- const { formValidations } = useAppSelector((state) => state.formValidation);
13
- const createItemSelect = (rowIndex, defaultValue) => (_jsx(SelectFieldWithoutValidation, { name: "item_select", isClearable: true, onChange: (value) => {
14
- const selectedItem = items?.find((x) => x.value === value?.value);
15
- updateRow(rowIndex, selectedItem);
16
- }, options: items, defaultValue: defaultValue }, rowIndex));
17
- const createItemQuantity = (rowIndex, defaultValue) => (_jsx(TextFieldWithoutValidation, { name: "item_quantity", type: "number", integer: true, defaultValue: defaultValue ?? 1, min: 1, onChange: (value) => {
18
- updateRow(rowIndex, undefined, Number(value));
19
- } }, rowIndex));
20
- const createTemplateName = (rowIndex, defaultValue) => (_jsx("div", { children: defaultValue != "" ? defaultValue : "No hay etiqueta" }, rowIndex));
21
- const createRow = (rowIndex, item, quantity) => {
22
- const itemCreated = createItemSelect(rowIndex, item ?? undefined);
23
- const quantityCreated = createItemQuantity(rowIndex, quantity ?? 1);
24
- const templateCreated = createTemplateName(rowIndex, item ? item.template : "Seleccione un item para visualizar su etiqueta.");
25
- return [itemCreated, quantityCreated, templateCreated];
26
- };
27
- const [tableData, setTableData] = useState([]);
28
- const [isInitialItemAdded, setIsInitialItemAdded] = useState(false);
29
- const insertItems = useCallback((newItems) => {
30
- setTableData((prevData) => [
31
- ...(prevData ?? []),
32
- ...newItems.map((item, index) => {
33
- const rowIndex = (prevData?.length ?? 0) + index;
34
- const [itemCreated, quantityCreated, templateCreated] = createRow(rowIndex, item);
35
- updateRow(rowIndex, item, 1);
36
- return [itemCreated, quantityCreated, templateCreated];
37
- }),
38
- ]);
39
- }, [items]);
40
- const getTableState = (temp) => {
41
- const updatedData = temp ?? tableData;
42
- const tableState = updatedData?.map((rowData) => {
43
- const firstElement = rowData[0];
44
- const item_id = React.isValidElement(firstElement)
45
- ? firstElement.props.defaultValue?.value
46
- : undefined;
47
- const secondElement = rowData[1];
48
- const quantity = React.isValidElement(secondElement)
49
- ? secondElement.props.defaultValue
50
- : undefined;
51
- return {
52
- item_id,
53
- quantity,
54
- };
55
- });
56
- return tableState;
57
- };
58
- const updateRow = (rowIndex, item, quantity) => {
59
- setTableData((prevData) => {
60
- const updatedData = prevData?.map((_, index) => {
61
- if (index === rowIndex) {
62
- const firstElement = prevData[index][0];
63
- const selectedItem = item ??
64
- (React.isValidElement(firstElement)
65
- ? items?.find((x) => x.value === firstElement.props.defaultValue?.value)
66
- : undefined);
67
- const secondElement = prevData[index][1];
68
- const newQuantity = quantity
69
- ? quantity
70
- : React.isValidElement(secondElement)
71
- ? secondElement.props.defaultValue
72
- : undefined;
73
- return createRow(rowIndex, selectedItem, newQuantity);
74
- }
75
- else {
76
- return prevData[index];
77
- }
78
- });
79
- if (onChange) {
80
- const tableState = getTableState(updatedData);
81
- onChange(tableState);
82
- }
83
- return updatedData;
84
- });
85
- };
86
- const addRow = () => {
87
- setTableData((prevData) => [
88
- ...(prevData ?? []),
89
- createRow(prevData?.length ?? 0),
90
- ]);
91
- };
92
- const removeRow = (rowIndex) => {
93
- setTableData((prevData) => prevData?.filter((_, index) => index !== rowIndex));
94
- };
95
- React.useImperativeHandle(forwardedRef, () => ({
96
- insertItems,
97
- getTableState,
98
- }));
99
- const pastelGrayBackground = {
100
- backgroundColor: "#B69E99",
101
- };
102
- const renderHeader = () => (_jsxs("tr", { style: { ...pastelGrayBackground }, children: [_jsx("th", { className: "text-left align-middle p-2", children: "Item" }), _jsx("th", { className: "text-left align-middle p-2", children: "Cantidad" }), _jsx("th", { className: "text-left align-middle p-2", children: "Etiqueta" }), _jsx("th", { className: "w-16" })] }));
103
- const renderRow = (rowData, rowIndex) => (_jsxs("tr", { children: [rowData.map((cellData, cellIndex) => (_jsx("td", { className: "align-middle p-2", children: cellData }, cellIndex))), rowIndex !== 0 && (_jsx("td", { className: "align-middle w-16", children: _jsx("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: (event) => {
104
- event.preventDefault();
105
- event.stopPropagation();
106
- removeRow(rowIndex);
107
- }, type: "button", children: "x" }) }))] }, rowIndex));
108
- const renderRows = () => {
109
- return tableData?.map((rowData, rowIndex) => renderRow(rowData, rowIndex));
110
- };
111
- const error = formValidations[props.formName ?? "-1"][props.name];
112
- const borderColor = error ? "border-red-500" : "border-transparent";
113
- useEffect(() => {
114
- if (!isInitialItemAdded && items?.length > 0) {
115
- insertItems([items[0]]);
116
- setIsInitialItemAdded(true);
117
- }
118
- }, [isInitialItemAdded, items, insertItems]);
119
- return (_jsxs("div", { className: `${className} ${borderColor} border-2`, style: { overflowX: "auto" }, children: [!!error && _jsx("div", { className: "text-red-500 text-sm mb-2", children: error }), _jsxs("table", { className: "w-full", children: [_jsx("thead", { children: renderHeader() }), _jsx("tbody", { children: renderRows() }), _jsx("tfoot", { children: _jsxs("tr", { children: [_jsx("td", { className: "align-middle", children: _jsx("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: (event) => {
120
- event.preventDefault();
121
- event.stopPropagation();
122
- addRow();
123
- }, type: "button", children: "+" }) }), _jsxs("td", { colSpan: 2, children: ["Total de etiquetas a imprimir:", " ", tableData?.reduce((sum, x) => {
124
- const val = React.isValidElement(x[1])
125
- ? x[1]?.props?.defaultValue
126
- : undefined;
127
- if (!sum)
128
- return val;
129
- return sum + val;
130
- }, 0)] })] }) })] })] }));
131
- };
@@ -1,24 +0,0 @@
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 {};
@@ -1,192 +0,0 @@
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/index.js";
4
- import { TextFieldWithoutValidation } from "../Form/TextField/index.js";
5
- import { CheckboxWithoutValidation } from "../Form/Checkbox/index.js";
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,21 +0,0 @@
1
- import React from "react";
2
- import { GenericDynamicTableColumn, RowDataType, SelectFieldOption } from "@zauru-sdk/types";
3
- type Props = {
4
- name?: string;
5
- className?: string;
6
- columns: GenericDynamicTableColumn[];
7
- onChange?: (tableState?: any[]) => void;
8
- defaultValue?: RowDataType[];
9
- footerRow?: RowDataType;
10
- thCSSProperties?: React.CSSProperties;
11
- thElementsClassName?: string;
12
- editable?: boolean;
13
- searcheables?: SelectFieldOption[];
14
- loading?: boolean;
15
- paginated?: boolean;
16
- defaultItemsPerPage?: number;
17
- itemsPerPageOptions?: number[];
18
- withoutBg?: boolean;
19
- };
20
- export declare const GenericDynamicTable: (props: Props) => import("react/jsx-runtime").JSX.Element;
21
- export {};
@@ -1,196 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useEffect, useState } from "react";
3
- import { SelectFieldWithoutValidation } from "../Form/SelectField/index.js";
4
- import { TextFieldWithoutValidation } from "../Form/TextField/index.js";
5
- import { CheckboxWithoutValidation } from "../Form/Checkbox/index.js";
6
- import { createModal } from "../Modal/index.js";
7
- import { Button } from "../Buttons/index.js";
8
- import { useAppSelector } from "@zauru-sdk/redux";
9
- import { generateClientUUID } from "@zauru-sdk/common";
10
- import { LoadingInputSkeleton } from "../Skeletons/index.js";
11
- import { WithTooltip } from "../WithTooltip/index.js";
12
- import { TrashSvg } from "@zauru-sdk/icons";
13
- const GenericDynamicTableErrorComponent = ({ name, formName, }) => {
14
- const { formValidations } = useAppSelector((state) => state.formValidation);
15
- const error = formValidations[formName ?? "-1"]?.[name ?? "-1"];
16
- return error ? (_jsxs("p", { className: `mt-2 text-sm text-red-600 dark:text-red-500`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error] })) : (_jsx(_Fragment, {}));
17
- };
18
- export const GenericDynamicTable = (props) => {
19
- const { columns, onChange, className, footerRow, defaultValue = [], thCSSProperties, thElementsClassName = "", editable = true, searcheables = [], loading = false, paginated = true, defaultItemsPerPage = 10, itemsPerPageOptions = [10, 50, 100], name, withoutBg = false, } = props;
20
- const [tableData, setTableData] = useState(defaultValue);
21
- const [deletedData, setDeletedData] = useState([]);
22
- const [search, setSearch] = useState("");
23
- const [filteredTableData, setFilteredTableData] = useState(tableData);
24
- const [currentPage, setCurrentPage] = useState(1);
25
- const [itemsPerPage, setItemsPerPage] = useState(defaultItemsPerPage);
26
- useEffect(() => {
27
- if (defaultValue.length) {
28
- setTableData(defaultValue);
29
- }
30
- }, []);
31
- useEffect(() => {
32
- setFilteredTableData(tableData);
33
- }, [tableData]);
34
- useEffect(() => {
35
- changeFilteredData();
36
- }, [tableData, search]);
37
- const totalPages = () => {
38
- return Math.ceil(filteredTableData.length / itemsPerPage);
39
- };
40
- const addRow = () => {
41
- const defs = {};
42
- columns.forEach((x) => {
43
- defs[`${x.name}`] =
44
- x.type == "label" || x.type == "textField"
45
- ? ""
46
- : x.type == "selectField"
47
- ? 0
48
- : x.type == "checkbox"
49
- ? false
50
- : 0;
51
- });
52
- setTableData((prevData) => [
53
- ...prevData,
54
- { id: generateClientUUID(), ...defs },
55
- ]);
56
- };
57
- const removeRow = (rowId) => {
58
- const newDeletedData = [...deletedData];
59
- const deletedItem = tableData?.find((x) => x.id === rowId);
60
- if (deletedItem && !isNaN(deletedItem.id)) {
61
- newDeletedData.push(deletedItem);
62
- }
63
- setDeletedData(newDeletedData);
64
- setTableData((prevData) => prevData?.filter((x) => x.id !== rowId));
65
- };
66
- const handleChange = (name, value, rowId) => {
67
- // Encontrar el índice de la fila que está cambiando
68
- const rowIndex = tableData.findIndex((x) => x.id === rowId);
69
- // Crear una copia del objeto en esa fila
70
- const updatedRow = { ...tableData[rowIndex], [name]: value };
71
- // Copiar todo el array
72
- const updatedData = [...tableData];
73
- // Reemplazar el objeto en la fila que cambió
74
- updatedData[rowIndex] = updatedRow;
75
- // Actualizar el estado con el nuevo array
76
- setTableData(updatedData);
77
- onChange && onChange(updatedData);
78
- };
79
- const renderHeader = () => (_jsxs("tr", { style: { ...thCSSProperties }, children: [columns.map((column, index) => {
80
- const ancho = column.width ?? (editable ? 94 : 100) / (columns.length ?? 1);
81
- return (_jsx("th", { className: `text-left align-middle p-2 ${thElementsClassName}`, style: { width: `${ancho}%` }, children: column.label }, index));
82
- }), editable && _jsx("th", { style: { width: "4%" } })] }));
83
- const renderRow = (rowData, index) => {
84
- return (_jsxs("tr", { className: index % 2 === 0 ? `${withoutBg ? "" : "bg-gray-200"}` : "", children: [columns.map((column) => {
85
- if (loading) {
86
- return (_jsx("td", { className: "align-middle p-1", children: _jsx(LoadingInputSkeleton, {}) }, `${rowData.id}-${column.name}`));
87
- }
88
- const tempVal = rowData[column.name];
89
- const defaultVal = column.type === "selectField"
90
- ? column.options?.find((x) => x.value === tempVal)
91
- : tempVal;
92
- if (column.type === "label") {
93
- return (_jsx("td", { className: "align-middle p-1", children: _jsx("div", { children: defaultVal }) }, `${rowData.id}-${column.name}`));
94
- }
95
- const FieldComponent = column.type === "textField"
96
- ? TextFieldWithoutValidation
97
- : column.type === "checkbox"
98
- ? CheckboxWithoutValidation
99
- : SelectFieldWithoutValidation;
100
- const setTableValue = (columnName, newValue) => {
101
- setTableData((prevState) => {
102
- // Encontrar el índice de la fila que está cambiando
103
- const rowIndex = prevState.findIndex((x) => x.id === rowData.id);
104
- // Crear una copia del objeto en esa fila
105
- const updatedRow = {
106
- ...prevState[rowIndex],
107
- [columnName]: newValue,
108
- };
109
- // Copiar todo el array
110
- const updatedData = [...prevState];
111
- // Reemplazar el objeto en la fila que cambió
112
- updatedData[rowIndex] = updatedRow;
113
- return updatedData;
114
- });
115
- };
116
- return (_jsx("td", { className: "align-middle p-1", children: column.loadingOptions ? (_jsx(LoadingInputSkeleton, {})) : (_jsx(FieldComponent, {
117
- //name={column.name}
118
- type: column.textFieldType, integer: !!column.integer, disabled: column.disabled, isClearable: true, onChange: (value) => {
119
- const sendValue = value?.value ?? value;
120
- handleChange(column.name, sendValue, rowData.id);
121
- column.onChange &&
122
- column.onChange(rowData, sendValue, setTableValue);
123
- }, defaultValue: defaultVal, options: column.options ?? [] }, `${rowData.id}-${column.name}`)) }, `${rowData.id}-${column.name}`));
124
- }), editable && (_jsx("td", { className: "align-middle w-16", children: _jsx(WithTooltip, { text: "Eliminar", children: _jsx("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: (event) => {
125
- event.preventDefault();
126
- event.stopPropagation();
127
- createModal({
128
- title: "¿Está seguro que quiere eliminar este registro?",
129
- description: "Una vez eliminada la información no podrá ser recuperada.",
130
- }).then((response) => {
131
- if (response === "OK") {
132
- removeRow(rowData.id);
133
- }
134
- });
135
- }, type: "button", children: _jsx(TrashSvg, {}) }) }) }))] }, rowData.id));
136
- };
137
- const renderRows = () => {
138
- let mapeable = filteredTableData.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage);
139
- if (loading) {
140
- mapeable = [
141
- { id: 1 },
142
- { id: 2 },
143
- { id: 3 },
144
- { id: 4 },
145
- { id: 5 },
146
- { id: 6 },
147
- { id: 7 },
148
- { id: 8 },
149
- { id: 9 },
150
- { id: 10 },
151
- ];
152
- }
153
- return mapeable.map((rowData, index) => renderRow(rowData, index));
154
- };
155
- const handleChangeSearch = (newSearch) => {
156
- setSearch(newSearch);
157
- };
158
- const changeFilteredData = () => {
159
- if (search) {
160
- const filteredData = tableData.filter((rowData) => {
161
- for (const searchable of searcheables) {
162
- const column = columns.find((col) => col.name === searchable.value);
163
- if (column) {
164
- const tempVal = rowData[column.name];
165
- const defaultVal = column.type === "selectField"
166
- ? column.options?.find((x) => x.value === tempVal)?.label
167
- : tempVal;
168
- if (defaultVal
169
- ?.toString()
170
- .toLowerCase()
171
- .includes(search.toLowerCase())) {
172
- return true;
173
- }
174
- }
175
- }
176
- return false;
177
- });
178
- setFilteredTableData(filteredData);
179
- }
180
- else {
181
- setFilteredTableData(tableData);
182
- }
183
- };
184
- return (_jsxs(_Fragment, { children: [name && (_jsxs(_Fragment, { children: [_jsx(GenericDynamicTableErrorComponent, { name: name }), _jsx("input", { name: name, type: "hidden", value: JSON.stringify(tableData), hidden: true }), _jsx("input", { name: `deleted_${name}`, type: "hidden", value: JSON.stringify(deletedData), hidden: true })] })), _jsxs("div", { className: `${className}`, children: [searcheables.length > 0 && (_jsx("div", { children: _jsx(TextFieldWithoutValidation, { className: "mb-2", name: "search", title: `Buscar por: ${searcheables
185
- .map((x) => x.label)
186
- .join(", ")}`, onChange: handleChangeSearch, disabled: loading }) })), _jsxs("table", { className: "w-full", children: [_jsx("thead", { children: renderHeader() }), _jsx("tbody", { children: renderRows() }), footerRow && !editable ? (_jsx("tfoot", { className: "border-t-2 border-black", children: _jsx("tr", { children: Object.keys(footerRow ?? {})?.map((x, indx) => {
187
- return (_jsx("td", { className: "align-middle", children: footerRow[x] }, indx));
188
- }) }) })) : editable ? (_jsx("tfoot", { children: _jsx("tr", { children: _jsx("td", { className: "align-middle", children: _jsx("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: (event) => {
189
- event.preventDefault();
190
- event.stopPropagation();
191
- addRow();
192
- }, type: "button", children: "+" }) }) }) })) : (_jsx(_Fragment, {}))] }), paginated && totalPages() > 1 && (_jsxs("div", { className: "flex justify-between items-center mt-4", children: [_jsxs("div", { className: "flex items-center", children: [_jsx(Button, { type: "button", disabled: currentPage === 1, onClickSave: () => setCurrentPage((old) => Math.max(old - 1, 1)), children: "Anterior" }), _jsx("span", { className: "mx-2", children: `Página ${currentPage} de ${totalPages()}` }), _jsx(Button, { type: "button", disabled: currentPage === totalPages(), onClickSave: () => setCurrentPage((old) => Math.min(old + 1, totalPages())), children: "Siguiente" })] }), _jsx("div", { children: _jsx("select", { value: itemsPerPage, onChange: (e) => {
193
- setItemsPerPage(Number(e.target.value));
194
- setCurrentPage(1); // resetear la página al cambiar los elementos por página
195
- }, children: itemsPerPageOptions.map((option) => (_jsxs("option", { value: option, children: [option, " elementos por p\u00E1gina"] }, option))) }) })] }))] })] }));
196
- };
@@ -1,4 +0,0 @@
1
- export * from "./BasicPrintDynamicTable.js";
2
- export * from "./DynamicPrintTable.js";
3
- export * from "./DynamicTable.js";
4
- export * from "./GenericDynamicTable.js";
@@ -1,4 +0,0 @@
1
- export * from "./BasicPrintDynamicTable.js";
2
- export * from "./DynamicPrintTable.js";
3
- export * from "./DynamicTable.js";
4
- export * from "./GenericDynamicTable.js";