@hexure/ui 1.14.8 → 1.14.9
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/cjs/index.js +26 -12
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +26 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +82 -82
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -4507,31 +4507,45 @@ const FileUpload = ({ accept, onChange, disabled = false, onError, maxFiles = 10
|
|
|
4507
4507
|
const addFiles = (addedFiles) => {
|
|
4508
4508
|
const newFiles = [];
|
|
4509
4509
|
const errors = [];
|
|
4510
|
-
|
|
4510
|
+
for (const file of addedFiles) {
|
|
4511
4511
|
let valid = true;
|
|
4512
|
-
if
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4512
|
+
// Validate max files count - check if we've already reached the limit
|
|
4513
|
+
const currentTotalFiles = files.length + newFiles.length;
|
|
4514
|
+
if (currentTotalFiles >= maxFiles) {
|
|
4515
|
+
errors.push({
|
|
4516
|
+
file,
|
|
4517
|
+
message: 'Maximum number of files reached.',
|
|
4518
|
+
});
|
|
4519
|
+
break;
|
|
4520
4520
|
}
|
|
4521
|
-
|
|
4521
|
+
// Validate file type
|
|
4522
|
+
if (valid && accept && !accept.includes(file.type)) {
|
|
4523
|
+
errors.push({
|
|
4524
|
+
file,
|
|
4525
|
+
message: 'File type is not permitted.',
|
|
4526
|
+
});
|
|
4522
4527
|
valid = false;
|
|
4528
|
+
}
|
|
4529
|
+
// Validate file size
|
|
4530
|
+
if (valid && file.size > maxSize * 1000000) {
|
|
4523
4531
|
errors.push({
|
|
4524
4532
|
file,
|
|
4525
4533
|
message: 'File size exceeds limit.',
|
|
4526
4534
|
});
|
|
4535
|
+
valid = false;
|
|
4527
4536
|
}
|
|
4528
|
-
|
|
4537
|
+
// Custom validation
|
|
4538
|
+
if (valid && validateFile && !validateFile(file)) {
|
|
4539
|
+
errors.push({
|
|
4540
|
+
file,
|
|
4541
|
+
message: 'Custom validation failed.',
|
|
4542
|
+
});
|
|
4529
4543
|
valid = false;
|
|
4530
4544
|
}
|
|
4531
4545
|
if (valid) {
|
|
4532
4546
|
newFiles.push(file);
|
|
4533
4547
|
}
|
|
4534
|
-
}
|
|
4548
|
+
}
|
|
4535
4549
|
if (errors.length && onError) {
|
|
4536
4550
|
onError(errors);
|
|
4537
4551
|
}
|