mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 12:11:47 +00:00
Improve types for handlers
This commit is contained in:
Vendored
+13
-9
@@ -1,22 +1,26 @@
|
||||
// Type definitions for react-dropzone 3.13
|
||||
// Project: https://github.com/okonet/react-dropzone
|
||||
// Definitions by: Mathieu Larouche Dube <https://github.com/matdube>, Ivo Jesus <https://github.com/LynxEyes>, Luís Rodrigues <https://github.com/goblindegook>, Ben Bayard <https://github.com/benbayard>
|
||||
// Definitions by: Mathieu Larouche Dube <https://github.com/matdube>,
|
||||
// Ivo Jesus <https://github.com/LynxEyes>,
|
||||
// Luís Rodrigues <https://github.com/goblindegook>,
|
||||
// Ben Bayard <https://github.com/benbayard>,
|
||||
// Karol Janyst <https://github.com/LKay>
|
||||
// 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;
|
||||
<E extends DragEvent<HTMLDivElement>>(event: E): void;
|
||||
}
|
||||
export type DropFileEventHandler = (acceptedOrRejected: ImageFile[], event: DragEvent<HTMLDivElement>) => void;
|
||||
export type DropFilesEventHandler = (accepted: ImageFile[], rejected: ImageFile[], event: DragEvent<HTMLDivElement>) => void;
|
||||
|
||||
interface DropzoneProps extends InputHTMLAttributes<HTMLDivElement> {
|
||||
type PickedAttributes = "accept" | "className" | "multiple" | "name" | "onClick" | "onDragStart" | "onDragEnter" | "onDragOver" | "onDragLeave" | "style";
|
||||
|
||||
export interface DropzoneProps extends Pick<InputHTMLAttributes<HTMLDivElement>, 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<HTMLDivElement>) => {};
|
||||
|
||||
handleDropFiles = (accepted: File[], rejected?: File[]) => {};
|
||||
handleDropFiles = (accepted: File[], rejected: File[], event: DragEvent<HTMLDivElement>) => {};
|
||||
|
||||
handleDefault = (e: SyntheticEvent<HTMLDivElement>) => {}
|
||||
|
||||
handleFileDialog = () => {}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Dropzone
|
||||
ref={(node) => { 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" }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user