Dropzone

A file upload dropzone for drag-and-drop or click-based document and media uploads.

Import
the javascript logo
import { Dropzone } from "@schukai/monster/source/components/form/dropzone.mjs";
Source
the git logo
Package
the npm logo
Since
4.40.0

Introduction

The Monster Dropzone handles click-based and drag-and-drop uploads in one consistent upload surface. Use it when files, images or documents should be attached through a clear drop area instead of a hidden file input alone.

When to use Dropzone

  • Use it for uploads with visual affordance: Users immediately understand where files belong.
  • Use it for media and document workflows: Especially useful when multiple upload paths should feel unified.
  • Do not use it for tiny hidden uploads: If there is no visible upload workflow, a plain file input may be enough.

Typical mistakes

Make the upload contract clear. Users should know file types, size limits and what happens after upload, otherwise even a visually good dropzone still feels unreliable.

Simple Dropzone

A basic dropzone for multiple files. Auto upload is disabled so you can validate or prepare files before sending them to the server.

Javascript

import '@schukai/monster/source/components/form/dropzone.mjs';

const dropzone = document.querySelector('#dropzone');

dropzone.setOption('features.autoUpload', false);
dropzone.setOption('accept', '.pdf,.png,.jpg,.jpeg');

dropzone.setOption('labels.title', 'Upload documents');
dropzone.setOption('labels.hint', 'or drag and drop them here');
dropzone.setOption('labels.button', 'Choose files');<script type="module">import '@schukai/monster/source/components/form/dropzone.mjs';

const dropzone = document.createElement('monster-dropzone');

dropzone.setOption('features.autoUpload', false);
dropzone.setOption('accept', '.pdf,.png,.jpg,.jpeg');

dropzone.setOption('labels.title', 'Upload documents');
dropzone.setOption('labels.hint', 'or drag and drop them here');
dropzone.setOption('labels.button', 'Choose files');

document.getElementById('dropzone-simple').appendChild(dropzone);</script>

HTML

<monster-dropzone id="dropzone"></monster-dropzone>

Stylesheet

/** no additional stylesheet is defined **/
Open in playground

Profile Image Upload

A single-file dropzone for profile images. File types are restricted to images, and the control shows previews for quick confirmation.

Javascript

import '@schukai/monster/source/components/form/dropzone.mjs';

const dropzone = document.querySelector('#avatar-dropzone');

dropzone.setOption('features.autoUpload', false);
dropzone.setOption('features.previewImages', true);
dropzone.setOption('multiple', false);
dropzone.setOption('accept', 'image/*');

dropzone.setOption('labels.title', 'Upload a profile image');
dropzone.setOption('labels.hint', 'PNG or JPG, max 5 MB');
dropzone.setOption('labels.button', 'Choose image');<script type="module">import '@schukai/monster/source/components/form/dropzone.mjs';

const dropzone = document.createElement('monster-dropzone');

dropzone.setOption('features.autoUpload', false);
dropzone.setOption('features.previewImages', true);
dropzone.setOption('multiple', false);
dropzone.setOption('accept', 'image/*');

dropzone.setOption('labels.title', 'Upload a profile image');
dropzone.setOption('labels.hint', 'PNG or JPG, max 5 MB');
dropzone.setOption('labels.button', 'Choose image');

document.getElementById('dropzone-avatar').appendChild(dropzone);</script>

HTML

<monster-dropzone id="avatar-dropzone"></monster-dropzone>

Stylesheet

/** no additional stylesheet is defined **/
Open in playground

Component Design

The dropzone is implemented with the Shadow DOM, which encapsulates its structure and styling. Customization is enabled through exported parts and theme variables.

Exported Parts

Use the ::part() selector to style the component without breaking encapsulation.

  • control: Wrapper for the dropzone, status, and list.
  • dropzone: The interactive drag-and-drop area.
  • content: Container for title and hint.
  • title: Title text inside the dropzone.
  • hint: Hint text inside the dropzone.
  • button: The internal action button.
  • input: The hidden file input.
  • status: Upload status line below the dropzone.
  • list: List container for selected files.

monster-dropzone::part(dropzone) {
    border-style: solid;
    border-color: #c7d2fe;
    background-color: #f8faff;
}

monster-dropzone::part(title) {
    font-weight: 700;
}

monster-dropzone::part(list) {
    margin-top: 1rem;
}

Theme Variables

The component relies on global Monster theme variables. You can override them on the host to align the dropzone with your design system.


monster-dropzone {
    --monster-border-radius: 12px;
    --monster-bg-color-primary-1: #f5f6f8;
    --monster-color-primary-1: #1f2937;
}

HTML Structure

<monster-dropzone></monster-dropzone>

JavaScript Initialization

const element = document.createElement('monster-dropzone');
document.body.appendChild(element);

Exported

Dropzone

Derived from

CustomElement

Options

The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomElement.

Option
Type
Default
Description
templates
object
Template definitions
templates.main
string
undefined
Main template
labels
object
undefined
Label definitions
labels.title
string
undefined
Title text
labels.hint
string
undefined
Hint text
labels.button
string
undefined
Button label
labels.statusIdle
string
undefined
Status text for idle state
labels.statusUploading
string
undefined
Status text for uploading state
labels.statusSuccess
string
undefined
Status text for success state
labels.statusError
string
undefined
Status text for error state
labels.statusMissingUrl
string
undefined
Status text for missing URL
classes
object
Class definitions
classes.dropzone
string
monster-dropzone
Dropzone CSS class
classes.button
string
monster-button-outline-primary
Monster button class
url
string
Upload URL
fieldName
string
files
e for files
accept
string
File input accept attribute
multiple
boolean
true
Allow multiple file selection
disabled
boolean
false
Disable interaction
data
object
undefined
Additional data appended to the FormData
features
object
Feature flags
features.autoUpload
boolean
true
Automatically upload after selection
features.previewImages
boolean
true
Show image previews
features.disappear
boolean
true
Enable auto-removal of finished items
disappear
object
Disappear settings
disappear.time
number
undefined
Delay before auto-removal (ms)
disappear.duration
number
3000
Delay before auto-removal (ms)
actions
object
Action definitions for custom event handling
actions.fileAdded
function
Called after a file is added to the list
actions.fileRemoved
function
Called after a file is removed
actions.fileRetry
function
Called before retrying a failed upload
actions.uploadStart
function
Called when uploads start
actions.uploadSuccess
function
Called after successful upload
actions.uploadError
function
Called when upload fails
actions.beforeUpload
function
Called before upload, return false to cancel
fetch
object
Fetch options
string
fetch.method="POST"
string
fetch.redirect="error"
string
fetch.mode="same-origin"
string
fetch.credentials="same-origin"
object
fetch.headers={"accept":"application/json"}

  • since
  • deprecated

Properties and Attributes

The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomElement.

  • data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.
  • data-monster-option-[name]: Sets the value of the configuration option [name] for the collapse component when used as an HTML attribute.

Methods

The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomElement.

Behavioral methods

open()
Returns
  • {void}
Open the native file picker.

Static methods

[instanceSymbol]()
Returns
  • {symbol}
This method is called by the instanceof operator.
getCSSStyleSheet()
Returns
  • {CSSStyleSheet[]}
getTag()
Returns
  • {string}

Lifecycle methods

Lifecycle methods are called by the environment and are usually not intended to be called directly.

[assembleMethodSymbol]()

Other methods

upload(files)
Parameters
  • files {filelist|file[]}: files
Returns
  • {Promise}
Upload files programmatically.

Events

The component emits the following events:

  • monster-dropzone-selected
  • monster-dropzone-file-added
  • monster-dropzone-file-removed
  • monster-dropzone-file-retry
  • monster-dropzone-file-upload-start
  • monster-dropzone-file-upload-success
  • monster-dropzone-file-upload-error
  • monster-dropzone-upload-start
  • monster-dropzone-upload-success
  • monster-dropzone-upload-error

For more information on how to handle events, see the mdn documentation.

The current width of the area is too small to display the content correctly.