Giter Club home page Giter Club logo

react-dropzone's People

Contributors

anuragces avatar appleboy avatar chrisbuttery avatar dimitarchristoff avatar donavon avatar frankwallis avatar glennreyes avatar greenkeeper[bot] avatar jonathanhudak avatar maffoobristol avatar morijenab avatar mwolson avatar nfantone avatar nuc avatar okonet avatar paramaggarwal avatar rikschennink avatar robmclarty avatar rolandjitsu avatar rxmarbles avatar saravieira avatar strmer15 avatar subtirelumihail avatar tikotzky avatar tmarshall avatar tobilen avatar toshipon avatar vlindhol avatar voronianski avatar wmartins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-dropzone's Issues

Make styles optional?

This looks like a great component I'd use someday. Could you make the styles optional? If I were to use this in any real project, I'd want to control the styling myself.

Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs

I tried to this component but end up with error:
image

Here is my code:

var Dropzone = require('react-dropzone');

var PfUpload = React.createClass({
    render: function () {

        var style = {
            backgroundImage: "url(" + this.props.img + ")",
            position: 'relative'
        };

        if(this.props.editing) {
            return (
                <div id="pf-upload" style={style}>
                    <Dropzone onDrop={this._onDrop} size={42}>
                    </Dropzone>
                </div>
            );
        }

        return (
            <div id="pf-upload" style={style}>
            </div>
        );
    },

    _onDrop: function(file) {
        console.log(file);
    }
});

module.exports = PfUpload;

brackets dont match

Hi,
Is it only me or there are really unbalanced brackets in sample code.
And how on earth it is working here on github in read.me file?

I don't even dare to ask about the magic that lets HTML in render function to return successfully (no quoting?).

var component = React.createClass({

  fileHandler: function(file) {
      uploadScript(file, uploadURL, function(err, res) {
        if (res.code == 200) {console.log("Upload success.")}
      });
    }
  },

  render: function() {
    return (
      <div>
        <Dropzone handler={this.fileHandler} size={200} message="Drag and drop a file here"/>
      </div>
    );
  }
});

onDrop does not fire for same filename with different content

Steps to reproduce:

  1. Choose a file A from file system in dropzone
  2. onDrop does fire, the file eventuanaly sent
  3. Modify body of the file A
  4. Choose the same file
  5. onDrop does not fire since it mapped to onChange form's event

Could fix if by adding the following line to onClick function.

React.findDOMNode(this.refs.fileInput).value = null;

Dropping anywhere outside of dropzone causes default browser action

When having a dropzone component on the page, but dropping a file outside it, browser is performing a default action (like, displaying an image or downloading a file etc.) for this file. This is very annoying IMO. I think better UX would be to prevent the default action on the whole document when dropzone is present on the page. I'm not sure if this might cause some inconsistent behavior with other components, but I don't believe so. Anyway, I think this should be an opt-out prop (enabled by default).

this.state may not exist

In your example code this.state may be null causing the this.state.files to error out on the console.

                {this.state.files ? <div>
                    <h>Uploading {files.length} files...</h>
                </div> : null}

Allow custom attributes for file input

For the file input, I'd like to be able to not have "multiple" set to true, and to configure the "accept" attribute. It would be nice to pass those attributes down in props.

Regression in 3.2.0 / 3.2.1 - "ReferenceError: document is not defined"

I encountered this in an isomorphic app, I'm importing dropzone at the top of a component:

import Dropzone from 'react-dropzone';

However, when the Express server is executed, it returns ReferenceError: document is not defined for the following line:

var supportMultiple = document && document.createElement ? 'multiple' in document.createElement('input') : true;

I haven't looked at the changes that were introduced to know what the best solution is, however, since document doesn't exist in node, maybe the assignment to supportMultiple could be done in componentDidMount instead.

Moving back to =3.1.0 works for now

Using with gulp and browserify.

Newbie here guys. I could not get the component to render and it is showing me this error.
screen shot 2015-10-09 at 8 59 40 pm

Below are my codes and it was working fine until I added the component in App.js.
screen shot 2015-10-09 at 8 58 14 pm 2

Any help will be appreciated!

Upload example

Hi,
Could you create additional example how to use react-dropzone to upload file?

Remove inline styling

Please get rid of forced inline width and height styling, styling should be left to css.

Same with DragActive, it should just add / remove a class

var style = this.props.style || {
  width: this.props.size || 100,  //get rid of these two lines please
  height: this.props.size || 100,  //get rid of these two lines please
  borderStyle: this.state.isDragActive ? 'solid' : 'dashed'
};

Possible typo in onDragEnter

I'm getting errors on this line in the onDragEnter function:

var dataTransferItems = Array.prototype.slice.call(e.dataTransfer ? e.dataTransfer.items : e.target.files);

because e.dataTransfer.items is undefined. I believe this is supposed to read e.dataTransfer.files to match up with the rest of the usages.

For reference here's the mozilla documentation on the DataTransfer object: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer

Active class disappears when drag over children

Looks like it's this issue. If I have time I'll open a PR to fix it. We're causing this with just the following code

<Dropzone className='dropzone-component' activeClassName='dropzone-component__active'
  onDrop={this.onUploadHero} size={150}>
  Upload Background Image
</Dropzone>

Upgrade to React 0.14 and release a new major version

Discussion already has been starter in #77 but I think it's easier to track as a separate issue.

My suggestion would be

  1. Upgrade the code to React 0.14
  2. Release a new major version 3.0 of the package
  3. Leave the 2.x as a maintenance branch for React 0.13 support

WYT?

Supporting Radium

Hi, while looking at the source code, it seems like the module may not fully support Radium yet, mainly due to this restriction:

style: React.PropTypes.object,
activeStyle: React.PropTypes.object,

For Radium can accept an array of style objects and merge them. Would you be willing to accept a PR which would fix this?

string style ref causes ref error in certain implementations

The legacy (string) style of ref is causing a ref error when implementing in a nested and component-passed-as-props fashion. Updating to the callback style of ref fixes the error:

change line 115 to: var fileInput = this._fileInput;

change line 180 to: ref={_ => this._fileInput = _}

I tried to make a pull request but couldn't.

README misleading

If no style or className properties are defined, the style object will default to the width and height properties (or 100px if they aren't defined) along with a borderStyle of "solid" or "dashed" depending on if drag actions are taking place.

It doesn't seem you can actually specify width or height props:

  propTypes: {
    onDrop: React.PropTypes.func.isRequired,
    size: React.PropTypes.number,
    style: React.PropTypes.object,
    supportClick: React.PropTypes.bool,
    accept: React.PropTypes.string,
    multiple: React.PropTypes.bool
  },

this.props.width and this.props.height aren't used at all in the source.

As a solution I've passed style={{width: N, height: N}} but by doing so that doesn't set the borderStyle appropriately. Since I've supplied a style prop it is ignoring the borderStyle here.

var style = this.props.style || {
    width: this.props.size || 100,
    height: this.props.size || 100, 
    borderStyle: this.state.isDragActive ? 'solid' : 'dashed'
};

I guess that is expected based on the quoted section of the README above but I don't think it's preferable since it's not really possible to recreate the borderStyle when dragging over using style.

Also the docs don't mention the supportClick, accept, or multiple properties.

Drag & Drop From Application Non-Functional in OS/X / Chrome

To test this, pop open the demo in Chrome and head over to an OS/X application like iTunes.

Select one or more files (I am using 3 for the sake of testing) and drag them into the drop area. The hover event will fire, but onDrop never occurs and the files are never actually uploaded.

Validating files and disabling preview

How it's supposed to validate, for example, file size? Or separate valid files from invalid ones?

How about introducing smth like validate callback? We can pass each dropped file there, split them by returned result and then pass corresponding arrays to onDropAccepted and onDropRejected.


Also, it's said "We might want to disable the preview creation to support big files", but there is no way to detect whether file is actually "big". So we should either disable previews at all, or create previews for everything. Maybe, it's worth to add another function to check whether preview for particular file should be created?


And, shouldn't it be this.props.disablePreview here?

Using Script Directlly? (without browserify)

I'm testing a prototype and wanted to include this module directly in between <script> tags like so:

<script type="text/jsx">

var Dropzone = React.createClass({

          getDefaultProps: function() {
            return {
              disableClick: false,
              multiple: true
            };
          },

          getInitialState: function() {
            return {
              isDragActive: false
            };
          },

 // etc ..

I'm also including React in my footer scripts

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>

However, this doesn't seem to be working. I get a console error around this line. Something to do with the 'style' line:

<input
                  type='file'
                  ref='fileInput'
                  style={{ display : 'none' }}
                  multiple={this.props.multiple}
                  onChange={this.onDrop}

it says unexpected :

Is it not possible to implement this way?

Pre-compile to JS from JSX

Hello,

When installing with npm the index.js is still in jsx format. I'd love to use it directly without having to compile it as a 3p lib within my application. Could you compile to JS as part of the build?

A bit new to react so if there is a better way I'd love to know!
Thanks.

multiple option with false value through props not working in 2.x

Hi,
look like 2.x issue with curly bracket as i got somewhere in commits that for disabling multiple attribute as below:
multiple={false}

The above string works perfect but below string not working
multiple="false"
multiple={this.props.multiple}

so looks like its curly bracket issue? below code does not throw error but also does not disable multiple upload.

return (
            <div>
                {this.state.files.length > 0 ? <div>
                <div>{this.state.files.map((file) => <img src={file.preview} style={{width:100}} /> )}</div>
                </div> : <Dropzone ref={this.props.id} onDrop={this.onDrop} multiple={this.props.multiple}>
                    <div>Try dropping some files here, or click to select files to upload.</div>
                </Dropzone>
                }
            </div>
        );

Export the transpiled JS instead of the ES6

Related to #14

Currently, with the latest published version on npm, I cannot require and use this module (I get the following error: Cannot find module 'reactify' from 'node_modules/react-dropzone').

Looking more closely, it appears the reactify Browserify transform is listed in the package.json (recently changed to babelify on master branch, but the same issue persists).

This error is then caused because reactify (now babelify) is not listed in the dependencies section anywhere, so npm install does not install it and thus Browserify can't run the transform.

This in and of itself is an issue, but the bigger issue is that the module is requiring the consumer to perform any transpilation. Instead, the source should be transpiled before publishing to npm so that no extra build step is required for the consumer of the library.

See this StackOverflow question for more information; the general guidance is to create a separate location for your compiled code (which is optionally added to .gitignore), add your source code to .npmignore, and then add the compile step to the prepublish hook in your package.json to automate the whole thing.


Edit: In my original post I assumed Babel was being used to transpile the core component source, but I see now it is only used for the demo page. In that case the demo page should have it's own package.json which handles this so the core project can remain pure—otherwise this issue is going to persist.

adding a className breaks JSX compile

for some reason if I use <Dropzone .../> without a className, everything works fine, but adding my own <Dropzone className="dropzone" ... /> breaks JSX compile because of

Error: Invariant Violation: The `style` prop expects a mapping from style properties to values, not a string.

You'll have to use something like this:

...
var className = "dropzone",
    style = DropzoneStyle;

if (this.props.className) {
  className = this.props.className;
  style = false;
}

return (<div ... className={className} style={style} ...>
  ...
</div>);

Manually trigger file prompt

Hi, I need to disable the click on entire dropzone box (still allowing to drop files), and I need to add a trigger to open the file prompt.

What do you think about creating a function open, that does same thing as onClick (this.refs.fileInput.getDOMNode().click()), but that can be called from outside (using this.ref.dropzoneComponent.open() for example)?

I will submit a PR for that!

Enhancement ideas

As this project is picking up steam, lets plan where we should take it next.

[Updated items as per suggestions in the comments below]

  • Add tests
  • disabled state

Add tests

Looking at all regressions produced by latest PRs I feel that we should focus on stability now. This should include adding ESLint and Unit tests.

  • Add linting with ESLint
  • Add unit tests

Handle folder drops recursively

When Dropping in a folder of files it treats the folder a 1 file. It would be nice if files and sub folders could be represented when one single folder is dropped in the drop zone. I'm not sure if this is a limitation of the HTML5 input file type or not.

Input props

Input is standart html tag. There should be an option for passing props to input element or option for passing custom input element which you can clone/extend in DropZone component.

README uses some mystery variables

The README.md shows

  fileHandler: function(file) {
    uploadScript(file, uploadURL, function(err, res) {
      if (res.code == 200) {console.log("Upload success.")}
    });
  },

but makes no mention of what uploadScript is supposed to do, or where uploadURL comes from. (just a console.log(file, uploadURL) throws an error, suggesting it doesn't actually exist for use inside the fileHandler, which means this example can't be used with the code as-is)

Active class doesn't appear in Firefox

I wasn't able to diagnose the issue's root cause, but I can't get the active class to appear at all. Maybe it's because you need to preventDefault on the nativeEvent as well? Firefox seems to have strict rules about what counts as a valid drop target.

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.