diff --git a/apps/admin-x-settings/src/admin-x-ds/global/form/FileUpload.tsx b/apps/admin-x-settings/src/admin-x-ds/global/form/FileUpload.tsx index 98c176cffc..43778f3c7d 100644 --- a/apps/admin-x-settings/src/admin-x-ds/global/form/FileUpload.tsx +++ b/apps/admin-x-settings/src/admin-x-ds/global/form/FileUpload.tsx @@ -1,4 +1,5 @@ import React, {CSSProperties, ChangeEvent, useState} from 'react'; +import clsx from 'clsx'; export interface FileUploadProps { id: string; @@ -10,14 +11,16 @@ export interface FileUploadProps { */ children?: string | React.ReactNode; className?: string; + dragIndicatorClassName?: string; onUpload: (file: File) => void; style?: CSSProperties; unstyled?: boolean; inputRef?: React.RefObject; } -const FileUpload: React.FC = ({id, onUpload, children, style, unstyled = false, inputRef, ...props}) => { +const FileUpload: React.FC = ({id, onUpload, children, style, unstyled = false, inputRef, className, dragIndicatorClassName, ...props}) => { const [fileKey, setFileKey] = useState(Date.now()); + const [isDragging, setIsDragging] = useState(false); const handleFileChange = (event: ChangeEvent) => { const selectedFile = event.target.files?.[0]; @@ -27,8 +30,28 @@ const FileUpload: React.FC = ({id, onUpload, children, style, u setFileKey(Date.now()); }; + const handleDrop = (event: React.DragEvent) => { + handleStopDragging(event); + const selectedFile = event.dataTransfer.files?.[0]; + if (selectedFile) { + onUpload?.(selectedFile); + } + setFileKey(Date.now()); + }; + + const handleDragging = (event: React.DragEvent) => { + event.preventDefault(); + setIsDragging(true); + }; + + const handleStopDragging = (event: React.DragEvent) => { + event.preventDefault(); + setIsDragging(false); + }; + return ( -