Skip to content

Commit 9956c32

Browse files
Merge pull request #144 from etienne-lambert/master
Adding typescript definitions
2 parents bfd6fb4 + 510735a commit 9956c32

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
],
1919
"peerDependencies": {
2020
"react-dom": ">15.0.1",
21-
"react": ">15.0.1"
21+
"react": ">15.0.1",
22+
"@types/dropzone": ">5.0.2"
2223
},
2324
"devDependencies": {
2425
"babel-core": "^6.26.0",
@@ -59,5 +60,6 @@
5960
]
6061
},
6162
"main": "dist/react-dropzone.js",
62-
"standalone": "React-Dropzone"
63+
"standalone": "React-Dropzone",
64+
"types": "typescript/types.d.ts"
6365
}

typescript/types.d.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import * as React from 'react';
2+
import * as Dropzone from 'dropzone';
3+
4+
/* type aliases for callbacks */
5+
type VoidCallback = () => any;
6+
type InitCallback = (dropzone: Dropzone) => any;
7+
type DragEventCallback = (event: DragEvent) => any;
8+
type FileCallback = (file: Dropzone.DropzoneFile) => any;
9+
type FileArrayCallback = (files: Dropzone.DropzoneFile[]) => any;
10+
type ThumbnailCallback = (file: Dropzone.DropzoneFile, dataUrl: string) => any;
11+
type ErrorCallback = (file: Dropzone.DropzoneFile, message: string | Error) => any;
12+
type ErrorMultipleCallback = (files: Dropzone.DropzoneFile[], message: string | Error) => any;
13+
type UploadProgressCallback = (file: Dropzone.DropzoneFile, progress: number, bytesSent: number) => any;
14+
type TotalUploadProgressCallback = (totalProgress: number, totalBytes: number, totalBytesSent: number) => any;
15+
type SendingCallback = (file: Dropzone.DropzoneFile, xhr: XMLHttpRequest, formData: FormData) => any;
16+
type SendingMultipleCallback = (files: Dropzone.DropzoneFile[], xhr: XMLHttpRequest, formData: FormData) => any;
17+
18+
/* handlers based on ts definitions for Dropzone.js (@types/dropzone) */
19+
export declare interface DropzoneComponentHandlers {
20+
init?: InitCallback | InitCallback[];
21+
22+
// All of these receive the event as first parameter:
23+
drop?: DragEventCallback | DragEventCallback[];
24+
dragstart?: DragEventCallback | DragEventCallback[];
25+
dragend?: DragEventCallback | DragEventCallback[];
26+
dragenter?: DragEventCallback | DragEventCallback[];
27+
dragover?: DragEventCallback | DragEventCallback[];
28+
dragleave?: DragEventCallback | DragEventCallback[];
29+
paste?: DragEventCallback | DragEventCallback[];
30+
31+
reset?: VoidCallback | VoidCallback[];
32+
33+
addedfile?: FileCallback | FileCallback[];
34+
addedfiles?: FileArrayCallback | FileArrayCallback[];
35+
removedfile?: FileCallback | FileCallback[];
36+
thumbnail?: ThumbnailCallback | ThumbnailCallback[];
37+
38+
error?: ErrorCallback | ErrorCallback[];
39+
errormultiple?: ErrorMultipleCallback | ErrorMultipleCallback[];
40+
41+
processing?: FileCallback | FileCallback[];
42+
processingmultiple?: FileArrayCallback | FileArrayCallback[];
43+
44+
uploadprogress?: UploadProgressCallback | UploadProgressCallback[];
45+
totaluploadprogress?: TotalUploadProgressCallback | TotalUploadProgressCallback[];
46+
47+
sending?: SendingCallback | SendingCallback[];
48+
sendingmultiple?: SendingMultipleCallback | SendingMultipleCallback[];
49+
50+
success?: FileCallback | FileCallback[];
51+
successmultiple?: FileArrayCallback | FileArrayCallback[];
52+
53+
canceled?: FileCallback | FileCallback[];
54+
canceledmultiple?: FileArrayCallback | FileArrayCallback[];
55+
56+
complete?: FileCallback | FileCallback[];
57+
completemultiple?: FileArrayCallback | FileArrayCallback[];
58+
59+
maxfilesexceeded?: FileCallback | FileCallback[];
60+
maxfilesreached?: FileArrayCallback | FileArrayCallback[];
61+
62+
queuecomplete?: VoidCallback | VoidCallback[];
63+
}
64+
65+
export declare interface DropzoneComponentConfig {
66+
showFiletypeIcon?: boolean;
67+
iconFiletypes?: string[];
68+
postUrl?: string;
69+
dropzoneSelector?: string;
70+
}
71+
72+
interface DropzoneComponentProps {
73+
djsConfig?: Dropzone.DropzoneOptions;
74+
config?: DropzoneComponentConfig;
75+
eventHandlers?: DropzoneComponentHandlers;
76+
className?: string;
77+
action?: string;
78+
}
79+
80+
export declare class DropzoneComponent extends React.Component<DropzoneComponentProps, {}> {
81+
}

0 commit comments

Comments
 (0)