@apexcura/ui-components 0.0.11-Beta12 → 0.0.11-Beta14
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 +45 -9
- package/dist/index.mjs +45 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -361,13 +361,31 @@ var ButtonElement = () => /* @__PURE__ */ import_react12.default.createElement(i
|
|
|
361
361
|
// src/Components/AddMoreTable.tsx
|
|
362
362
|
var import_react13 = __toESM(require("react"));
|
|
363
363
|
var import_antd11 = require("antd");
|
|
364
|
+
var import_icons2 = require("@ant-design/icons");
|
|
364
365
|
var AddMoreTable = (props) => {
|
|
365
366
|
const { thead, tbody } = props;
|
|
366
367
|
const [tableData, setTableData] = (0, import_react13.useState)({});
|
|
368
|
+
const [rows, setRows] = (0, import_react13.useState)(tbody || []);
|
|
369
|
+
function isColumnType(column) {
|
|
370
|
+
return column.dataIndex !== void 0;
|
|
371
|
+
}
|
|
367
372
|
const onHandleChange = (name, value) => {
|
|
368
373
|
setTableData((prev) => ({ ...prev, [name]: value }));
|
|
369
374
|
console.log(tableData);
|
|
370
375
|
};
|
|
376
|
+
const onHandleRows = () => {
|
|
377
|
+
const lastRow = rows[rows.length - 1];
|
|
378
|
+
const newId = lastRow ? lastRow.id + 1 : lastRow.id;
|
|
379
|
+
const newRow = {
|
|
380
|
+
...lastRow,
|
|
381
|
+
id: newId
|
|
382
|
+
};
|
|
383
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
384
|
+
};
|
|
385
|
+
const onHandleDelete = (index) => {
|
|
386
|
+
const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
|
|
387
|
+
setRows(remainingRows);
|
|
388
|
+
};
|
|
371
389
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
372
390
|
title: eachHeadEl.label,
|
|
373
391
|
dataIndex: eachHeadEl.name,
|
|
@@ -384,20 +402,38 @@ var AddMoreTable = (props) => {
|
|
|
384
402
|
return null;
|
|
385
403
|
}
|
|
386
404
|
};
|
|
387
|
-
const dataSource =
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
405
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
406
|
+
const rowElements = {};
|
|
407
|
+
if (eachRow.element && eachRow.label) {
|
|
408
|
+
rowElements[eachRow.label] = renderInputElement(eachRow);
|
|
409
|
+
}
|
|
410
|
+
const variableData = eachRow.variable_data && Array.isArray(eachRow.variable_data) ? eachRow.variable_data.reduce((acc, curr) => {
|
|
411
|
+
for (let i = 0; i < curr.length; i++) {
|
|
412
|
+
Object.keys(curr[i].forEach((key) => {
|
|
413
|
+
if (curr[i][key] && curr[i][key].element) {
|
|
414
|
+
rowElements[eachRow.label] = renderInputElement(eachRow);
|
|
415
|
+
}
|
|
416
|
+
}));
|
|
417
|
+
}
|
|
392
418
|
return acc;
|
|
393
|
-
}, {});
|
|
419
|
+
}, {}) : {};
|
|
420
|
+
console.log("-----------");
|
|
394
421
|
return {
|
|
395
422
|
key: index.toString(),
|
|
423
|
+
"#": index + 1,
|
|
396
424
|
...eachRow,
|
|
397
|
-
...
|
|
425
|
+
...rowElements,
|
|
426
|
+
...variableData,
|
|
427
|
+
actions: /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement("button", { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.DeleteOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ import_react13.default.createElement("button", { onClick: onHandleRows }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)))
|
|
398
428
|
};
|
|
399
|
-
})
|
|
400
|
-
|
|
429
|
+
});
|
|
430
|
+
if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
|
|
431
|
+
columns.push({
|
|
432
|
+
title: "Actions",
|
|
433
|
+
dataIndex: "actions",
|
|
434
|
+
key: "actions"
|
|
435
|
+
});
|
|
436
|
+
}
|
|
401
437
|
return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
|
|
402
438
|
import_antd11.Table,
|
|
403
439
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -314,13 +314,31 @@ var ButtonElement = () => /* @__PURE__ */ React11.createElement(Flex2, { gap: "s
|
|
|
314
314
|
// src/Components/AddMoreTable.tsx
|
|
315
315
|
import React12, { useState as useState3 } from "react";
|
|
316
316
|
import { Table } from "antd";
|
|
317
|
+
import { PlusOutlined, DeleteOutlined } from "@ant-design/icons";
|
|
317
318
|
var AddMoreTable = (props) => {
|
|
318
319
|
const { thead, tbody } = props;
|
|
319
320
|
const [tableData, setTableData] = useState3({});
|
|
321
|
+
const [rows, setRows] = useState3(tbody || []);
|
|
322
|
+
function isColumnType(column) {
|
|
323
|
+
return column.dataIndex !== void 0;
|
|
324
|
+
}
|
|
320
325
|
const onHandleChange = (name, value) => {
|
|
321
326
|
setTableData((prev) => ({ ...prev, [name]: value }));
|
|
322
327
|
console.log(tableData);
|
|
323
328
|
};
|
|
329
|
+
const onHandleRows = () => {
|
|
330
|
+
const lastRow = rows[rows.length - 1];
|
|
331
|
+
const newId = lastRow ? lastRow.id + 1 : lastRow.id;
|
|
332
|
+
const newRow = {
|
|
333
|
+
...lastRow,
|
|
334
|
+
id: newId
|
|
335
|
+
};
|
|
336
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
337
|
+
};
|
|
338
|
+
const onHandleDelete = (index) => {
|
|
339
|
+
const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
|
|
340
|
+
setRows(remainingRows);
|
|
341
|
+
};
|
|
324
342
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
325
343
|
title: eachHeadEl.label,
|
|
326
344
|
dataIndex: eachHeadEl.name,
|
|
@@ -337,20 +355,38 @@ var AddMoreTable = (props) => {
|
|
|
337
355
|
return null;
|
|
338
356
|
}
|
|
339
357
|
};
|
|
340
|
-
const dataSource =
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
358
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
359
|
+
const rowElements = {};
|
|
360
|
+
if (eachRow.element && eachRow.label) {
|
|
361
|
+
rowElements[eachRow.label] = renderInputElement(eachRow);
|
|
362
|
+
}
|
|
363
|
+
const variableData = eachRow.variable_data && Array.isArray(eachRow.variable_data) ? eachRow.variable_data.reduce((acc, curr) => {
|
|
364
|
+
for (let i = 0; i < curr.length; i++) {
|
|
365
|
+
Object.keys(curr[i].forEach((key) => {
|
|
366
|
+
if (curr[i][key] && curr[i][key].element) {
|
|
367
|
+
rowElements[eachRow.label] = renderInputElement(eachRow);
|
|
368
|
+
}
|
|
369
|
+
}));
|
|
370
|
+
}
|
|
345
371
|
return acc;
|
|
346
|
-
}, {});
|
|
372
|
+
}, {}) : {};
|
|
373
|
+
console.log("-----------");
|
|
347
374
|
return {
|
|
348
375
|
key: index.toString(),
|
|
376
|
+
"#": index + 1,
|
|
349
377
|
...eachRow,
|
|
350
|
-
...
|
|
378
|
+
...rowElements,
|
|
379
|
+
...variableData,
|
|
380
|
+
actions: /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement("button", { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ React12.createElement("button", { onClick: onHandleRows }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)))
|
|
351
381
|
};
|
|
352
|
-
})
|
|
353
|
-
|
|
382
|
+
});
|
|
383
|
+
if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
|
|
384
|
+
columns.push({
|
|
385
|
+
title: "Actions",
|
|
386
|
+
dataIndex: "actions",
|
|
387
|
+
key: "actions"
|
|
388
|
+
});
|
|
389
|
+
}
|
|
354
390
|
return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
|
|
355
391
|
Table,
|
|
356
392
|
{
|