-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathImageFailureMessage.jsx
More file actions
44 lines (38 loc) · 1.27 KB
/
ImageFailureMessage.jsx
File metadata and controls
44 lines (38 loc) · 1.27 KB
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
import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import PropTypes from 'prop-types';
import FailedImageContext from '../contexts/FailedImageContext';
const MessageContainer = styled(Box)(({ theme }) => ({
position: 'absolute',
top: theme.spacing(2),
left: '50%',
transform: 'translateX(-50%)',
backgroundColor: theme.palette.primary.main,
color: theme.palette.common.white,
padding: theme.spacing(1, 2),
borderRadius: theme.shape.borderRadius,
zIndex: 1000,
pointerEvents: 'none',
}));
/**
* Displays an accessible message when images fail to load in the OSD viewer
*/
export function ImageFailureMessage({ imageUrls = [] }) {
const { failedImages } = useContext(FailedImageContext);
const { t } = useTranslation();
const hasFailedImage = imageUrls.some(url => failedImages.has(url));
if (!hasFailedImage) return null;
return (
<MessageContainer role="status" aria-live="polite">
<Typography variant="body2">
{t('imageFailedToLoad')}
</Typography>
</MessageContainer>
);
}
ImageFailureMessage.propTypes = {
imageUrls: PropTypes.arrayOf(PropTypes.string),
};