import * as React from 'react'; import ItemList from './ItemList'; import UploadState from './UploadState'; import makeDroppable from '../common/droppable'; import type { UploadFile, UploadFileWithAPIOptions, UploadItem } from '../../common/types/upload'; import type { DOMStringList, View } from '../../common/types/core'; import './DroppableContent.scss'; type Props = { addDataTransferItemsToUploadQueue: (droppedItems: DataTransfer) => void, addFiles: (files?: Array) => void, allowedTypes: Array; canDrop: boolean, isFolderUploadEnabled: boolean, isOver: boolean, isTouch: boolean, items: UploadItem[], onClick: (item: UploadItem) => void, view: View, }; /** * Definition for drag and drop behavior. */ const dropDefinition = { /** * Validates whether a file can be dropped or not. */ dropValidator: ( { allowedTypes }: { allowedTypes: Array }, { types }: { types: Array | DOMStringList }, ) => { if (types instanceof Array) { return Array.from(types).some(type => allowedTypes.indexOf(type) > -1); } const allowedList = allowedTypes.filter(allowed => types.contains(allowed)); return allowedList.length > 0; }, /** * Determines what happens after a file is dropped */ onDrop: (event, { addDataTransferItemsToUploadQueue }: Props) => { const { dataTransfer } = event; addDataTransferItemsToUploadQueue(dataTransfer); }, }; const DroppableContent = makeDroppable(dropDefinition)(({ addFiles, canDrop, isFolderUploadEnabled, isOver, isTouch, items, onClick, view, }: Props) => { const handleSelectFiles = ({ target: { files } }: any) => addFiles(files); const hasItems = items.length > 0; return (
); }); export default DroppableContent;