Skip to content

Commit b89717f

Browse files
authored
Add a @minFileSizeKB argument to the <AuFileUpload> component (#532)
1 parent 1c7b3a9 commit b89717f

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

addon/components/au-file-upload.gts

+16-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface AuFileUploadSignature {
2020
helpTextDragDrop?: string;
2121
helpTextFileNotSupported?: string;
2222
maxFileSizeMB?: number;
23+
minFileSizeKB?: number;
2324
multiple?: boolean;
2425
onFinishUpload?: (uploadedFile: number, queueInfo: QueueInfo) => void;
2526
onQueueUpdate?: (queueInfo: QueueInfo) => void;
@@ -87,6 +88,10 @@ export default class AuFileUpload extends Component<AuFileUploadSignature> {
8788
return this.args.maxFileSizeMB || 20;
8889
}
8990

91+
get minFileSizeKB() {
92+
return this.args.minFileSizeKB || 0;
93+
}
94+
9095
get hasErrors() {
9196
return this.uploadErrorData.length > 0;
9297
}
@@ -138,7 +143,17 @@ export default class AuFileUpload extends Component<AuFileUploadSignature> {
138143
}
139144
}
140145

141-
if (!isValidFileSize(file.size, this.maxFileSizeMB)) {
146+
if (file.size === 0) {
147+
this.addError(file, 'Bestand is leeg (0 bytes)');
148+
return false;
149+
}
150+
151+
if (file.size < this.minFileSizeKB * 1024) {
152+
this.addError(file, `Bestand is te klein (min ${this.minFileSizeKB} KB)`);
153+
return false;
154+
}
155+
156+
if (file.size >= this.maxFileSizeMB * Math.pow(1024, 2)) {
142157
this.addError(file, `Bestand is te groot (max ${this.maxFileSizeMB} MB)`);
143158
return false;
144159
}
@@ -301,7 +316,3 @@ function isValidExtension(
301316
): boolean {
302317
return validExtensions.includes(extension);
303318
}
304-
305-
function isValidFileSize(fileSize: number, maximumSize: number): boolean {
306-
return fileSize < maximumSize * Math.pow(1024, 2);
307-
}

stories/5-components/Forms/AuFileUpload.stories.js

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export default {
2525
control: 'number',
2626
description: 'Maximum filesize allowed (in MB)',
2727
},
28+
minFileSizeKB: {
29+
control: 'number',
30+
description: 'Minimum filesize allowed (in KB)',
31+
},
2832
multiple: {
2933
control: 'boolean',
3034
description: 'Whether multiple files can be selected when uploading',
@@ -52,6 +56,7 @@ const Template = (args) => ({
5256
@helpTextDragDrop={{this.helpTextDragDrop}}
5357
@helpTextFileNotSupported={{this.helpTextFileNotSupported}}
5458
@maxFileSizeMB={{this.maxFileSizeMB}}
59+
@minFileSizeKB={{this.minFileSizeKB}}
5560
@multiple={{this.multiple}}
5661
@onFinishUpload={{this.onFinishUpload}}
5762
@onQueueUpdate={{this.onQueueUpdate}}
@@ -67,6 +72,7 @@ Component.args = {
6772
helpTextDragDrop: 'Sleep de bestanden naar hier om toe te voegen',
6873
helpTextFileNotSupported: 'Dit bestandsformaat wordt niet ondersteund.',
6974
maxFileSizeMB: 20,
75+
minFileSizeKB: 0,
7076
multiple: false,
7177
onFinishUpload: null,
7278
onQueueUpdate: null,

0 commit comments

Comments
 (0)