Raccourci clavier : Ctrl + K
Commencer

Sélecteur de fichiers

VFilePicker est une zone de dépôt avec un sélecteur natif et une liste d’aperçus facultative. Le modèle est toujours un File[].

Utilisation

vue
Drag your files herePDF or PNG, up to 5 MBou
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

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

<template>
  <VFilePicker v-model="files" title="Drag your files here" subtitle="PDF or PNG, up to 5 MB" />
</template>

Exemples

Titre et sous-titre

Utilisez title pour la consigne et subtitle pour les contraintes de fichiers.

vue
Drop your files hereou
Drop your files hereImages or PDF, up to 5 MB eachou
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

const plain = ref<File[]>([])
const described = ref<File[]>([])
</script>

<template>
  <div class="column">
    <VFilePicker v-model="plain" title="Drop your files here" />

    <VFilePicker
      v-model="described"
      multiple
      accept="image/*,.pdf"
      :max-size="5_000_000"
      title="Drop your files here"
      subtitle="Images or PDF, up to 5 MB each"
    />
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
</style>

La liste des fichiers

preview="bottom" liste les fichiers sous la zone. preview="end" les place à côté, puis en dessous si le composant est étroit.

vue
Listed under the zoneWhat a narrow form wants, there being no room beside itou
Listed beside the zoneNarrow the window and it folds back underneathou
Not listed, the defaultTwo files are held all the same: the value never depends on this propou
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

const under = ref<File[]>([])
const beside = ref<File[]>([])
const none = ref<File[]>([])

/* Create sample File objects after mounting for server rendering. */
onMounted(() => {
  const seed = () => [
    new File([new Uint8Array(320_000)], 'contract.pdf', { type: 'application/pdf' }),
    new File([new Uint8Array(48_000)], 'figures.csv', { type: 'text/csv' }),
  ]
  under.value = seed()
  beside.value = seed()
  none.value = seed()
})
</script>

<template>
  <div class="column">
    <div class="narrow">
      <VFilePicker
        v-model="under"
        multiple
        preview="bottom"
        title="Listed under the zone"
        subtitle="What a narrow form wants, there being no room beside it"
      />
    </div>

    <VFilePicker
      v-model="beside"
      multiple
      preview="end"
      title="Listed beside the zone"
      subtitle="Narrow the window and it folds back underneath"
    />

    <div class="narrow">
      <VFilePicker
        v-model="none"
        multiple
        title="Not listed, the default"
        subtitle="Two files are held all the same: the value never depends on this prop"
      />
    </div>
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
}
.narrow {
  max-inline-size: 26rem;
}
</style>

Icônes personnalisées

Personnalisez l’icône de la zone avec icon et celles des types de fichiers avec typeIcons.

vue
Drop your sources hereou
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VFilePicker } from 'vectis-ui'
import { attach_file as attachFile, description } from 'vectis-ui/icons'

const files = ref<File[]>([])

/* Create sample File objects after mounting for server rendering. */
onMounted(() => {
  files.value = [
    new File([new Uint8Array(24_000)], 'styles.css', { type: 'text/css' }),
    new File([new Uint8Array(180_000)], 'assets.zip', { type: 'application/zip' }),
  ]
})
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="files"
      multiple
      preview="bottom"
      title="Drop your sources here"
      :icon="attachFile"
      :type-icons="{ code: description }"
    />
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
</style>

Vignettes

Les images affichent des miniatures. hideThumbnails les remplace par des icônes de type de fichier.

vue
Thumbnails, the defaultAn image is shown as itselfou
hideThumbnailsEvery file shows its kind insteadou
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

const shown = ref<File[]>([])
const hidden = ref<File[]>([])

/* Generate a decodable PNG in the browser to demonstrate image thumbnails. */
async function gradientPng(name: string): Promise<File> {
  const canvas = document.createElement('canvas')
  canvas.width = 96
  canvas.height = 96
  const context = canvas.getContext('2d')
  if (!context) return new File([], name, { type: 'image/png' })
  const gradient = context.createLinearGradient(0, 0, 96, 96)
  gradient.addColorStop(0, '#6366f1')
  gradient.addColorStop(1, '#ec4899')
  context.fillStyle = gradient
  context.fillRect(0, 0, 96, 96)
  const blob = await new Promise<Blob | null>((resolve) => canvas.toBlob(resolve, 'image/png'))
  return new File(blob ? [blob] : [], name, { type: 'image/png' })
}

onMounted(async () => {
  const files = [
    await gradientPng('cover.png'),
    new File([new Uint8Array(90_000)], 'notes.pdf', { type: 'application/pdf' }),
  ]
  shown.value = files
  hidden.value = [...files]
})
</script>

<template>
  <div class="grid">
    <VFilePicker
      v-model="shown"
      multiple
      preview="bottom"
      title="Thumbnails, the default"
      subtitle="An image is shown as itself"
    />

    <VFilePicker
      v-model="hidden"
      multiple
      hide-thumbnails
      preview="bottom"
      title="hideThumbnails"
      subtitle="Every file shows its kind instead"
    />
  </div>
</template>

<style scoped>
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: var(--vectis-space-5);
}
</style>

Fichiers multiples

multiple autorise plusieurs fichiers ; maxFiles limite la sélection.

vue
One fileDrop two and the second is refusedou
As many as you likemultiple, with nothing else to bound itou
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker, type FileRejection } from 'vectis-ui'

const one = ref<File[]>([])
const several = ref<File[]>([])

const refused = ref('')

function onReject({ file }: FileRejection) {
  refused.value = `${file.name} was turned away: this zone takes one file.`
}
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="one"
      preview="bottom"
      title="One file"
      subtitle="Drop two and the second is refused"
      @reject="onReject"
    />
    <p v-if="refused" class="value">{{ refused }}</p>

    <VFilePicker
      v-model="several"
      multiple
      preview="bottom"
      title="As many as you like"
      subtitle="multiple, with nothing else to bound it"
    />
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
.value {
  margin: 0;
  font-size: var(--vectis-text-body-sm-size);
  color: var(--vectis-color-danger-text);
}
</style>

Types acceptés

accept filtre les sélections et les dépôts. Ajoutez des extensions si les types MIME peuvent être absents.

vue
Images and PDFBrowse and the dialog offers nothing else; drop and the rule is applied againou
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker, type FileRejection } from 'vectis-ui'

const files = ref<File[]>([])
const refused = ref('')

function onReject({ file }: FileRejection) {
  refused.value = `${file.name} was turned away: images and PDF only.`
}
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="files"
      multiple
      accept="image/*,.pdf"
      preview="bottom"
      title="Images and PDF"
      subtitle="Browse and the dialog offers nothing else; drop and the rule is applied again"
      @reject="onReject"
    />
    <p v-if="refused" class="value">{{ refused }}</p>
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
.value {
  margin: 0;
  font-size: var(--vectis-text-body-sm-size);
  color: var(--vectis-color-danger-text);
}
</style>

Taille maximale

maxSize limite chaque fichier en octets. Écoutez reject pour expliquer les refus.

vue
Up to 500 kB per fileEach file is weighed on its own, so a small one still gets throughou
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker, type FileRejection } from 'vectis-ui'

const files = ref<File[]>([])
const refused = ref('')

function onReject({ file }: FileRejection) {
  refused.value = `${file.name} was turned away: 500 kB at most per file.`
}
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="files"
      multiple
      :max-size="500_000"
      preview="bottom"
      title="Up to 500 kB per file"
      subtitle="Each file is weighed on its own, so a small one still gets through"
      @reject="onReject"
    />
    <p v-if="refused" class="value">{{ refused }}</p>
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
.value {
  margin: 0;
  font-size: var(--vectis-text-body-sm-size);
  color: var(--vectis-color-danger-text);
}
</style>

Taille totale et nombre

maxTotalSize limite toute la sélection, fichiers déjà présents compris.

vue
1 MB in all, three files at mostWhat is already in the list counts towards the totalou
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker, type FileRejection } from 'vectis-ui'

const files = ref<File[]>([])
const refused = ref('')

function onReject({ file, reason }: FileRejection) {
  refused.value =
    reason === 'count'
      ? `${file.name} was turned away: three files at most.`
      : `${file.name} was turned away: 1 MB for the whole selection.`
}
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="files"
      multiple
      :max-total-size="1_000_000"
      :max-files="3"
      preview="bottom"
      title="1 MB in all, three files at most"
      subtitle="What is already in the list counts towards the total"
      @reject="onReject"
    />
    <p v-if="refused" class="value">{{ refused }}</p>
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
.value {
  margin: 0;
  font-size: var(--vectis-text-body-sm-size);
  color: var(--vectis-color-danger-text);
}
</style>

États

readonly empêche les ajouts et retraits tout en conservant le focus. loading remplace l’icône de la zone par un indicateur sans désactiver la sélection.

vue
Read-onlyWhat was taken stays on show, its remove buttons disabled along with the zoneou
DisabledNo dialog, no drop, and the zone greys through the colour tokensou
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

const taken = ref<File[]>([])
const empty = ref<File[]>([])

onMounted(() => {
  taken.value = [
    new File([new Uint8Array(320_000)], 'contract.pdf', { type: 'application/pdf' }),
    new File([new Uint8Array(48_000)], 'figures.csv', { type: 'text/csv' }),
  ]
})
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="taken"
      multiple
      readonly
      preview="bottom"
      title="Read-only"
      subtitle="What was taken stays on show, its remove buttons disabled along with the zone"
    />

    <VFilePicker
      v-model="empty"
      disabled
      title="Disabled"
      subtitle="No dialog, no drop, and the zone greys through the colour tokens"
    />
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
</style>

API

Props

PropTypeDéfaut
titlestringaucune
Consigne de dépôt obligatoire.
subtitlestringaucune
Contraintes de fichiers facultatives sous le titre.
iconIconSourcecloud_upload
Grande icône de la zone de dépôt.
hideBrowsebooleanfalse
Masque le bouton de parcours et transforme la zone en bouton, activable avec Entrée ou Espace.
browseTextstringaucune
Texte visible et nom accessible du bouton de parcours. Utilise le dictionnaire de la bibliothèque par défaut.
previewFilePickerPreviewfalse | 'bottom' | 'end'false
Position des aperçus : false, bottom ou end. La liste latérale passe en dessous dans un conteneur étroit.
hideThumbnailsbooleanfalse
Utilise des icônes de type de fichier à la place des miniatures.
typeIconsPartial<Record<FilePickerKind, IconSource>>aucune
Icônes personnalisées par catégorie de fichier.
removeIconIconSourceclose
Icône du bouton de retrait d’un fichier.
multiplebooleanfalse
Autorise plusieurs fichiers. Sinon, les fichiers supplémentaires sont refusés.
acceptstringaucune
Types acceptés, selon la syntaxe native comme image/*,.pdf. Filtre les sélections et les fichiers déposés.
maxSizenumberaucune
Taille maximale par fichier, en octets.
maxTotalSizenumberaucune
Taille maximale de la sélection, en octets.
maxFilesnumberaucune
Nombre maximal de fichiers sélectionnés.
disabledbooleanfalse
Désactive les interactions.
readonlybooleanfalse
Empêche l’ouverture du sélecteur, le dépôt et le retrait de fichiers. Les contrôles conservent le focus.
invalidbooleanfalse
Marque le contrôle comme invalide et applique le style d’erreur. Validez séparément la sélection de fichiers.
loadingbooleanfalse
Affiche un indicateur à la place de l’icône sans désactiver la sélection.
loadingTextstringaucune
Texte de chargement et nom accessible de l’indicateur. Utilise le dictionnaire de la bibliothèque par défaut.
v-modelFile[][]
Fichiers sélectionnés sous forme de File[], même pour un seul fichier.

Événements

ÉvénementType
change[files: File[]]
La sélection a changé. Reçoit le File[] complet.
reject[rejection: FileRejection]
Émis pour chaque fichier refusé. Reçoit le fichier et un motif : type, size, count ou total-size.
remove[file: File, index: number]
Un fichier a été retiré. Reçoit le fichier et son index.

Slots

SlotType
icon{}
Illustration de la zone. Gardez-la non interactive.
title{}
Contenu de la consigne. Utilisez du texte et des éléments en ligne non interactifs.
subtitle{}
Contenu des contraintes. Utilisez du texte et des éléments en ligne non interactifs.
browseFilePickerBrowseSlotProps
Contrôle de parcours personnalisé. Reçoit open et disabled ; appelez open pour ouvrir le sélecteur.
itemFilePickerRow
Ligne d’aperçu entière. Reçoit le fichier, l’index, la catégorie, la miniature, l’icône, la taille formatée et remove.
thumbnailFilePickerRow
Visuel de l’aperçu. Reçoit les mêmes données que item.
removeFilePickerRemoveSlotProps
Contrôle de retrait. Appelez remove et utilisez removeLabel comme nom accessible.

Types

Types utilisés dans les tables d’API. Importez les types exportés depuis vectis-ui.

export interface BuiltinIcon {
  name: string
  paths: readonly [string] | readonly [string, string]
}
export interface FilePickerBrowseSlotProps {
  open: () => void
  disabled: boolean
}
export type FilePickerKind =
  | 'image'
  | 'pdf'
  | 'audio'
  | 'video'
  | 'archive'
  | 'spreadsheet'
  | 'code'
  | 'file'
export interface FilePickerRemoveSlotProps {
  file: File
  index: number
  remove: () => void
  removeLabel: string
}
export interface FilePickerRow {
  file: File
  index: number
  kind: FilePickerKind
  thumbnail: string | undefined
  icon: IconSource
  sizeText: string
  remove: () => void
}
export type FileRejectReason = 'type' | 'size' | 'count' | 'total-size'
export interface FileRejection {
  file: File
  reason: FileRejectReason
}
export type IconRender =
  | { path: string; viewBox?: string }
  | { component: Component; props?: Record<string, unknown> }
  | { src: string }
  | { text: string; class?: string }
  | { class: string }
export type IconSource = string | BuiltinIcon | IconRender

Variables CSS

TokenValeur
--vectis-control-size-file-picker-min-block10rem
--vectis-control-size-file-picker-icon2.5rem
--vectis-control-size-file-picker-thumb2.5rem