diff --git a/types/react-dropzone/index.d.ts b/types/react-dropzone/index.d.ts index dd0daec880..8225fa4ab8 100644 --- a/types/react-dropzone/index.d.ts +++ b/types/react-dropzone/index.d.ts @@ -1,22 +1,26 @@ // Type definitions for react-dropzone 3.13 // Project: https://github.com/okonet/react-dropzone -// Definitions by: Mathieu Larouche Dube , Ivo Jesus , Luís Rodrigues , Ben Bayard +// Definitions by: Mathieu Larouche Dube , +// Ivo Jesus , +// Luís Rodrigues , +// Ben Bayard , +// Karol Janyst // Definitions: https://github.com/Vooban/DefinitelyTyped // TypeScript Version: 2.3 import { CSSProperties, Component, DragEvent, InputHTMLAttributes } from "react"; declare namespace Dropzone { - interface ImageFile extends File { + export interface ImageFile extends File { preview?: string; } - interface DropFilesEventHandler { - (accepted: ImageFile[], rejected?: ImageFile[]): void; - >(event: E): void; - } + export type DropFileEventHandler = (acceptedOrRejected: ImageFile[], event: DragEvent) => void; + export type DropFilesEventHandler = (accepted: ImageFile[], rejected: ImageFile[], event: DragEvent) => void; - interface DropzoneProps extends InputHTMLAttributes { + type PickedAttributes = "accept" | "className" | "multiple" | "name" | "onClick" | "onDragStart" | "onDragEnter" | "onDragOver" | "onDragLeave" | "style"; + + export interface DropzoneProps extends Pick, PickedAttributes> { disableClick?: boolean; disablePreview?: boolean; preventDropOnDocument?: boolean; @@ -28,8 +32,8 @@ declare namespace Dropzone { activeStyle?: CSSProperties; rejectStyle?: CSSProperties; onDrop?: DropFilesEventHandler; - onDropAccepted?: DropFilesEventHandler; - onDropRejected?: DropFilesEventHandler; + onDropAccepted?: DropFileEventHandler; + onDropRejected?: DropFileEventHandler; onFileDialogCancel?: () => void; } } diff --git a/types/react-dropzone/react-dropzone-tests.tsx b/types/react-dropzone/react-dropzone-tests.tsx index cc1b2d03d8..d0477e3e4c 100644 --- a/types/react-dropzone/react-dropzone-tests.tsx +++ b/types/react-dropzone/react-dropzone-tests.tsx @@ -1,5 +1,7 @@ import * as React from "react"; -import * as Dropzone from "react-dropzone"; +import { DragEvent, SyntheticEvent} from "react"; +import Dropzone = require("react-dropzone"); +import { ImageFile } from "react-dropzone"; class Test extends React.Component { @@ -9,41 +11,43 @@ class Test extends React.Component { this.dz.open(); } - handleDropFile = (files: File[]) => {}; + handleDropFile = (files: ImageFile[], e: DragEvent) => {}; - handleDropFiles = (accepted: File[], rejected?: File[]) => {}; + handleDropFiles = (accepted: File[], rejected: File[], event: DragEvent) => {}; + + handleDefault = (e: SyntheticEvent) => {} + + handleFileDialog = () => {} render() { return (
{ this.dz = node } } - onClick={ (e: any) => { e.preventDefault(); } } - onDrop={ this.handleDropFiles } - onDropAccepted={ this.handleDropFile } - onDropRejected={ this.handleDropFile } - onDragStart={ (e: any) => { e.preventDefault(); } } - onDragEnter={ (e: any) => { e.preventDefault(); } } - onDragLeave={ (e: any) => { e.preventDefault(); } } - onFileDialogCancel={ () => undefined } + ref={(node) => { this.dz = node }} + onClick={this.handleDefault} + onDrop={this.handleDropFiles} + onDropAccepted={this.handleDropFile } + onDropRejected={this.handleDropFile } + onDragStart={this.handleDefault} + onDragEnter={this.handleDefault} + onDragLeave={this.handleDefault} + onFileDialogCancel={this.handleFileDialog} style={{ borderStyle: "dashed" }} activeStyle={{ borderStyle: "dotted" }} rejectStyle={{ borderStyle: "dotted" }} className="regular" activeClassName="active" rejectClassName="reject" - minSize={ 2000 } - maxSize={ Infinity } + minSize={2000} + maxSize={Infinity} disablePreview disableClick - multiple={ false } + multiple={false} accept="*.png" name="dropzone" - inputProps={ { id : "dropzone" } } + inputProps={{ id : "dropzone" }} />
- - ); } }