1
0
mirror of https://github.com/oceanprotocol/ipfs synced 2024-06-23 01:36:44 +02:00
ipfs/src/components/Dropzone.tsx

50 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-10-16 17:02:04 +02:00
import React, { useCallback } from 'react'
import { useDropzone } from 'react-dropzone'
2019-10-17 00:13:54 +02:00
import styles from './Dropzone.module.css'
2019-10-16 17:02:04 +02:00
2019-10-17 00:13:54 +02:00
export default function Dropzone({
handleOnDrop,
disabled,
2019-10-18 19:12:49 +02:00
multiple,
error
2019-10-17 00:13:54 +02:00
}: {
handleOnDrop(files: File[]): void
disabled?: boolean
multiple?: boolean
2019-10-18 19:12:49 +02:00
error?: string
2019-10-17 00:13:54 +02:00
}) {
2019-10-16 17:02:04 +02:00
const onDrop = useCallback(acceptedFiles => handleOnDrop(acceptedFiles), [
handleOnDrop
])
const {
getRootProps,
getInputProps,
isDragActive,
isDragReject
} = useDropzone({ onDrop })
return (
<div
{...getRootProps({
className: isDragActive
2019-10-16 22:10:03 +02:00
? styles.dragover
2019-10-16 17:02:04 +02:00
: disabled
2019-10-16 22:10:03 +02:00
? styles.disabled
: styles.dropzone
2019-10-16 17:02:04 +02:00
})}
>
<input {...getInputProps({ multiple })} />
2019-10-18 19:12:49 +02:00
{isDragActive && !isDragReject ? (
`Drop it like it's hot!`
) : multiple ? (
`Drag 'n' drop some files here, or click to select files`
) : error ? (
<div className={styles.error}>{error}</div>
) : (
`Drag 'n' drop a file here, or click to select a file`
)}
2019-10-16 17:02:04 +02:00
</div>
)
}