Skip to content

Commit

Permalink
[@mantine/dropzone] Add the getFilesFromEvent and validator props (#3053
Browse files Browse the repository at this point in the history
)

* Add the getFilesFromEvent and validator props

* Remove values from defaultProps

* Remove values from defaultProps
  • Loading branch information
mpinedami committed Dec 2, 2022
1 parent c92a349 commit 4b90fe3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/mantine-dropzone/src/Dropzone.tsx
@@ -1,5 +1,12 @@
import React from 'react';
import { useDropzone, FileRejection, Accept, FileWithPath } from 'react-dropzone';
import {
useDropzone,
FileRejection,
Accept,
FileWithPath,
DropEvent,
FileError,
} from 'react-dropzone';
import {
DefaultProps,
Selectors,
Expand Down Expand Up @@ -97,6 +104,12 @@ export interface DropzoneProps

/** Set to true to use the File System Access API to open the file picker instead of using an <input type="file"> click event, defaults to true */
useFsAccessApi?: boolean;

/** Use this to provide a custom file aggregator */
getFilesFromEvent?: (event: DropEvent) => Promise<Array<File | DataTransferItem>>;

/** Custom validation function. It must return null if there's no errors. */
validator?: <T extends File>(file: T) => FileError | FileError[] | null;
}

export const defaultProps: Partial<DropzoneProps> = {
Expand Down Expand Up @@ -144,6 +157,8 @@ export function _Dropzone(props: DropzoneProps) {
onFileDialogOpen,
preventDropOnDocument,
useFsAccessApi,
getFilesFromEvent,
validator,
...others
} = useComponentDefaultProps('Dropzone', defaultProps, props);

Expand Down Expand Up @@ -173,6 +188,8 @@ export function _Dropzone(props: DropzoneProps) {
onFileDialogOpen,
preventDropOnDocument,
useFsAccessApi,
getFilesFromEvent,
validator,
});

assignRef(openRef, open);
Expand Down

0 comments on commit 4b90fe3

Please sign in to comment.