@apexcura/ui-components 0.0.11-Beta6 → 0.0.11-Beta60
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 +112 -14
- package/dist/index.mjs +113 -15
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -361,20 +361,89 @@ 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 : 1;
|
|
379
|
+
let newRow = {
|
|
380
|
+
...lastRow,
|
|
381
|
+
id: newId,
|
|
382
|
+
variable_data: [
|
|
383
|
+
{
|
|
384
|
+
id: 1,
|
|
385
|
+
Route: { label: "Route", element: "singleselect", type: "text" },
|
|
386
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
387
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
388
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
389
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
390
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
391
|
+
icons: { delete: "plusOutlined", add: "plusOut-lined" }
|
|
392
|
+
}
|
|
393
|
+
]
|
|
394
|
+
};
|
|
395
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
396
|
+
};
|
|
397
|
+
const onHandleDelete = (index) => {
|
|
398
|
+
if (rows.length > 1) {
|
|
399
|
+
const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
|
|
400
|
+
setRows(remainingRows);
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
const onHandleSubRowsAdd = (rowIndex) => {
|
|
404
|
+
setRows((prevRows) => {
|
|
405
|
+
return prevRows.map((row, index) => {
|
|
406
|
+
if (index === rowIndex) {
|
|
407
|
+
const newSubRow = {
|
|
408
|
+
id: row.variable_data.length + 1,
|
|
409
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
410
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
411
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
412
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
413
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
414
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
415
|
+
icons: { delete: "plusOutlined", add: "plusOutlined" }
|
|
416
|
+
};
|
|
417
|
+
return {
|
|
418
|
+
...row,
|
|
419
|
+
variable_data: [...row.variable_data, newSubRow]
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
return row;
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
const onHandleSubRowsDelete = (rowIndex, subIndex) => {
|
|
427
|
+
setRows((prevRows) => {
|
|
428
|
+
return prevRows.map((row, index) => {
|
|
429
|
+
if (index === rowIndex) {
|
|
430
|
+
const updatedVariableData = row.variable_data.filter((_, i) => i !== subIndex);
|
|
431
|
+
return {
|
|
432
|
+
...row,
|
|
433
|
+
variable_data: updatedVariableData
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
return row;
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
};
|
|
371
440
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
372
441
|
title: eachHeadEl.label,
|
|
373
442
|
dataIndex: eachHeadEl.name,
|
|
374
443
|
key: eachHeadEl.id
|
|
375
444
|
})) : [];
|
|
376
445
|
const renderInputElement = (element) => {
|
|
377
|
-
const { type, label } = element;
|
|
446
|
+
const { element: type, label } = element;
|
|
378
447
|
if (type === "single-select") {
|
|
379
448
|
return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
380
449
|
} else if (type === "textarea") {
|
|
@@ -383,26 +452,55 @@ var AddMoreTable = (props) => {
|
|
|
383
452
|
return null;
|
|
384
453
|
}
|
|
385
454
|
};
|
|
386
|
-
const dataSource =
|
|
387
|
-
|
|
388
|
-
const
|
|
389
|
-
acc[curr.label] = renderInputElement(curr);
|
|
390
|
-
return acc;
|
|
391
|
-
}, {});
|
|
392
|
-
return {
|
|
455
|
+
const dataSource = rows.flatMap((eachRow, index) => {
|
|
456
|
+
const rowData = [];
|
|
457
|
+
const mainRow = {
|
|
393
458
|
key: index.toString(),
|
|
459
|
+
"#": index + 1,
|
|
394
460
|
...eachRow,
|
|
395
|
-
|
|
461
|
+
actions: /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.DeleteOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: onHandleRows }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)))
|
|
396
462
|
};
|
|
397
|
-
|
|
398
|
-
|
|
463
|
+
const subRowElements = [];
|
|
464
|
+
if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
|
|
465
|
+
eachRow.variable_data.forEach((variable, subIndex) => {
|
|
466
|
+
const subRowElement = {};
|
|
467
|
+
Object.entries(variable).forEach(([key, value]) => {
|
|
468
|
+
if (key === "icons" && value) {
|
|
469
|
+
subRowElement["sub rows"] = /* @__PURE__ */ import_react13.default.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: () => onHandleSubRowsDelete(index, subIndex) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: () => onHandleSubRowsAdd(index) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
|
|
470
|
+
} else if (value && value.element && value.label) {
|
|
471
|
+
subRowElement[value.label] = renderInputElement(value);
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
subRowElements.push(subRowElement);
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
rowData.push({
|
|
478
|
+
...mainRow,
|
|
479
|
+
"Medicine": renderInputElement({
|
|
480
|
+
element: eachRow.element,
|
|
481
|
+
label: eachRow.label
|
|
482
|
+
}),
|
|
483
|
+
"sub rows": subRowElements
|
|
484
|
+
});
|
|
485
|
+
console.log("rowData++++++++++", rowData);
|
|
486
|
+
return rowData;
|
|
487
|
+
});
|
|
488
|
+
if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
|
|
489
|
+
columns.push({
|
|
490
|
+
title: "Actions",
|
|
491
|
+
dataIndex: "actions",
|
|
492
|
+
key: "actions"
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
return /* @__PURE__ */ import_react13.default.createElement(
|
|
399
496
|
import_antd11.Table,
|
|
400
497
|
{
|
|
401
498
|
columns,
|
|
402
|
-
|
|
403
|
-
|
|
499
|
+
dataSource,
|
|
500
|
+
pagination: false,
|
|
501
|
+
bordered: true
|
|
404
502
|
}
|
|
405
|
-
)
|
|
503
|
+
);
|
|
406
504
|
};
|
|
407
505
|
// Annotate the CommonJS export names for ESM import in node:
|
|
408
506
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -313,21 +313,90 @@ var ButtonElement = () => /* @__PURE__ */ React11.createElement(Flex2, { gap: "s
|
|
|
313
313
|
|
|
314
314
|
// src/Components/AddMoreTable.tsx
|
|
315
315
|
import React12, { useState as useState3 } from "react";
|
|
316
|
-
import { Table } from "antd";
|
|
316
|
+
import { Table, Button as Button3 } 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 : 1;
|
|
332
|
+
let newRow = {
|
|
333
|
+
...lastRow,
|
|
334
|
+
id: newId,
|
|
335
|
+
variable_data: [
|
|
336
|
+
{
|
|
337
|
+
id: 1,
|
|
338
|
+
Route: { label: "Route", element: "singleselect", type: "text" },
|
|
339
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
340
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
341
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
342
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
343
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
344
|
+
icons: { delete: "plusOutlined", add: "plusOut-lined" }
|
|
345
|
+
}
|
|
346
|
+
]
|
|
347
|
+
};
|
|
348
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
349
|
+
};
|
|
350
|
+
const onHandleDelete = (index) => {
|
|
351
|
+
if (rows.length > 1) {
|
|
352
|
+
const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
|
|
353
|
+
setRows(remainingRows);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
const onHandleSubRowsAdd = (rowIndex) => {
|
|
357
|
+
setRows((prevRows) => {
|
|
358
|
+
return prevRows.map((row, index) => {
|
|
359
|
+
if (index === rowIndex) {
|
|
360
|
+
const newSubRow = {
|
|
361
|
+
id: row.variable_data.length + 1,
|
|
362
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
363
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
364
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
365
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
366
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
367
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
368
|
+
icons: { delete: "plusOutlined", add: "plusOutlined" }
|
|
369
|
+
};
|
|
370
|
+
return {
|
|
371
|
+
...row,
|
|
372
|
+
variable_data: [...row.variable_data, newSubRow]
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
return row;
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
const onHandleSubRowsDelete = (rowIndex, subIndex) => {
|
|
380
|
+
setRows((prevRows) => {
|
|
381
|
+
return prevRows.map((row, index) => {
|
|
382
|
+
if (index === rowIndex) {
|
|
383
|
+
const updatedVariableData = row.variable_data.filter((_, i) => i !== subIndex);
|
|
384
|
+
return {
|
|
385
|
+
...row,
|
|
386
|
+
variable_data: updatedVariableData
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
return row;
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
};
|
|
324
393
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
325
394
|
title: eachHeadEl.label,
|
|
326
395
|
dataIndex: eachHeadEl.name,
|
|
327
396
|
key: eachHeadEl.id
|
|
328
397
|
})) : [];
|
|
329
398
|
const renderInputElement = (element) => {
|
|
330
|
-
const { type, label } = element;
|
|
399
|
+
const { element: type, label } = element;
|
|
331
400
|
if (type === "single-select") {
|
|
332
401
|
return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
333
402
|
} else if (type === "textarea") {
|
|
@@ -336,26 +405,55 @@ var AddMoreTable = (props) => {
|
|
|
336
405
|
return null;
|
|
337
406
|
}
|
|
338
407
|
};
|
|
339
|
-
const dataSource =
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
acc[curr.label] = renderInputElement(curr);
|
|
343
|
-
return acc;
|
|
344
|
-
}, {});
|
|
345
|
-
return {
|
|
408
|
+
const dataSource = rows.flatMap((eachRow, index) => {
|
|
409
|
+
const rowData = [];
|
|
410
|
+
const mainRow = {
|
|
346
411
|
key: index.toString(),
|
|
412
|
+
"#": index + 1,
|
|
347
413
|
...eachRow,
|
|
348
|
-
|
|
414
|
+
actions: /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: onHandleRows }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)))
|
|
349
415
|
};
|
|
350
|
-
|
|
351
|
-
|
|
416
|
+
const subRowElements = [];
|
|
417
|
+
if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
|
|
418
|
+
eachRow.variable_data.forEach((variable, subIndex) => {
|
|
419
|
+
const subRowElement = {};
|
|
420
|
+
Object.entries(variable).forEach(([key, value]) => {
|
|
421
|
+
if (key === "icons" && value) {
|
|
422
|
+
subRowElement["sub rows"] = /* @__PURE__ */ React12.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleSubRowsDelete(index, subIndex) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleSubRowsAdd(index) }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
|
|
423
|
+
} else if (value && value.element && value.label) {
|
|
424
|
+
subRowElement[value.label] = renderInputElement(value);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
subRowElements.push(subRowElement);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
rowData.push({
|
|
431
|
+
...mainRow,
|
|
432
|
+
"Medicine": renderInputElement({
|
|
433
|
+
element: eachRow.element,
|
|
434
|
+
label: eachRow.label
|
|
435
|
+
}),
|
|
436
|
+
"sub rows": subRowElements
|
|
437
|
+
});
|
|
438
|
+
console.log("rowData++++++++++", rowData);
|
|
439
|
+
return rowData;
|
|
440
|
+
});
|
|
441
|
+
if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
|
|
442
|
+
columns.push({
|
|
443
|
+
title: "Actions",
|
|
444
|
+
dataIndex: "actions",
|
|
445
|
+
key: "actions"
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
return /* @__PURE__ */ React12.createElement(
|
|
352
449
|
Table,
|
|
353
450
|
{
|
|
354
451
|
columns,
|
|
355
|
-
|
|
356
|
-
|
|
452
|
+
dataSource,
|
|
453
|
+
pagination: false,
|
|
454
|
+
bordered: true
|
|
357
455
|
}
|
|
358
|
-
)
|
|
456
|
+
);
|
|
359
457
|
};
|
|
360
458
|
export {
|
|
361
459
|
AddMoreTable,
|