项目作者: evenchange4

项目描述 :
Dropzone with render props built with react-dnd.
高级语言: JavaScript
项目地址: git://github.com/evenchange4/react-dnd-dropzone.git
创建时间: 2018-01-28T08:21:38Z
项目社区:https://github.com/evenchange4/react-dnd-dropzone

开源协议:MIT License

下载


react-dnd-dropzone

Dropzone with render props built with react-dnd.
This is a simple component for the use case of native files.

Travis
Codecov Status
npm package
npm downloads

prettier
license

Installation

  1. $ yarn add react-dnd-dropzone

Demo

Usage

  1. import Dropzone from 'react-dnd-dropzone';
  2. <Dropzone
  3. onDrop={files => console.log(files)}
  4. render={({ canDrop, isOver }) => (
  5. <div>
  6. Drop file here!
  7. <pre>{JSON.stringify({ canDrop, isOver })}</pre>
  8. </div>
  9. )}
  10. />;

With custom React-dnd context (PR #56 by @smallfx).

  1. import * as React from 'react';
  2. import { DragDropContext } from 'react-dnd';
  3. import HTML5Backend from 'react-dnd-html5-backend';
  4. import { DropTarget, Target } from 'react-dnd-dropzone';
  5. const HTML5DropContext = DragDropContext(HTML5Backend)(({ children }) => (
  6. <div>{children}</div>
  7. ));
  8. const Dropzone = DropTarget(Target);
  9. const App = () => (
  10. <HTML5DropContext>
  11. <Dropzone
  12. onDrop={files => console.log(files)}
  13. render={({ canDrop, isOver }) => (
  14. <div>
  15. <pre>{JSON.stringify({ canDrop, isOver }, null, 2)}</pre>
  16. </div>
  17. )}
  18. />
  19. </HTML5DropContext>
  20. );

API

  1. type DropzoneProps = {
  2. onDrop: (files: Array<File>, monitor: any) => void,
  3. render: ({ canDrop: boolean, isOver: boolean }) => React.Element<any>,
  4. accepts?: Array<string>,
  5. };

Development

Requirements

  • node >= 11.9.0
  • yarn >= 1.13.0
  1. $ yarn install --pure-lockfile
  2. $ yarn start

Test

  1. $ yarn run format
  2. $ yarn run eslint
  3. $ yarn run flow
  4. $ yarn run test:watch
  5. $ yarn run build

Publish

  1. $ npm version patch
  2. $ npm run changelog
  3. git commit & push

CONTRIBUTING

  • ⇄ Pull requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.
  • Pull requests must be accompanied by passing automated tests.

CHANGELOG

LICENSE

MIT: http://michaelhsu.mit-license.org