GithubHelp home page GithubHelp logo

alecshoppe / react-drag-drop-files Goto Github PK

View Code? Open in Web Editor NEW

This project forked from karimmokhtar/react-drag-drop-files

0.0 0.0 0.0 1.34 MB

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.

License: MIT License

JavaScript 14.75% TypeScript 73.87% CSS 2.41% HTML 8.97%

react-drag-drop-files's Introduction

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

Option Type Description value example
name string the name for your form (if exist) "myFile"
multiple boolean a boolean to determine whether the multiple files is enabled or not true OR false - false by default
label string the label (text) for your form (if exist) inside the uploading box - first word underlined "Upload or drop a file right here"
required boolean Conditionally set the input field as required true or false
disabled boolean this for disabled the input true OR false
hideTypes boolean set this to true to hide the UI showing types true OR false
hoverTitle string text appears(hover) when trying to drop a file "Drop here"
fileOrFiles Array or File or null this mainly made because if you would like to remove uploaded file(s) pass null or pass another file as initial
classes string string with the classes wished to add "drop_area drop_zone"
types Array array of strings with extensions to check and go throw ['png', 'jpeg', ...]
onTypeError function function that will be called only of error occurred related to type (err) => console.log(err)
children JSX Element, any if 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
maxSize number the maximum size of the file (number in mb) 2
minSize number the minimum size of the file (number in mb) 1
onSizeError function function that will be called only if error related to min or max size occurred (file) => console.log(file)
onDrop function function that will be called when the user drops file(s) on the drop area only (file) => console.log(file)
onSelect function function that will be called when the user selects file(s) on click the file area only (file) => console.log(file)
handleChange function function that will be called when the user selects or drops file(s) (file) => console.log(file)
onDraggingStateChange function function that will be called with the state of dragging (dragging) => console.log(dragging)
dropMessageStyle CSS Properties A CSS property to style the hover message {backgroundColor: 'red'}
messages object Object to change the static texts {disabled?: string, uploaded?: string,upload_another?: string, error?: string, drop?: string, upload?: string, or_message?: string}

How to contribute:

  • Please follow the instructions inside this file: here

Upcoming...

  • Contribution Guide
  • Github actions

License

MIT

react-drag-drop-files's People

Contributors

karimmokhtar avatar iamdipanshusingh avatar anadoly avatar alecshoppe avatar aprilmintacpineda avatar dante01yoon avatar thebedroomprogrammer avatar jirihofman avatar lukeflima avatar anti-duhring avatar mykybo avatar room9design avatar troywolf avatar vj-27 avatar saitharunsai avatar tvox15 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.