ipfs/src/components/Add/Dropzone.tsx

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-07-08 01:30:27 +02:00
import React, { useCallback, ReactElement } from 'react'
2021-09-13 21:09:46 +02:00
import { FileWithPath, useDropzone } from 'react-dropzone'
2019-10-20 01:40:55 +02:00
import styles from './Dropzone.module.css'
export default function Dropzone({
handleOnDrop,
disabled,
multiple,
error
}: {
2021-09-13 21:09:46 +02:00
handleOnDrop(files: FileWithPath[]): void
2019-10-20 01:40:55 +02:00
disabled?: boolean
multiple?: boolean
error?: string
2020-07-08 01:30:27 +02:00
}): ReactElement {
2021-09-12 17:00:43 +02:00
const onDrop = useCallback(
(acceptedFiles) => handleOnDrop(acceptedFiles),
[handleOnDrop]
)
2019-10-20 01:40:55 +02:00
2021-09-12 17:00:43 +02:00
const { getRootProps, getInputProps, isDragActive, isDragReject } =
useDropzone({ onDrop })
2019-10-20 01:40:55 +02:00
return (
<div
{...getRootProps({
className: isDragActive
? styles.dragover
: disabled
? styles.disabled
: styles.dropzone
})}
>
<input {...getInputProps({ multiple })} />
{isDragActive && !isDragReject ? (
`Drop it like it's hot!`
) : multiple === false ? (
`Drag 'n' drop a file here, or click to select a file.`
2021-09-12 16:41:30 +02:00
) : error !== undefined ? (
2019-10-20 01:40:55 +02:00
<div className={styles.error}>{error}</div>
) : (
`Drag 'n' drop some files here, or click to select files.`
2019-10-20 01:40:55 +02:00
)}
</div>
)
}