This repository has been archived by the owner on Dec 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Image.tsx
89 lines (85 loc) · 2.9 KB
/
Image.tsx
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { ValueStatus } from "mendix";
import { createElement, FunctionComponent, useCallback } from "react";
import { ImageViewerContainerProps } from "../typings/ImageViewerProps";
import { ImageViewer as ImageViewerComponent, ImageViewerImageProps } from "./components/Image/index";
function getImageProps({
datasource,
imageIcon,
imageObject,
imageUrl,
defaultImageDynamic
}: ImageViewerContainerProps): ImageViewerImageProps {
const fallback: ImageViewerImageProps = {
type: "image",
image: undefined
};
switch (datasource) {
case "image": {
if (imageObject?.status === ValueStatus.Available) {
return {
type: "image",
image: imageObject.value.uri
};
} else if (
imageObject?.status === ValueStatus.Unavailable &&
defaultImageDynamic?.status === ValueStatus.Available
) {
return {
type: "image",
image: defaultImageDynamic.value.uri
};
}
return {
type: "image",
image: undefined
};
}
case "imageUrl":
return {
type: "image",
image: imageUrl?.status === ValueStatus.Available ? imageUrl.value : undefined
};
case "icon": {
if (imageIcon?.status === ValueStatus.Available) {
if (imageIcon.value?.type === "glyph") {
return {
type: "icon",
image: imageIcon.value.iconClass
};
}
if (imageIcon.value?.type === "image") {
return {
type: "image",
image: imageIcon.value.iconUrl
};
}
}
return fallback;
}
default:
return fallback;
}
}
export const ImageViewer: FunctionComponent<ImageViewerContainerProps> = props => {
const onClick = useCallback(() => props.onClick?.execute(), [props.onClick]);
const { type, image } = getImageProps(props);
const altText = props.alternativeText?.status === ValueStatus.Available ? props.alternativeText.value : undefined;
return (
<ImageViewerComponent
class={props.class}
style={props.style}
widthUnit={props.widthUnit}
width={props.width}
heightUnit={props.heightUnit}
height={props.height}
iconSize={props.iconSize}
responsive={props.responsive}
onClickType={props.onClickType}
onClick={props.onClick ? onClick : undefined}
type={type}
image={image}
altText={altText}
displayAs={props.displayAs}
/>
);
};