gbs-add-block 0.0.5 → 0.0.6
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
|
@@ -0,0 +1,103 @@
|
|
|
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";
|
|
4
|
+
import { GetFileIcon } from "./uploaderIcon";
|
|
5
|
+
|
|
6
|
+
export const FileUploader = ({ showImagePreview = false }: any) => {
|
|
7
|
+
const [files, setFiles] = useState<any[]>([]);
|
|
8
|
+
const [previewUrls, setPreviewUrls] = useState<{ [key: string]: string }>({});
|
|
9
|
+
const fileInputRef = useRef<any>(null);
|
|
10
|
+
|
|
11
|
+
// adds files to file array
|
|
12
|
+
const handleFileChange = (e: any) => {
|
|
13
|
+
const selectedFiles = Array.from(e.target.files);
|
|
14
|
+
const newPreviewUrls = { ...previewUrls };
|
|
15
|
+
|
|
16
|
+
selectedFiles.forEach((file: any) => {
|
|
17
|
+
if (showImagePreview && file.type.startsWith("image/")) {
|
|
18
|
+
const reader = new FileReader();
|
|
19
|
+
reader.onload = () => {
|
|
20
|
+
newPreviewUrls[file.name] = reader.result as string;
|
|
21
|
+
setPreviewUrls(newPreviewUrls);
|
|
22
|
+
};
|
|
23
|
+
reader.readAsDataURL(file);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
setFiles((prevFiles: any) => [...prevFiles, ...selectedFiles]);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// remove file from the file array
|
|
31
|
+
const removeFile = (index: any) => {
|
|
32
|
+
const fileToRemove = files[index];
|
|
33
|
+
setFiles((prevFiles) => prevFiles.filter((_, i) => i !== index));
|
|
34
|
+
setPreviewUrls((prevPreviews) => {
|
|
35
|
+
const { [fileToRemove.name]: _, ...rest } = prevPreviews;
|
|
36
|
+
return rest;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className="w-full max-w-md mx-auto">
|
|
42
|
+
<div
|
|
43
|
+
className="flex flex-col items-center border-2 border-dashed border-gray-300 rounded-lg p-4 text-center cursor-pointer hover:border-gray-400 transition-colors"
|
|
44
|
+
onClick={() => fileInputRef.current.click()}
|
|
45
|
+
>
|
|
46
|
+
<Icon
|
|
47
|
+
dimensions={{ width: "36", height: "36" }}
|
|
48
|
+
elements={upload}
|
|
49
|
+
svgClass={"stroke-gray-400 fill-none dark:stroke-white"}
|
|
50
|
+
/>
|
|
51
|
+
<p className="mt-2 text-sm text-gray-500">
|
|
52
|
+
Click to upload or drag and drop
|
|
53
|
+
</p>
|
|
54
|
+
<p className="text-xs text-gray-400">Supports multiple file uploads</p>
|
|
55
|
+
</div>
|
|
56
|
+
<input
|
|
57
|
+
type="file"
|
|
58
|
+
ref={fileInputRef}
|
|
59
|
+
className="hidden"
|
|
60
|
+
onChange={handleFileChange}
|
|
61
|
+
multiple
|
|
62
|
+
/>
|
|
63
|
+
|
|
64
|
+
{files.length > 0 && (
|
|
65
|
+
<div className="mt-4 space-y-2">
|
|
66
|
+
{files.map((file: any, index) => (
|
|
67
|
+
<div
|
|
68
|
+
key={index}
|
|
69
|
+
className="flex items-center justify-between bg-gray-50 p-2 rounded-md"
|
|
70
|
+
>
|
|
71
|
+
<div className="flex items-center space-x-2">
|
|
72
|
+
<GetFileIcon
|
|
73
|
+
file={file}
|
|
74
|
+
showImagePreview={showImagePreview}
|
|
75
|
+
previewUrls={previewUrls}
|
|
76
|
+
/>
|
|
77
|
+
<div>
|
|
78
|
+
<p className="text-sm font-medium text-gray-700">
|
|
79
|
+
{file.name}
|
|
80
|
+
</p>
|
|
81
|
+
<p className="text-xs text-gray-500">
|
|
82
|
+
{(file.size / 1024 / 1024).toFixed(2)} MB
|
|
83
|
+
</p>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
onClick={() => removeFile(index)}
|
|
89
|
+
className="text-red-500 hover:text-red-700 transition-colors"
|
|
90
|
+
>
|
|
91
|
+
<Icon
|
|
92
|
+
dimensions={{ width: "16", height: "16" }}
|
|
93
|
+
elements={x}
|
|
94
|
+
svgClass={"stroke-red-500 fill-none dark:stroke-white"}
|
|
95
|
+
/>
|
|
96
|
+
</button>
|
|
97
|
+
</div>
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
)}
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fileimage,
|
|
3
|
+
filespreadsheet,
|
|
4
|
+
filetext,
|
|
5
|
+
film,
|
|
6
|
+
music,
|
|
7
|
+
upload,
|
|
8
|
+
x,
|
|
9
|
+
} from "../../icon/iconPaths";
|
|
10
|
+
import Icon from "../../icon/Icon";
|
|
11
|
+
|
|
12
|
+
// returns an icon based on the selected file type
|
|
13
|
+
export const GetFileIcon = ({ file, showImagePreview, previewUrls }: any) => {
|
|
14
|
+
if (file.type.startsWith("image/"))
|
|
15
|
+
return showImagePreview ? (
|
|
16
|
+
<img
|
|
17
|
+
src={previewUrls[file.name]}
|
|
18
|
+
alt={file.name}
|
|
19
|
+
className="mt-2 w-8 h-8 object-cover rounded-lg"
|
|
20
|
+
/>
|
|
21
|
+
) : (
|
|
22
|
+
<Icon
|
|
23
|
+
dimensions={{ width: "26", height: "26" }}
|
|
24
|
+
elements={fileimage}
|
|
25
|
+
svgClass={"stroke-blue-500 fill-none dark:stroke-white"}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
if (file.type === "application/pdf")
|
|
29
|
+
return (
|
|
30
|
+
<Icon
|
|
31
|
+
dimensions={{ width: "26", height: "26" }}
|
|
32
|
+
elements={filetext}
|
|
33
|
+
svgClass={"stroke-red-500 fill-none dark:stroke-white"}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
if (file.type.includes("spreadsheet") || file.type.includes("excel"))
|
|
37
|
+
return (
|
|
38
|
+
<Icon
|
|
39
|
+
dimensions={{ width: "26", height: "26" }}
|
|
40
|
+
elements={filespreadsheet}
|
|
41
|
+
svgClass={"stroke-green-500 fill-none dark:stroke-white"}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
if (file.type.startsWith("video/"))
|
|
45
|
+
return (
|
|
46
|
+
<Icon
|
|
47
|
+
dimensions={{ width: "26", height: "26" }}
|
|
48
|
+
elements={film}
|
|
49
|
+
svgClass={"stroke-purple-500 fill-none dark:stroke-white"}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
if (file.type.startsWith("audio/"))
|
|
53
|
+
return (
|
|
54
|
+
<Icon
|
|
55
|
+
dimensions={{ width: "26", height: "26" }}
|
|
56
|
+
elements={music}
|
|
57
|
+
svgClass={"stroke-yellow-500 fill-none dark:stroke-white"}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
return (
|
|
61
|
+
<Icon
|
|
62
|
+
dimensions={{ width: "16", height: "16" }}
|
|
63
|
+
elements={filetext}
|
|
64
|
+
svgClass={"stroke-red-500 fill-none dark:stroke-white"}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
};
|
package/source/icon/iconPaths.ts
CHANGED
|
@@ -90,3 +90,79 @@ export let sun: any = [
|
|
|
90
90
|
export let moon: any = [
|
|
91
91
|
{ type: "path", d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z", key: "a7tn18" },
|
|
92
92
|
];
|
|
93
|
+
|
|
94
|
+
export const upload: any = [
|
|
95
|
+
{
|
|
96
|
+
type: "path",
|
|
97
|
+
d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",
|
|
98
|
+
key: "ih7n3h",
|
|
99
|
+
},
|
|
100
|
+
{ type: "polyline", points: "17 8 12 3 7 8", key: "t8dd8p" },
|
|
101
|
+
{ type: "line", x1: "12", x2: "12", y1: "3", y2: "15", key: "widbto" },
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
export const filetext: any = [
|
|
105
|
+
{
|
|
106
|
+
type: "path",
|
|
107
|
+
d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",
|
|
108
|
+
key: "1rqfz7",
|
|
109
|
+
},
|
|
110
|
+
{ type: "path", d: "M14 2v4a2 2 0 0 0 2 2h4", key: "tnqrlb" },
|
|
111
|
+
{ type: "path", d: "M10 9H8", key: "b1mrlr" },
|
|
112
|
+
{ type: "path", d: "M16 13H8", key: "t4e002" },
|
|
113
|
+
{ type: "path", d: "M16 17H8", key: "z1uh3a" },
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
export const fileimage: any = [
|
|
117
|
+
{
|
|
118
|
+
type: "path",
|
|
119
|
+
d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",
|
|
120
|
+
key: "1rqfz7",
|
|
121
|
+
},
|
|
122
|
+
{ type: "path", d: "M14 2v4a2 2 0 0 0 2 2h4", key: "tnqrlb" },
|
|
123
|
+
{ type: "circle", cx: "10", cy: "12", r: "2", key: "737tya" },
|
|
124
|
+
{
|
|
125
|
+
type: "path",
|
|
126
|
+
d: "m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",
|
|
127
|
+
key: "wt3hpn",
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
export const music: any = [
|
|
132
|
+
{ type: "path", d: "M9 18V5l12-2v13", key: "1jmyc2" },
|
|
133
|
+
{ type: "circle", cx: "6", cy: "18", r: "3", key: "fqmcym" },
|
|
134
|
+
{ type: "circle", cx: "18", cy: "16", r: "3", key: "1hluhg" },
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
export const film: any = [
|
|
138
|
+
{
|
|
139
|
+
type: "rect",
|
|
140
|
+
width: "18",
|
|
141
|
+
height: "18",
|
|
142
|
+
x: "3",
|
|
143
|
+
y: "3",
|
|
144
|
+
rx: "2",
|
|
145
|
+
key: "afitv7",
|
|
146
|
+
},
|
|
147
|
+
{ type: "path", d: "M7 3v18", key: "bbkbws" },
|
|
148
|
+
{ type: "path", d: "M3 7.5h4", key: "zfgn84" },
|
|
149
|
+
{ type: "path", d: "M3 12h18", key: "1i2n21" },
|
|
150
|
+
{ type: "path", d: "M3 16.5h4", key: "1230mu" },
|
|
151
|
+
{ type: "path", d: "M17 3v18", key: "in4fa5" },
|
|
152
|
+
{ type: "path", d: "M17 7.5h4", key: "myr1c1" },
|
|
153
|
+
{ type: "path", d: "M17 16.5h4", key: "go4c1d" },
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
export const filespreadsheet: any = [
|
|
157
|
+
{
|
|
158
|
+
type: "path",
|
|
159
|
+
d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",
|
|
160
|
+
key: "1rqfz7",
|
|
161
|
+
},
|
|
162
|
+
,
|
|
163
|
+
{ type: "path", d: "M14 2v4a2 2 0 0 0 2 2h4", key: "tnqrlb" },
|
|
164
|
+
{ type: "path", d: "M8 13h2", key: "yr2amv" },
|
|
165
|
+
{ type: "path", d: "M14 13h2", key: "un5t4a" },
|
|
166
|
+
{ type: "path", d: "M8 17h2", key: "2yhykz" },
|
|
167
|
+
{ type: "path", d: "M14 17h2", key: "10kma7" },
|
|
168
|
+
];
|