2019-11-28 15:17:39 +00:00
|
|
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
2019-06-19 14:40:52 +00:00
|
|
|
import IconButton from "@material-ui/core/IconButton";
|
2019-11-28 15:17:39 +00:00
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
2019-06-19 14:40:52 +00:00
|
|
|
import DeleteIcon from "@material-ui/icons/Delete";
|
|
|
|
import EditIcon from "@material-ui/icons/Edit";
|
2019-11-28 15:17:39 +00:00
|
|
|
import classNames from "classnames";
|
|
|
|
import React from "react";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-12-03 15:28:40 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
|
|
|
image: {
|
|
|
|
height: "100%",
|
|
|
|
objectFit: "contain",
|
|
|
|
userSelect: "none",
|
|
|
|
width: "100%"
|
|
|
|
},
|
|
|
|
imageContainer: {
|
|
|
|
"&:hover, &.dragged": {
|
|
|
|
"& $imageOverlay": {
|
|
|
|
display: "block"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
background: theme.palette.background.paper,
|
|
|
|
border: `1px solid ${theme.palette.divider}`,
|
|
|
|
borderRadius: theme.spacing(),
|
|
|
|
height: 148,
|
|
|
|
overflow: "hidden",
|
|
|
|
padding: theme.spacing(2),
|
|
|
|
position: "relative",
|
|
|
|
width: 148
|
|
|
|
},
|
|
|
|
imageOverlay: {
|
|
|
|
background: "rgba(0, 0, 0, 0.6)",
|
|
|
|
cursor: "move",
|
|
|
|
display: "none",
|
|
|
|
height: 148,
|
|
|
|
left: 0,
|
|
|
|
position: "absolute",
|
|
|
|
top: 0,
|
|
|
|
width: 148
|
|
|
|
},
|
|
|
|
imageOverlayShow: {
|
|
|
|
"&$imageOverlay": {
|
|
|
|
alignItems: "center",
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "center"
|
2019-10-30 14:34:24 +00:00
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
2019-12-03 15:28:40 +00:00
|
|
|
imageOverlayToolbar: {
|
2019-11-28 15:17:39 +00:00
|
|
|
display: "flex",
|
2019-12-03 15:28:40 +00:00
|
|
|
justifyContent: "flex-end"
|
2019-11-28 15:17:39 +00:00
|
|
|
}
|
2019-12-03 15:28:40 +00:00
|
|
|
}),
|
|
|
|
{ name: "ImageTile" }
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
interface ImageTileProps {
|
2019-06-19 14:40:52 +00:00
|
|
|
image: {
|
|
|
|
alt?: string;
|
|
|
|
url: string;
|
|
|
|
};
|
2019-11-28 15:17:39 +00:00
|
|
|
loading?: boolean;
|
2019-06-19 14:40:52 +00:00
|
|
|
onImageDelete?: () => void;
|
|
|
|
onImageEdit?: (event: React.ChangeEvent<any>) => void;
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const ImageTile: React.FC<ImageTileProps> = props => {
|
2019-11-28 15:17:39 +00:00
|
|
|
const { loading, onImageDelete, onImageEdit, image } = props;
|
2019-10-30 14:34:24 +00:00
|
|
|
|
|
|
|
const classes = useStyles(props);
|
|
|
|
|
|
|
|
return (
|
2019-08-27 13:29:00 +00:00
|
|
|
<div className={classes.imageContainer} data-tc="product-image">
|
2019-11-28 15:17:39 +00:00
|
|
|
<div
|
|
|
|
className={classNames(classes.imageOverlay, {
|
|
|
|
[classes.imageOverlayShow]: loading
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{loading ? (
|
|
|
|
<CircularProgress size={32} />
|
|
|
|
) : (
|
|
|
|
<div className={classes.imageOverlayToolbar}>
|
|
|
|
{onImageEdit && (
|
|
|
|
<IconButton color="primary" onClick={onImageEdit}>
|
|
|
|
<EditIcon />
|
|
|
|
</IconButton>
|
|
|
|
)}
|
|
|
|
{onImageDelete && (
|
|
|
|
<IconButton color="primary" onClick={onImageDelete}>
|
|
|
|
<DeleteIcon />
|
|
|
|
</IconButton>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2019-06-19 14:40:52 +00:00
|
|
|
</div>
|
|
|
|
<img className={classes.image} src={image.url} alt={image.alt} />
|
|
|
|
</div>
|
2019-10-30 14:34:24 +00:00
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
ImageTile.displayName = "ImageTile";
|
|
|
|
export default ImageTile;
|