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 | ): JSX.Element;
|
8 | export function useDropzone(options?: DropzoneOptions): DropzoneState;
|
9 |
|
10 | export interface DropzoneProps extends DropzoneOptions {
|
11 | children?(state: DropzoneState): JSX.Element;
|
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 |
|
68 | export type DropzoneState = DropzoneRef & {
|
69 | isFocused: boolean;
|
70 | isDragActive: boolean;
|
71 | isDragAccept: boolean;
|
72 | isDragReject: boolean;
|
73 | isFileDialogActive: boolean;
|
74 | acceptedFiles: readonly FileWithPath[];
|
75 | fileRejections: readonly FileRejection[];
|
76 | rootRef: React.RefObject<HTMLElement>;
|
77 | inputRef: React.RefObject<HTMLInputElement>;
|
78 | getRootProps: <T extends DropzoneRootProps>(props?: T) => T;
|
79 | getInputProps: <T extends DropzoneInputProps>(props?: T) => T;
|
80 | };
|
81 |
|
82 | export interface DropzoneRef {
|
83 | open: () => void;
|
84 | }
|
85 |
|
86 | export interface DropzoneRootProps extends React.HTMLAttributes<HTMLElement> {
|
87 | refKey?: string;
|
88 | [key: string]: any;
|
89 | }
|
90 |
|
91 | export interface DropzoneInputProps
|
92 | extends React.InputHTMLAttributes<HTMLInputElement> {
|
93 | refKey?: string;
|
94 | }
|
95 |
|
96 | type PropTypes = "multiple" | "onDragEnter" | "onDragOver" | "onDragLeave";
|
97 |
|
98 | export interface Accept {
|
99 | [key: string]: readonly string[];
|
100 | }
|