gbs-add-block 0.0.6 → 0.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gbs-add-block",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "React Component Library",
5
5
  "files": [
6
6
  "index.js",
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Copyright (c) Grampro Business Services and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from "react";
9
+
10
+ const AestheticProcessingAnimation = () => {
11
+ return (
12
+ <div className="w-full max-w-md mx-auto p-2">
13
+ <div className="w-full h-1 bg-gray-200 rounded-full overflow-hidden">
14
+ <div className="h-full w-1/3 bg-black rounded-full animate-processing"></div>
15
+ </div>
16
+ <p className="text-xs mt-2 text-center">
17
+ Uploading in Progress, Please Wait...
18
+ </p>
19
+ </div>
20
+ );
21
+ };
22
+
23
+ const AestheticProcessingAnimationWithStyles = () => (
24
+ <>
25
+ <style jsx global>{`
26
+ @keyframes processing {
27
+ 0% {
28
+ transform: translateX(-100%);
29
+ }
30
+ 100% {
31
+ transform: translateX(300%);
32
+ }
33
+ }
34
+ .animate-processing {
35
+ animation: processing 2s ease-in-out infinite;
36
+ }
37
+ `}</style>
38
+ <AestheticProcessingAnimation />
39
+ </>
40
+ );
41
+
42
+ export default AestheticProcessingAnimationWithStyles;
@@ -1,13 +1,33 @@
1
- import React, { useState, useRef } from "react";
2
- import { upload, x } from "@/src/component-lib/icon/iconPaths";
3
- import Icon from "@/src/component-lib/icon/Icon";
1
+ /**
2
+ * Copyright (c) Grampro Business Services and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React, { useState, useRef, useEffect } from "react";
9
+ import { upload, x } from "../../icon/iconPaths";
10
+ import Icon from "../../icon/Icon";
4
11
  import { GetFileIcon } from "./uploaderIcon";
12
+ import AestheticProcessingAnimationWithStyles from "./ProgressAnimation";
5
13
 
6
- export const FileUploader = ({ showImagePreview = false }: any) => {
14
+ export const FileUploader = ({
15
+ showImagePreview = false,
16
+ multiple = true,
17
+ onChange,
18
+ startsUpload = false,
19
+ selectedFiles = [],
20
+ }: any) => {
7
21
  const [files, setFiles] = useState<any[]>([]);
8
22
  const [previewUrls, setPreviewUrls] = useState<{ [key: string]: string }>({});
9
23
  const fileInputRef = useRef<any>(null);
10
24
 
25
+ useEffect(() => {
26
+ if (selectedFiles && selectedFiles.length > 0) {
27
+ setFiles(selectedFiles);
28
+ }
29
+ }, [selectedFiles]);
30
+
11
31
  // adds files to file array
12
32
  const handleFileChange = (e: any) => {
13
33
  const selectedFiles = Array.from(e.target.files);
@@ -24,17 +44,24 @@ export const FileUploader = ({ showImagePreview = false }: any) => {
24
44
  }
25
45
  });
26
46
 
27
- setFiles((prevFiles: any) => [...prevFiles, ...selectedFiles]);
47
+ const updatedFiles = [...files, ...selectedFiles];
48
+ setFiles(updatedFiles);
49
+
50
+ if (onChange) onChange(updatedFiles);
28
51
  };
29
52
 
30
53
  // remove file from the file array
31
54
  const removeFile = (index: any) => {
32
55
  const fileToRemove = files[index];
33
- setFiles((prevFiles) => prevFiles.filter((_, i) => i !== index));
56
+ const updatedFiles = files.filter((_, i) => i !== index);
57
+
58
+ setFiles(updatedFiles);
34
59
  setPreviewUrls((prevPreviews) => {
35
60
  const { [fileToRemove.name]: _, ...rest } = prevPreviews;
36
61
  return rest;
37
62
  });
63
+
64
+ if (onChange) onChange(updatedFiles);
38
65
  };
39
66
 
40
67
  return (
@@ -51,16 +78,22 @@ export const FileUploader = ({ showImagePreview = false }: any) => {
51
78
  <p className="mt-2 text-sm text-gray-500">
52
79
  Click to upload or drag and drop
53
80
  </p>
54
- <p className="text-xs text-gray-400">Supports multiple file uploads</p>
81
+ {multiple && (
82
+ <p className="text-xs text-gray-400">
83
+ Supports multiple file uploads
84
+ </p>
85
+ )}
55
86
  </div>
56
87
  <input
57
88
  type="file"
58
89
  ref={fileInputRef}
59
90
  className="hidden"
60
91
  onChange={handleFileChange}
61
- multiple
92
+ multiple={multiple}
62
93
  />
63
94
 
95
+ {startsUpload && <AestheticProcessingAnimationWithStyles />}
96
+
64
97
  {files.length > 0 && (
65
98
  <div className="mt-4 space-y-2">
66
99
  {files.map((file: any, index) => (
@@ -1,11 +1,16 @@
1
+ /**
2
+ * Copyright (c) Grampro Business Services and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
1
8
  import {
2
9
  fileimage,
3
10
  filespreadsheet,
4
11
  filetext,
5
12
  film,
6
13
  music,
7
- upload,
8
- x,
9
14
  } from "../../icon/iconPaths";
10
15
  import Icon from "../../icon/Icon";
11
16