@apexcura/ui-components 0.0.12-Beta3 → 0.0.12-Beta5

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.js CHANGED
@@ -361,13 +361,27 @@ 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 : lastRow.id;
379
+ const newRow = {
380
+ ...lastRow,
381
+ id: newId
382
+ };
383
+ setRows((prevData) => [...prevData, newRow]);
384
+ };
371
385
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
372
386
  title: eachHeadEl.label,
373
387
  dataIndex: eachHeadEl.name,
@@ -384,10 +398,9 @@ var AddMoreTable = (props) => {
384
398
  return null;
385
399
  }
386
400
  };
387
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
401
+ const dataSource = rows.map((eachRow, index) => {
388
402
  const rowElements = {};
389
403
  if (eachRow.element && eachRow.label) {
390
- rowElements[eachRow.id] = String(index);
391
404
  rowElements[eachRow.label] = renderInputElement(eachRow);
392
405
  }
393
406
  const variableData = eachRow.variable_data && Array.isArray(eachRow.variable_data) ? eachRow.variable_data.reduce((acc, curr) => {
@@ -400,12 +413,20 @@ var AddMoreTable = (props) => {
400
413
  }, {}) : {};
401
414
  return {
402
415
  key: index.toString(),
416
+ "#": index + 1,
403
417
  ...eachRow,
404
418
  ...rowElements,
405
- ...variableData
419
+ ...variableData,
420
+ actions: index === rows.length - 1 ? /* @__PURE__ */ import_react13.default.createElement("button", { onClick: onHandleRows }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)) : null
406
421
  };
407
- }) : [];
408
- console.log("dataSource.........", dataSource);
422
+ });
423
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
424
+ columns.push({
425
+ title: "Actions",
426
+ dataIndex: "actions",
427
+ key: "actions"
428
+ });
429
+ }
409
430
  return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
410
431
  import_antd11.Table,
411
432
  {
package/dist/index.mjs CHANGED
@@ -314,13 +314,27 @@ var ButtonElement = () => /* @__PURE__ */ React11.createElement(Flex2, { gap: "s
314
314
  // src/Components/AddMoreTable.tsx
315
315
  import React12, { useState as useState3 } from "react";
316
316
  import { Table } from "antd";
317
+ import { PlusOutlined } 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 : lastRow.id;
332
+ const newRow = {
333
+ ...lastRow,
334
+ id: newId
335
+ };
336
+ setRows((prevData) => [...prevData, newRow]);
337
+ };
324
338
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
325
339
  title: eachHeadEl.label,
326
340
  dataIndex: eachHeadEl.name,
@@ -337,10 +351,9 @@ var AddMoreTable = (props) => {
337
351
  return null;
338
352
  }
339
353
  };
340
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
354
+ const dataSource = rows.map((eachRow, index) => {
341
355
  const rowElements = {};
342
356
  if (eachRow.element && eachRow.label) {
343
- rowElements[eachRow.id] = String(index);
344
357
  rowElements[eachRow.label] = renderInputElement(eachRow);
345
358
  }
346
359
  const variableData = eachRow.variable_data && Array.isArray(eachRow.variable_data) ? eachRow.variable_data.reduce((acc, curr) => {
@@ -353,12 +366,20 @@ var AddMoreTable = (props) => {
353
366
  }, {}) : {};
354
367
  return {
355
368
  key: index.toString(),
369
+ "#": index + 1,
356
370
  ...eachRow,
357
371
  ...rowElements,
358
- ...variableData
372
+ ...variableData,
373
+ actions: index === rows.length - 1 ? /* @__PURE__ */ React12.createElement("button", { onClick: onHandleRows }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)) : null
359
374
  };
360
- }) : [];
361
- console.log("dataSource.........", dataSource);
375
+ });
376
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
377
+ columns.push({
378
+ title: "Actions",
379
+ dataIndex: "actions",
380
+ key: "actions"
381
+ });
382
+ }
362
383
  return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
363
384
  Table,
364
385
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.12-Beta3",
3
+ "version": "0.0.12-Beta5",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",