All Projects → sarink → React File Drop

sarink / React File Drop

React component for Gmail or Facebook -like drag and drop file uploader

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React File Drop

image-uploader
Simple Drag & Drop image uploader plugin to static forms, without using AJAX
Stars: ✭ 70 (-43.09%)
Mutual labels:  drag-and-drop, drag, file-upload
vue-simple-upload-component
A simple upload component for Vue.js 2.x
Stars: ✭ 14 (-88.62%)
Mutual labels:  drag-and-drop, drag, file-upload
React Beautiful Dnd
Beautiful and accessible drag and drop for lists with React
Stars: ✭ 25,810 (+20883.74%)
Mutual labels:  drag-and-drop, drag
Ng2 Dnd
Angular 2 Drag-and-Drop without dependencies
Stars: ✭ 861 (+600%)
Mutual labels:  drag-and-drop, drag
React Dropzone
Simple HTML5 drag-drop zone with React.js.
Stars: ✭ 8,639 (+6923.58%)
Mutual labels:  drag-and-drop, file-upload
Dragdropswiperecyclerview
Kotlin Android library that extends RecyclerView to support gestures like drag & drop and swipe, among others. It works with vertical, horizontal and grid lists.
Stars: ✭ 469 (+281.3%)
Mutual labels:  drag-and-drop, drag
Kddraganddropcollectionview
This component allows for the transfer of data items between collection views through drag and drop
Stars: ✭ 476 (+286.99%)
Mutual labels:  drag-and-drop, drag
Filepond Boilerplate Php
🔥 A FilePond PHP project starter kit
Stars: ✭ 45 (-63.41%)
Mutual labels:  drag-and-drop, file-upload
React Native Drag Sort
🔥🔥🔥Drag and drop sort control for react-native
Stars: ✭ 397 (+222.76%)
Mutual labels:  drag-and-drop, drag
Angular File Uploader
Angular file uploader is an Angular 2/4/5/6/7/8/9/10 + file uploader module with Real-Time Progress Bar, Responsive design, Angular Universal Compatibility, localization and multiple themes which includes Drag and Drop and much more.
Stars: ✭ 92 (-25.2%)
Mutual labels:  drag-and-drop, file-upload
Android
Android projects with reusable components which will be useful in your applications.
Stars: ✭ 81 (-34.15%)
Mutual labels:  facebook, drag
Html5sortable
VanillaJS sortable lists and grids using native HTML5 drag and drop API.
Stars: ✭ 1,384 (+1025.2%)
Mutual labels:  drag-and-drop, drag
Darkness
Dark Themes for Popular Websites
Stars: ✭ 467 (+279.67%)
Mutual labels:  gmail, facebook
Vvvebjs
Drag and drop website builder javascript library.
Stars: ✭ 4,609 (+3647.15%)
Mutual labels:  drag-and-drop, drag
Sortable
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Stars: ✭ 23,641 (+19120.33%)
Mutual labels:  drag-and-drop, drag
Smooth Dnd
drag and drop library for javascript
Stars: ✭ 408 (+231.71%)
Mutual labels:  drag-and-drop, drag
Silex
Silex is a static website builder in the cloud.
Stars: ✭ 958 (+678.86%)
Mutual labels:  drag-and-drop, drag
React Smooth Dnd
react wrapper components for smooth-dnd
Stars: ✭ 1,560 (+1168.29%)
Mutual labels:  drag-and-drop, drag
Dropzone
Dropzone is an easy to use drag'n'drop library. It supports image previews and shows nice progress bars.
Stars: ✭ 16,097 (+12986.99%)
Mutual labels:  drag-and-drop, file-upload
React Uploady
Modern file uploading - components & hooks for React
Stars: ✭ 372 (+202.44%)
Mutual labels:  drag-and-drop, file-upload

react-file-drop

Zero dependency 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 a hook for every event so you can use it to develop any custom behavior that you want.

V3 is out! See the changelog

Demo

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

Why?

I wanted that behavior that 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!

Dependencies

None! (well, just prop-types, but that should already be removed from your prod bundle anyway)

Browser support

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

Installation

npm install --save 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 target will get a file-drop-dragging-over-frame class name, and the onFrameDragEnter callback will fire.

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.

You can also define an onTargetClick prop if you want to let user browse their files from disk. Below you can find instruction how to do that.

Styling

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

For custom class names (if you're using something like JSS) you can use the following props:

  • className
  • targetClassName
  • draggingOverFrameClassName
  • draggingOverTargetClassName

Classnames

.file-drop: The outer container element

.file-drop > .file-drop-target: This is the target the user has to drag their files to.

.file-drop > .file-drop-target.file-drop-dragging-over-frame: This class will be added to the 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: This class will be added to the target whenever the user begins dragging a file over the target, and it will be removed when they leave

Props

onDrop: function(files, event): Callback when the user drops files onto the target

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.

onTargetClick: function(event): Callback when the user clicks anywhere on the 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.

className: string (default: "file-drop"): Class given to the outer container div.

targetClassName: string (default: "file-drop-target"): Class given to the target div.

draggingOverFrameClassName: string (default: "file-drop-dragging-over-frame"): Class given to the target div when file is being dragged over frame.

draggingOverTargetClassName: string (default: "file-drop-dragging-over-target"): Class given to the target div when file is being dragged over target.

Uploading files using click handler

In order to let user upload files with click on the file-drop-target, you will need to specify an input[type="file"] somewhere in your code. You will also need a ref, that will be passed to the input, to call a click method on it.

Steps:

  1. Define ref for input:
const fileInputRef = useRef(null);
  1. Define input change handler:
const onFileInputChange = (event) => {
  const { files } = event.target;
  // do something with your files...
}
  1. Add input to your code:
<input
  onChange={onFileInputChange}
  ref={fileInputRef}
  type="file"
  className="hidden"
/>
  1. Define target click handler:
const onTargetClick = () => {
  fileInputRef.current.click()
}
  1. Add target click handler to FileDrop component:
<FileDrop
  onTargetClick={onTargetClick}

Contributing

Your PRs are welcome! To run the app locally:

nvm use # Probably optional, but it can't hurt

cd file-drop
npm install
npm start

cd demo
npm install
npm start

Now both the apps are running in watch mode. If you make a change to the file-drop code, you should see the demo code automatically rebuild and update in your browser.

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].