-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowImgOrSpinner.js
55 lines (52 loc) · 1.65 KB
/
ShowImgOrSpinner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React, { Fragment } from "react";
import Spinner from './loadingIndicators/Spinner';
import { CLIENT_URL } from "../config/clientUrl";
import PropTypes from 'prop-types';
ShowImgOrSpinner.propTypes = {
id: PropTypes.string,
url: PropTypes.string.isRequired,
alt: PropTypes.string,
setStatus: PropTypes.func.isRequired,
status: PropTypes.bool,
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
// spinnerOpt: PropTypes.shape({
// width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
// height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
// backgroundColor: PropTypes.string,
// }).isRequired,
imgOpt: PropTypes.shape({
style: PropTypes.object,
className: PropTypes.string,
})
}
export default function ShowImgOrSpinner({
id,
url,
alt,
width,
height,
setStatus,
status,
spinnerOpt,
imgOpt }) {
const imageUrl = `${CLIENT_URL}/api/${url}/photo/${id}`;
return(
<Fragment>
<div style={{ display: status ? 'block' : 'none'}}>
<Spinner />
</div>
<div style={{ display: status ? 'none' : 'block'}}>
<img
className={imgOpt && imgOpt.className}
src={imageUrl}
alt={alt}
style={imgOpt && imgOpt.style}
width={width}
height={height}
onLoad={() => setStatus(false)}
/>
</div>
</Fragment>
);
}