Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-drag-drop-files

Package Overview
Dependencies
Maintainers
0
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-drag-drop-files

Light React Drag & Drop files and images library styled by styled-components

  • 2.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
78K
decreased by-10.86%
Maintainers
0
Weekly downloads
 
Created
Source

React Drag and Drop Files

Version code style: prettier npm download

Light and simple reactjs drag and drop files library to use with very flexible options to change, so you put whatever the design you want for your drop-area. Users can drag and drop or even select the file anywhere in the window.

Demo

Edit react-drag-drop-files

Installation

Install it from npm (using NPM).

npm i --save react-drag-drop-files

or:

yarn add react-drag-drop-files

Usage

Using react hooks just as simple as:

import React, { useState } from "react";
import { FileUploader } from "react-drag-drop-files";

const fileTypes = ["JPG", "PNG", "GIF"];

function DragDrop() {
  const [file, setFile] = useState(null);
  const handleChange = (file) => {
    setFile(file);
  };
  return (
    <FileUploader handleChange={handleChange} name="file" types={fileTypes} />
  );
}

export default DragDrop;

Options

OptionTypeDescriptionvalue example
namestringthe name for your form (if exist)"myFile"
multiplebooleana boolean to determine whether the multiple files is enabled or nottrue OR false - false by default
labelstringthe label (text) for your form (if exist) inside the uploading box - first word underlined"Upload or drop a file right here"
uploadedLabelstringthe label (text) for your form (if exist) after a file was uploaded inside the uploading box"Uploaded Successfully! Upload another?"
requiredbooleanConditionally set the input field as requiredtrue or false
disabledbooleanthis for disabled the inputtrue OR false
hoverTitlestringtext appears(hover) when trying to drop a file"Drop here"
fileOrFilesArray or File or nullthis mainly made because if you would like to remove uploaded file(s) pass null or pass another file as initial
classesstringstring with the classes wished to add"drop_area drop_zone"
typesArrayarray of strings with extensions to check and go throw['png', 'jpeg', ...]
onTypeErrorfunctionfunction that will be called only of error occurred related to type(err) => console.log(err)
childrenJSX Element, anyif you want to replace the current design inside the box of drop zone. (it will remove the default exist style)<div><p>this is inside drop area</p></div> or just text
maxSizenumberthe maximum size of the file (number in mb)2
minSizenumberthe minimum size of the file (number in mb)1
onSizeErrorfunctionfunction that will be called only if error related to min or max size occurred(file) => console.log(file)
onDropfunctionfunction that will be called when the user drops file(s) on the drop area only(file) => console.log(file)
onSelectfunctionfunction that will be called when the user selects file(s) on click the file area only(file) => console.log(file)
handleChangefunctionfunction that will be called when the user selects or drops file(s)(file) => console.log(file)
onDraggingStateChangefunctionfunction that will be called with the state of dragging(dragging) => console.log(dragging)
dropMessageStyleCSS PropertiesA CSS property to style the hover message{backgroundColor: 'red'}

How to contribute:

  • Please follow the instructions inside this file: here

Upcoming...

  • Contribution Guide
  • Github actions

License

MIT

Keywords

FAQs

Package last updated on 22 Oct 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc