-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathLarkImage.tsx
More file actions
36 lines (31 loc) · 845 Bytes
/
LarkImage.tsx
File metadata and controls
36 lines (31 loc) · 845 Bytes
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
import { TableCellValue } from 'mobx-lark';
import { FC } from 'react';
import { Image, ImageProps } from 'react-bootstrap';
import { fileURLOf } from '../models/Base';
import { DefaultImage } from '../models/configuration';
export interface LarkImageProps extends Omit<ImageProps, 'src'> {
src?: TableCellValue;
}
export const LarkImage: FC<LarkImageProps> = ({
src = DefaultImage,
alt,
...props
}) => (
<Image
fluid
loading="lazy"
{...props}
src={fileURLOf(src, true)}
alt={alt}
onError={({ currentTarget: image }) => {
const path = fileURLOf(src),
errorURL = decodeURI(image.src);
if (!path) return;
if (errorURL.endsWith(path)) {
if (!alt) image.src = DefaultImage;
} else if (!errorURL.endsWith(DefaultImage)) {
image.src = path;
}
}}
/>
);