Profile image
Accept one image through the picker or drop area.
Components / Forms
Pick or drop files, see image thumbnails and file details, and preview images and PDFs.
Last changed in version 0.14.2: Improve keyboard navigation, action feedback, and selected colors across Vue components.
bunx --bun @getweini/cli@latest add file-uploadImport the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your task.
<script setup lang="ts">
import { ref } from 'vue'
import FileUpload from './components/ui/file-upload/FileUpload.vue'
const files = ref<File[]>([])
const messages = {
browse: 'Add files',
drop: 'Drop files here',
hint: 'Images and PDFs',
clear: 'Clear',
selectedCount: (count: number) => `${count} files selected`,
previewFile: (name: string) => `Preview ${name} (opens in a new tab)`,
removeFile: (name: string) => `Remove ${name}`,
}
</script>
<template>
<FileUpload
v-model="files"
name="attachments"
accept="image/*,.pdf"
multiple
class="max-w-md"
:messages="messages"
/>
</template>The drop zone becomes a local preview when you add a file. Drop more files into the same area or use Add files. When multiple files are selected, click a filename below the preview to switch files. PDFs display inline in browsers with an embedded PDF viewer and can also open in a new tab. The native file input participates in forms. Your application handles uploads and validation messages.
Accept one image through the picker or drop area.
Collect several PDFs or images and allow removal before submission.
accept filters picker and drop selection consistently.
<script setup lang="ts">
import { ref } from 'vue'
import FileUpload from './components/ui/file-upload/FileUpload.vue'
const files = ref<File[]>([])
const messages = {
browse: 'Choose image',
drop: 'Drop image here',
clear: 'Clear',
selectedCount: (count: number) => `${count} selected`,
removeFile: (name: string) => `Remove ${name}`,
}
</script>
<template>
<label for="avatar">Profile image</label>
<FileUpload id="avatar" v-model="files" name="avatar" accept="image/*" :messages="messages" />
</template>The model contains the selected File objects; upload them in your form flow.
<script setup lang="ts">
import { ref } from 'vue'
import FileUpload from './components/ui/file-upload/FileUpload.vue'
const files = ref<File[]>([])
const messages = {
browse: 'Choose attachments',
drop: 'Drop attachments here',
clear: 'Clear all',
selectedCount: (count: number) => `${count} files selected`,
removeFile: (name: string) => `Remove ${name}`,
}
function reportRejected(rejected: File[]) {
console.warn('Unsupported files', rejected)
}
</script>
<template>
<label for="attachments">Attachments</label>
<FileUpload
id="attachments"
v-model="files"
name="attachments"
accept="image/*,.pdf"
multiple
:messages="messages"
@reject="reportRejected"
/>
</template>Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.
| Name | Type or signature | Default | What it does |
|---|---|---|---|
idprop | string | undefined | Not set | Give the control an ID so a label or description can refer to it. |
nameprop | string | undefined | Not set | Name used when this control submits a value with a form. |
formprop | string | undefined | Not set | Associate the control with a form by its ID. |
acceptprop | string | undefined | Not set | Limit the file types that can be chosen. |
multipleprop | boolean | undefined | Not set | Allow more than one item or file to be selected. |
captureprop | boolean | "user" | "environment" | undefined | Not set | Suggest which camera to use when choosing a file on a supported device. |
requiredprop | boolean | undefined | Not set | Ask the browser to require a value before form submission. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
invalidprop | boolean | undefined | Not set | Show the invalid state; also provide a visible error message. |
previewprop | boolean | undefined | true | Show local thumbnails and offer previews for supported files. Defaults to true. |
sizeprop | ControlSize | undefined | "md" | Choose the visual size. Medium is the usual default where available. |
messagesprop | FileUploadMessages | Required | Supply the text this component displays for its built-in actions and states. |
modelValuemodel | File[] | undefined | [] | Current value. Use v-model to keep it in sync with your page. |
selectevent | [files: File[]] | — | Emitted when the user selects an item. |
update:modelValueevent | [value: File[]] | — | Requests a new model value from the parent. |
rejectevent | [files: File[]] | — | Emitted when reject happens. |
errorslot | { message: string; messages: string[]; } | Optional | Content for the error area of FileUpload. |
elementexposed | HTMLInputElement | null | — | Reference to the underlying HTML element. |
focusexposed | () => void | undefined | — | Move keyboard focus to this control. |
openexposed | () => void | — | Open this component from application code. |
clearexposed | () => void | — | Access clear from a component template ref. |
// packages/frameworks/vue/components/file-upload/types.ts
// ------- IMPORTS -------
import type { ControlSize } from '@getweini/vue/types'
// ------- TYPES -------
export interface FileUploadMessages {
browse: string
drop: string
clear: string
selectedCount: (count: number) => string
removeFile: (name: string) => string
/** Optional instructions shown below the drop label. */
hint?: string
/** Name for the action that opens an image or PDF in a new tab. */
previewFile?: (name: string) => string
/** Override the default compact file size label. */
fileSize?: (bytes: number) => string
}
export interface FileUploadProps {
id?: string
name?: string
form?: string
accept?: string
multiple?: boolean
capture?: boolean | 'user' | 'environment'
required?: boolean
disabled?: boolean
invalid?: boolean
/** Show local thumbnails and offer previews for supported files. Defaults to true. */
preview?: boolean
size?: ControlSize
messages: FileUploadMessages
}
// packages/frameworks/vue/dist/types/index.d.ts
export type { ButtonOptions, ButtonProps } from './button';
export type ControlSize = 'sm' | 'md' | 'lg';
export interface SelectOption<T = unknown> {
label: string;
value: T;
disabled?: boolean;
}
/** Application-owned copy. Bind translated strings reactively when the locale changes. */
export interface ListboxMessages {
/** Popup name when no aria-label or aria-labelledby is supplied. */
listboxLabel: string;
empty: string;
clearSelection: string;
}
export interface ListboxProps<T> {
options: readonly SelectOption<T>[];
messages: ListboxMessages;
id?: string;
disabled?: boolean;
required?: boolean;
invalid?: boolean;
name?: string;
form?: string;
placeholder?: string;
size?: ControlSize;
clearable?: boolean;
gap?: number;
/** Supply stable equality for object values. Values must be unique. */
by?: (a: T, b: T) => boolean;
/** Required for meaningful form submission of object values. */
serialize?: (value: T) => string;
}
// packages/frameworks/vue/dist/types/button.d.ts
import type { Component } from 'vue';
/** Options shared by button implementations across frameworks. */
export interface ButtonOptions<Variant extends string = string, Size extends string = string> {
variant?: Variant;
size?: Size;
disabled?: boolean;
loading?: boolean;
type?: 'button' | 'submit' | 'reset';
}
/** Vue-specific target options extend the reusable button contract. */
export interface ButtonProps<Variant extends string = 'default' | 'secondary' | 'outline' | 'ghost' | 'destructive', Size extends string = 'sm' | 'md' | 'lg'> extends ButtonOptions<Variant, Size> {
as?: 'button' | 'a' | Component;
asChild?: boolean;
}preview to false to keep file names and sizes without opening local previews.