@apexcura/ui-components 0.0.11-Beta2 → 0.0.11-Beta20
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 +72 -10
- package/dist/index.mjs +73 -11
- 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,88 @@ 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 : 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
|
+
};
|
|
366
389
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
367
390
|
title: eachHeadEl.label,
|
|
368
391
|
dataIndex: eachHeadEl.name,
|
|
369
392
|
key: eachHeadEl.id
|
|
370
393
|
})) : [];
|
|
371
|
-
const
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
return
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
394
|
+
const renderInputElement = (element) => {
|
|
395
|
+
const { element: type, label } = element;
|
|
396
|
+
if (type === "single-select") {
|
|
397
|
+
return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
398
|
+
} else if (type === "textarea") {
|
|
399
|
+
return /* @__PURE__ */ import_react13.default.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
|
|
400
|
+
} else {
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
405
|
+
const rowElements = {};
|
|
406
|
+
if (eachRow.element && eachRow.label) {
|
|
407
|
+
rowElements[eachRow.label] = renderInputElement(eachRow);
|
|
408
|
+
}
|
|
409
|
+
if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
|
|
410
|
+
eachRow.variable_data.forEach((variable) => {
|
|
411
|
+
Object.entries(variable).forEach(([key, value]) => {
|
|
412
|
+
if (value && value.element && value.label) {
|
|
413
|
+
rowElements[value.label] = renderInputElement(value);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
if (eachRow.variable_data.length > 0) {
|
|
418
|
+
const addIconObject = {
|
|
419
|
+
id: { id: eachRow.variable_data.length + 1 },
|
|
420
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
421
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
422
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
423
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
424
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
425
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
426
|
+
addIcon: /* @__PURE__ */ import_react13.default.createElement("button", { onClick: () => console.log("Add more clicked") }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null))
|
|
427
|
+
};
|
|
428
|
+
rowElements["AddMoreIcon"] = addIconObject.addIcon;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
378
431
|
return {
|
|
379
432
|
key: index.toString(),
|
|
380
|
-
|
|
381
|
-
...eachRow
|
|
433
|
+
"#": index + 1,
|
|
434
|
+
...eachRow,
|
|
435
|
+
...rowElements,
|
|
436
|
+
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
437
|
};
|
|
383
|
-
})
|
|
438
|
+
});
|
|
439
|
+
if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
|
|
440
|
+
columns.push({
|
|
441
|
+
title: "Actions",
|
|
442
|
+
dataIndex: "actions",
|
|
443
|
+
key: "actions"
|
|
444
|
+
});
|
|
445
|
+
}
|
|
384
446
|
return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
|
|
385
447
|
import_antd11.Table,
|
|
386
448
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -312,28 +312,90 @@ 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 : 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
|
+
};
|
|
319
342
|
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
320
343
|
title: eachHeadEl.label,
|
|
321
344
|
dataIndex: eachHeadEl.name,
|
|
322
345
|
key: eachHeadEl.id
|
|
323
346
|
})) : [];
|
|
324
|
-
const
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
return
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
347
|
+
const renderInputElement = (element) => {
|
|
348
|
+
const { element: type, label } = element;
|
|
349
|
+
if (type === "single-select") {
|
|
350
|
+
return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
|
|
351
|
+
} else if (type === "textarea") {
|
|
352
|
+
return /* @__PURE__ */ React12.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
|
|
353
|
+
} else {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
const dataSource = rows.map((eachRow, index) => {
|
|
358
|
+
const rowElements = {};
|
|
359
|
+
if (eachRow.element && eachRow.label) {
|
|
360
|
+
rowElements[eachRow.label] = renderInputElement(eachRow);
|
|
361
|
+
}
|
|
362
|
+
if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
|
|
363
|
+
eachRow.variable_data.forEach((variable) => {
|
|
364
|
+
Object.entries(variable).forEach(([key, value]) => {
|
|
365
|
+
if (value && value.element && value.label) {
|
|
366
|
+
rowElements[value.label] = renderInputElement(value);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
if (eachRow.variable_data.length > 0) {
|
|
371
|
+
const addIconObject = {
|
|
372
|
+
id: { id: eachRow.variable_data.length + 1 },
|
|
373
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
374
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
375
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
376
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
377
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
378
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
379
|
+
addIcon: /* @__PURE__ */ React12.createElement("button", { onClick: () => console.log("Add more clicked") }, /* @__PURE__ */ React12.createElement(PlusOutlined, null))
|
|
380
|
+
};
|
|
381
|
+
rowElements["AddMoreIcon"] = addIconObject.addIcon;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
331
384
|
return {
|
|
332
385
|
key: index.toString(),
|
|
333
|
-
|
|
334
|
-
...eachRow
|
|
386
|
+
"#": index + 1,
|
|
387
|
+
...eachRow,
|
|
388
|
+
...rowElements,
|
|
389
|
+
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
390
|
};
|
|
336
|
-
})
|
|
391
|
+
});
|
|
392
|
+
if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
|
|
393
|
+
columns.push({
|
|
394
|
+
title: "Actions",
|
|
395
|
+
dataIndex: "actions",
|
|
396
|
+
key: "actions"
|
|
397
|
+
});
|
|
398
|
+
}
|
|
337
399
|
return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
|
|
338
400
|
Table,
|
|
339
401
|
{
|