From 4b90fe3dc607ba27ec024cc4874feef795ad97b6 Mon Sep 17 00:00:00 2001
From: Maynor Pineda <104800424+mpinedami@users.noreply.github.com>
Date: Fri, 2 Dec 2022 02:00:42 -0600
Subject: [PATCH] [@mantine/dropzone] Add the getFilesFromEvent and validator
props (#3053)
* Add the getFilesFromEvent and validator props
* Remove values from defaultProps
* Remove values from defaultProps
---
src/mantine-dropzone/src/Dropzone.tsx | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/mantine-dropzone/src/Dropzone.tsx b/src/mantine-dropzone/src/Dropzone.tsx
index a5a33b993fd..22d2c7bb8ec 100644
--- a/src/mantine-dropzone/src/Dropzone.tsx
+++ b/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,
@@ -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 click event, defaults to true */
useFsAccessApi?: boolean;
+
+ /** Use this to provide a custom file aggregator */
+ getFilesFromEvent?: (event: DropEvent) => Promise>;
+
+ /** Custom validation function. It must return null if there's no errors. */
+ validator?: (file: T) => FileError | FileError[] | null;
}
export const defaultProps: Partial = {
@@ -144,6 +157,8 @@ export function _Dropzone(props: DropzoneProps) {
onFileDialogOpen,
preventDropOnDocument,
useFsAccessApi,
+ getFilesFromEvent,
+ validator,
...others
} = useComponentDefaultProps('Dropzone', defaultProps, props);
@@ -173,6 +188,8 @@ export function _Dropzone(props: DropzoneProps) {
onFileDialogOpen,
preventDropOnDocument,
useFsAccessApi,
+ getFilesFromEvent,
+ validator,
});
assignRef(openRef, open);