import React, { useCallback } from 'react' import { Label, Portal, Overlay, Row } from '../UI' import { useDropzone } from 'react-dropzone' import { DropZone, ImageContainer, ImagePreview, Instructions, ImageLargePreview, Remove } from './StyledImage' import { useInputContext } from '../../context' import { usePopin } from '../../hooks' import type { ImageProps } from './image-types' export function ImageComponent() { const { label, value, onUpdate, disabled } = useInputContext() const { popinRef, wrapperRef, shown, show, hide } = usePopin() const onDrop = useCallback( (acceptedFiles: File[]) => { if (acceptedFiles.length) onUpdate(acceptedFiles[0]) }, [onUpdate] ) const clear = useCallback( (e: React.MouseEvent) => { e.stopPropagation() onUpdate(undefined) }, [onUpdate] ) const { getRootProps, getInputProps, isDragAccept } = useDropzone({ maxFiles: 1, accept: 'image/*', onDrop, disabled, }) // TODO fix any in DropZone return ( !!value && show()} onPointerUp={hide} style={{ backgroundImage: value ? `url(${value})` : 'none' }} /> {shown && !!value && ( )} {isDragAccept ? 'drop image' : 'click or drop'} ) }