@@ -8,6 +8,7 @@ import { useMessageInputContext, useTranslationContext } from '../../context';
88import { useAttachmentManagerState , useMessageComposer } from './hooks' ;
99import { useStateStore } from '../../store' ;
1010import { useIsCooldownActive } from './hooks/useIsCooldownActive' ;
11+ import { IconFileArrowLeftIn } from '../Icons' ;
1112
1213const DragAndDropUploadContext = React . createContext < {
1314 subscribeToDrop : ( ( fn : ( files : File [ ] ) => void ) => ( ) => void ) | null ;
@@ -72,8 +73,6 @@ export const WithDragAndDropUpload = ({
7273 style ?: CSSProperties ;
7374} > ) => {
7475 const dropHandlersRef = useRef < Set < ( f : File [ ] ) => void > > ( new Set ( ) ) ;
75- const { t } = useTranslationContext ( ) ;
76-
7776 const messageInputContext = useMessageInputContext ( ) ;
7877 const dragAndDropUploadContext = useDragAndDropUploadContext ( ) ;
7978 const messageComposer = useMessageComposer ( ) ;
@@ -108,7 +107,11 @@ export const WithDragAndDropUpload = ({
108107 dropHandlersRef . current . forEach ( ( fn ) => fn ( files ) ) ;
109108 } , [ ] ) ;
110109
111- const { getRootProps, isDragActive, isDragReject } = useDropzone ( {
110+ const {
111+ getRootProps,
112+ isDragActive,
113+ isDragReject : isDragRejected ,
114+ } = useDropzone ( {
112115 accept,
113116 // apply `disabled` rules if available, otherwise allow anything and
114117 // let the `uploadNewFiles` handle the limitations internally
@@ -126,26 +129,45 @@ export const WithDragAndDropUpload = ({
126129 return < Component className = { className } > { children } </ Component > ;
127130 }
128131
132+ const rootClassName = clsx ( 'str-chat__dropzone-root' , className ) ;
133+
129134 return (
130- < DragAndDropUploadContext . Provider
131- value = { {
132- subscribeToDrop,
133- } }
134- >
135- < Component { ...getRootProps ( { className, style } ) } >
136- { /* TODO: could be a replaceable component */ }
135+ < DragAndDropUploadContext . Provider value = { { subscribeToDrop } } >
136+ < Component { ...getRootProps ( { className : rootClassName , style } ) } >
137137 { isDragActive && (
138138 < div
139139 className = { clsx ( 'str-chat__dropzone-container' , {
140- 'str-chat__dropzone-container--not-accepted' : isDragReject ,
140+ 'str-chat__dropzone-container--not-accepted' : isDragRejected ,
141141 } ) }
142+ role = 'presentation'
142143 >
143- { ! isDragReject && < p > { t ( 'Drag your files here' ) } </ p > }
144- { isDragReject && < p > { t ( 'Some of the files will not be accepted' ) } </ p > }
144+ < FileDragAndDropContent isDragRejected = { isDragRejected } />
145145 </ div >
146146 ) }
147147 { children }
148148 </ Component >
149149 </ DragAndDropUploadContext . Provider >
150150 ) ;
151151} ;
152+
153+ export type FileDragAndDropContentProps = {
154+ isDragRejected : boolean ;
155+ } ;
156+
157+ export const FileDragAndDropContent = ( {
158+ isDragRejected,
159+ } : FileDragAndDropContentProps ) => {
160+ const { t } = useTranslationContext ( ) ;
161+ return (
162+ < div className = 'str-chat__dropzone-container__content' >
163+ { isDragRejected ? (
164+ < p > { t ( 'Some of the files will not be accepted' ) } </ p >
165+ ) : (
166+ < >
167+ < IconFileArrowLeftIn />
168+ < p > { t ( 'Drag your files here' ) } </ p >
169+ </ >
170+ ) }
171+ </ div >
172+ ) ;
173+ } ;
0 commit comments