merge(['class' => 'min-w-0']) }}
x-data="{
files: [],
maxFiles: {{ (int) $maxFiles }},
addFiles(fileList) {
const incoming = Array.from(fileList || []);
const room = this.maxFiles - this.files.length;
if (room <= 0) {
return;
}
this.files = this.files.concat(incoming.slice(0, room));
this.syncInput();
},
removeAt(index) {
this.files = this.files.filter((_, i) => i !== index);
this.syncInput();
},
syncInput() {
const input = this.$refs.fileInput;
if (!input || typeof DataTransfer === 'undefined') {
return;
}
const dt = new DataTransfer();
this.files.forEach((file) => dt.items.add(file));
input.files = dt.files;
},
formatSize(bytes) {
if (!bytes) {
return '';
}
if (bytes < 1024) {
return bytes + ' B';
}
if (bytes < 1024 * 1024) {
return (bytes / 1024).toFixed(1) + ' KB';
}
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
},
}"
>
Choose files
or drag and drop
{{ $hint }}