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

@loopmode/react-file-drop

v0.4.8

Published

React component for Gmail or Facbook -like drag and drop file uploader. Drag files anywhere onto the window to highlight a 'drop area' of the page

Downloads

49

Readme

react-file-drop

React component for Gmail or Facebook -like drag and drop file uploader. Drag files anywhere onto the window (or user defined "frame" prop)! Very extensible, provides many hooks so you can use it to develop any custom behavior that you desire.

fork: @loopmode/react-file-drop

This is a fork of the original react-file-drop library. It adds support for custom render function for wrappers, and enables it to be used in SVG context.

Furthermore, it accepts any kind of dropped content (not just files) and provides a third argument details to the onDrop callback.

V2 is out! See the changelog before upgrading

Demo/Example

http://sarink.github.io/react-file-drop/dist/Demo - A very simple demo with example code and sample CSS

By default, there are no styles! You must include some CSS if you want to see anything!

You can grab the demo CSS to get started

Browser support

✅ Chrome ✅ Firefox ✅ Safari ✅ IE 11 ✅ IE Edge

Typescript?

Yup! (For typing event handlers, use the native DragEvent for frame handlers, and the React lib's DragEvent for others)

Why?

I wanted that behavior like facebook, gmail, etc. have where a part of the page highlights immediately when you start dragging a file anywhere on the window. I couldn't find any React component that already did this, so, I made one.

Installation

npm install react-file-drop

Usage

import FileDrop from 'react-file-drop

How it works

First, you define the frame prop (default is the document), whenever the user begins dragging file(s) anywhere over this frame, the <div class="file-drop-target"> will be inserted into the DOM.
Next, define an onDrop prop, whenever a user drops their files onto the target, this callback will be triggered.
Lastly, you'll need to style it. Check out the Styling section below for details.

Props

disabled - Boolean

If true, any drag/drop is ignored. No callbacks will be invoked.

onDrop - function(files, event)

Callback when the user drops files onto the target Fork info: the third argument, details, has the signature {files:Array<String>, links:Array<String>, images:Array<String>, text:String, html:String}

onDragOver - function(event)

Callback when the user is dragging over the target. Also adds the file-drop-dragging-over-target class to the file-drop-target

onDragLeave - function(event)

Callback when the user leaves the target. Removes the file-drop-dragging-over-target class from the file-drop-target

dropEffect - String "copy" || "move" || "link" || "none" (default: "copy")

Learn more about HTML5 dropEffects. Not available in IE :(

frame - document || HTMLElement (default: document)

This is the "scope" or frame that the user must drag some file(s) over to kick things off.

onFrameDragEnter - function(event)

Callback when the user begins dragging over the frame

onFrameDragLeave - function(event)

Callback when the user stops dragging over the frame

onFrameDrop - function(event)

Callback when the user drops files anywhere over the frame

outerComponent - String || function(props) (default: div)

Component or tag name for rendering the outer wrapper.

innerComponent - String || function(props) (default: div)

Component or tag name for rendering the inner wrapper.

Supported types for outerComponent and innerComponent:

  • String - Any HTML or SVG tag name like div, span, g etc.
  • Function - A render function or component class. Receives props and renders a react element.
    • props passed to outerComponent: className, onDragOver, onDragLeave, onDrop
    • props passed to innerComponent: className
    • example: component class: <FileDrop outerComponent={MyReactComponent}>
    • example: render function: <FileDrop outerComponent={(props) => <span {...props} />} />

Styling

By default, the component comes with no styles. You can grab the demo CSS to get you started.

.file-drop

The outer container element

.file-drop > .file-drop-target

This is the target the user has to drag their files to. It will be inserted into the DOM whenever the user starts dragging over the frame.

.file-drop > .file-drop-target.file-drop-dragging-over-frame

The file-drop-dragging-over-frame class will be added to the file-drop-target whenever the user begins dragging a file over the frame, and it will be removed when they leave

.file-drop > .file-drop-target.file-drop-dragging-over-target

The file-drop-dragging-over-target class will be added to the file-drop-target whenever the user begins dragging a file over the file-drop-target div, and it will be removed when they leave