import * as React from 'react'; import { useDropzone } from 'react-dropzone'; import * as styles from './DropZone.scss'; import { useI18n } from '../util/i18n'; export type Props = { readonly inner?: boolean; onDrop(files: Array): unknown; onDragActive?(active: boolean): unknown; }; const getClassName = ({ inner }: Props, isDragActive: boolean) => { if (inner) { return styles.base; } if (isDragActive) { return styles.active; } return styles.standalone; }; export const DropZone = (props: Props) => { const { inner, onDrop, onDragActive } = props; const i18n = useI18n(); const handleDrop = React.useCallback( files => { onDrop(files.map(({ path }) => path)); }, [onDrop] ); const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop: handleDrop, accept: ['image/png'], }); React.useEffect( () => { if (onDragActive) { onDragActive(isDragActive); } }, [isDragActive, onDragActive] ); return (
{/* tslint:disable-next-line */} {!inner ? (

{isDragActive ? i18n('StickerCreator--DropZone--staticText') : i18n('StickerCreator--DropZone--activeText')}

) : null}
); };