Socket
Socket
Sign inDemoInstall

droppable

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    droppable

A library to give file dropping super-powers to any HTML element.


Version published
Maintainers
1
Created

Readme

Source
droppable logo

A javascript library to give file dropping super-powers to any HTML element.

Build Status Human Friendly Coverage Statusnpm version

Table of Contents

Motivation

Wouldn't it be great if you could drop files in any HTML element allowing you to style the item however you like?

Well now you can! 🎉

Features

  • Restrict drop to single or multiple files
  • CSS class added when files are being dragged on top of the HTML element (configurable)
  • Clicking on the html element also prompts user for files (configurable)
  • Zero dependencies
  • Tiny! (~4 KB Minified)
  • Accessibility support

Basic usage

const Droppable = require('droppable');

const droppable = new Droppable({
    element: document.querySelector('#my-droppable-element')
})

droppable.onFilesDropped((files) => {
    console.log('Files were dropped:', files);
});

// Clean up when you're done!
droppable.destroy();

Browser Compatibility

ChromeFirefoxIEOperaSafariEdge
10+ ✔

Installation

npm install droppable

Advanced usage

Create a droppable element

const Droppable = require('droppable');

const droppable = new Droppable({
    element: document.querySelector('#my-droppable-element')
});

Listen for dropped files

droppable.onFilesDropped((files) => {
    console.log('Files were dropped:', files);
});

Remove listener for dropped files

onFilesDropped returns a function which when called removes the event listener

const eventRemover = droppable.onFilesDropped((files) => {
    console.log('Files were dropped on the element:', files);
});

eventRemover();

Get the latest dropped files

const latestDroppedFiles = droppable.getLatestDroppedFiles();

Trigger prompt for files

Sometimes you will want to prompt the user for files without him dropping files or clicking the element.

droppable.promptForFiles();

Enable prompt for files when clicked

This is by default true

The user will be prompted for files when the droppable element is clicked

// On instantiation
const droppable = new Droppable({
    element,
    isClickable: true
})

// On runtime
droppable.setIsClickable(true);

Disable prompt for files when clicked

The user won't be prompted for files when the droppable element is clicked

// On instantiation
const droppable = new Droppable({
    element,
    isClickable: false
})

// On runtime
droppable.setIsClickable(false);

Enable multiple files drop

This is by default true

The user will be able to drop or select multiple files.

// On instantiation
const droppable = new Droppable({
    element,
    acceptsMultipleFiles: true
})

// On runtime
droppable.setAcceptsMultipleFiles(true);

Disable multiple files drop

The user will be able to drop or select one single file.

// On instantiation
const droppable = new Droppable({
    element,
    acceptsMultipleFiles: false
})

// On runtime
droppable.setAcceptsMultipleFiles(false);

Enable append CSS class when files are dragged on element

This is by default true

The class dragover will be added to the droppable element when files are being dragged on it.

// On instantiation
const droppable = new Droppable({
    element,
    appendStatusClasses: true
})

// On runtime
droppable.setAppendStatusClasses(true);

Disable append CSS class when files are dragged on element

The class dragover won't be added to the droppable element when files are being dragged on it.

// On instantiation
const droppable = new Droppable({
    element,
    appendStatusClasses: false
})

// On runtime
droppable.setAppendStatusClasses(false);

Destroy

The library attaches several events to the HTML element made droppable. The destroy function not only removes all of them but also the onFilesDropped listeners.

droppable.destroy();

Development

Clone the repository

git clone git@github.com:lifenautjoe/droppable.git

Use npm commands

  • npm t: Run test suite
  • npm start: Runs npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code
  • npm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)

Author Joel Hernandez

Keywords

FAQs

Last updated on 08 Apr 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc