import { type DragEvent } from "react"; /** * @since 5.1.3 * @since 6.0.0 The element type is dynamically inferred on each handler * instead of the `DropzoneHandlers` type. */ export interface DropzoneHandlers { onDrop: (event: DragEvent) => void; onDragEnter?: (event: DragEvent) => void; onDragOver?: (event: DragEvent) => void; onDragLeave?: (event: DragEvent) => void; } /** * @since 6.0.0 */ export interface DropzoneOptions extends DropzoneHandlers { /** * By default, the `useDropzone` hook will listen to any `dragenter`/`dragover` * events on the page and enabling the {@link DragHookReturnValue.isDragging} * flag to show that the user is dragging _something_ and they might want to * drag that something into the dropzone. * * So set this option to `true` if that behavior is not required and only * drag events on the dropzone element need to be captured. * * @defaultValue `false` * @see {@link DropzoneImplementation.isDragging} */ disableDragging?: boolean; } /** * @since 2.9.0 * @since 6.0.0 Renamed from `DropzoneHookReturnValue` to * `DropzoneImplementation` to match other naming conventions. Returns an * object instead of an ordered array of `[isOver: boolean, dropzoneHandlers: * DropzoneHandlers]`. Also returns a new `isDragging` state. */ export interface DropzoneImplementation { /** * This will be `true` when the user is dragging something over the dropzone * target. */ isOver: boolean; /** * This will be `true` when the user is dragging anything within the document. * The main use case for this is detecting when a user is dragging a file into * the document so you can help highlight the dropzone area. * * This will always be `false` if {@link DropzoneOptions.disableDragging} is * `true`. */ isDragging: boolean; /** * The event handlers that should be passed to the dropzone target. */ dropzoneHandlers: Required; } /** * @example Simple Example * ```tsx * import { useFileUpload } from "@react-md/core/files/useFileUpload"; * import { useDropzone } from "@react-md/core/useDropzone"; * import { type CSSProperties, type ReactElement } from "react"; * * const style: CSSProperties = { * border: '1px solid blue', * }; * * function Example(): ReactElement { * const { onDrop } = useFileUpload() * const { isOver, dropzoneHandlers } = useDropzone({ * onDrop(event) { * // normally use the `onDrop` behavior from `useFileUpload` to upload * // files: * // onDrop(event); * }, * disableDragging: true, * }); * * return ( *
* Drag and drop some files! * {isOver && } *
* ); * } * ``` * * @example Dragging Example * ```tsx * import { useFileUpload } from "@react-md/core/files/useFileUpload"; * import { useDropzone } from "@react-md/core/useDropzone"; * import { type CSSProperties, type ReactElement } from "react"; * * const draggingStyle: CSSProperties = { * backgroundColor: "orange", * }; * const overStyle: CSSProperties = { * border: '1px solid blue', * }; * * function Example(): ReactElement { * const { onDrop } = useFileUpload() * const { isOver, isDragging, dropzoneHandlers } = useDropzone({ * onDrop(event) { * // normally use the `onDrop` behavior from `useFileUpload` to upload * // files: * // onDrop(event); * }, * }); * * return ( *
* Drag and drop some files! * {isOver && } *
* ); * } * ``` * * @since 2.9.0 * @since 6.0.0 Supports document-level dragging flag; */ export declare function useDropzone(options: DropzoneOptions): DropzoneImplementation;