@apexcura/ui-components 0.0.11-Beta10 → 0.0.11-Beta100

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 CHANGED
@@ -7,7 +7,7 @@ type ElementType = {
7
7
  disabled?: boolean;
8
8
  prefix?: React.ReactNode;
9
9
  type?: string;
10
- value?: string | number | boolean | any[];
10
+ value?: string | number | boolean | any[] | null;
11
11
  status?: "error" | "warning";
12
12
  styles?: React.CSSProperties;
13
13
  classNames?: string;
@@ -17,11 +17,13 @@ type ElementType = {
17
17
  suffix?: React.ReactNode;
18
18
  maxLength?: number;
19
19
  fieldNames?: any[];
20
+ options?: any[];
20
21
  onChange?: (value: string | number | boolean | any[]) => void;
21
22
  dropDownOptions?: any[];
22
23
  id?: number;
23
24
  thead?: any[];
24
25
  tbody?: any[];
26
+ variable_data?: any[];
25
27
  };
26
28
 
27
29
  interface ElementExecuterProps$3 extends ElementType {
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ type ElementType = {
7
7
  disabled?: boolean;
8
8
  prefix?: React.ReactNode;
9
9
  type?: string;
10
- value?: string | number | boolean | any[];
10
+ value?: string | number | boolean | any[] | null;
11
11
  status?: "error" | "warning";
12
12
  styles?: React.CSSProperties;
13
13
  classNames?: string;
@@ -17,11 +17,13 @@ type ElementType = {
17
17
  suffix?: React.ReactNode;
18
18
  maxLength?: number;
19
19
  fieldNames?: any[];
20
+ options?: any[];
20
21
  onChange?: (value: string | number | boolean | any[]) => void;
21
22
  dropDownOptions?: any[];
22
23
  id?: number;
23
24
  thead?: any[];
24
25
  tbody?: any[];
26
+ variable_data?: any[];
25
27
  };
26
28
 
27
29
  interface ElementExecuterProps$3 extends ElementType {
package/dist/index.js CHANGED
@@ -188,14 +188,23 @@ var SelectElement = (props) => {
188
188
  var import_react6 = __toESM(require("react"));
189
189
  var import_antd6 = require("antd");
190
190
  var RadioElement = (props) => {
191
+ const [isDisabled, setIsDisabled] = (0, import_react6.useState)(props.disabled);
191
192
  const handleChange = (e) => {
192
193
  if (props.onChange) {
193
194
  const selectedVal = e.target.value;
194
195
  const selectedOptions = [{ id: selectedVal, value: selectedVal }];
195
196
  props.onChange(selectedOptions);
197
+ setIsDisabled(true);
196
198
  }
197
199
  };
198
- return /* @__PURE__ */ import_react6.default.createElement(import_antd6.Radio.Group, { name: "radiogroup", defaultValue: 1 }, /* @__PURE__ */ import_react6.default.createElement(import_antd6.Radio, { value: 1, onChange: handleChange }, "A"), /* @__PURE__ */ import_react6.default.createElement(import_antd6.Radio, { value: 2, onChange: handleChange }, "B"), /* @__PURE__ */ import_react6.default.createElement(import_antd6.Radio, { value: 3, onChange: handleChange }, "C"), /* @__PURE__ */ import_react6.default.createElement(import_antd6.Radio, { value: 4, onChange: handleChange }, "D"));
200
+ return /* @__PURE__ */ import_react6.default.createElement(
201
+ import_antd6.Radio.Group,
202
+ {
203
+ options: props.options,
204
+ onChange: handleChange,
205
+ disabled: isDisabled
206
+ }
207
+ );
199
208
  };
200
209
 
201
210
  // src/Components/Checkbox.tsx
@@ -361,49 +370,127 @@ var ButtonElement = () => /* @__PURE__ */ import_react12.default.createElement(i
361
370
  // src/Components/AddMoreTable.tsx
362
371
  var import_react13 = __toESM(require("react"));
363
372
  var import_antd11 = require("antd");
373
+ var import_icons2 = require("@ant-design/icons");
364
374
  var AddMoreTable = (props) => {
365
375
  const { thead, tbody } = props;
366
- const [tableData, setTableData] = (0, import_react13.useState)({});
367
- const onHandleChange = (name, value) => {
368
- setTableData((prev) => ({ ...prev, [name]: value }));
369
- console.log(tableData);
376
+ const [rows, setRows] = (0, import_react13.useState)(tbody || []);
377
+ const onHandleRows = () => {
378
+ const newId = rows.length > 0 ? rows[rows.length - 1].id + 1 : 1;
379
+ let newRow = {
380
+ id: newId,
381
+ label: "Medicine",
382
+ name: "Medicine",
383
+ type: "text",
384
+ variable_data: [
385
+ {
386
+ id: 1,
387
+ Route: { label: "Route", element: "single-select", type: "text" },
388
+ Dose: { label: "Dose", element: "single-select", type: "text" },
389
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
390
+ When: { label: "When", element: "textarea", type: "text" },
391
+ Duration: { label: "Duration", element: "textarea", type: "text" },
392
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
393
+ SubRows: { delete: "delete", add: "plus" }
394
+ }
395
+ ]
396
+ };
397
+ setRows((prevData) => [...prevData, newRow]);
370
398
  };
371
- const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
372
- title: eachHeadEl.label,
373
- dataIndex: eachHeadEl.name,
374
- key: eachHeadEl.id
375
- })) : [];
376
- const renderInputElement = (element) => {
377
- const { type, label } = element;
399
+ const onHandleDelete = (id) => {
400
+ setRows((prevRows) => prevRows.filter((row) => row.id !== id));
401
+ };
402
+ const onHandleSubRowsAdd = (rowIndex) => {
403
+ setRows((prevRows) => {
404
+ return prevRows.map((row, index) => {
405
+ if (index === rowIndex) {
406
+ const newSubRow = {
407
+ id: row.variable_data.length + 1,
408
+ Route: { label: "Route", element: "single-select", type: "text" },
409
+ Dose: { label: "Dose", element: "single-select", type: "text" },
410
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
411
+ When: { label: "When", element: "textarea", type: "text" },
412
+ Duration: { label: "Duration", element: "textarea", type: "text" },
413
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
414
+ SubRows: { delete: "delete", add: "plus" }
415
+ };
416
+ const updatedVariableData = [...row.variable_data, newSubRow];
417
+ return {
418
+ ...row,
419
+ variable_data: updatedVariableData
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
+ };
440
+ (0, import_react13.useEffect)(() => {
441
+ console.log(rows);
442
+ }, [rows]);
443
+ const renderInputElement = (element, value) => {
444
+ if (!element)
445
+ return null;
446
+ const { element: type, label } = element;
378
447
  if (type === "single-select") {
379
- return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
448
+ return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value2) => console.log(label, value2) });
380
449
  } else if (type === "textarea") {
381
- return /* @__PURE__ */ import_react13.default.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
450
+ return /* @__PURE__ */ import_react13.default.createElement(TextareaElement, { onChange: (value2) => console.log(label, value2) });
382
451
  } else {
383
452
  return null;
384
453
  }
385
454
  };
386
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
387
- const variableData = eachRow.variable_data.reduce((acc, curr) => {
388
- acc[curr.label] = renderInputElement(curr);
389
- console.log("acc", acc);
390
- return acc;
391
- }, {});
392
- return {
393
- key: index.toString(),
394
- ...eachRow,
395
- ...variableData
455
+ const dataSource = rows.map((eachRow, rowIndex) => {
456
+ const rowData = {
457
+ key: eachRow.id,
458
+ "#": rowIndex + 1
396
459
  };
397
- }) : [];
398
- console.log("dataSource.........", dataSource);
399
- return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
460
+ rowData["Medicine"] = renderInputElement(eachRow.variable_data[0].Medicine);
461
+ eachRow.variable_data.map((variable, subIndex) => {
462
+ Object.keys(variable).forEach((key) => {
463
+ if (key === "SubRows") {
464
+ rowData[`${key}`] = /* @__PURE__ */ import_react13.default.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: () => onHandleSubRowsDelete(rowIndex, 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(rowIndex) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
465
+ } else {
466
+ rowData[`${key}`] = renderInputElement(variable[key]);
467
+ }
468
+ });
469
+ });
470
+ rowData.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)), rowIndex === rows.length - 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: onHandleRows }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
471
+ return rowData;
472
+ });
473
+ const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
474
+ title: eachHeadEl.label,
475
+ dataIndex: eachHeadEl.name,
476
+ key: eachHeadEl.id
477
+ })) : [];
478
+ if (!columns.some((col) => col.dataIndex === "actions")) {
479
+ columns.push({
480
+ title: "Actions",
481
+ dataIndex: "actions",
482
+ key: "actions"
483
+ });
484
+ }
485
+ return /* @__PURE__ */ import_react13.default.createElement(
400
486
  import_antd11.Table,
401
487
  {
402
488
  columns,
403
- expandable: { defaultExpandedRowKeys: ["0"] },
404
- dataSource
489
+ dataSource,
490
+ pagination: false,
491
+ bordered: true
405
492
  }
406
- ));
493
+ );
407
494
  };
408
495
  // Annotate the CommonJS export names for ESM import in node:
409
496
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -138,27 +138,36 @@ var SelectElement = (props) => {
138
138
  };
139
139
 
140
140
  // src/Components/RadioElement.tsx
141
- import React6 from "react";
141
+ import React6, { useState as useState2 } from "react";
142
142
  import { Radio } from "antd";
143
143
  var RadioElement = (props) => {
144
+ const [isDisabled, setIsDisabled] = useState2(props.disabled);
144
145
  const handleChange = (e) => {
145
146
  if (props.onChange) {
146
147
  const selectedVal = e.target.value;
147
148
  const selectedOptions = [{ id: selectedVal, value: selectedVal }];
148
149
  props.onChange(selectedOptions);
150
+ setIsDisabled(true);
149
151
  }
150
152
  };
151
- return /* @__PURE__ */ React6.createElement(Radio.Group, { name: "radiogroup", defaultValue: 1 }, /* @__PURE__ */ React6.createElement(Radio, { value: 1, onChange: handleChange }, "A"), /* @__PURE__ */ React6.createElement(Radio, { value: 2, onChange: handleChange }, "B"), /* @__PURE__ */ React6.createElement(Radio, { value: 3, onChange: handleChange }, "C"), /* @__PURE__ */ React6.createElement(Radio, { value: 4, onChange: handleChange }, "D"));
153
+ return /* @__PURE__ */ React6.createElement(
154
+ Radio.Group,
155
+ {
156
+ options: props.options,
157
+ onChange: handleChange,
158
+ disabled: isDisabled
159
+ }
160
+ );
152
161
  };
153
162
 
154
163
  // src/Components/Checkbox.tsx
155
- import React7, { useState as useState2 } from "react";
164
+ import React7, { useState as useState3 } from "react";
156
165
  import { Checkbox, Divider } from "antd";
157
166
  var CheckboxGroup = Checkbox.Group;
158
167
  var plainOptions = ["Apple", "Pear", "Orange"];
159
168
  var defaultCheckedList = [];
160
169
  var CheckboxElement = (props) => {
161
- const [checkedList, setCheckedList] = useState2(defaultCheckedList);
170
+ const [checkedList, setCheckedList] = useState3(defaultCheckedList);
162
171
  const checkAll = plainOptions.length === checkedList.length;
163
172
  const handleChange = (list) => {
164
173
  setCheckedList(list);
@@ -312,51 +321,129 @@ import { Button as Button2, Flex as Flex2 } from "antd";
312
321
  var ButtonElement = () => /* @__PURE__ */ React11.createElement(Flex2, { gap: "small" }, /* @__PURE__ */ React11.createElement(Button2, { type: "primary" }, "Primary Button"));
313
322
 
314
323
  // src/Components/AddMoreTable.tsx
315
- import React12, { useState as useState3 } from "react";
316
- import { Table } from "antd";
324
+ import React12, { useEffect, useState as useState4 } from "react";
325
+ import { Table, Button as Button3 } from "antd";
326
+ import { PlusOutlined, DeleteOutlined } from "@ant-design/icons";
317
327
  var AddMoreTable = (props) => {
318
328
  const { thead, tbody } = props;
319
- const [tableData, setTableData] = useState3({});
320
- const onHandleChange = (name, value) => {
321
- setTableData((prev) => ({ ...prev, [name]: value }));
322
- console.log(tableData);
329
+ const [rows, setRows] = useState4(tbody || []);
330
+ const onHandleRows = () => {
331
+ const newId = rows.length > 0 ? rows[rows.length - 1].id + 1 : 1;
332
+ let newRow = {
333
+ id: newId,
334
+ label: "Medicine",
335
+ name: "Medicine",
336
+ type: "text",
337
+ variable_data: [
338
+ {
339
+ id: 1,
340
+ Route: { label: "Route", element: "single-select", type: "text" },
341
+ Dose: { label: "Dose", element: "single-select", type: "text" },
342
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
343
+ When: { label: "When", element: "textarea", type: "text" },
344
+ Duration: { label: "Duration", element: "textarea", type: "text" },
345
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
346
+ SubRows: { delete: "delete", add: "plus" }
347
+ }
348
+ ]
349
+ };
350
+ setRows((prevData) => [...prevData, newRow]);
323
351
  };
324
- const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
325
- title: eachHeadEl.label,
326
- dataIndex: eachHeadEl.name,
327
- key: eachHeadEl.id
328
- })) : [];
329
- const renderInputElement = (element) => {
330
- const { type, label } = element;
352
+ const onHandleDelete = (id) => {
353
+ setRows((prevRows) => prevRows.filter((row) => row.id !== id));
354
+ };
355
+ const onHandleSubRowsAdd = (rowIndex) => {
356
+ setRows((prevRows) => {
357
+ return prevRows.map((row, index) => {
358
+ if (index === rowIndex) {
359
+ const newSubRow = {
360
+ id: row.variable_data.length + 1,
361
+ Route: { label: "Route", element: "single-select", type: "text" },
362
+ Dose: { label: "Dose", element: "single-select", type: "text" },
363
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
364
+ When: { label: "When", element: "textarea", type: "text" },
365
+ Duration: { label: "Duration", element: "textarea", type: "text" },
366
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
367
+ SubRows: { delete: "delete", add: "plus" }
368
+ };
369
+ const updatedVariableData = [...row.variable_data, newSubRow];
370
+ return {
371
+ ...row,
372
+ variable_data: updatedVariableData
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
+ };
393
+ useEffect(() => {
394
+ console.log(rows);
395
+ }, [rows]);
396
+ const renderInputElement = (element, value) => {
397
+ if (!element)
398
+ return null;
399
+ const { element: type, label } = element;
331
400
  if (type === "single-select") {
332
- return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
401
+ return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value2) => console.log(label, value2) });
333
402
  } else if (type === "textarea") {
334
- return /* @__PURE__ */ React12.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
403
+ return /* @__PURE__ */ React12.createElement(TextareaElement, { onChange: (value2) => console.log(label, value2) });
335
404
  } else {
336
405
  return null;
337
406
  }
338
407
  };
339
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
340
- const variableData = eachRow.variable_data.reduce((acc, curr) => {
341
- acc[curr.label] = renderInputElement(curr);
342
- console.log("acc", acc);
343
- return acc;
344
- }, {});
345
- return {
346
- key: index.toString(),
347
- ...eachRow,
348
- ...variableData
408
+ const dataSource = rows.map((eachRow, rowIndex) => {
409
+ const rowData = {
410
+ key: eachRow.id,
411
+ "#": rowIndex + 1
349
412
  };
350
- }) : [];
351
- console.log("dataSource.........", dataSource);
352
- return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
413
+ rowData["Medicine"] = renderInputElement(eachRow.variable_data[0].Medicine);
414
+ eachRow.variable_data.map((variable, subIndex) => {
415
+ Object.keys(variable).forEach((key) => {
416
+ if (key === "SubRows") {
417
+ rowData[`${key}`] = /* @__PURE__ */ React12.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleSubRowsDelete(rowIndex, subIndex) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleSubRowsAdd(rowIndex) }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
418
+ } else {
419
+ rowData[`${key}`] = renderInputElement(variable[key]);
420
+ }
421
+ });
422
+ });
423
+ rowData.actions = /* @__PURE__ */ React12.createElement("div", null, /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), rowIndex === rows.length - 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: onHandleRows }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
424
+ return rowData;
425
+ });
426
+ const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
427
+ title: eachHeadEl.label,
428
+ dataIndex: eachHeadEl.name,
429
+ key: eachHeadEl.id
430
+ })) : [];
431
+ if (!columns.some((col) => col.dataIndex === "actions")) {
432
+ columns.push({
433
+ title: "Actions",
434
+ dataIndex: "actions",
435
+ key: "actions"
436
+ });
437
+ }
438
+ return /* @__PURE__ */ React12.createElement(
353
439
  Table,
354
440
  {
355
441
  columns,
356
- expandable: { defaultExpandedRowKeys: ["0"] },
357
- dataSource
442
+ dataSource,
443
+ pagination: false,
444
+ bordered: true
358
445
  }
359
- ));
446
+ );
360
447
  };
361
448
  export {
362
449
  AddMoreTable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.11-Beta10",
3
+ "version": "0.0.11-Beta100",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",