FileUploader
A drop zone to pick or drag and drop files, showing the uploaded ones in a list with a loading state while they upload.
Showcase
This is a helper message
<LnxFileUpload @upload="..." <-- When a file is added to the input @delete="..." <-- When a file needs to be removed > Enter something <template #error> This is an error message </template> <template #helper> This is a helper message </template> </LnxFileUpload>
isUploading
booleanWhen uploading a file, it is disabled and shows a different content Default value: falsecustomValidity
stringThe error message of the input. It is the default value for the `error` slot Default value: undefinedWhen to use
- To let users attach files by picking them or dropping them on the field.
- It doesn't upload anything by itself: it hands you the files and shows the list you give it.
Examples
Uploading files
Listen to upload to send the files to your server, set is-uploading meanwhile, and add what the server returns to files. delete tells you which file the user wants to remove.
You can add several files at once
vue
<LnxFileUploader
:files="documents"
:is-uploading="isUploadingDocuments"
multiple
@upload="uploadDocuments"
@delete="deleteDocument"
>
Attachments
<template #helper>You can add several files at once</template>
</LnxFileUploader>1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
ts
async function uploadDocuments(newFiles: File[]) {
isUploadingDocuments.value = true;
documents.value.push(...await api.upload(newFiles)); // Each one with its `url` and `name`
isUploadingDocuments.value = false;
}
function deleteDocument(file: UploadedFile) {
documents.value = documents.value.filter(document => document.url !== file.url);
}1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
API
Props
| Prop | Type | Description |
|---|---|---|
files | UploadedFile[] | When a file is uploaded, the url to it |
is-uploading | boolean | When uploading a file, it is disabled and shows a different content Default: false |
is-loading | boolean | When loading, it is disabled and shows a different content Default: false |
has-error | boolean | Indicates if it should show the error slot Default: false |
custom-validity | string | The error message of the input. It is the default value for the error slot |
Native attributes
| Attribute | Type | Description |
|---|---|---|
disabled | boolean | Native HTML attribute to disable the input Default: false |
multiple | boolean | Native HTML attribute to allow multiple file selection |
capture | "user" | "environment" | Native HTML attribute to select the capture mode |
Events
| Event | Payload | Description |
|---|---|---|
upload | File | File[] | When a file is added to the input |
delete | UploadedFile | When a file needs to be removed |
Slots
| Slot | Scope | Description |
|---|---|---|
default | — | Label content of the input |
error | — | Message to be shown when the input has an error |
helper | — | Message to be shown below the input to add extra context |
textWaitingState | — | Text to be shown when idle |
textDraggedOverState | — | Text to be shown when a file is being dragged over the component |
textUploading | — | Text to be shown when a file is being uploaded |
Types
UploadedFile
ts
export interface UploadedFile {
url: string;
name: string;
}1
2
3
4
2
3
4