Skip to content

File uploader - AvFileUpload

✨ Introduction

The AvFileUpload component allows you to upload files by clicking on the file upload area or by dragging and dropping files. It supports both single and multiple file uploads with two display variants (default and compact).

🏷️ Props

NameTypeDefaultMandatoryDescription
idstringfile-upload-${crypto.randomUUID()}Unique identifier for the file upload component. If not specified, a random ID is generated.
ariaLabelstring''ARIA label for file upload button.
acceptstring | string[]undefinedAccepted file types, specified as a string (like HTML accept attribute) or an array of strings (which will be transformed into a string).
maxFileSizeMbnumberundefinedMaximum allowed file size in megabytes.
validMessagestring''Message indicating that the uploaded file is valid.
errorstring''Error message to be displayed in case of upload problem.
modelValueFile[] | nullnullArray of selected files.
maxWidthstring'none'Max width of the component.
fileNamestringundefinedName of the file to display as default (e.g., for server-persisted uploads).
titlestringTitle of the file upload section.
descriptionstringDescription of the file upload section.
deleteButtonLabelstringRemoveDelete button label.
disabledbooleanfalseWhether the file upload input is disabled.
compactbooleanfalseDisplay in compact mode with file pills.
enableMultiplebooleanfalseEnable multiple file uploads.
filePillDownloadPrefixLabelstring'Download'Prefix label for the download button in file pills.
filePillDeletePrefixLabelstring'Delete'

🔊 Events

NameData (payload)Description
'update:modelValue'The updated files array (File[] | null)Event emitted when the files array is updated.
'update:validMessage'The updated message (string | null)Event emitted when the validMessage is updated.
'update:error'The updated error message (string | null)Event emitted when the error is updated.
'change'The new list of selected files (FileList | File[])Event emitted when the selected file(s) change.
'deleteFile'Optional file or index (File | number)Event emitted when a file is deleted.
'acceptTypeError'Event emitted when a file of wrong type is dropped or selected.
'fileSizeError'Event emitted when a file exceeds the configured max size.

🎨 Slots

| Name | Description | |-----------| --- --- --- -| | hint | Slot for the hint description. | | left | Slot for the left content. | | default | Default slot for global content between the left and right icons. |

🚀 Storybook demos

You can find examples of use and demo of the component on its dedicated Storybook page.

💡 Examples of use

Default variant (single file)

vue
<script setup lang="ts">
import { AvFileUpload } from '@avenirs-esr/avenirs-dsav'
import { ref } from 'vue'

const files = ref<File[] | null>(null)
function handleFileChange (fileList: FileList | File[]) {
  console.log('Files selected:', fileList)
}
</script>

<template>
  <AvFileUpload
    v-model="files"
    title="Upload a document"
    description="or drag and drop here"
    :accept="['.pdf', '.jpg', '.png']"
    @change="handleFileChange"
  >
    <template #hint>
      PDF: <span class="caption-bold">10MB • </span>
      Images: <span class="caption-bold">5MB</span>
    </template>
  </AvFileUpload>
</template>

Compact variant (multiple files)

vue
<script setup lang="ts">
import { AvFileUpload } from '@avenirs-esr/avenirs-dsav'
import { ref } from 'vue'

const files = ref<File[] | null>(null)
</script>

<template>
  <AvFileUpload
    v-model="files"
    compact
    title="Attach documents"
    :enable-multiple="true"
    :accept="['.pdf', '.doc']"
  />
</template>