@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 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
- addedFiles.forEach(file => {
4510
+ for (const file of addedFiles) {
4511
4511
  let valid = true;
4512
- if (accept) {
4513
- if (!accept.includes(file.type)) {
4514
- valid = false;
4515
- errors.push({
4516
- file,
4517
- message: 'File type is not permitted.',
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
- if (file.size > maxSize * 1000000 || files.length + newFiles.length === maxFiles) {
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
- if (validateFile && !validateFile(file)) {
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
  }