1.9.19 • Published 3 years ago

@unlimited-react-components/react-drop-zone v1.9.19

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Español 🚀️

license npm latest package npm latest package dependencies tests Dependabot Status

This is my very first npm package, so if you have any issue or suggestion let me know it on the github section: "issues".

Description

Amazing React drop zone component for loading and validating input files.

Installation

React-drop-zone is available as an npm package.

// with npm
npm i @unlimited-react-components/react-drop-zone

Main Features:

  • Input File Button included by props.
  • Free handling: You are free to handle the loaded files because this component returns an array of files (FILE objects) each of them has 2 properties (the own file and an array of errors according to the limits you set).
  • Usable: It will fit the parent container. So make sure you give it an appropiate container to it.
  • Customizable: you can change the theme color to combine correctly with the rest of the page.
  • Localization: English and Spanish versions.

Usage (basic example)

Here is a quick example to get you started, it's all you need:

Interactive and live demo:

Edit Button

import "./styles.css";

import { useState } from "react";
import { DropZone } from "@unlimited-react-components/react-drop-zone";

const App = (props) => {
 
  const handleFileSelect = (files) => {
    ...
  };
  return (
    <div className="App">
     ...

      <DropZone
        handleFileSelect={handleFileSelect}
        //localization={"es-ES"}
      />

      ...
    </div>
  );
};
export default App;

```

Usage 2 (example with styles and validations)

Interactive and live demo:

Edit Button

Here is an example to customize styles and behaviour:

In this example we are telling the drop zone:

  • to admit up to 4 files (if you select or drop more, it will take the first 4 files).
  • to admit files size up to 50 mb.- to admit fies with extensions"json", "exe", "pdf", "png"
  • to admit files wich mimetype is included in the list:"application/json", "image/png"

You can personalize the style of the component by giving a color theme and a nice background image got from internet.

  • themeColor:#5500ff
  • backgroundImage: "https://miro.medium.com/max/670/1*wPqqYFfNreXF4INrNhYkeQ.jpeg"

You can also change the text style ( in this example I am using fonts from Google fonts).It is necessary to add the corresponding link tag on the index.html file.

<!DOCTYPE html>
<html lang="en">
  <head>
   ...
  <link rel="preconnect" href="https://fonts.gstatic.com" />
    <link
      href="https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap"
      rel="stylesheet"
    />
    <link
      href="https://fonts.googleapis.com/css2?family=Indie+Flower&family=Long+Cang&display=swap"
      rel="stylesheet"
    />
    ...
</head>

  <body>
      ...
  </body>
</html>
// App.jsx
import "./styles.css";
import { DropZone } from "react-drop-zone-responsive";
import { useState } from "react";

const useLimits = {
  extensions: ["json", "pdf", "png"], //admited extensions
  mimeType: ["application/json", "application/pdf", "image/png"], //admited mymetypes
  maxSize: 50 // MB
};

const useDropZoneStyles = {
  themeColor: "#0000ff",
  backgroundImage:
    "https://miro.medium.com/max/670/1*wPqqYFfNreXF4INrNhYkeQ.jpeg",
  mainTextStyle: {
    fontFamily: "",
    color: "",
    fontSize: ""
  },
  bottonTextStyle: {
    fontFamily: "",
    color: "",
    fontSize: ""
  }
  //backgroundColor: "#013e62"
};

const numberOfFiles = 4;

const App = (props) => {
  ...
  return (
    <div className="App">
     ...
      <DropZone
        style={useDropZoneStyles}
        amountOfFiles={numberOfFiles}
        limits={useLimits}
        handleFileSelect={handleFileSelect}
        //localization={"es-ES"}
      />
     ...
    </div>
  );
};
export default App;

Props (all are optional)

NameDescriptionDefault
styleObject that contains the main styles for the component.themeColor:#ff6c37, backgroundImage:"https://www.postman.com/assets/use-cases-by-role.svg"
limitsObject that contains the criteria to validate files that we want to load and files we don't.undefined: allows any kind of file
amountOfFilesThe max number of files that will be loaded.10
handleFileSelectThe handler function when files are droped or selected. This function receives the list of files after validation.undefined
localizationThe text label translation in other languages. Supporting now only Englishen-EN and Spanish es-ES.en-EN: by default
inputButtonBoolean value that specify whether to include input file butoon or not.undefined: by default
multipleBoolean value that, if present or has thurty value, makes the inpput button to filter the files according to thelimits.extensions and limits.mimetype props.undefined: by default
cutomLabelsObject wich labels to show in the dropzone.undefined: by default

Details

  • themeColor?: Main color for borders and button theme color.
  • mainTextStyle? andbottonTextStyle?: Styles for labels on the top and botton.
    • fontFamily?: string;
    • color?: string;
    • fontSize?: string | number;
  • backgroundImage?: An url to an image on internet to fit the background of the drop zone.
  • backgroundColor?: The background color, by default is white.
  • extensions?: a string array of extensions
  • mimeType?: a string array of mimetypes
  • maxSize?: maximun size in megabytes per file.
  • mainLabel?: a string that is the main label to show on the top of the drop zone.
  • mainLabel_or?: a string label between the main alabel and the input file button
  • buttonLabel?: a string label to be shwon on the button.
  • bottonLabel?: a string label to show on the botton before the list with allowed extentions.

👀️ Custom labels example: Edit Button

License

This project is licensed under the terms of the MIT license.

1.9.19

3 years ago

1.9.18

3 years ago

1.9.17

3 years ago

1.9.16

3 years ago

1.9.15

3 years ago

1.9.14

3 years ago

1.9.13

3 years ago

1.9.12

3 years ago

1.9.11

3 years ago

1.9.10

3 years ago

1.9.9

3 years ago

1.9.8

3 years ago

1.9.7

3 years ago

1.9.6

3 years ago

1.9.5

3 years ago

1.9.4

3 years ago

1.9.3

3 years ago

1.9.2

3 years ago

1.9.1

3 years ago

1.9.0

3 years ago

1.8.9

3 years ago

1.8.8

3 years ago

1.8.7

3 years ago

1.8.6

3 years ago

1.8.4

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.8

3 years ago

1.7.7

3 years ago

1.7.6

3 years ago

1.8.3

3 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.5

3 years ago

1.7.4

3 years ago

1.6.4

3 years ago

1.7.0

3 years ago

1.6.9

3 years ago

1.6.7

3 years ago

1.6.6

3 years ago

1.6.5

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.9

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.6

3 years ago

1.5.2

3 years ago

1.4.6

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.9

3 years ago

1.4.8

3 years ago

1.4.10

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago