@mbao01/common 0.0.35 → 0.0.36
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Dispatch, SetStateAction } from "react";
|
|
1
|
+
import type { Dispatch, Ref, SetStateAction } from "react";
|
|
2
2
|
import type { DropzoneState, DropzoneOptions } from "react-dropzone";
|
|
3
3
|
export type FileUploaderProps = {
|
|
4
4
|
value: File[] | null;
|
|
@@ -19,4 +19,5 @@ export type FileUploaderContextType = {
|
|
|
19
19
|
setActiveIndex: Dispatch<SetStateAction<number>>;
|
|
20
20
|
orientation: "horizontal" | "vertical";
|
|
21
21
|
direction: DirectionOptions;
|
|
22
|
+
hiddenInputRef: Ref<HTMLInputElement>;
|
|
22
23
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbao01/common",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.36",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Ayomide Bakare",
|
|
7
7
|
"license": "MIT",
|
|
@@ -145,5 +145,5 @@
|
|
|
145
145
|
"react-dom": "^18.2.0",
|
|
146
146
|
"typescript": "^5.2.2"
|
|
147
147
|
},
|
|
148
|
-
"gitHead": "
|
|
148
|
+
"gitHead": "56575cccb960383ac1b9397068161bbd1b25a477"
|
|
149
149
|
}
|
|
@@ -24,6 +24,7 @@ export const FileUploader = ({
|
|
|
24
24
|
dir,
|
|
25
25
|
...props
|
|
26
26
|
}: FileUploaderProps) => {
|
|
27
|
+
const hiddenInputRef = useRef<HTMLInputElement>(null);
|
|
27
28
|
const [isFileTooBig, setIsFileTooBig] = useState(false);
|
|
28
29
|
const [isLOF, setIsLOF] = useState(false);
|
|
29
30
|
const [activeIndex, setActiveIndex] = useState(-1);
|
|
@@ -131,6 +132,16 @@ export const FileUploader = ({
|
|
|
131
132
|
|
|
132
133
|
onValueChange(newValues);
|
|
133
134
|
|
|
135
|
+
if (hiddenInputRef.current) {
|
|
136
|
+
// Note the specific way we need to munge the file into the hidden input
|
|
137
|
+
// https://stackoverflow.com/a/68182158/1068446
|
|
138
|
+
const dataTransfer = new DataTransfer();
|
|
139
|
+
newValues.forEach((v) => {
|
|
140
|
+
dataTransfer.items.add(v);
|
|
141
|
+
});
|
|
142
|
+
hiddenInputRef.current.files = dataTransfer.files;
|
|
143
|
+
}
|
|
144
|
+
|
|
134
145
|
if (rejectedFiles.length > 0) {
|
|
135
146
|
for (const rejectedFile of rejectedFiles) {
|
|
136
147
|
if (rejectedFile.errors[0]?.code === "file-too-large") {
|
|
@@ -182,6 +193,7 @@ export const FileUploader = ({
|
|
|
182
193
|
setActiveIndex,
|
|
183
194
|
orientation,
|
|
184
195
|
direction,
|
|
196
|
+
hiddenInputRef,
|
|
185
197
|
}}
|
|
186
198
|
>
|
|
187
199
|
<div
|
|
@@ -276,7 +288,8 @@ const FileUploaderInput = ({
|
|
|
276
288
|
children,
|
|
277
289
|
...props
|
|
278
290
|
}: FileUploaderInputProps) => {
|
|
279
|
-
const { dropzoneState, isFileTooBig, isLOF } =
|
|
291
|
+
const { dropzoneState, isFileTooBig, isLOF, hiddenInputRef } =
|
|
292
|
+
useFileUpload();
|
|
280
293
|
const rootProps = isLOF ? {} : dropzoneState.getRootProps();
|
|
281
294
|
return (
|
|
282
295
|
<div
|
|
@@ -303,6 +316,11 @@ const FileUploaderInput = ({
|
|
|
303
316
|
</div>
|
|
304
317
|
<input
|
|
305
318
|
{...props}
|
|
319
|
+
ref={hiddenInputRef}
|
|
320
|
+
type="file"
|
|
321
|
+
style={{ opacity: 0, display: "none" }}
|
|
322
|
+
/>
|
|
323
|
+
<input
|
|
306
324
|
disabled={isLOF}
|
|
307
325
|
ref={dropzoneState.inputRef}
|
|
308
326
|
{...dropzoneState.getInputProps()}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Dispatch, SetStateAction } from "react";
|
|
1
|
+
import type { Dispatch, Ref, SetStateAction } from "react";
|
|
2
2
|
import type { DropzoneState, DropzoneOptions } from "react-dropzone";
|
|
3
3
|
|
|
4
4
|
export type FileUploaderProps = {
|
|
@@ -24,4 +24,5 @@ export type FileUploaderContextType = {
|
|
|
24
24
|
setActiveIndex: Dispatch<SetStateAction<number>>;
|
|
25
25
|
orientation: "horizontal" | "vertical";
|
|
26
26
|
direction: DirectionOptions;
|
|
27
|
+
hiddenInputRef: Ref<HTMLInputElement>;
|
|
27
28
|
};
|