@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
106 lines (102 loc) • 3.13 kB
JavaScript
"use client";
import { assignRef, mergeRefs } from "../../utils/ref.js";
import { utils_exports } from "../../utils/index.js";
import { useFieldProps } from "../field/use-field-props.js";
import { useCallback, useId } from "react";
import { fromEvent } from "file-selector";
import { useDropzone } from "react-dropzone";
//#region src/components/dropzone/use-dropzone.ts
const useDropzone$1 = (props = {}) => {
const { props: { id, name, accept, autoFocus = false, disabled, getFilesFromEvent = fromEvent, loading, maxFiles = 0, maxSize = Infinity, minSize = 0, multiple = false, noClick = false, noDrag = false, noDragEventsBubbling = false, noKeyboard = false, openRef, preventDropOnDocument = true, readOnly, useFsAccessApi = false, validator, onDragEnter, onDragLeave, onDragOver, onDrop, onDropAccepted, onDropRejected, onError, onFileDialogCancel, onFileDialogOpen,...rest }, ariaProps, dataProps, eventProps } = useFieldProps(props);
const labelledbyId = useId();
const interactive = !(loading || readOnly || disabled);
const { acceptedFiles, fileRejections, isDragAccept: dragAccept, isDragActive: dragActive, isDragReject: dragReject, isFocused: focused, open, getInputProps: getOriginalInputProps, getRootProps: getOriginalRootProps } = useDropzone({
accept: (0, utils_exports.isArray)(accept) ? accept.reduce((prev, current) => ({
...prev,
[current]: []
}), {}) : accept,
autoFocus,
disabled: !interactive,
getFilesFromEvent,
maxFiles,
maxSize,
minSize,
multiple,
noClick,
noDrag,
noDragEventsBubbling,
noKeyboard,
preventDropOnDocument,
useFsAccessApi,
validator,
onDragEnter,
onDragLeave,
onDragOver,
onDrop,
onDropAccepted,
onDropRejected,
onError,
onFileDialogCancel,
onFileDialogOpen
});
const dragIdle = !dragAccept && !dragReject;
assignRef(openRef, open);
const getRootProps = useCallback(({ ref,...props$1 } = {}) => getOriginalRootProps({
id: labelledbyId,
...dataProps,
...eventProps,
"aria-disabled": (0, utils_exports.ariaAttr)(!interactive),
"data-accept": (0, utils_exports.dataAttr)(dragAccept),
"data-idle": (0, utils_exports.dataAttr)(dragIdle),
"data-loading": (0, utils_exports.dataAttr)(loading),
"data-reject": (0, utils_exports.dataAttr)(dragReject),
...rest,
...props$1,
ref: mergeRefs(ref, rest.ref)
}), [
getOriginalRootProps,
labelledbyId,
dataProps,
eventProps,
interactive,
dragAccept,
dragIdle,
loading,
dragReject,
rest
]);
return {
acceptedFiles,
dragAccept,
dragActive,
dragIdle,
dragReject,
fileRejections,
focused,
loading,
open,
getInputProps: useCallback(({ "aria-labelledby": ariaLabelledby,...props$1 } = {}) => getOriginalInputProps({
id,
name,
disabled,
readOnly,
...ariaProps,
...dataProps,
...props$1,
"aria-labelledby": (0, utils_exports.cx)(ariaLabelledby, labelledbyId)
}), [
getOriginalInputProps,
id,
name,
disabled,
readOnly,
ariaProps,
dataProps,
labelledbyId
]),
getRootProps
};
};
//#endregion
export { useDropzone$1 as useDropzone };
//# sourceMappingURL=use-dropzone.js.map