| 1 |
import * as React from "react"; |
| 2 |
|
| 3 |
import { FileWithPath } from "file-selector"; |
| 4 |
export { FileWithPath }; |
| 5 |
export default function Dropzone( |
| 6 |
props: DropzoneProps & React.RefAttributes<DropzoneRef> |
| 7 |
): React.ReactElement; |
| 8 |
export function useDropzone(options?: DropzoneOptions): DropzoneState; |
| 9 |
|
| 10 |
export interface DropzoneProps extends DropzoneOptions { |
| 11 |
children?(state: DropzoneState): React.ReactElement; |
| 12 |
} |
| 13 |
|
| 14 |
export enum ErrorCode { |
| 15 |
FileInvalidType = "file-invalid-type", |
| 16 |
FileTooLarge = "file-too-large", |
| 17 |
FileTooSmall = "file-too-small", |
| 18 |
TooManyFiles = "too-many-files", |
| 19 |
} |
| 20 |
|
| 21 |
export interface FileError { |
| 22 |
message: string; |
| 23 |
code: ErrorCode | string; |
| 24 |
} |
| 25 |
|
| 26 |
export interface FileRejection { |
| 27 |
file: FileWithPath; |
| 28 |
errors: readonly FileError[]; |
| 29 |
} |
| 30 |
|
| 31 |
export type DropzoneOptions = Pick<React.HTMLProps<HTMLElement>, PropTypes> & { |
| 32 |
accept?: Accept; |
| 33 |
minSize?: number; |
| 34 |
maxSize?: number; |
| 35 |
maxFiles?: number; |
| 36 |
preventDropOnDocument?: boolean; |
| 37 |
noClick?: boolean; |
| 38 |
noKeyboard?: boolean; |
| 39 |
noDrag?: boolean; |
| 40 |
noDragEventsBubbling?: boolean; |
| 41 |
disabled?: boolean; |
| 42 |
onDrop?: <T extends File>( |
| 43 |
acceptedFiles: T[], |
| 44 |
fileRejections: FileRejection[], |
| 45 |
event: DropEvent |
| 46 |
) => void; |
| 47 |
onDropAccepted?: <T extends File>(files: T[], event: DropEvent) => void; |
| 48 |
onDropRejected?: (fileRejections: FileRejection[], event: DropEvent) => void; |
| 49 |
getFilesFromEvent?: ( |
| 50 |
event: DropEvent |
| 51 |
) => Promise<Array<File | DataTransferItem>>; |
| 52 |
onFileDialogCancel?: () => void; |
| 53 |
onFileDialogOpen?: () => void; |
| 54 |
onError?: (err: Error) => void; |
| 55 |
validator?: <T extends File>( |
| 56 |
file: T |
| 57 |
) => FileError | readonly FileError[] | null; |
| 58 |
useFsAccessApi?: boolean; |
| 59 |
autoFocus?: boolean; |
| 60 |
}; |
| 61 |
|
| 62 |
export type DropEvent = |
| 63 |
| React.DragEvent<HTMLElement> |
| 64 |
| React.ChangeEvent<HTMLInputElement> |
| 65 |
| DragEvent |
| 66 |
| Event |
| 67 |
| Array<FileSystemFileHandle>; |
| 68 |
|
| 69 |
export type DropzoneState = DropzoneRef & { |
| 70 |
isFocused: boolean; |
| 71 |
isDragActive: boolean; |
| 72 |
isDragAccept: boolean; |
| 73 |
isDragReject: boolean; |
| 74 |
isDragGlobal: boolean; |
| 75 |
isFileDialogActive: boolean; |
| 76 |
acceptedFiles: readonly FileWithPath[]; |
| 77 |
fileRejections: readonly FileRejection[]; |
| 78 |
rootRef: React.RefObject<HTMLElement>; |
| 79 |
inputRef: React.RefObject<HTMLInputElement>; |
| 80 |
getRootProps: <T extends DropzoneRootProps>(props?: T) => T; |
| 81 |
getInputProps: <T extends DropzoneInputProps>(props?: T) => T; |
| 82 |
}; |
| 83 |
|
| 84 |
export interface DropzoneRef { |
| 85 |
open: () => void; |
| 86 |
} |
| 87 |
|
| 88 |
export interface DropzoneRootProps extends React.HTMLAttributes<HTMLElement> { |
| 89 |
refKey?: string; |
| 90 |
[key: string]: any; |
| 91 |
} |
| 92 |
|
| 93 |
export interface DropzoneInputProps |
| 94 |
extends React.InputHTMLAttributes<HTMLInputElement> { |
| 95 |
refKey?: string; |
| 96 |
} |
| 97 |
|
| 98 |
type PropTypes = "multiple" | "onDragEnter" | "onDragOver" | "onDragLeave"; |
| 99 |
|
| 100 |
export interface Accept { |
| 101 |
[key: string]: readonly string[]; |
| 102 |
} |