1.9.2 • Published 3 years ago

@hecht-a/dropzone v1.9.2

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

Quickstart

Install:

npm install --save @hecht-a/dropzone
# or with yarn
yarn add @hecht-a/dropzone
# or with pnpm
pnpm install @hecht-a/dropzone

Use as ES6 module:

import {Dropzone} from '@hecht-a/dropzone'

const input = document.querySelector('input#id')
const dropzone = new Dropzone(input, {})

Or use as CommonJS module:

const {Dropzone} = require('@hecht-a/dropzone')

const input = document.querySelector('input#id')
const dropzone = new Dropzone(input, {})

Documentation

Options

Options are defined in the second argument of the Dropzone constructor in an object.
For example:

const input = document.querySelector('input#id')
const dropzone = new Dropzone(input, {
    id: 'id'
})

All these options are optionnal.

namedescriptiontypedefault value
idCustom id to apply to the dropzonestring"dropzone"
labelDefine the label shown on the dropzonestring"Upload files"
hoverLabelDefine the label shown on the dropzone when it's hoveredstring"hover"
minDefine the minimum amount of file(s) to upload (see Dropzone#setMin)number0
maxDefine the maximum amount of file(s) to upload (see Dropzone#setMax)number2
containerTemplateDefine the global template of the dropzone(max: number, files?: FileList, label?: string, id?: string) => string-
fileTemplateDefine the template of the file container when a file is uploaded(fileName: string) => string-
onHoverDefine the event hover() => void-
onLeaveDefine the event onLeave() => void-
onAddFileDefine the event addFile(file: File) => void-
onAddFilesDefine the event addFiles(file: FileList) => void-
onErrorDefine the event error(error: Error) => void-
onDropDefine the event drop(files: FileList) => void-
onDragEnterDefine the event dragEnter() => void-
onDragLeaveDefine the event dragLeave() => void-
onDragOverDefine the event dragOver() => void-
onRefreshDropzoneDefine the event refreshDropzone() => void-
onRemoveFileDefine the event removeFile(file: File) => void-
onClearDropzoneDefine the event clearDropzone(files: FileList) => void-

Events

Events are received with:

dropzone.on('event_name', callback)

where event_name is the name of the targeted event, callback is what you want to execute when the event is received.

hover

Event fired when the mouse is hovering the dropzone.

leave

Event fired when the mouse leave the dropzone area.

addFile

Event fired when a file is uploaded to the dropzone.

addFiles

Event fired when multiple files are uploaded to the dropzone.

onError

Event fired when an error is thrown.

onDrop

Event fired when a file is drop on the dropzone.

onDragEnter

Event fired when the mouse enter on the dropzone are with a file.

onDragLeave

Event fired when the mouse enter on the dropzone area with a file.

onDragOver

Event fired when the mouse is hovering the dropzone with a file.

onRefreshDropzone

Event fired when the dropzone is refreshed.
The dropzone is refresh when:

  • one or multiple file(s) is / are uploaded
  • a file is removed
  • the dropzone is cleared

onRemoveFile

Event fired when a file is removed.

onClearDropzone

Event fired when the dropzone is cleared. See Dropzone#clearDropzone.

Methods

Dropzone#clearDropzone

Remove all the files uploaded in the dropzone. Use:

const input = document.querySelector('input#id')
const dropzone = new Dropzone(input, {})
dropzone.clearFiles()

Dropzone#setMin

Set the minimum amount of files. Use:

const input = document.querySelector('input#id')
const dropzone = new Dropzone(input, {})
dropzone.setMin(2)

Dropzone#setMax

Set the maximum amount of files. Use:

const input = document.querySelector('input#id')
const dropzone = new Dropzone(input, {})
dropzone.setMax(5)
1.9.1

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.9.2

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago