A react component for drag and drop photo files
This is a React Component firstly designed for private use and has been chosen to be publicly available, so the implementation details can be confusing. And so there won't be regular updates.
yarn add @tallis/react-dndp
import Image from 'next/image';
import Uploader from '@tallis/react-dndp';
import Paper from '@mui/material';
import UploadIconIllustration from './UploadIconIllustration';
// other code
<Paper variant='outlined' sx={{
position: 'relative',
height: photoSizes?.width * 0.7,
width: photoSizes?.width * 0.7,
overflow: 'hidden',
borderRadius: '10px',
mt: 1
}}>
<Uploader
containerProps={{
sx: {
position: 'absolute',
top: 0,
zIndex: 2,
width: '100%',
height: '100%',
cursor: 'pointer',
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center'
},
container: true
}}
stylesImage={{
style: {
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
}
}}
stylesImage2={{
style: {
width: '100%',
height: '100%',
position: 'relative'
}
}}
setData={(data, base64) => {
photo?.set('illustration', data);
photo?.set('photo', base64);
setPhoto(photo);
}}
data={Boolean(photo?.get('photo')) ? photo?.get('photo') : null}
CustomIcon={UploadIconIllustration}
showIconUpload={Boolean(photo?.get('photo')) ? false : true}
getFileSize={(data) => setIsOver10MB(data)}
isFormik
clickWhole
NextImage={Image}
React={React}
onError={() => dispatch({ type: t.SHOW_SNACKBAR, payload: { message: 'Only image file is allowed', type: 'error' } })}
/>
</Paper>
// other code