11import React , { useState , useRef , useEffect , useCallback } from 'react'
22import PropTypes from 'prop-types'
3- import {
4- Button , Grid , Typography , Alert , Paper , Box , Hidden ,
3+ import {
4+ Button ,
5+ Grid ,
6+ Alert ,
7+ Paper ,
8+ Box ,
9+ Hidden ,
10+ Typography ,
11+ useMediaQuery ,
512} from '@mui/material'
613import { useTheme , styled } from '@mui/material/styles'
714import FileAttachment from "./FileAttachment.jsx"
@@ -53,7 +60,8 @@ function FileUpload(props) {
5360 allowedExtensions,
5461 buttonRemoveLabel,
5562 filesContainerHeight,
56- maxFilesContainerHeight
63+ maxFilesContainerHeight,
64+ placeholderImageDimension
5765 } = props
5866 const theme = useTheme ( )
5967
@@ -63,6 +71,20 @@ function FileUpload(props) {
6371
6472 const oneMega = 1024 * 1024
6573 const filesCardRef = useRef ( )
74+
75+ let imageDimension = { width : 128 , height : 128 }
76+ if ( useMediaQuery ( theme . breakpoints . up ( 'xs' ) ) && placeholderImageDimension ?. xs ) {
77+ imageDimension = placeholderImageDimension . xs
78+ }
79+ if ( useMediaQuery ( theme . breakpoints . up ( 'sm' ) ) && placeholderImageDimension ?. sm ) {
80+ imageDimension = placeholderImageDimension . sm
81+ }
82+ if ( useMediaQuery ( theme . breakpoints . up ( 'md' ) ) && placeholderImageDimension ?. md ) {
83+ imageDimension = placeholderImageDimension . md
84+ }
85+ if ( useMediaQuery ( theme . breakpoints . up ( 'lg' ) ) && placeholderImageDimension ?. lg ) {
86+ imageDimension = placeholderImageDimension . lg
87+ }
6688
6789 /**
6890 * @name renderPreview
@@ -265,22 +287,12 @@ function FileUpload(props) {
265287 xs = { 12 } sm = { 3 } md = { 4 }
266288 sx = { { textAlign : 'center' } }
267289 >
268- < Hidden smDown >
269- < img
270- alt = ""
271- width = { 120 }
272- height = { 120 }
273- src = { imageSrc || uploadImage }
274- />
275- </ Hidden >
276- < Hidden smUp >
277- < img
278- alt = ""
279- width = { 128 }
280- height = { 128 }
281- src = { imageSrc || uploadImage }
282- />
283- </ Hidden >
290+ < img
291+ alt = "Loading image..."
292+ src = { imageSrc || uploadImage }
293+ width = { imageDimension . width }
294+ height = { imageDimension . height }
295+ />
284296 </ Grid >
285297 < Grid
286298 item
@@ -391,7 +403,8 @@ FileUpload.propTypes = {
391403 errorSizeMessage : PropTypes . string ,
392404 allowedExtensions : PropTypes . array ,
393405 onError : PropTypes . func ,
394- onFilesChange : PropTypes . func
406+ onFilesChange : PropTypes . func ,
407+ placeholderImageDimension : PropTypes . object
395408}
396409
397410FileUpload . defaultProps = {
@@ -402,7 +415,8 @@ FileUpload.defaultProps = {
402415 leftLabel : "or" ,
403416 rightLabel : "to select files" ,
404417 buttonLabel : "click here" ,
405- maxFilesContainerHeight : 300
418+ maxFilesContainerHeight : 300 ,
419+ placeholderImageDimension : [ ]
406420}
407421
408422export default FileUpload
0 commit comments