@apexcura/ui-components 0.0.11-Beta7 → 0.0.11-Beta70
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 +97 -18
- package/dist/index.mjs +98 -19
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -361,22 +361,82 @@ 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
|
-
console.log("-----------tbody", tbody);
|
|
367
|
-
console.log("..........thead", thead);
|
|
368
367
|
const [tableData, setTableData] = (0, import_react13.useState)({});
|
|
368
|
+
const [rows, setRows] = (0, import_react13.useState)(tbody || []);
|
|
369
369
|
const onHandleChange = (name, value) => {
|
|
370
370
|
setTableData((prev) => ({ ...prev, [name]: value }));
|
|
371
371
|
console.log(tableData);
|
|
372
372
|
};
|
|
373
|
+
const onHandleRows = () => {
|
|
374
|
+
const lastRow = rows[rows.length - 1];
|
|
375
|
+
const newId = lastRow ? lastRow.id + 1 : 1;
|
|
376
|
+
let newRow = {
|
|
377
|
+
id: newId,
|
|
378
|
+
variable_data: [
|
|
379
|
+
{
|
|
380
|
+
id: 1,
|
|
381
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
382
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
383
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
384
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
385
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
386
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
387
|
+
icons: { delete: "delete", add: "plus" }
|
|
388
|
+
}
|
|
389
|
+
]
|
|
390
|
+
};
|
|
391
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
392
|
+
};
|
|
393
|
+
const onHandleDelete = (id) => {
|
|
394
|
+
setRows((prevRows) => prevRows.filter((row) => row.id !== id));
|
|
395
|
+
};
|
|
396
|
+
const onHandleSubRowsAdd = (rowIndex) => {
|
|
397
|
+
setRows((prevRows) => {
|
|
398
|
+
return prevRows.map((row, index) => {
|
|
399
|
+
if (index === rowIndex) {
|
|
400
|
+
const newSubRow = {
|
|
401
|
+
id: row.variable_data.length + 1,
|
|
402
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
403
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
404
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
405
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
406
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
407
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
408
|
+
icons: { delete: "delete", add: "plus" }
|
|
409
|
+
};
|
|
410
|
+
return {
|
|
411
|
+
...row,
|
|
412
|
+
variable_data: [...row.variable_data, newSubRow]
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
return row;
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
const onHandleSubRowsDelete = (rowIndex, subIndex) => {
|
|
420
|
+
setRows((prevRows) => {
|
|
421
|
+
return prevRows.map((row, index) => {
|
|
422
|
+
if (index === rowIndex) {
|
|
423
|
+
const updatedVariableData = row.variable_data.filter((_, i) => i !== subIndex);
|
|
424
|
+
return {
|
|
425
|
+
...row,
|
|
426
|
+
variable_data: updatedVariableData
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
return row;
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
};
|
|
373
433
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
374
434
|
title: eachHeadEl.label,
|
|
375
435
|
dataIndex: eachHeadEl.name,
|
|
376
436
|
key: eachHeadEl.id
|
|
377
437
|
})) : [];
|
|
378
438
|
const renderInputElement = (element) => {
|
|
379
|
-
const { type, label } = element;
|
|
439
|
+
const { element: type, label } = element;
|
|
380
440
|
if (type === "single-select") {
|
|
381
441
|
return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
382
442
|
} else if (type === "textarea") {
|
|
@@ -385,26 +445,45 @@ var AddMoreTable = (props) => {
|
|
|
385
445
|
return null;
|
|
386
446
|
}
|
|
387
447
|
};
|
|
388
|
-
const dataSource =
|
|
389
|
-
console.log("
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
448
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
449
|
+
console.log("eachrow---------", eachRow);
|
|
450
|
+
const subRow = eachRow.variable_data.map((variable, subIndex) => ({
|
|
451
|
+
key: `${eachRow.id}-${subIndex}`,
|
|
452
|
+
...Object.fromEntries(Object.entries(variable).map(([key, value]) => {
|
|
453
|
+
if (key === "icons") {
|
|
454
|
+
return ["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)))];
|
|
455
|
+
} else {
|
|
456
|
+
return [key, renderInputElement(value)];
|
|
457
|
+
}
|
|
458
|
+
}))
|
|
459
|
+
}));
|
|
460
|
+
const rowData = {
|
|
461
|
+
"#": index + 1,
|
|
462
|
+
"Medicine": renderInputElement({
|
|
463
|
+
element: eachRow.element,
|
|
464
|
+
label: eachRow.label
|
|
465
|
+
}),
|
|
466
|
+
subRow: [...subRow],
|
|
467
|
+
actions: /* @__PURE__ */ import_react13.default.createElement("div", 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)))
|
|
398
468
|
};
|
|
399
|
-
|
|
400
|
-
|
|
469
|
+
return [rowData];
|
|
470
|
+
}).flat();
|
|
471
|
+
if (!columns.some((col) => col.dataIndex === "actions")) {
|
|
472
|
+
columns.push({
|
|
473
|
+
title: "Actions",
|
|
474
|
+
dataIndex: "actions",
|
|
475
|
+
key: "actions"
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return /* @__PURE__ */ import_react13.default.createElement(
|
|
401
479
|
import_antd11.Table,
|
|
402
480
|
{
|
|
403
481
|
columns,
|
|
404
|
-
|
|
405
|
-
|
|
482
|
+
dataSource,
|
|
483
|
+
pagination: false,
|
|
484
|
+
bordered: true
|
|
406
485
|
}
|
|
407
|
-
)
|
|
486
|
+
);
|
|
408
487
|
};
|
|
409
488
|
// Annotate the CommonJS export names for ESM import in node:
|
|
410
489
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -313,23 +313,83 @@ 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
|
-
console.log("-----------tbody", tbody);
|
|
320
|
-
console.log("..........thead", thead);
|
|
321
320
|
const [tableData, setTableData] = useState3({});
|
|
321
|
+
const [rows, setRows] = useState3(tbody || []);
|
|
322
322
|
const onHandleChange = (name, value) => {
|
|
323
323
|
setTableData((prev) => ({ ...prev, [name]: value }));
|
|
324
324
|
console.log(tableData);
|
|
325
325
|
};
|
|
326
|
+
const onHandleRows = () => {
|
|
327
|
+
const lastRow = rows[rows.length - 1];
|
|
328
|
+
const newId = lastRow ? lastRow.id + 1 : 1;
|
|
329
|
+
let newRow = {
|
|
330
|
+
id: newId,
|
|
331
|
+
variable_data: [
|
|
332
|
+
{
|
|
333
|
+
id: 1,
|
|
334
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
335
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
336
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
337
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
338
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
339
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
340
|
+
icons: { delete: "delete", add: "plus" }
|
|
341
|
+
}
|
|
342
|
+
]
|
|
343
|
+
};
|
|
344
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
345
|
+
};
|
|
346
|
+
const onHandleDelete = (id) => {
|
|
347
|
+
setRows((prevRows) => prevRows.filter((row) => row.id !== id));
|
|
348
|
+
};
|
|
349
|
+
const onHandleSubRowsAdd = (rowIndex) => {
|
|
350
|
+
setRows((prevRows) => {
|
|
351
|
+
return prevRows.map((row, index) => {
|
|
352
|
+
if (index === rowIndex) {
|
|
353
|
+
const newSubRow = {
|
|
354
|
+
id: row.variable_data.length + 1,
|
|
355
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
356
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
357
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
358
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
359
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
360
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
361
|
+
icons: { delete: "delete", add: "plus" }
|
|
362
|
+
};
|
|
363
|
+
return {
|
|
364
|
+
...row,
|
|
365
|
+
variable_data: [...row.variable_data, newSubRow]
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return row;
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
const onHandleSubRowsDelete = (rowIndex, subIndex) => {
|
|
373
|
+
setRows((prevRows) => {
|
|
374
|
+
return prevRows.map((row, index) => {
|
|
375
|
+
if (index === rowIndex) {
|
|
376
|
+
const updatedVariableData = row.variable_data.filter((_, i) => i !== subIndex);
|
|
377
|
+
return {
|
|
378
|
+
...row,
|
|
379
|
+
variable_data: updatedVariableData
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
return row;
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
};
|
|
326
386
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
327
387
|
title: eachHeadEl.label,
|
|
328
388
|
dataIndex: eachHeadEl.name,
|
|
329
389
|
key: eachHeadEl.id
|
|
330
390
|
})) : [];
|
|
331
391
|
const renderInputElement = (element) => {
|
|
332
|
-
const { type, label } = element;
|
|
392
|
+
const { element: type, label } = element;
|
|
333
393
|
if (type === "single-select") {
|
|
334
394
|
return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
335
395
|
} else if (type === "textarea") {
|
|
@@ -338,26 +398,45 @@ var AddMoreTable = (props) => {
|
|
|
338
398
|
return null;
|
|
339
399
|
}
|
|
340
400
|
};
|
|
341
|
-
const dataSource =
|
|
342
|
-
console.log("
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
401
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
402
|
+
console.log("eachrow---------", eachRow);
|
|
403
|
+
const subRow = eachRow.variable_data.map((variable, subIndex) => ({
|
|
404
|
+
key: `${eachRow.id}-${subIndex}`,
|
|
405
|
+
...Object.fromEntries(Object.entries(variable).map(([key, value]) => {
|
|
406
|
+
if (key === "icons") {
|
|
407
|
+
return ["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)))];
|
|
408
|
+
} else {
|
|
409
|
+
return [key, renderInputElement(value)];
|
|
410
|
+
}
|
|
411
|
+
}))
|
|
412
|
+
}));
|
|
413
|
+
const rowData = {
|
|
414
|
+
"#": index + 1,
|
|
415
|
+
"Medicine": renderInputElement({
|
|
416
|
+
element: eachRow.element,
|
|
417
|
+
label: eachRow.label
|
|
418
|
+
}),
|
|
419
|
+
subRow: [...subRow],
|
|
420
|
+
actions: /* @__PURE__ */ React12.createElement("div", 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)))
|
|
351
421
|
};
|
|
352
|
-
|
|
353
|
-
|
|
422
|
+
return [rowData];
|
|
423
|
+
}).flat();
|
|
424
|
+
if (!columns.some((col) => col.dataIndex === "actions")) {
|
|
425
|
+
columns.push({
|
|
426
|
+
title: "Actions",
|
|
427
|
+
dataIndex: "actions",
|
|
428
|
+
key: "actions"
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return /* @__PURE__ */ React12.createElement(
|
|
354
432
|
Table,
|
|
355
433
|
{
|
|
356
434
|
columns,
|
|
357
|
-
|
|
358
|
-
|
|
435
|
+
dataSource,
|
|
436
|
+
pagination: false,
|
|
437
|
+
bordered: true
|
|
359
438
|
}
|
|
360
|
-
)
|
|
439
|
+
);
|
|
361
440
|
};
|
|
362
441
|
export {
|
|
363
442
|
AddMoreTable,
|