Skip to content

Dropzone

The Dropzone component provides an easy and user-friendly way to upload files using drag & drop or click-to-upload. It includes built-in support for file validation, image preview, and cropping.

Installation

shell
npx shadcn-vue@latest add https://lib.adrianondik.com/r/dropzone.json

Usage

vue
<template>
    <Dropzone />
</template>

<script setup lang="ts">
import Dropzone from '@/Components/Dropzone';
</script>

Props

PropTypeDescription
maxFilesnumberMaximum number of files that can be uploaded at once. Additional files will be rejected.
maxSizenumberMaximum allowed file size in bytes. Files exceeding this limit will trigger a validation error.
acceptstring[]List of accepted MIME types or file extensions (e.g. image/png, image/jpeg).
modelValueFile[]Current list of uploaded files. Used for v-model binding.
existingImagestring | nullURL of an existing image to display as a preview (e.g. previously uploaded image).
disabledbooleanDisables the dropzone and prevents user interaction.
enableCropbooleanEnables image cropping before the file is accepted.
aspectRationumberFixed aspect ratio for the crop area (e.g. 16/9, 1 for square). If not set, free cropping is allowed.

Examples

Disabled

vue
<template>
    <Dropzone
        disabled
    />
</template>

<script setup lang="ts">
import Dropzone from '@/Components/Dropzone';
</script>

Enable Crop

vue
<template>
    <Dropzone
        :enableCrop="true/false"
    />
</template>

<script setup lang="ts">
import Dropzone from '@/Components/Dropzone';
</script>

Max Files

Use any number, it depends on how many images you want to upload.

vue
<template>
    <Dropzone
        :maxFiles="1"
    />
</template>

<script setup lang="ts">
import Dropzone from '@/Components/Dropzone';
</script>

Model Value

Uses the method to save the image to the database

vue
<template>
    <Dropzone
        @update:model-value=""
    />
</template>

<script setup lang="ts">
import Dropzone from '@/Components/Dropzone';
</script>