All Projects → lifenautjoe → Droppable

lifenautjoe / Droppable

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

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Droppable

React Files
A file input (dropzone) management component for React
Stars: ✭ 126 (-38.24%)
Mutual labels:  files, drop
Uploadcare Widget
Uploadcare Widget, an ultimate tool for HTML5 file upload supporting multiple file upload, drag&drop, validation by file size/file extension/MIME file type, progress bar for file uploads, image preview.
Stars: ✭ 183 (-10.29%)
Mutual labels:  files
Ltecleanerfoss
The last Android cleaner you'll ever need!
Stars: ✭ 141 (-30.88%)
Mutual labels:  files
Diagram Maker
A library to display an interactive editor for any graph-like data.
Stars: ✭ 2,086 (+922.55%)
Mutual labels:  drop
Angular Skyhook
An implementation of react-dnd for Angular.
Stars: ✭ 146 (-28.43%)
Mutual labels:  drop
Zip
Swift framework for zipping and unzipping files.
Stars: ✭ 2,120 (+939.22%)
Mutual labels:  files
Globby
User-friendly glob matching
Stars: ✭ 1,864 (+813.73%)
Mutual labels:  files
Nova Filemanager
A Filemanager tool for Laravel Nova
Stars: ✭ 189 (-7.35%)
Mutual labels:  files
Filebuster
An extremely fast and flexible web fuzzer
Stars: ✭ 176 (-13.73%)
Mutual labels:  files
Fselect
Find files with SQL-like queries
Stars: ✭ 3,103 (+1421.08%)
Mutual labels:  files
Vuegg
🐣 vue GUI generator
Stars: ✭ 2,056 (+907.84%)
Mutual labels:  drop
Angular Tree Dnd
Display tree table (or list) & event Drap & Drop (allow drag multi tree-table include all type: table, ol, ul) by AngularJS
Stars: ✭ 146 (-28.43%)
Mutual labels:  drop
Exa
A modern replacement for ‘ls’.
Stars: ✭ 15,471 (+7483.82%)
Mutual labels:  files
Xcv
✂️ Cut, Copy and Paste files with Bash
Stars: ✭ 144 (-29.41%)
Mutual labels:  files
Filekit
Simple and expressive file management in Swift
Stars: ✭ 2,183 (+970.1%)
Mutual labels:  files
Gonzo
Go File Processing Framework.
Stars: ✭ 133 (-34.8%)
Mutual labels:  files
Ngx Smooth Dnd
angular wrapper for smooth-dnd
Stars: ✭ 152 (-25.49%)
Mutual labels:  drop
Twitch Watcher
Automatic watching the twitch to get Valorant drop
Stars: ✭ 162 (-20.59%)
Mutual labels:  drop
Fancytree
JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading
Stars: ✭ 2,398 (+1075.49%)
Mutual labels:  drop
Getjs
A tool to fastly get all javascript sources/files
Stars: ✭ 190 (-6.86%)
Mutual labels:  files
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?

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

Usecases

When files get dropped or selected into your element you will retrieve them as File objects. This means you can do anything you want with the dropped/selected files!

Here are some concrete usecases.

  • Upload the files (e.g. chat media/attachment, file chunking, file sharing)
  • Edit the files (e.g. Text editor, image editor)
  • Inspect the files (e.g. syntax validator, file stats)
  • Encrypt the files (Yes you can)

Demo

You can see the library in action here.

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

Chrome Firefox IE Opera Safari Edge
10+ ✔

Installation

npm

npm install droppable

Scripts

The library is also available as a standalone script in multiple formats (UMD, ES5, ES6 ...).

You can get the latest version from /dist or the stable one from the releases page.

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 users for files without them 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();

FAQ

My droppable element has a border around it when focused

The library makes the droppable elements accesible, this means that they can get focused by the user.

Your browser by default adds an outline to the focused items. To remove it, in your css:

    #your-droppable-item:focus{
        outline: 0;
    }

I want to add a style to my droppable element when focused

In your css:

    #your-droppable-item:focus:not(:active){
        // Here you can do anything! For example adding a shadow
        box-shadow: 0 0 0 0.125em rgba(111, 14, 217, 0.25);
    }

Development

Clone the repository

git clone [email protected]: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 😉)

Author Joel Hernandez

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].