@@ -9,18 +9,27 @@ import type { StateRef } from '../useRefState/useRefState';
9
9
import { useRefState } from '../useRefState/useRefState' ;
10
10
11
11
type DragEventType = 'drop' | 'enter' | 'leave' | 'over' ;
12
+ type DataTypes = ( ( types : string [ ] ) => boolean ) | string [ ] ;
12
13
13
14
export interface UseDropZoneOptions {
14
- dataTypes ?: ( ( types : string [ ] ) => boolean ) | string [ ] ;
15
+ /** The data types for drop zone */
16
+ dataTypes ?: DataTypes ;
17
+ /** The multiple mode for drop zone */
15
18
multiple ?: boolean ;
19
+ /** The on drop callback */
16
20
onDrop ?: ( files : File [ ] | null , event : DragEvent ) => void ;
21
+ /** The on enter callback */
17
22
onEnter ?: ( files : File [ ] | null , event : DragEvent ) => void ;
23
+ /** The on leave callback */
18
24
onLeave ?: ( files : File [ ] | null , event : DragEvent ) => void ;
25
+ /** The on over callback */
19
26
onOver ?: ( files : File [ ] | null , event : DragEvent ) => void ;
20
27
}
21
28
22
- interface UseDropZoneReturn {
29
+ export interface UseDropZoneReturn {
30
+ /** The files that was dropped in drop zone */
23
31
files : File [ ] | null ;
32
+ /** The boolean flag that indicate when drop zone is over */
24
33
isOver : boolean ;
25
34
}
26
35
@@ -52,12 +61,46 @@ export interface UseDropZone {
52
61
* @description - Hook that provides drop zone functionality
53
62
* @category Elements
54
63
*
64
+ * @overload
65
+ * @template Target The target element
66
+ * @param {Target } target The target element drop zone's
67
+ * @param {DataTypes } [options.dataTypes] The data types
68
+ * @param {boolean } [options.multiple] The multiple mode
69
+ * @param {(files: File[] | null, event: DragEvent) => void } [options.onDrop] The on drop callback function
70
+ * @param {(files: File[] | null, event: DragEvent) => void } [options.onEnter] The on enter callback function
71
+ * @param {(files: File[] | null, event: DragEvent) => void } [options.onLeave] The on leave callback function
72
+ * @param {(files: File[] | null, event: DragEvent) => void } [options.onOver] The on over callback function
73
+ * @returns {[boolean, File[] | null] } The object with drop zone states
55
74
*
56
75
* @example
57
- * const {ref, isOver} = useDropZone({onDrop})
76
+ * const {isOver, files} = useDropZone(ref, options);
77
+ *
78
+ * @overload
79
+ * @param {Target } target The target element drop zone's
80
+ * @param {(files: File[] | null, event: DragEvent) => void } [callback] The callback function to be invoked on drop
81
+ * @returns {[boolean, File[] | null] } The object with drop zone states
82
+ *
83
+ * @example
84
+ * const {isOver, files} = useDropZone(ref, () => console.log('callback'));
85
+ *
86
+ * @overload
87
+ * @param {DataTypes } [options.dataTypes] The data types
88
+ * @param {boolean } [options.multiple] The multiple mode
89
+ * @param {(files: File[] | null, event: DragEvent) => void } [options.onDrop] The on drop callback function
90
+ * @param {(files: File[] | null, event: DragEvent) => void } [options.onEnter] The on enter callback function
91
+ * @param {(files: File[] | null, event: DragEvent) => void } [options.onLeave] The on leave callback function
92
+ * @param {(files: File[] | null, event: DragEvent) => void } [options.onOver] The on over callback function
93
+ * @returns {[StateRef<Target>, boolean, File[] | null] } The object with drop zone states and ref
94
+ *
95
+ * @example
96
+ * const { ref, isOver, files } = useDropZone(options);
97
+ *
98
+ * @overload
99
+ * @param {(files: File[] | null, event: DragEvent) => void } [callback] The callback function to be invoked on drop
100
+ * @returns {[StateRef<Target>, boolean, File[] | null] } The object with drop zone states and ref
58
101
*
59
102
* @example
60
- * const { isOver } = useDropZone(ref, {onDrop} );
103
+ * const { ref, isOver, files } = useDropZone(() => console.log('callback') );
61
104
*/
62
105
63
106
export const useDropZone = ( ( ...params : any [ ] ) => {
0 commit comments