-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathModuleNavigation.tsx
140 lines (127 loc) · 3.64 KB
/
ModuleNavigation.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React from "react";
import {
Image,
ImageSourcePropType,
ImageURISource,
StyleSheet,
View
} from "react-native";
import Placeholder from "rn-placeholder";
import {
IOListItemVisualParams,
IOSelectionListItemVisualParams,
IOSpacer,
IOVisualCostants,
useIOTheme
} from "../../core";
import { WithTestID } from "../../utils/types";
import { Badge } from "../badge";
import { IOIcons, Icon } from "../icons";
import { HStack, VStack } from "../stack";
import { LabelMini, BodySmall } from "../typography";
import { useIOFontDynamicScale } from "../../utils/accessibility";
import { ModuleStatic } from "./ModuleStatic";
import {
PressableModuleBase,
PressableModuleBaseProps
} from "./PressableModuleBase";
type LoadingProps = {
isLoading: true;
};
type ImageProps =
| { icon: IOIcons; image?: never }
| { icon?: never; image: ImageURISource | ImageSourcePropType };
type BaseProps = {
isLoading?: false;
title: string;
subtitle?: string;
badge?: Badge;
} & ImageProps &
PressableModuleBaseProps;
type ModuleNavigationProps = LoadingProps | BaseProps;
export const ModuleNavigation = (props: WithTestID<ModuleNavigationProps>) => {
const theme = useIOTheme();
const { hugeFontEnabled } = useIOFontDynamicScale();
if (props.isLoading) {
return <ModuleNavigationSkeleton />;
}
const { icon, image, title, subtitle, onPress, badge, ...pressableProps } =
props;
const iconComponent = icon && !hugeFontEnabled && (
<Icon
name={icon}
size={IOSelectionListItemVisualParams.iconSize}
color="grey-300"
/>
);
const imageComponent = image && (
<Image
source={image}
style={styles.image}
accessibilityIgnoresInvertColors={true}
/>
);
return (
<PressableModuleBase {...pressableProps} onPress={onPress}>
<HStack space={8} style={{ alignItems: "center" }}>
<HStack
space={IOVisualCostants.iconMargin as IOSpacer}
style={{ alignItems: "center", flexGrow: 1, flexShrink: 1 }}
>
{iconComponent ?? imageComponent}
<View style={{ flexShrink: 1 }}>
<BodySmall
color={theme["interactiveElem-default"]}
weight="Semibold"
numberOfLines={2}
lineBreakMode="middle"
style={{ flexShrink: 1 }}
>
{title}
</BodySmall>
{subtitle && (
<LabelMini weight="Regular" color={theme["textBody-tertiary"]}>
{subtitle}
</LabelMini>
)}
</View>
</HStack>
{badge ? (
<Badge {...badge} />
) : onPress ? (
<Icon
name="chevronRightListItem"
color={theme["interactiveElem-default"]}
size={IOListItemVisualParams.chevronSize}
/>
) : null}
</HStack>
</PressableModuleBase>
);
};
const ModuleNavigationSkeleton = () => (
<ModuleStatic
startBlock={
<HStack
style={{ alignItems: "center" }}
space={IOVisualCostants.iconMargin as IOSpacer}
>
<Placeholder.Box animate="fade" width={24} height={24} radius={8} />
<VStack space={4}>
<Placeholder.Box animate="fade" width={96} height={16} radius={8} />
<Placeholder.Box animate="fade" width={160} height={12} radius={8} />
</VStack>
</HStack>
}
endBlock={
<Placeholder.Box animate="fade" width={64} height={24} radius={16} />
}
/>
);
const styles = StyleSheet.create({
image: {
width: IOSelectionListItemVisualParams.iconSize,
height: IOSelectionListItemVisualParams.iconSize,
resizeMode: "contain"
}
});