next-recomponents 2.0.0 → 2.0.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/dist/index.js +388 -446
- package/dist/index.mjs +388 -448
- package/package.json +1 -1
- package/src/calendar/index.tsx +25 -28
- package/src/table/index.tsx +46 -29
- package/tsconfig.json +1 -1
package/package.json
CHANGED
package/src/calendar/index.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import DatePicker from "react-datepicker";
|
|
10
10
|
import "./react-datepicker.css";
|
|
11
11
|
import CalendarIcon from "./calendar.icon";
|
|
12
|
+
import { Dialog } from "@mui/material";
|
|
12
13
|
|
|
13
14
|
interface CalendarProps extends DetailedHTMLProps<
|
|
14
15
|
InputHTMLAttributes<HTMLInputElement>,
|
|
@@ -29,16 +30,15 @@ export default function MyCalendar({
|
|
|
29
30
|
value,
|
|
30
31
|
...otherProps
|
|
31
32
|
}: CalendarProps) {
|
|
32
|
-
const modalRef = useRef<HTMLDialogElement>(null);
|
|
33
33
|
const [selectedDate, setSelectedDate] = useState<Date | null>(null);
|
|
34
34
|
const [dateStr, setDateStr] = useState<string | number | readonly string[]>(
|
|
35
35
|
defaultValue || value || "",
|
|
36
36
|
);
|
|
37
|
-
const [
|
|
37
|
+
const [open, setOpen] = useState(false);
|
|
38
38
|
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
|
|
41
|
-
}, []);
|
|
39
|
+
// useEffect(() => {
|
|
40
|
+
// setVisible(typeof window !== "undefined");
|
|
41
|
+
// }, []);
|
|
42
42
|
|
|
43
43
|
function handleChange(date: Date | null) {
|
|
44
44
|
if (!date) return;
|
|
@@ -46,7 +46,7 @@ export default function MyCalendar({
|
|
|
46
46
|
const formattedDate = date.toISOString().split("T")[0];
|
|
47
47
|
setDateStr(formattedDate);
|
|
48
48
|
onChange?.({ target: { value: formattedDate } });
|
|
49
|
-
|
|
49
|
+
setOpen(false);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// 🔧 Convertir strings a fechas sin zona horaria
|
|
@@ -69,8 +69,8 @@ export default function MyCalendar({
|
|
|
69
69
|
</div>
|
|
70
70
|
<div>
|
|
71
71
|
<div
|
|
72
|
-
onClick={() => modalRef?.current?.showModal?.()}
|
|
73
72
|
className="cursor-pointer flex items-center justify-center"
|
|
73
|
+
onClick={(e) => setOpen(true)}
|
|
74
74
|
>
|
|
75
75
|
<input
|
|
76
76
|
{...otherProps}
|
|
@@ -91,27 +91,24 @@ export default function MyCalendar({
|
|
|
91
91
|
</div>
|
|
92
92
|
</label>
|
|
93
93
|
|
|
94
|
-
{
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
</div>
|
|
113
|
-
</dialog>
|
|
114
|
-
)}
|
|
94
|
+
<Dialog open={open}>
|
|
95
|
+
<div className="flex justify-end p-5 font-bold">
|
|
96
|
+
<button
|
|
97
|
+
className=" border-lg w-[20px] bg-red-500 text-white shadow rounded"
|
|
98
|
+
onClick={(e) => setOpen(false)}
|
|
99
|
+
>
|
|
100
|
+
x
|
|
101
|
+
</button>
|
|
102
|
+
</div>
|
|
103
|
+
<div className=" w-[300px] flex items-start justify-center h-[300px] p-5">
|
|
104
|
+
<DatePicker
|
|
105
|
+
inline
|
|
106
|
+
selected={selectedDate}
|
|
107
|
+
onChange={handleChange}
|
|
108
|
+
includeDates={normalizedEnabledDates}
|
|
109
|
+
/>
|
|
110
|
+
</div>
|
|
111
|
+
</Dialog>
|
|
115
112
|
</div>
|
|
116
113
|
);
|
|
117
114
|
}
|
package/src/table/index.tsx
CHANGED
|
@@ -34,6 +34,7 @@ interface TableProps {
|
|
|
34
34
|
hideColumns?: string[];
|
|
35
35
|
footer?: FooterType;
|
|
36
36
|
symbols?: any;
|
|
37
|
+
|
|
37
38
|
[key: string]: any;
|
|
38
39
|
}
|
|
39
40
|
export default function Table(props: TableProps) {
|
|
@@ -88,7 +89,7 @@ function IHTable({
|
|
|
88
89
|
buttons,
|
|
89
90
|
exportName,
|
|
90
91
|
modal,
|
|
91
|
-
height =
|
|
92
|
+
height = 600,
|
|
92
93
|
width = "100%",
|
|
93
94
|
header,
|
|
94
95
|
hideColumns = [],
|
|
@@ -118,7 +119,7 @@ function IHTable({
|
|
|
118
119
|
if (!rows.length) return [];
|
|
119
120
|
|
|
120
121
|
const arr = Object.keys(rows[0])
|
|
121
|
-
.filter((key) => !key.startsWith("_") && !hideColumns.includes(key))
|
|
122
|
+
.filter((key) => !key.startsWith("_") && !hideColumns.includes(key))
|
|
122
123
|
.map((key, i) => ({
|
|
123
124
|
field: key,
|
|
124
125
|
headerName: key,
|
|
@@ -128,6 +129,7 @@ function IHTable({
|
|
|
128
129
|
renderCell: buttons?.[key]
|
|
129
130
|
? (params: any) =>
|
|
130
131
|
React.cloneElement(buttons[key], {
|
|
132
|
+
className: (params?.className ?? "") + " m-auto text-xs ",
|
|
131
133
|
children: params?.row?.[key],
|
|
132
134
|
onClick: (e: any) => {
|
|
133
135
|
e.row = params?.row;
|
|
@@ -164,6 +166,7 @@ function IHTable({
|
|
|
164
166
|
|
|
165
167
|
return arr;
|
|
166
168
|
}, [rows]);
|
|
169
|
+
|
|
167
170
|
const handleRowUpdate = (newRow: GridRowModel) => {
|
|
168
171
|
if (!newRow.id) throw new Error("Fila sin id");
|
|
169
172
|
newRow._edited = true;
|
|
@@ -171,15 +174,6 @@ function IHTable({
|
|
|
171
174
|
return newRow;
|
|
172
175
|
};
|
|
173
176
|
|
|
174
|
-
// useEffect(() => {
|
|
175
|
-
// if (modal) {
|
|
176
|
-
// const ids = Array.from(selectedRows?.ids || []);
|
|
177
|
-
// if (ids.length == 1) {
|
|
178
|
-
// // ref.current?.showModal();
|
|
179
|
-
// handleOpen();
|
|
180
|
-
// }
|
|
181
|
-
// }
|
|
182
|
-
// }, [selectedRows]);
|
|
183
177
|
const ref = useRef<HTMLDialogElement>(null);
|
|
184
178
|
const cat1: any = {
|
|
185
179
|
1: 110,
|
|
@@ -203,6 +197,7 @@ function IHTable({
|
|
|
203
197
|
}
|
|
204
198
|
return filtered;
|
|
205
199
|
}, [selectedRows]);
|
|
200
|
+
|
|
206
201
|
return (
|
|
207
202
|
rows.length > 0 && (
|
|
208
203
|
<Box
|
|
@@ -215,13 +210,7 @@ function IHTable({
|
|
|
215
210
|
}}
|
|
216
211
|
>
|
|
217
212
|
{modal && (
|
|
218
|
-
<Dialog
|
|
219
|
-
open={open}
|
|
220
|
-
onClose={handleClose}
|
|
221
|
-
maxWidth="xl"
|
|
222
|
-
fullWidth
|
|
223
|
-
// className="w-lg h-screen rounded-lg p-6 shadow-lg border border-gray-300 bg-white"
|
|
224
|
-
>
|
|
213
|
+
<Dialog open={open} onClose={handleClose} maxWidth="xl" fullWidth>
|
|
225
214
|
<div className="flex justify-end">
|
|
226
215
|
<button
|
|
227
216
|
onClick={() => {
|
|
@@ -293,7 +282,6 @@ function IHTable({
|
|
|
293
282
|
checkboxSelection={Boolean(onSelect)}
|
|
294
283
|
rowSelectionModel={selectedRows}
|
|
295
284
|
onRowSelectionModelChange={(newSelection) => {
|
|
296
|
-
console.log(newSelection);
|
|
297
285
|
setSelectedRows(newSelection);
|
|
298
286
|
}}
|
|
299
287
|
sx={{
|
|
@@ -305,8 +293,6 @@ function IHTable({
|
|
|
305
293
|
editMode="row"
|
|
306
294
|
processRowUpdate={handleRowUpdate}
|
|
307
295
|
pageSizeOptions={[5, 10]}
|
|
308
|
-
// pagination={true}
|
|
309
|
-
// hideFooter={hideFooter}
|
|
310
296
|
/>
|
|
311
297
|
<CustomFooter footer={footer || {}} rows={rows} />
|
|
312
298
|
</Box>
|
|
@@ -314,17 +300,48 @@ function IHTable({
|
|
|
314
300
|
);
|
|
315
301
|
}
|
|
316
302
|
|
|
317
|
-
function CustomFooter(
|
|
318
|
-
|
|
303
|
+
function CustomFooter({
|
|
304
|
+
rows,
|
|
305
|
+
footer,
|
|
306
|
+
}: {
|
|
307
|
+
rows: GridValidRowModel[];
|
|
308
|
+
footer: FooterType;
|
|
309
|
+
}) {
|
|
310
|
+
const entries = Object.entries(footer);
|
|
311
|
+
if (!entries.length) return null;
|
|
312
|
+
|
|
313
|
+
const compute = (key: string, type: "sum" | "avg" | "count") => {
|
|
314
|
+
const values = rows
|
|
315
|
+
.map((r) => Number(r[key] ?? 0))
|
|
316
|
+
.filter((v) => !isNaN(v));
|
|
317
|
+
if (type === "sum") return values.reduce((acc, v) => acc + v, 0);
|
|
318
|
+
if (type === "avg")
|
|
319
|
+
return values.length
|
|
320
|
+
? values.reduce((acc, v) => acc + v, 0) / values.length
|
|
321
|
+
: 0;
|
|
322
|
+
if (type === "count") return values.length;
|
|
323
|
+
return 0;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const label: Record<string, string> = {
|
|
327
|
+
sum: "Suma",
|
|
328
|
+
avg: "Promedio",
|
|
329
|
+
count: "Conteo",
|
|
330
|
+
};
|
|
319
331
|
|
|
320
332
|
return (
|
|
321
|
-
<div>
|
|
322
|
-
{
|
|
323
|
-
const
|
|
333
|
+
<div className="flex justify-end gap-6 px-4 py-2 bg-gray-100 border-t border-gray-300 text-sm font-semibold text-gray-700">
|
|
334
|
+
{entries.map(([key, type]) => {
|
|
335
|
+
const value = compute(key, type);
|
|
336
|
+
const formatted =
|
|
337
|
+
type === "avg"
|
|
338
|
+
? value.toLocaleString(undefined, { maximumFractionDigits: 2 })
|
|
339
|
+
: value.toLocaleString();
|
|
324
340
|
return (
|
|
325
|
-
<
|
|
326
|
-
|
|
327
|
-
|
|
341
|
+
<span key={key}>
|
|
342
|
+
{label[type]} de <span className="text-gray-900">{key}</span>:{" "}
|
|
343
|
+
<span className="text-blue-700">{formatted}</span>
|
|
344
|
+
</span>
|
|
328
345
|
);
|
|
329
346
|
})}
|
|
330
347
|
</div>
|