@apexcura/ui-components 0.0.13-Beta39 → 0.0.13-Beta40

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.css CHANGED
@@ -338,6 +338,10 @@ video {
338
338
  .m-\[10px\] {
339
339
  margin: 10px;
340
340
  }
341
+ .mx-auto {
342
+ margin-left: auto;
343
+ margin-right: auto;
344
+ }
341
345
  .flex {
342
346
  display: flex;
343
347
  }
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import React$1 from 'react';
2
2
  import { SizeType } from 'antd/es/config-provider/SizeContext';
3
+ import { UploadFile } from 'antd/lib/upload/interface';
3
4
 
4
5
  type ElementType = {
5
6
  [x: string]: any;
@@ -95,7 +96,19 @@ declare const DatePickerElement: (props: ElementType) => React$1.JSX.Element;
95
96
 
96
97
  declare const DateRangePickerElement: (props: ElementType) => React$1.JSX.Element;
97
98
 
98
- declare const UploadElement: (props: ElementType) => React$1.JSX.Element;
99
+ declare const UploadElement: (feildData: {
100
+ value?: any;
101
+ name?: any;
102
+ label?: any;
103
+ max_count?: any;
104
+ accept?: any;
105
+ list_type?: any;
106
+ multiple?: any;
107
+ errors?: any;
108
+ }, onInputChanges: (arg0: {
109
+ name: any;
110
+ value: any[] | UploadFile<any>[];
111
+ }) => void) => React$1.JSX.Element;
99
112
 
100
113
  declare const Image: (props: ElementType) => React$1.JSX.Element;
101
114
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import React$1 from 'react';
2
2
  import { SizeType } from 'antd/es/config-provider/SizeContext';
3
+ import { UploadFile } from 'antd/lib/upload/interface';
3
4
 
4
5
  type ElementType = {
5
6
  [x: string]: any;
@@ -95,7 +96,19 @@ declare const DatePickerElement: (props: ElementType) => React$1.JSX.Element;
95
96
 
96
97
  declare const DateRangePickerElement: (props: ElementType) => React$1.JSX.Element;
97
98
 
98
- declare const UploadElement: (props: ElementType) => React$1.JSX.Element;
99
+ declare const UploadElement: (feildData: {
100
+ value?: any;
101
+ name?: any;
102
+ label?: any;
103
+ max_count?: any;
104
+ accept?: any;
105
+ list_type?: any;
106
+ multiple?: any;
107
+ errors?: any;
108
+ }, onInputChanges: (arg0: {
109
+ name: any;
110
+ value: any[] | UploadFile<any>[];
111
+ }) => void) => React$1.JSX.Element;
99
112
 
100
113
  declare const Image: (props: ElementType) => React$1.JSX.Element;
101
114
 
package/dist/index.js CHANGED
@@ -830,28 +830,114 @@ var DateRangePickerElement = (props) => {
830
830
 
831
831
  // src/Components/UploadElement.tsx
832
832
  var import_react24 = __toESM(require("react"));
833
- var import_icons5 = require("@ant-design/icons");
834
833
  var import_antd17 = require("antd");
835
- var uploadProps = {
836
- name: "file",
837
- multiple: true,
838
- // action: 'https://660d2bd96ddfa2943b33731c.mockapi.io/api/upload',
839
- headers: {
840
- authorization: "authorization-text"
841
- },
842
- onChange(info) {
843
- if (info.file.status !== "uploading") {
844
- console.log(info.file, info.fileList);
834
+ var import_icons5 = require("@ant-design/icons");
835
+ var UploadElement = (feildData, onInputChanges) => {
836
+ const [previewTitle, setPreviewTitle] = (0, import_react24.useState)(null);
837
+ const [previewOpen, setPreviewOpen] = (0, import_react24.useState)(false);
838
+ const [previewType, setPreviewType] = (0, import_react24.useState)(null);
839
+ const [previewImage, setPreviewImage] = (0, import_react24.useState)(null);
840
+ const uploadChange = (fileList) => {
841
+ if (!fileList || fileList.length === 0) return;
842
+ const selectedFile = fileList[0];
843
+ if (!selectedFile) return;
844
+ const isCorrectFile = ["image/png", "image/jpg", "image/jpeg"].includes(selectedFile.type);
845
+ if (!isCorrectFile) {
846
+ import_antd17.Modal.error({
847
+ title: `(${selectedFile.name}) is an invalid file.`,
848
+ content: `Please upload files with the following extensions only (.png/.jpg/.jpeg)`,
849
+ zIndex: 1022
850
+ });
851
+ return;
852
+ }
853
+ const newFile = {
854
+ uid: `id${Math.random().toString(16).slice(2)}`,
855
+ name: selectedFile.name,
856
+ status: "done",
857
+ type: selectedFile.type,
858
+ size: selectedFile.size,
859
+ url: URL.createObjectURL(selectedFile)
860
+ // originFileObj: selectedFile,
861
+ };
862
+ const reader = new FileReader();
863
+ reader.onload = (e) => {
864
+ if (e.target?.result) {
865
+ newFile.thumbUrl = e.target.result.toString();
866
+ }
867
+ };
868
+ reader.readAsDataURL(selectedFile);
869
+ const newFileList = feildData.value ? [...feildData.value, newFile] : [newFile];
870
+ onInputChanges({
871
+ name: feildData.name,
872
+ value: newFileList
873
+ });
874
+ };
875
+ const uploadChange2 = ({ file, fileList }) => {
876
+ const newFileList = fileList.filter((f) => f.name !== file.name);
877
+ onInputChanges({
878
+ name: feildData.name,
879
+ value: newFileList
880
+ });
881
+ };
882
+ const handlePreview = async (file) => {
883
+ if (!file.url && !file.preview) {
884
+ file.preview = await URL.createObjectURL(file.originFileObj);
845
885
  }
846
- if (info.file.status === "done") {
847
- import_antd17.message.success(`${info.file.name} file uploaded successfully`);
848
- } else if (info.file.status === "error") {
849
- import_antd17.message.error(`${info.file.name} file upload failed.`);
886
+ setPreviewType(file.type || file.name.substring(file.name.lastIndexOf(".") + 1));
887
+ setPreviewTitle(file.name || (file.url || "").substring((file.url || "").lastIndexOf("/") + 1));
888
+ setPreviewOpen(true);
889
+ };
890
+ const handleCancel = () => {
891
+ setPreviewImage(null);
892
+ setPreviewType(null);
893
+ setPreviewOpen(false);
894
+ setPreviewTitle(null);
895
+ };
896
+ return /* @__PURE__ */ import_react24.default.createElement(import_react24.default.Fragment, null, Object.keys(feildData).length !== 0 && /* @__PURE__ */ import_react24.default.createElement("span", { className: "native-camera-lib" }, /* @__PURE__ */ import_react24.default.createElement("p", { className: "flat-label text-capitalize" }, feildData.label), /* @__PURE__ */ import_react24.default.createElement("label", { className: "native-camera-button" }, /* @__PURE__ */ import_react24.default.createElement("div", { className: "ant-btn" }, /* @__PURE__ */ import_react24.default.createElement(import_icons5.UploadOutlined, null), " ", feildData.max_count ? `Upload (Max:${feildData.max_count})` : "Upload"), /* @__PURE__ */ import_react24.default.createElement(
897
+ "input",
898
+ {
899
+ id: "upload",
900
+ type: "file",
901
+ accept: "image/*;capture=camera",
902
+ onChange: (e) => uploadChange(e.target.files)
850
903
  }
851
- }
852
- };
853
- var UploadElement = (props) => {
854
- return /* @__PURE__ */ import_react24.default.createElement(import_antd17.Upload, { ...uploadProps }, /* @__PURE__ */ import_react24.default.createElement(import_antd17.Button, { icon: /* @__PURE__ */ import_react24.default.createElement(import_icons5.UploadOutlined, null) }, "Click to Upload"));
904
+ )), /* @__PURE__ */ import_react24.default.createElement(
905
+ import_antd17.Upload,
906
+ {
907
+ accept: feildData.accept,
908
+ listType: feildData.list_type,
909
+ maxCount: feildData.max_count,
910
+ multiple: feildData.multiple,
911
+ fileList: feildData.value,
912
+ onChange: uploadChange2,
913
+ onPreview: handlePreview,
914
+ showUploadList: true
915
+ },
916
+ feildData.list_type === "picture-card" && /* @__PURE__ */ import_react24.default.createElement("div", null, /* @__PURE__ */ import_react24.default.createElement(import_icons5.PlusOutlined, null), /* @__PURE__ */ import_react24.default.createElement("div", { style: { marginTop: 8 } }, "Upload ", /* @__PURE__ */ import_react24.default.createElement("small", { className: "d-flex" }, "(Max:", feildData.max_count, ")"))),
917
+ feildData.list_type === "picture" && /* @__PURE__ */ import_react24.default.createElement(import_antd17.Button, { icon: /* @__PURE__ */ import_react24.default.createElement(import_icons5.UploadOutlined, null) }, feildData.max_count ? `Upload (Max:${feildData.max_count})` : "Upload")
918
+ ), feildData.errors && feildData.errors.length > 0 && feildData.errors.map((error, eKey) => /* @__PURE__ */ import_react24.default.createElement("small", { key: eKey, className: "text-danger animated flash" }, error.message)), /* @__PURE__ */ import_react24.default.createElement(
919
+ import_antd17.Modal,
920
+ {
921
+ visible: previewOpen,
922
+ width: "100%",
923
+ zIndex: 1025,
924
+ centered: true,
925
+ maskClosable: false,
926
+ title: previewTitle,
927
+ footer: null,
928
+ onCancel: handleCancel,
929
+ destroyOnClose: true
930
+ },
931
+ /* @__PURE__ */ import_react24.default.createElement(import_antd17.Tooltip, { title: "Close", placement: "bottom" }, /* @__PURE__ */ import_react24.default.createElement(import_icons5.CloseOutlined, { className: "border popup-close", onClick: handleCancel })),
932
+ previewType === "application/pdf" || previewType === "pdf" ? /* @__PURE__ */ import_react24.default.createElement(
933
+ "iframe",
934
+ {
935
+ title: "document",
936
+ style: { width: "95vw", height: "40vw" },
937
+ src: `${previewImage}#toolbar=0`
938
+ }
939
+ ) : /* @__PURE__ */ import_react24.default.createElement("img", { alt: "image", src: previewImage || void 0, className: "d-flex mx-auto w-100" })
940
+ )));
855
941
  };
856
942
 
857
943
  // src/Components/Image.tsx
@@ -882,7 +968,7 @@ var MultiSelect = (props) => {
882
968
  const filterOption2 = props.options && props.options.find((eachOption) => eachOption.value === value);
883
969
  console.log("filterOption1--------", filterOption2);
884
970
  setSelectedValue((prev) => ({ ...prev, firstValue: filterOption2 && filterOption2 }));
885
- props.onChange(selectedValue);
971
+ props.onChange(selectedValue.firstValue && selectedValue);
886
972
  }
887
973
  };
888
974
  const handleSecondChange = (value) => {
@@ -890,7 +976,7 @@ var MultiSelect = (props) => {
890
976
  const filterOption2 = props.options && props.options.find((eachOption) => eachOption.value === value);
891
977
  console.log("filterOption2--------", filterOption2);
892
978
  setSelectedValue((prev) => ({ ...prev, secondValue: filterOption2 && filterOption2 }));
893
- props.onChange(selectedValue);
979
+ props.onChange(selectedValue.secondValue && selectedValue);
894
980
  }
895
981
  };
896
982
  return /* @__PURE__ */ import_react27.default.createElement("div", { className: props.className, style: { display: "flex", flexDirection: "row", backgroundColor: "white", borderRadius: 10, border: "1px solid gray", width: "100px" } }, /* @__PURE__ */ import_react27.default.createElement(
package/dist/index.mjs CHANGED
@@ -773,29 +773,115 @@ var DateRangePickerElement = (props) => {
773
773
  };
774
774
 
775
775
  // src/Components/UploadElement.tsx
776
- import React23 from "react";
777
- import { UploadOutlined } from "@ant-design/icons";
778
- import { Button as Button3, message, Upload } from "antd";
779
- var uploadProps = {
780
- name: "file",
781
- multiple: true,
782
- // action: 'https://660d2bd96ddfa2943b33731c.mockapi.io/api/upload',
783
- headers: {
784
- authorization: "authorization-text"
785
- },
786
- onChange(info) {
787
- if (info.file.status !== "uploading") {
788
- console.log(info.file, info.fileList);
776
+ import React23, { useState as useState7 } from "react";
777
+ import { Upload, Button as Button3, Modal as Modal2, Tooltip } from "antd";
778
+ import { UploadOutlined, PlusOutlined as PlusOutlined2, CloseOutlined } from "@ant-design/icons";
779
+ var UploadElement = (feildData, onInputChanges) => {
780
+ const [previewTitle, setPreviewTitle] = useState7(null);
781
+ const [previewOpen, setPreviewOpen] = useState7(false);
782
+ const [previewType, setPreviewType] = useState7(null);
783
+ const [previewImage, setPreviewImage] = useState7(null);
784
+ const uploadChange = (fileList) => {
785
+ if (!fileList || fileList.length === 0) return;
786
+ const selectedFile = fileList[0];
787
+ if (!selectedFile) return;
788
+ const isCorrectFile = ["image/png", "image/jpg", "image/jpeg"].includes(selectedFile.type);
789
+ if (!isCorrectFile) {
790
+ Modal2.error({
791
+ title: `(${selectedFile.name}) is an invalid file.`,
792
+ content: `Please upload files with the following extensions only (.png/.jpg/.jpeg)`,
793
+ zIndex: 1022
794
+ });
795
+ return;
796
+ }
797
+ const newFile = {
798
+ uid: `id${Math.random().toString(16).slice(2)}`,
799
+ name: selectedFile.name,
800
+ status: "done",
801
+ type: selectedFile.type,
802
+ size: selectedFile.size,
803
+ url: URL.createObjectURL(selectedFile)
804
+ // originFileObj: selectedFile,
805
+ };
806
+ const reader = new FileReader();
807
+ reader.onload = (e) => {
808
+ if (e.target?.result) {
809
+ newFile.thumbUrl = e.target.result.toString();
810
+ }
811
+ };
812
+ reader.readAsDataURL(selectedFile);
813
+ const newFileList = feildData.value ? [...feildData.value, newFile] : [newFile];
814
+ onInputChanges({
815
+ name: feildData.name,
816
+ value: newFileList
817
+ });
818
+ };
819
+ const uploadChange2 = ({ file, fileList }) => {
820
+ const newFileList = fileList.filter((f) => f.name !== file.name);
821
+ onInputChanges({
822
+ name: feildData.name,
823
+ value: newFileList
824
+ });
825
+ };
826
+ const handlePreview = async (file) => {
827
+ if (!file.url && !file.preview) {
828
+ file.preview = await URL.createObjectURL(file.originFileObj);
789
829
  }
790
- if (info.file.status === "done") {
791
- message.success(`${info.file.name} file uploaded successfully`);
792
- } else if (info.file.status === "error") {
793
- message.error(`${info.file.name} file upload failed.`);
830
+ setPreviewType(file.type || file.name.substring(file.name.lastIndexOf(".") + 1));
831
+ setPreviewTitle(file.name || (file.url || "").substring((file.url || "").lastIndexOf("/") + 1));
832
+ setPreviewOpen(true);
833
+ };
834
+ const handleCancel = () => {
835
+ setPreviewImage(null);
836
+ setPreviewType(null);
837
+ setPreviewOpen(false);
838
+ setPreviewTitle(null);
839
+ };
840
+ return /* @__PURE__ */ React23.createElement(React23.Fragment, null, Object.keys(feildData).length !== 0 && /* @__PURE__ */ React23.createElement("span", { className: "native-camera-lib" }, /* @__PURE__ */ React23.createElement("p", { className: "flat-label text-capitalize" }, feildData.label), /* @__PURE__ */ React23.createElement("label", { className: "native-camera-button" }, /* @__PURE__ */ React23.createElement("div", { className: "ant-btn" }, /* @__PURE__ */ React23.createElement(UploadOutlined, null), " ", feildData.max_count ? `Upload (Max:${feildData.max_count})` : "Upload"), /* @__PURE__ */ React23.createElement(
841
+ "input",
842
+ {
843
+ id: "upload",
844
+ type: "file",
845
+ accept: "image/*;capture=camera",
846
+ onChange: (e) => uploadChange(e.target.files)
794
847
  }
795
- }
796
- };
797
- var UploadElement = (props) => {
798
- return /* @__PURE__ */ React23.createElement(Upload, { ...uploadProps }, /* @__PURE__ */ React23.createElement(Button3, { icon: /* @__PURE__ */ React23.createElement(UploadOutlined, null) }, "Click to Upload"));
848
+ )), /* @__PURE__ */ React23.createElement(
849
+ Upload,
850
+ {
851
+ accept: feildData.accept,
852
+ listType: feildData.list_type,
853
+ maxCount: feildData.max_count,
854
+ multiple: feildData.multiple,
855
+ fileList: feildData.value,
856
+ onChange: uploadChange2,
857
+ onPreview: handlePreview,
858
+ showUploadList: true
859
+ },
860
+ feildData.list_type === "picture-card" && /* @__PURE__ */ React23.createElement("div", null, /* @__PURE__ */ React23.createElement(PlusOutlined2, null), /* @__PURE__ */ React23.createElement("div", { style: { marginTop: 8 } }, "Upload ", /* @__PURE__ */ React23.createElement("small", { className: "d-flex" }, "(Max:", feildData.max_count, ")"))),
861
+ feildData.list_type === "picture" && /* @__PURE__ */ React23.createElement(Button3, { icon: /* @__PURE__ */ React23.createElement(UploadOutlined, null) }, feildData.max_count ? `Upload (Max:${feildData.max_count})` : "Upload")
862
+ ), feildData.errors && feildData.errors.length > 0 && feildData.errors.map((error, eKey) => /* @__PURE__ */ React23.createElement("small", { key: eKey, className: "text-danger animated flash" }, error.message)), /* @__PURE__ */ React23.createElement(
863
+ Modal2,
864
+ {
865
+ visible: previewOpen,
866
+ width: "100%",
867
+ zIndex: 1025,
868
+ centered: true,
869
+ maskClosable: false,
870
+ title: previewTitle,
871
+ footer: null,
872
+ onCancel: handleCancel,
873
+ destroyOnClose: true
874
+ },
875
+ /* @__PURE__ */ React23.createElement(Tooltip, { title: "Close", placement: "bottom" }, /* @__PURE__ */ React23.createElement(CloseOutlined, { className: "border popup-close", onClick: handleCancel })),
876
+ previewType === "application/pdf" || previewType === "pdf" ? /* @__PURE__ */ React23.createElement(
877
+ "iframe",
878
+ {
879
+ title: "document",
880
+ style: { width: "95vw", height: "40vw" },
881
+ src: `${previewImage}#toolbar=0`
882
+ }
883
+ ) : /* @__PURE__ */ React23.createElement("img", { alt: "image", src: previewImage || void 0, className: "d-flex mx-auto w-100" })
884
+ )));
799
885
  };
800
886
 
801
887
  // src/Components/Image.tsx
@@ -817,16 +903,16 @@ var SingleCheckbox = (props) => {
817
903
  };
818
904
 
819
905
  // src/Components/MultiSelect.tsx
820
- import React26, { useState as useState7 } from "react";
906
+ import React26, { useState as useState8 } from "react";
821
907
  import { Select as Select4 } from "antd";
822
908
  var MultiSelect = (props) => {
823
- const [selectedValue, setSelectedValue] = useState7({ firstValue: {}, secondValue: {} });
909
+ const [selectedValue, setSelectedValue] = useState8({ firstValue: {}, secondValue: {} });
824
910
  const handleFirstChange = (value) => {
825
911
  if (props.onChange) {
826
912
  const filterOption2 = props.options && props.options.find((eachOption) => eachOption.value === value);
827
913
  console.log("filterOption1--------", filterOption2);
828
914
  setSelectedValue((prev) => ({ ...prev, firstValue: filterOption2 && filterOption2 }));
829
- props.onChange(selectedValue);
915
+ props.onChange(selectedValue.firstValue && selectedValue);
830
916
  }
831
917
  };
832
918
  const handleSecondChange = (value) => {
@@ -834,7 +920,7 @@ var MultiSelect = (props) => {
834
920
  const filterOption2 = props.options && props.options.find((eachOption) => eachOption.value === value);
835
921
  console.log("filterOption2--------", filterOption2);
836
922
  setSelectedValue((prev) => ({ ...prev, secondValue: filterOption2 && filterOption2 }));
837
- props.onChange(selectedValue);
923
+ props.onChange(selectedValue.secondValue && selectedValue);
838
924
  }
839
925
  };
840
926
  return /* @__PURE__ */ React26.createElement("div", { className: props.className, style: { display: "flex", flexDirection: "row", backgroundColor: "white", borderRadius: 10, border: "1px solid gray", width: "100px" } }, /* @__PURE__ */ React26.createElement(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.13-Beta39",
3
+ "version": "0.0.13-Beta40",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",