1.0.1 • Published 3 years ago

media-dropzone-vuejs v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Media-dropzone-vuejs

Vue component that provides drag and drop Files upload with preview.

Installation

npm install media-dropzone-vuejs

Basic usage

<template>
    <media-dropzone-vuejs ref="dropzone" :options="options" />
</template>
<script>
    import MediaDropzoneVuejs from "media-dropzone-vuejs"
    ...
    export default {
            components: {
                MediaDropzoneVuejs,
            },
    ...
</script>

Configuration options

NameTypeDefaultDescription
rtlBooleanfalseDisplayed Files Direction ( from Right to Left).
maxFilesizeNumber256The maximum filesize (in bytes) that is allowed to be uploaded
maxFilesNumbernullwhether to include default Dropzone styles on the component
clickableBoolean, Array, StringtrueIf true, the dropzone element itself will be clickable, if false nothing will be clickable. You can also pass an HTML element, a CSS selector (for multiple elements) or an array of those. In that case, all of those elements will trigger an upload when clicked.
internalCliclableBooleanfalseIf false, nothing will be clickable Inside Dropzone. if true it will add clickable Inside dropzone When it is empty of files
acceptedFilesBoolean, Array, StringnullThe default implementation of accept checks the file's mime type or extension against this list. This is a comma separated list of mime types or file extensions. This option will also be used as accept
showOnDropBoolean, Array, StringfalseIf false, nothing will be. if true Dropzone will disappear and will appear when files are added. You can also pass two HTML element or a CSS selector.First Element mean Dragging Element (default body). second Element mean Dropzone Display Element (default body) Eg.:trueor div.container,div.containeror ['div.container','div.container']
thumbnailWidthNumber StringnullThis with for file thumbnail
thumbnailHeightNumber StringnullThe same as thumbnailWidth
iconsObject{}Set Icon for Displayed Files Eg.:{ pdf: 'icon' } accept iconFont image svg
containerClassStringnullSet Class Name to Dropzone Element
previewClassStringnullSet Class Name to Displayed Files Element
internalButtonClassStringnullSet Class Name to Internal Button
titleStringDrop files here to upload"The text used before any files are dropped
subtitleStringDrop files here to upload"The text used before any files are dropped and after title
msFileTooBigStringnullIf the filesize is too big. {{filesize}} and {{maxFilesize}} will be replaced with the respective configuration values.
msgInvalidFileTypeStringInvalid extension for file {{fileName}}.If the file doesn't match the file type.
msgFilesTooManyStringNumber of files selected for upload {{filesCount}} exceeds maximum allowed limit of {{maxFiles}}.Displayed if maxFiles is st and exceeded. The string {{maxFiles}} will be replaced by the configuration value.

Slots

All content is configurable by slots.
Slots receive the instance itself as their scope, meaning all relevant fields are directly accessible.

Example

<media-dropzone-vuejs :options="options">
    <template v-slot="{files, showViewer, removeFile}">
        <figure v-for="file in files" :key="file.id" @click="showViewer(file)">
            <img v-if="file.thumbnail" :src="file.thumbnail" :alt="file.name" />
            <figcaption>
                {{file.name}}
            </figcaption>
            <button @click="removeFile">remove</button>
        </figure>
    </template>
    <template #title>
        <h4>Drag and drop to upload content</h4>
    </template>
    <template #subtitle>
        <div>...or click to select a file from your computer</div>
    </template>
</media-dropzone-vuejs>

Solts Properties

NameScopedDescription
defaultfiles removeFile showViewerChange the design of all files all types.
imagefiles removeFile showViewerChange the design of all files Only Image.
videofiles removeFile showViewerChange the design of all files Only Video.
pdffiles removeFile showViewerChange the design of all files Only Pdf.
withIconfiles removeFileChange the design of all files all types Except image, video and pdf.
remove-buttonremoveFileRemove File.
titleNoThe text used before any files are dropped
subTitleNoThe text used before any files are dropped and after title.

Slot scoped properties

PropertyTypeDescription
filesObjectDisplay Dropped Files.
removeFileFunctionRemove File. accept one parameter(File).
showViewerFunctionDisplay File. accept one parameter(File).

Events

Use standard Vue event handling to listen for events and respond to them.

<media-dropzone-vuejs
    :options="options"
    @drop="onDrop"
    @success="onSuccess"
/>

Events List

NameDescription
dropThe user dropped something onto the dropzone
dragstartThe user started to drag anywhere
dragendDragging has ended
dragenterThe user dragged a file onto the Dropzone
dragoverThe user is dragging a file over the Dropzone
dragleaveThe user dragged a file out of the Dropzone
filesArray of all files
errorGet Error
changeFired when new images are added or deleted it always returns uploaded files