import { Box } from './Box'; import { DropzoneOptions, useDropzone } from 'react-dropzone'; import { GeneratedPropTypes } from '../types'; import { PulseIcon } from './PulseIcon'; import { Text } from './Typography'; import { colors } from '../theme/colors'; import { generateProps } from 'styled-gen'; import { inputWrapperStyle } from '../theme/fx'; import React, { useEffect } from 'react'; import styled from 'styled-components'; export type InputUploadProps = { children?: any; disabled?: boolean; handleFiles: Function; hint?: string; name?: string; withError?: boolean; wrapperProps?: GeneratedPropTypes; } & DropzoneOptions; const InputBoxWrapper = styled.a` align-items: center; cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')} !important; display: flex; flex-direction: column; flex-wrap: nowrap; ${inputWrapperStyle}; padding: 1rem; ${generateProps} `; const InputElement = styled.input``; export const InputUpload: React.FC = props => { const { children, disabled, handleFiles, hint, name, withError, wrapperProps, ...dropzoneOptions } = props; const { acceptedFiles, getRootProps, getInputProps, open } = useDropzone({ // Disable click and keydown behavior disabled, noClick: true, noKeyboard: true, ...dropzoneOptions }); useEffect(() => { handleFiles(acceptedFiles); }, [acceptedFiles]); return ( <> {!!children && {children}} {!!hint && ( {hint} )} ); }; InputUpload.displayName = 'InputUpload';