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