3.3.8 • Published 10 months ago

@jaxtheprime/vue3-dropzone v3.3.8

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Vue3 Dropzone

A flexible Vue 3 dropzone component with unified preview and edit capabilities. Perfect for file uploads, image galleries, and product management interfaces. Demo

🎯 Key Features

Unified Data Handling

  • Multiple Data Sources: Combines File objects (new uploads) with URL strings (existing files)
  • Smart Type Detection: Automatically handles different file types and sources
  • Two-Way Binding: Reactive updates for both new files and existing previews

Three Flexible Modes

  • Drop Mode: Standard dropzone for new file selection
  • Preview Mode: Display existing files with optional interaction
  • Edit Mode: Combined functionality - show existing files AND allow modifications

File Management

  • Drag & Drop Support: Native HTML5 drag and drop with visual feedback
  • File Validation: Size limits, type restrictions, and custom validation
  • Progress Tracking: Built-in upload progress with server-side support
  • Error Handling: Comprehensive error states and user feedback

Layout Options

  • Preview Positioning: Display previews inside or outside the dropzone
  • Responsive Design: Adapts to different screen sizes and containers
  • Customizable Styling: CSS variables for easy theming
  • Slot Support: Override any part of the interface

📋 Props Reference

Core Configuration

PropTypeDefaultDescription
modelValueArray[]Array of File objects representing newly selected files. Two-way binding with v-model.
previewsArray[]Array of URL strings for existing files/images. Two-way binding with v-model:previews.
modeString"drop"Component behavior mode: "drop" (new files only), "preview" (display only), "edit" (combined functionality).
multipleBooleanfalseAllow selection of multiple files simultaneously.
disabledBooleanfalseCompletely disable all interactions with the dropzone.

File Selection & Strategy

PropTypeDefaultDescription
selectFileStrategyString"replace"How new files interact with existing ones: "replace" (clear existing), "merge" (add to existing).
allowSelectOnPreviewBooleanfalseAllow file selection in preview mode. When true, clicking on empty areas in the preview container triggers file selection, while clicks on images and preview items are prevented to avoid accidental selection. When false, preview mode is read-only.
maxFilesNumber5Maximum number of files that can be selected at once.
maxFileSizeNumber5Maximum file size allowed in megabytes (MB).
acceptStringundefinedComma-separated list of allowed file types (MIME types). Example: "image/*,application/pdf".

Visual Layout & Positioning

PropTypeDefaultDescription
widthNumber/StringautoWidth of the dropzone container. Can be px, %, or any CSS unit.
heightNumber/String200pxHeight of the dropzone container. Can be px, %, or any CSS unit.
previewPositionString"inside"Where to display file previews: "inside" (within dropzone), "outside" (below dropzone).
imgWidthNumber/StringautoWidth of individual preview images.
imgHeightNumber/StringautoHeight of individual preview images.
previewWrapperClassesString""Additional CSS classes to apply to the preview container.

User Interface Elements

PropTypeDefaultDescription
showSelectButtonBooleantrueDisplay the "Select File" button within the dropzone interface.
fileInputIdStringauto-generatedCustom ID for the hidden file input element. Auto-generated if not provided.
stateString"indeterminate"Visual state of the dropzone: "indeterminate", "success", "error". Affects border colors.

Server Integration

PropTypeDefaultDescription
serverSideBooleanfalseEnable server-side file upload functionality with progress tracking.
uploadEndpointStringundefinedURL endpoint for file uploads when serverSide is enabled.
deleteEndpointStringundefinedURL endpoint for file deletion when serverSide is enabled.
headersObject{}Additional HTTP headers to send with server requests.

🔄 Events Reference

EventPayloadDescription
update:modelValueArrayEmitted when the files array changes. Contains File objects.
update:previewsArrayEmitted when the previews array changes. Contains URL strings.
dropEventEmitted when files are dropped onto the dropzone.
fileUploadedObjectEmitted when a file successfully uploads (server-side mode).
fileRemovedObjectEmitted when a File object is removed from the list.
previewRemovedObjectEmitted when a preview URL is removed from the list.
errorObjectEmitted on validation errors or upload failures. Contains error type and files.

🎨 Styling & Customization

CSS Variables

The component uses CSS custom properties for easy theming:

VariableDefaultPurpose
--v3-dropzone--primary94, 112, 210Primary color (RGB values)
--v3-dropzone--border214, 216, 220Border color (RGB values)
--v3-dropzone--description190, 191, 195Description text color (RGB values)
--v3-dropzone--error255, 76, 81Error state color (RGB values)
--v3-dropzone--success36, 179, 100Success state color (RGB values)
--v3-dropzone--overlay40, 44, 53Overlay background color (RGB values)
--v3-dropzone--overlay-opacity0.3Overlay opacity value

Slot Support

Override default content with custom implementations:

SlotPurpose
placeholder-imgReplace the default placeholder image
titleReplace the default "Drop your files here" title
buttonReplace the default "Select File" button
descriptionReplace the default file requirements description
previewCustom preview item rendering

🔧 Component Methods

Access these methods via template ref:

MethodParametersDescription
clearFiles()NoneRemove all File objects (new uploads)
clearPreviews()NoneRemove all preview URLs (existing files)
clearAll()NoneRemove both files and previews completely
clearPreview()NoneLegacy method - equivalent to clearAll()

🎯 Use Cases

Product Management

Perfect for e-commerce platforms where users need to manage product images - showing existing images while allowing additions, removals, and replacements.

Profile/Avatar Updates

Ideal for user profile interfaces where you display current profile pictures and allow users to upload new ones.

Document Management

Great for document upload interfaces where users can see existing documents and add new ones.

Gallery Applications

Excellent for photo gallery management where users can view existing images and upload additional ones.

Content Management Systems

Perfect for CMS interfaces where content creators need to manage media files alongside text content.

General Media Management Admin Panels

Ideal for administrative interfaces across various platforms where administrators need to manage user-uploaded content, system assets, or shared media libraries. Works well for social platforms, educational systems, corporate portals, and any application requiring centralized media administration.

🚀 Features

File Handling

  • Automatically detects file types and displays appropriate previews
  • Handles both image files (with thumbnails) and other file types (with icons)
  • Maintains file metadata and upload status

Interaction Models

  • Read-only preview mode for display purposes
  • Interactive preview mode for file management
  • Combined edit mode for comprehensive file management
  • Smart click handling:
    • Click on empty preview container areas to select new files
    • Click prevention on images and preview items to avoid accidental file selection
    • Dedicated remove buttons for each preview item

Responsive Design

  • Adapts to container sizes automatically
  • Supports both fixed and flexible dimensions
  • Mobile-friendly touch interactions

Error Prevention

  • File size validation before upload
  • File type validation against accepted formats
  • Clear error messaging for user guidance

This component provides a complete solution for file management interfaces with the flexibility to adapt to various use cases and design requirements.

3.3.8

10 months ago

3.3.7

10 months ago

3.3.6

10 months ago

3.3.1

1 year ago

3.3.5

11 months ago

3.3.4

11 months ago

3.3.3

12 months ago

3.3.2

1 year ago

2.5.0

2 years ago

2.7.0

2 years ago

2.6.0

2 years ago

2.9.0

2 years ago

2.8.0

2 years ago

3.3.0

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.3.0

2 years ago

2.4.0

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

2.0.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago