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

@liara/react-drag-drop-files

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liara/react-drag-drop-files

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

  • 2.2.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
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"
labelstringthe label (text) for your form (if exist) inside the uploading box - first word underlined"Upload or drop a file right here"
disabledbooleanthis for disabled the inputtrue OR false
hoverTitlestringtext appears(hover) when trying to drop a file"Drop here"
filefile or nullthis mainly made because if you would like to remove uploaded file pass null or pass another file as initial
classesstringstring with the classes wished to add"drop_area drop_zone"
typesArrayarray of strings with extentions to check and go throw['png', 'jpeg', ...]
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 of error occured related to size min or max(file) => console.log(file)
onDropfunctionfunction that will be called when the user drop a file on the drop area only(file) => console.log(file)
onSelectfunctionfunction that will be called when the user select a file on click the file area only(file) => console.log(file)
handleChangefunctionfunction that will be called when the user select or drop a file(file) => console.log(file)

Upcoming...

  • Files Validation
  • Adding Multiple Files
  • Contribution Guide
  • Show different type of Errors
  • Add disabled props
  • Add custom label

License

MIT

Keywords

FAQs

Package last updated on 12 Jan 2022

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