Gathering detailed insights and metrics for react-dropzone-component
Gathering detailed insights and metrics for react-dropzone-component
Gathering detailed insights and metrics for react-dropzone-component
Gathering detailed insights and metrics for react-dropzone-component
npm install react-dropzone-component
85
Supply Chain
93.2
Quality
75.4
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,001 Stars
227 Commits
153 Forks
25 Watching
14 Branches
25 Contributors
Updated on 10 Oct 2024
Minified
Minified + Gzipped
JavaScript (99.73%)
CSS (0.2%)
HTML (0.07%)
Cumulative downloads
Total Downloads
Last day
0.7%
3,525
Compared to previous day
Last week
-2.1%
17,852
Compared to previous week
Last month
5.6%
75,264
Compared to previous month
Last year
5.7%
934,654
Compared to previous year
:warning: Maintainers wanted! I haven't been able to keep this component up to date and would gladly hand the keys over to someone who is.
A Dropzone component for ReactJS, allowing users to "drag and drop" files into an upload area. The component uses the battle-tested Dropzone.js to provide a cross-browser-compatible upload component.
You can see a demo of the uploader with minimal configuration here.
The component is initialized with a configuration object. Optional are a list of event handlers and a configuration object for dropzone.js.
If you are using one of the many module solutions, you can simply install and require this component like shown below. The package's main entry point is lib/dropzone.js
, which gives you all the dropzone components. If you're rolling with ES6/ES2015, feel free to use src/dropzone.js
. If you don't want any trouble at all, just add dist/dropzone.min.js
as a script to your app and use <DropzoneComponent />
.
:warning: Ensure that React and ReactDOM are global variables, so that they can be reached on
window.React
orglobal.React
. Many fancy boilerplates are overly fancy and somehow remove those variables.If you are using a fancy boilerplate, you might want to require the lib directly, by using
import DropzoneComponent from 'react-dropzone-component/lib/react-dropzone'
orrequire('react-dropzone-component/lib/react-dropzone')
.
Please ensure that you also include two required CSS files: node_modules/react-dropzone-component/styles/filepicker.css
and node_modules/dropzone/dist/min/dropzone.min.css
. There are currently a bunch of good ways to combine and process CSS in React, so I'll leave it to you to choose whatever method is best for you - the component does not automatically load CSS.
To use this component without React-DOM, use version
^0.6
- from0.7
on, we need it.
npm install react-dropzone-component
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import DropzoneComponent from 'react-dropzone-component'; 4 5var componentConfig = { 6 iconFiletypes: ['.jpg', '.png', '.gif'], 7 showFiletypeIcon: true, 8 postUrl: '/uploadHandler' 9}; 10 11ReactDOM.render( 12 <DropzoneComponent config={componentConfig} 13 eventHandlers={eventHandlers} 14 djsConfig={djsConfig} />, 15 document.getElementById('content') 16);
The configuration allows you to disable the display of CSS file type icons and to set the URL to which uploads should be posted.
There are a bunch of operations that might require accessing the dropzone object, especially when wanting to call dropzone methods.
To get said object, use the init
event, whose callback will receive a reference to the dropzone object as a parameter.
1var myDropzone; 2 3function initCallback (dropzone) { 4 myDropzone = dropzone; 5} 6 7function removeFile () { 8 if (myDropzone) { 9 myDropzone.removeFile(); 10 } 11}
If you want to use this component without posting automatically to a URL but instead do the posting yourself, then you can just fill the postUrl
option with a meaningless string and handle the displaying of progress by yourself using the provided event handlers. To see this in action, check out the examples
!
1var componentConfig = { postUrl: 'no-url' }; 2var djsConfig = { autoProcessQueue: false } 3var eventHandlers = { addedfile: (file) => console.log(file) } 4 5ReactDOM.render( 6 <DropzoneComponent config={componentConfig} 7 eventHandlers={eventHandlers} 8 djsConfig={djsConfig} />, 9 document.getElementById('content') 10);
The djsconfig property is compatible with all of the options in the official DropzoneJS documentation. Updating the preview template can be done as follows:
1var ReactDOMServer = require('react-dom/server');
2
3var djsConfig = {
4 previewTemplate: ReactDOMServer.renderToStaticMarkup(
5 <div className="dz-preview dz-file-preview">
6 <div className="dz-details">
7 <div className="dz-filename"><span data-dz-name="true"></span></div>
8 <img data-dz-thumbnail="true" />
9 </div>
10 <div className="dz-progress"><span className="dz-upload" data-dz-uploadprogress="true"></span></div>
11 <div className="dz-success-mark"><span>✔</span></div>
12 <div className="dz-error-mark"><span>✘</span></div>
13 <div className="dz-error-message"><span data-dz-errormessage="true"></span></div>
14 </div>
15 )
16}
To add custom parameters to your request, add a params
property to your Dropzone.js configuration object.
1var djsConfig = { 2 addRemoveLinks: true, 3 params: { 4 myParameter: "I'm a parameter!" 5 } 6}; 7 8var componentConfig = { 9 postUrl: '/uploadHandler' 10}; 11 12ReactDOM.render(<DropzoneComponent config={componentConfig} djsConfig={djsConfig} />, document.getElementById('content'));
In case you need to customize the dropzone area, you may pass a jQuery compatible selector in the config object.
1var componentConfig = { 2 postUrl: '/uploadHandler', 3 dropzoneSelector: 'body', 4}; 5 6ReactDOM.render( 7 <DropzoneComponent config={componentConfig} />, 8 document.getElementById('content'), 9);
The code above will use the entire page body
as the dropzone area.
Callbacks can be provided in an object literal.
1var eventHandlers = { 2 // This one receives the dropzone object as the first parameter 3 // and can be used to additional work with the dropzone.js 4 // object 5 init: null, 6 // All of these receive the event as first parameter: 7 drop: callbackArray, 8 dragstart: null, 9 dragend: null, 10 dragenter: null, 11 dragover: null, 12 dragleave: null, 13 // All of these receive the file as first parameter: 14 addedfile: simpleCallBack, 15 removedfile: null, 16 thumbnail: null, 17 error: null, 18 processing: null, 19 uploadprogress: null, 20 sending: null, 21 success: null, 22 complete: null, 23 canceled: null, 24 maxfilesreached: null, 25 maxfilesexceeded: null, 26 // All of these receive a list of files as first parameter 27 // and are only called if the uploadMultiple option 28 // in djsConfig is true: 29 processingmultiple: null, 30 sendingmultiple: null, 31 successmultiple: null, 32 completemultiple: null, 33 canceledmultiple: null, 34 // Special Events 35 totaluploadprogress: null, 36 reset: null, 37 queuecomplete: null 38}
To provide a single callback, simply override one of these events with your function reference. If you want to provide multiple callbacks, simply provide an array with your function references.
1var callbackArray = [ 2 function () { 3 console.log('Look Ma, I\'m a callback in an array!'); 4 }, 5 function () { 6 console.log('Wooooow!'); 7 } 8]; 9 10var simpleCallBack = function () { 11 console.log('I\'m a simple callback'); 12};
This React Component is a wrapper around Dropzone.js - meaning that Dropzone.js is not aware of the React component life cycle. When you update the component's properties, we will use a copy of jQuery's extend
method (see documentation) to merge new options into the Dropzone's properties object.
If you want to fundamentally change things about your dropzone, we recommend that you either modify the Dropzone object directly or destroy and recreate the component.
This component comes with a small server example. To try it out, simply run npm install
and npm start
from the example
folder. Visit http://localhost:8000/example/
to see the uploads working.
To check out the (super small) source code for this simple upload-accepting server, check out example/src-server/
and example/server.js
. The component works with any server infrastructure, though!
MIT. For details, please consult README.md
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 8/22 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
96 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More