1- import React , { useCallback , useRef } from 'react'
1+ import React , { useCallback , useRef , useState } from 'react'
22import PropTypes from 'prop-types'
33import fileExtension from './utils/fileExtension'
44import fileSizeReadable from './utils/fileSizeReadable'
@@ -25,6 +25,7 @@ const Files = ({
2525 const idCounter = useRef ( 1 )
2626 const dropzoneElement = useRef ( )
2727 const inputElement = useRef ( )
28+ const [ isDragging , setDragging ] = useState ( false )
2829
2930 const handleError = ( error , file ) => {
3031 onError ( error , file )
@@ -37,15 +38,29 @@ const Files = ({
3738
3839 const handleDragEnter = ( event ) => {
3940 const el = dropzoneElement . current
40- el . className = `${ el . className } ${ dragActiveClassName } `
41+ if ( dragActiveClassName && ! el . className . includes ( dragActiveClassName ) ) {
42+ el . className = `${ el . className } ${ dragActiveClassName } `
43+ }
44+
45+ if ( typeof children === 'function' ) {
46+ setDragging ( true )
47+ }
48+
4149 if ( onDragEnter ) {
4250 onDragEnter ( event )
4351 }
4452 }
4553
4654 const handleDragLeave = ( event ) => {
4755 const el = dropzoneElement . current
48- el . className = el . className . replace ( ` ${ dragActiveClassName } ` , '' )
56+ if ( dragActiveClassName ) {
57+ el . className = el . className . replace ( ` ${ dragActiveClassName } ` , '' )
58+ }
59+
60+ if ( typeof children === 'function' ) {
61+ setDragging ( false )
62+ }
63+
4964 if ( onDragLeave ) {
5065 onDragLeave ( event )
5166 }
@@ -164,7 +179,7 @@ const Files = ({
164179 onDragEnter = { handleDragEnter }
165180 onDragLeave = { handleDragLeave }
166181 style = { style } >
167- { children }
182+ { typeof children === 'function' ? children ( isDragging ) : children }
168183 </ div >
169184 </ >
170185 )
@@ -173,6 +188,7 @@ const Files = ({
173188Files . propTypes = {
174189 accepts : PropTypes . array ,
175190 children : PropTypes . oneOfType ( [
191+ PropTypes . func ,
176192 PropTypes . arrayOf ( PropTypes . node ) ,
177193 PropTypes . node
178194 ] ) ,
@@ -193,9 +209,9 @@ Files.propTypes = {
193209
194210Files . defaultProps = {
195211 accepts : null ,
196- className : 'files-dropzone' ,
212+ className : undefined ,
197213 clickable : true ,
198- dragActiveClassName : 'files-dropzone-active' ,
214+ dragActiveClassName : undefined ,
199215 multiple : true ,
200216 maxFiles : Infinity ,
201217 maxFileSize : Infinity ,
0 commit comments