npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-drop-element

v1.0.1

Published

File Drop Custom Element

Downloads

5,518

Readme

file-drop Custom Element

The file drop custom element is a simple Custom Element that accepts File objects being dropped on it and fires a dedicated event onfiledrop when a successful drop occurs.

Installation

npm i file-drop-element

Demo

You can try a quick demo of this element on glitch.

Usage

Directly as a module

Copy from node_modules in to a local directory.

<script src='file-drop.mjs' type='module'></script>

<file-drop>

  Drop file here

</file-drop>

Directly as a UMD, for non-ES6 Module supporting browsers

<script src='file-drop.umd.js'></script>

<file-drop>

  Drop file here

</file-drop>

Respond to when a file is dropped on the element

When a user has succesfully dropped a file on to the element, the element will emit a filedrop event. The filedrop event contains a file property which is a direct reference to the File that was dropped.

<file-drop id="dropTarget">Drop a file here</file-drop>

<script>
dropTarget.addEventListener('filedrop', (e) => {
  dropTarget.textContent = e.file.name;
});
</script>

Note: if more than one file is dropped on the element, only the first file will be included on the event.

Only allow certain files to be dropped on the element.

The element will accept any drop event that has the .dataTransfer object populated with any file. If you want to control the types of files that can be dropped on to the element, use the same syntax that <input> elements use when the accept attribute is set, that is:

  • <file-drop> - any file
  • <file-drop accept='image/*'> - all images
  • <file-drop accept='image/png'> - only Images that have the MIME-type of a PNG.

Allow multiple files to be dropped

The element can accept multiple files being dropped or pasted on to the element. By default the element will only accept return the first file if the user drops multiple files on it. If you want to receive multiple files in the event you can add the multiple attribute to the element.

<file-drop multiple>

  Drop file here

</file-drop>

If you add an accept attribute alongside the multiple element, the onfiledrop event will only trigger if there is at least one file that matches the criteria. It will return a filtered list of files where each file will match the value in the accept attribute.

<file-drop multiple accept='image/*'>

  Drop file here

</file-drop>

Styling

The element is an inline display element and it can be controlled like any normal element. The element does not use Shadow DOM so there are no internal elements to style.

The element will add two classes drop-valid and drop-invalid to the element depending on the mime-type of the file that is currently being dragged over the element.

<style>

file-drop.drop-valid {
  background-color: green;
}

file-drop.drop-invalid {
  background-color: red;
}

</style>