@mbao01/common 0.0.36 → 0.0.37
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.
|
@@ -5,7 +5,7 @@ export declare const FileUploader: {
|
|
|
5
5
|
displayName: string;
|
|
6
6
|
Content: import("react").ForwardRefExoticComponent<import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
|
|
7
7
|
Input: {
|
|
8
|
-
({
|
|
8
|
+
({ classes, children, ...props }: FileUploaderInputProps): import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
displayName: string;
|
|
10
10
|
};
|
|
11
11
|
Item: import("react").ForwardRefExoticComponent<{
|
|
@@ -7,7 +7,14 @@ export type FileUploaderProps = {
|
|
|
7
7
|
dropzoneOptions: DropzoneOptions;
|
|
8
8
|
orientation?: "horizontal" | "vertical";
|
|
9
9
|
} & React.HTMLAttributes<HTMLDivElement>;
|
|
10
|
-
export type FileUploaderInputProps = React.InputHTMLAttributes<HTMLInputElement
|
|
10
|
+
export type FileUploaderInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "className"> & {
|
|
11
|
+
classes?: Partial<{
|
|
12
|
+
all: string;
|
|
13
|
+
accepted: string;
|
|
14
|
+
rejected: string;
|
|
15
|
+
default: string;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
11
18
|
export type DirectionOptions = "rtl" | "ltr" | undefined;
|
|
12
19
|
export type FileUploaderContextType = {
|
|
13
20
|
dropzoneState: DropzoneState;
|
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.37",
|
|
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": "dc6e10ed230647d7e4626895c8d9b6a6808daab5"
|
|
149
149
|
}
|
|
@@ -55,54 +55,67 @@ export const FileUploader = ({
|
|
|
55
55
|
|
|
56
56
|
const handleKeyDown = useCallback(
|
|
57
57
|
(e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
?
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
58
|
+
const files = value ?? [];
|
|
59
|
+
const KEY_LIST = [
|
|
60
|
+
"ArrowLeft",
|
|
61
|
+
"ArrowRight",
|
|
62
|
+
"ArrowUp",
|
|
63
|
+
"ArrowDown",
|
|
64
|
+
"Enter",
|
|
65
|
+
"Space",
|
|
66
|
+
"Delete",
|
|
67
|
+
"Backspace",
|
|
68
|
+
"Escape",
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
if (KEY_LIST.includes(e.key)) {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
e.stopPropagation();
|
|
74
|
+
|
|
75
|
+
const moveNext = () => {
|
|
76
|
+
const nextIndex = activeIndex + 1;
|
|
77
|
+
setActiveIndex(nextIndex > files.length - 1 ? 0 : nextIndex);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const movePrev = () => {
|
|
81
|
+
const nextIndex = activeIndex - 1;
|
|
82
|
+
setActiveIndex(nextIndex < 0 ? files.length - 1 : nextIndex);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const prevKey =
|
|
86
|
+
orientation === "horizontal"
|
|
87
|
+
? direction === "ltr"
|
|
88
|
+
? "ArrowLeft"
|
|
89
|
+
: "ArrowRight"
|
|
90
|
+
: "ArrowUp";
|
|
91
|
+
|
|
92
|
+
const nextKey =
|
|
93
|
+
orientation === "horizontal"
|
|
94
|
+
? direction === "ltr"
|
|
95
|
+
? "ArrowRight"
|
|
96
|
+
: "ArrowLeft"
|
|
97
|
+
: "ArrowDown";
|
|
98
|
+
|
|
99
|
+
if (e.key === nextKey) {
|
|
100
|
+
moveNext();
|
|
101
|
+
} else if (e.key === prevKey) {
|
|
102
102
|
movePrev();
|
|
103
|
+
} else if (e.key === "Enter" || e.key === "Space") {
|
|
104
|
+
if (activeIndex === -1) {
|
|
105
|
+
dropzoneState.inputRef.current?.click();
|
|
106
|
+
}
|
|
107
|
+
} else if (e.key === "Delete" || e.key === "Backspace") {
|
|
108
|
+
if (activeIndex !== -1) {
|
|
109
|
+
removeFileFromSet(activeIndex);
|
|
110
|
+
if (files.length - 1 === 0) {
|
|
111
|
+
setActiveIndex(-1);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
movePrev();
|
|
115
|
+
}
|
|
116
|
+
} else if (e.key === "Escape") {
|
|
117
|
+
setActiveIndex(-1);
|
|
103
118
|
}
|
|
104
|
-
} else if (e.key === "Escape") {
|
|
105
|
-
setActiveIndex(-1);
|
|
106
119
|
}
|
|
107
120
|
},
|
|
108
121
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -197,17 +210,13 @@ export const FileUploader = ({
|
|
|
197
210
|
}}
|
|
198
211
|
>
|
|
199
212
|
<div
|
|
200
|
-
tabIndex={0}
|
|
201
213
|
onKeyDownCapture={handleKeyDown}
|
|
202
|
-
className={cn(
|
|
203
|
-
"
|
|
204
|
-
|
|
205
|
-
{
|
|
206
|
-
"gap-2": value && value.length > 0,
|
|
207
|
-
}
|
|
208
|
-
)}
|
|
214
|
+
className={cn("grid w-full overflow-hidden", className, {
|
|
215
|
+
"gap-2": value && value.length > 0,
|
|
216
|
+
})}
|
|
209
217
|
dir={dir}
|
|
210
218
|
{...props}
|
|
219
|
+
tabIndex={-1}
|
|
211
220
|
>
|
|
212
221
|
{children}
|
|
213
222
|
</div>
|
|
@@ -257,9 +266,9 @@ const FileUploaderItem = forwardRef<
|
|
|
257
266
|
<div
|
|
258
267
|
ref={ref}
|
|
259
268
|
className={cn(
|
|
260
|
-
"h-6 p-1 justify-between cursor-pointer relative",
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
"h-6 p-1 justify-between cursor-pointer relative rounded",
|
|
270
|
+
{ "bg-base-300": isSelected },
|
|
271
|
+
className
|
|
263
272
|
)}
|
|
264
273
|
{...props}
|
|
265
274
|
>
|
|
@@ -275,7 +284,12 @@ const FileUploaderItem = forwardRef<
|
|
|
275
284
|
onClick={() => removeFileFromSet(index)}
|
|
276
285
|
>
|
|
277
286
|
<span className="sr-only">remove item {index}</span>
|
|
278
|
-
<TrashIcon
|
|
287
|
+
<TrashIcon
|
|
288
|
+
className={cn(
|
|
289
|
+
"w-4 h-4 shrink-0 hover:stroke-destructive duration-200 ease-in-out",
|
|
290
|
+
{ "text-error": isSelected }
|
|
291
|
+
)}
|
|
292
|
+
/>
|
|
279
293
|
</button>
|
|
280
294
|
</div>
|
|
281
295
|
);
|
|
@@ -284,7 +298,7 @@ const FileUploaderItem = forwardRef<
|
|
|
284
298
|
FileUploaderItem.displayName = "FileUploaderItem";
|
|
285
299
|
|
|
286
300
|
const FileUploaderInput = ({
|
|
287
|
-
|
|
301
|
+
classes,
|
|
288
302
|
children,
|
|
289
303
|
...props
|
|
290
304
|
}: FileUploaderInputProps) => {
|
|
@@ -292,39 +306,35 @@ const FileUploaderInput = ({
|
|
|
292
306
|
useFileUpload();
|
|
293
307
|
const rootProps = isLOF ? {} : dropzoneState.getRootProps();
|
|
294
308
|
return (
|
|
295
|
-
<div
|
|
296
|
-
{...props}
|
|
297
|
-
className={`relative w-full ${
|
|
298
|
-
isLOF ? "opacity-50 cursor-not-allowed " : "cursor-pointer "
|
|
299
|
-
}`}
|
|
300
|
-
>
|
|
309
|
+
<div {...props} className="relative w-full">
|
|
301
310
|
<div
|
|
302
311
|
className={cn(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
className
|
|
312
|
+
classes?.all,
|
|
313
|
+
"w-full rounded-lg duration-300 ease-in-out",
|
|
314
|
+
isLOF ? "opacity-50 cursor-not-allowed" : "cursor-pointer",
|
|
315
|
+
dropzoneState.isDragAccept
|
|
316
|
+
? classes?.accepted
|
|
317
|
+
: dropzoneState.isDragReject || isFileTooBig
|
|
318
|
+
? classes?.rejected
|
|
319
|
+
: classes?.default
|
|
312
320
|
)}
|
|
313
321
|
{...rootProps}
|
|
314
322
|
>
|
|
315
323
|
{children}
|
|
316
324
|
</div>
|
|
317
325
|
<input
|
|
318
|
-
{...props}
|
|
319
326
|
ref={hiddenInputRef}
|
|
327
|
+
{...props}
|
|
320
328
|
type="file"
|
|
321
|
-
|
|
329
|
+
tabIndex={-1}
|
|
330
|
+
className="hidden opacity-0"
|
|
322
331
|
/>
|
|
323
332
|
<input
|
|
324
|
-
disabled={isLOF}
|
|
325
333
|
ref={dropzoneState.inputRef}
|
|
334
|
+
disabled={isLOF}
|
|
326
335
|
{...dropzoneState.getInputProps()}
|
|
327
|
-
|
|
336
|
+
tabIndex={-1}
|
|
337
|
+
className={cn({ "cursor-not-allowed": isLOF })}
|
|
328
338
|
/>
|
|
329
339
|
</div>
|
|
330
340
|
);
|
|
@@ -9,8 +9,17 @@ export type FileUploaderProps = {
|
|
|
9
9
|
orientation?: "horizontal" | "vertical";
|
|
10
10
|
} & React.HTMLAttributes<HTMLDivElement>;
|
|
11
11
|
|
|
12
|
-
export type FileUploaderInputProps =
|
|
13
|
-
React.InputHTMLAttributes<HTMLInputElement
|
|
12
|
+
export type FileUploaderInputProps = Omit<
|
|
13
|
+
React.InputHTMLAttributes<HTMLInputElement>,
|
|
14
|
+
"className"
|
|
15
|
+
> & {
|
|
16
|
+
classes?: Partial<{
|
|
17
|
+
all: string;
|
|
18
|
+
accepted: string;
|
|
19
|
+
rejected: string;
|
|
20
|
+
default: string;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
14
23
|
|
|
15
24
|
export type DirectionOptions = "rtl" | "ltr" | undefined;
|
|
16
25
|
|