Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/dropzone] Add the getFilesFromEvent and validator props #3053

Merged
merged 3 commits into from Dec 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/mantine-dropzone/src/Dropzone.tsx
@@ -1,5 +1,12 @@
import React from 'react';
mpinedami marked this conversation as resolved.
Show resolved Hide resolved
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