@apexcura/ui-components 0.0.11-Beta8 → 0.0.11-Beta80
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 -16
- package/dist/index.mjs +98 -17
- 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,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
367
|
const [tableData, setTableData] = (0, import_react13.useState)({});
|
|
368
|
+
const [rows, setRows] = (0, import_react13.useState)(tbody || []);
|
|
367
369
|
const onHandleChange = (name, value) => {
|
|
368
370
|
setTableData((prev) => ({ ...prev, [name]: value }));
|
|
369
371
|
console.log(tableData);
|
|
370
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
|
+
};
|
|
371
433
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
372
434
|
title: eachHeadEl.label,
|
|
373
435
|
dataIndex: eachHeadEl.name,
|
|
374
436
|
key: eachHeadEl.id
|
|
375
437
|
})) : [];
|
|
376
438
|
const renderInputElement = (element) => {
|
|
377
|
-
const { type, label } = element;
|
|
439
|
+
const { element: type, label } = element;
|
|
378
440
|
if (type === "single-select") {
|
|
379
441
|
return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
380
442
|
} else if (type === "textarea") {
|
|
@@ -383,26 +445,45 @@ var AddMoreTable = (props) => {
|
|
|
383
445
|
return null;
|
|
384
446
|
}
|
|
385
447
|
};
|
|
386
|
-
const dataSource =
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
...
|
|
448
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
449
|
+
const rowData = {
|
|
450
|
+
key: eachRow.id,
|
|
451
|
+
"#": index + 1,
|
|
452
|
+
"Medicine": renderInputElement({
|
|
453
|
+
element: eachRow.element,
|
|
454
|
+
label: eachRow.label
|
|
455
|
+
}),
|
|
456
|
+
...eachRow.variable_data.reduce((acc, variable, subIndex) => {
|
|
457
|
+
Object.keys(variable).forEach((key) => {
|
|
458
|
+
if (key === "sub rows") {
|
|
459
|
+
acc[`${key}`] = /* @__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)));
|
|
460
|
+
} else {
|
|
461
|
+
acc[`${key}`] = renderInputElement(variable[key]);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
return acc;
|
|
465
|
+
}, {}),
|
|
466
|
+
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)))
|
|
395
467
|
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
468
|
+
console.log(rowData);
|
|
469
|
+
return rowData;
|
|
470
|
+
});
|
|
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(
|
|
399
479
|
import_antd11.Table,
|
|
400
480
|
{
|
|
401
481
|
columns,
|
|
402
|
-
|
|
403
|
-
|
|
482
|
+
dataSource,
|
|
483
|
+
pagination: false,
|
|
484
|
+
bordered: true
|
|
404
485
|
}
|
|
405
|
-
)
|
|
486
|
+
);
|
|
406
487
|
};
|
|
407
488
|
// Annotate the CommonJS export names for ESM import in node:
|
|
408
489
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -313,21 +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
320
|
const [tableData, setTableData] = useState3({});
|
|
321
|
+
const [rows, setRows] = useState3(tbody || []);
|
|
320
322
|
const onHandleChange = (name, value) => {
|
|
321
323
|
setTableData((prev) => ({ ...prev, [name]: value }));
|
|
322
324
|
console.log(tableData);
|
|
323
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
|
+
};
|
|
324
386
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
325
387
|
title: eachHeadEl.label,
|
|
326
388
|
dataIndex: eachHeadEl.name,
|
|
327
389
|
key: eachHeadEl.id
|
|
328
390
|
})) : [];
|
|
329
391
|
const renderInputElement = (element) => {
|
|
330
|
-
const { type, label } = element;
|
|
392
|
+
const { element: type, label } = element;
|
|
331
393
|
if (type === "single-select") {
|
|
332
394
|
return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
333
395
|
} else if (type === "textarea") {
|
|
@@ -336,26 +398,45 @@ var AddMoreTable = (props) => {
|
|
|
336
398
|
return null;
|
|
337
399
|
}
|
|
338
400
|
};
|
|
339
|
-
const dataSource =
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
...
|
|
401
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
402
|
+
const rowData = {
|
|
403
|
+
key: eachRow.id,
|
|
404
|
+
"#": index + 1,
|
|
405
|
+
"Medicine": renderInputElement({
|
|
406
|
+
element: eachRow.element,
|
|
407
|
+
label: eachRow.label
|
|
408
|
+
}),
|
|
409
|
+
...eachRow.variable_data.reduce((acc, variable, subIndex) => {
|
|
410
|
+
Object.keys(variable).forEach((key) => {
|
|
411
|
+
if (key === "sub rows") {
|
|
412
|
+
acc[`${key}`] = /* @__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)));
|
|
413
|
+
} else {
|
|
414
|
+
acc[`${key}`] = renderInputElement(variable[key]);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
return acc;
|
|
418
|
+
}, {}),
|
|
419
|
+
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)))
|
|
348
420
|
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
421
|
+
console.log(rowData);
|
|
422
|
+
return rowData;
|
|
423
|
+
});
|
|
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(
|
|
352
432
|
Table,
|
|
353
433
|
{
|
|
354
434
|
columns,
|
|
355
|
-
|
|
356
|
-
|
|
435
|
+
dataSource,
|
|
436
|
+
pagination: false,
|
|
437
|
+
bordered: true
|
|
357
438
|
}
|
|
358
|
-
)
|
|
439
|
+
);
|
|
359
440
|
};
|
|
360
441
|
export {
|
|
361
442
|
AddMoreTable,
|