@apexcura/ui-components 0.0.11-Beta4 → 0.0.11-Beta40
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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +69 -9
- package/dist/index.mjs +70 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -361,26 +361,86 @@ 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;
|
|
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
|
+
}
|
|
372
|
+
const onHandleChange = (name, value) => {
|
|
373
|
+
setTableData((prev) => ({ ...prev, [name]: value }));
|
|
374
|
+
console.log(tableData);
|
|
375
|
+
};
|
|
376
|
+
const onHandleRows = () => {
|
|
377
|
+
const lastRow = rows[rows.length - 1];
|
|
378
|
+
const newId = lastRow ? lastRow.id + 1 : 1;
|
|
379
|
+
let newRow = {
|
|
380
|
+
...lastRow,
|
|
381
|
+
id: newId
|
|
382
|
+
};
|
|
383
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
384
|
+
};
|
|
385
|
+
const onHandleDelete = (index) => {
|
|
386
|
+
if (rows.length > 1) {
|
|
387
|
+
const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
|
|
388
|
+
setRows(remainingRows);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
const onHandleSubRowsAdd = () => {
|
|
392
|
+
console.log(rows);
|
|
393
|
+
};
|
|
366
394
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
367
395
|
title: eachHeadEl.label,
|
|
368
396
|
dataIndex: eachHeadEl.name,
|
|
369
397
|
key: eachHeadEl.id
|
|
370
398
|
})) : [];
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
399
|
+
const renderInputElement = (element) => {
|
|
400
|
+
const { element: type, label } = element;
|
|
401
|
+
if (type === "single-select") {
|
|
402
|
+
return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
403
|
+
} else if (type === "textarea") {
|
|
404
|
+
return /* @__PURE__ */ import_react13.default.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
|
|
405
|
+
} else {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
410
|
+
const rowElements = {};
|
|
411
|
+
if (eachRow.element && eachRow.label) {
|
|
412
|
+
rowElements[eachRow.label] = renderInputElement(eachRow);
|
|
413
|
+
}
|
|
414
|
+
if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
|
|
415
|
+
eachRow.variable_data.forEach((variable) => {
|
|
416
|
+
Object.entries(variable).forEach(([key, value]) => {
|
|
417
|
+
if (key === "icons" && value) {
|
|
418
|
+
{
|
|
419
|
+
eachRow.variable_data.map((variable2, subIndex) => {
|
|
420
|
+
rowElements["sub rows"] = /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, eachRow.variable_data.length > 1 && /* @__PURE__ */ import_react13.default.createElement("button", null, /* @__PURE__ */ import_react13.default.createElement(import_icons2.DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ import_react13.default.createElement("button", { onClick: onHandleSubRowsAdd }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
} else if (value && value.element && value.label) {
|
|
424
|
+
rowElements[value.label] = renderInputElement(value);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
}
|
|
378
429
|
return {
|
|
379
430
|
key: index.toString(),
|
|
431
|
+
"#": index + 1,
|
|
380
432
|
...eachRow,
|
|
381
|
-
...
|
|
433
|
+
...rowElements,
|
|
434
|
+
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)))
|
|
382
435
|
};
|
|
383
|
-
})
|
|
436
|
+
});
|
|
437
|
+
if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
|
|
438
|
+
columns.push({
|
|
439
|
+
title: "Actions",
|
|
440
|
+
dataIndex: "actions",
|
|
441
|
+
key: "actions"
|
|
442
|
+
});
|
|
443
|
+
}
|
|
384
444
|
return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
|
|
385
445
|
import_antd11.Table,
|
|
386
446
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -312,28 +312,88 @@ import { Button as Button2, Flex as Flex2 } from "antd";
|
|
|
312
312
|
var ButtonElement = () => /* @__PURE__ */ React11.createElement(Flex2, { gap: "small" }, /* @__PURE__ */ React11.createElement(Button2, { type: "primary" }, "Primary Button"));
|
|
313
313
|
|
|
314
314
|
// src/Components/AddMoreTable.tsx
|
|
315
|
-
import React12 from "react";
|
|
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;
|
|
320
|
+
const [tableData, setTableData] = useState3({});
|
|
321
|
+
const [rows, setRows] = useState3(tbody || []);
|
|
322
|
+
function isColumnType(column) {
|
|
323
|
+
return column.dataIndex !== void 0;
|
|
324
|
+
}
|
|
325
|
+
const onHandleChange = (name, value) => {
|
|
326
|
+
setTableData((prev) => ({ ...prev, [name]: value }));
|
|
327
|
+
console.log(tableData);
|
|
328
|
+
};
|
|
329
|
+
const onHandleRows = () => {
|
|
330
|
+
const lastRow = rows[rows.length - 1];
|
|
331
|
+
const newId = lastRow ? lastRow.id + 1 : 1;
|
|
332
|
+
let newRow = {
|
|
333
|
+
...lastRow,
|
|
334
|
+
id: newId
|
|
335
|
+
};
|
|
336
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
337
|
+
};
|
|
338
|
+
const onHandleDelete = (index) => {
|
|
339
|
+
if (rows.length > 1) {
|
|
340
|
+
const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
|
|
341
|
+
setRows(remainingRows);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
const onHandleSubRowsAdd = () => {
|
|
345
|
+
console.log(rows);
|
|
346
|
+
};
|
|
319
347
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
320
348
|
title: eachHeadEl.label,
|
|
321
349
|
dataIndex: eachHeadEl.name,
|
|
322
350
|
key: eachHeadEl.id
|
|
323
351
|
})) : [];
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
352
|
+
const renderInputElement = (element) => {
|
|
353
|
+
const { element: type, label } = element;
|
|
354
|
+
if (type === "single-select") {
|
|
355
|
+
return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
356
|
+
} else if (type === "textarea") {
|
|
357
|
+
return /* @__PURE__ */ React12.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
|
|
358
|
+
} else {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
363
|
+
const rowElements = {};
|
|
364
|
+
if (eachRow.element && eachRow.label) {
|
|
365
|
+
rowElements[eachRow.label] = renderInputElement(eachRow);
|
|
366
|
+
}
|
|
367
|
+
if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
|
|
368
|
+
eachRow.variable_data.forEach((variable) => {
|
|
369
|
+
Object.entries(variable).forEach(([key, value]) => {
|
|
370
|
+
if (key === "icons" && value) {
|
|
371
|
+
{
|
|
372
|
+
eachRow.variable_data.map((variable2, subIndex) => {
|
|
373
|
+
rowElements["sub rows"] = /* @__PURE__ */ React12.createElement(React12.Fragment, null, eachRow.variable_data.length > 1 && /* @__PURE__ */ React12.createElement("button", null, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ React12.createElement("button", { onClick: onHandleSubRowsAdd }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
} else if (value && value.element && value.label) {
|
|
377
|
+
rowElements[value.label] = renderInputElement(value);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
}
|
|
331
382
|
return {
|
|
332
383
|
key: index.toString(),
|
|
384
|
+
"#": index + 1,
|
|
333
385
|
...eachRow,
|
|
334
|
-
...
|
|
386
|
+
...rowElements,
|
|
387
|
+
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)))
|
|
335
388
|
};
|
|
336
|
-
})
|
|
389
|
+
});
|
|
390
|
+
if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
|
|
391
|
+
columns.push({
|
|
392
|
+
title: "Actions",
|
|
393
|
+
dataIndex: "actions",
|
|
394
|
+
key: "actions"
|
|
395
|
+
});
|
|
396
|
+
}
|
|
337
397
|
return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
|
|
338
398
|
Table,
|
|
339
399
|
{
|