-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathgetImageProps.ts
More file actions
58 lines (53 loc) · 1.85 KB
/
Copy pathgetImageProps.ts
File metadata and controls
58 lines (53 loc) · 1.85 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { ValueStatus } from "mendix";
import { ImageContainerProps } from "../../typings/ImageProps";
import { ImageType } from "../components/Image/Image";
export type GetImagePropsInput = Pick<
ImageContainerProps,
"datasource" | "imageIcon" | "imageObject" | "imageUrl" | "defaultImageDynamic"
>;
const fallback: ImageType = { type: "image", image: undefined };
export function getImageProps({
datasource,
imageIcon,
imageObject,
imageUrl,
defaultImageDynamic: defaultImage
}: GetImagePropsInput): ImageType {
switch (datasource) {
case "image": {
if (imageObject?.status === ValueStatus.Available || imageObject?.status === ValueStatus.Loading) {
return {
type: "image",
image: imageObject?.value?.uri
};
}
if (defaultImage?.status === ValueStatus.Available || defaultImage?.status === ValueStatus.Loading) {
return {
type: "image",
image: defaultImage?.value?.uri
};
}
return { type: "image", image: undefined };
}
case "imageUrl":
return {
type: "image",
image:
imageUrl?.status === ValueStatus.Available || imageUrl?.status === ValueStatus.Loading
? imageUrl.value
: undefined
};
case "icon": {
if (imageIcon?.status === ValueStatus.Available && imageIcon.value) {
const icon = imageIcon.value;
return {
type: icon.type,
image: icon.type === "image" ? icon.iconUrl : icon.iconClass
};
}
return fallback;
}
default:
return fallback;
}
}