Skip to content

Commit 4216fea

Browse files
committed
Add mts types and update readme
1 parent 33053b8 commit 4216fea

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
11
# react-dropzone-esm
2+
3+
`react-dropzone-esm` is a fork of [react-dropzone](https://github.com/react-dropzone/react-dropzone).
4+
The purpose of the fork is to provide a version of `react-dropzone` that is compatible with
5+
modern frameworks which use ES modules (Remix v2, newer versions of Next.js, Vite).
6+
7+
The package provides esm and cjs bundles. It is compatible both with modern build tools
8+
like Remix v2 and with older tools like Webpack 4.
9+
10+
## Differences from react-dropzone
11+
12+
- ESM and CJS bundles
13+
- Properly configured `package.json` exports
14+
- ESM bundle is shipped with `.mjs` extension
15+
- Unused files are removed from the published package (docs, logos, etc.)
16+
17+
Note that it is not planned to fix any bugs or add new features to this package.
18+
The only purpose of this package is to provide a version of `react-dropzone` that
19+
is compatible with modern frameworks. Source code of `react-dropzone` library is not modified
20+
in any way.
21+
22+
## Documentation
23+
24+
Documentation was removed from the forked package to simplify maintenance. [Please refer to the original package for documentation](https://react-dropzone.js.org/).

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"exports": {
99
".": {
1010
"import": {
11-
"types": "./types/react-dropzone.d.ts",
11+
"types": "./types/react-dropzone.d.mts",
1212
"default": "./dist/esm/index.mjs"
1313
},
1414
"require": {

types/react-dropzone.d.mts

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

0 commit comments

Comments
 (0)