@momo-kits/foundation 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Icon/index.tsx +1 -1
- package/Navigation/Components.tsx +7 -1
- package/Navigation/types.ts +1 -1
- package/Navigation/utils.tsx +4 -10
- package/index.ts +1 -3
- package/package.json +1 -1
- package/Playground/index.tsx +0 -249
- package/Playground/styles.ts +0 -16
- package/Playground/types.ts +0 -16
- /package/{Icon → Assets}/icon.json +0 -0
package/Icon/index.tsx
CHANGED
|
@@ -48,6 +48,10 @@ const HeaderLeft = (props: any) => {
|
|
|
48
48
|
|
|
49
49
|
const HeaderBackground: React.FC<HeaderBackgroundProps> = ({image}) => {
|
|
50
50
|
const {theme} = useContext(ApplicationContext);
|
|
51
|
+
let headerImage = image ?? theme.assets?.headerBackground;
|
|
52
|
+
if (image === null) {
|
|
53
|
+
headerImage = undefined;
|
|
54
|
+
}
|
|
51
55
|
return (
|
|
52
56
|
<View
|
|
53
57
|
style={[
|
|
@@ -57,7 +61,9 @@ const HeaderBackground: React.FC<HeaderBackgroundProps> = ({image}) => {
|
|
|
57
61
|
<StatusBar
|
|
58
62
|
barStyle={image || theme.dark ? 'light-content' : 'dark-content'}
|
|
59
63
|
/>
|
|
60
|
-
{
|
|
64
|
+
{headerImage && (
|
|
65
|
+
<Image style={styles.headerBackground} source={{uri: headerImage}} />
|
|
66
|
+
)}
|
|
61
67
|
</View>
|
|
62
68
|
);
|
|
63
69
|
};
|
package/Navigation/types.ts
CHANGED
package/Navigation/utils.tsx
CHANGED
|
@@ -34,9 +34,7 @@ const getStackOptions = (theme: Theme): StackNavigationOptions => {
|
|
|
34
34
|
return {
|
|
35
35
|
headerTitleAlign: 'center',
|
|
36
36
|
headerTitle: HeaderTitle,
|
|
37
|
-
headerBackground:
|
|
38
|
-
<HeaderBackground image={theme.assets?.headerBackground} />
|
|
39
|
-
),
|
|
37
|
+
headerBackground: HeaderBackground,
|
|
40
38
|
headerLeft: (props: any) => <HeaderLeft {...props} />,
|
|
41
39
|
...getTintColor(theme),
|
|
42
40
|
};
|
|
@@ -47,9 +45,7 @@ const getDialogOptions = (theme: Theme): StackNavigationOptions => {
|
|
|
47
45
|
headerTitleAlign: 'center',
|
|
48
46
|
headerTitle: HeaderTitle,
|
|
49
47
|
headerLeft: (props: any) => <HeaderLeft {...props} />,
|
|
50
|
-
headerBackground:
|
|
51
|
-
<HeaderBackground image={theme.assets?.headerBackground} />
|
|
52
|
-
),
|
|
48
|
+
headerBackground: HeaderBackground,
|
|
53
49
|
...getTintColor(theme),
|
|
54
50
|
...TransitionPresets.ModalTransition,
|
|
55
51
|
};
|
|
@@ -97,7 +93,7 @@ const getOptions = (params: NavigationOptions, theme: Theme) => {
|
|
|
97
93
|
|
|
98
94
|
if (params.surface == true) {
|
|
99
95
|
surfaceTheme = {
|
|
100
|
-
headerBackground: () => <HeaderBackground />,
|
|
96
|
+
headerBackground: () => <HeaderBackground image={null} />,
|
|
101
97
|
...getTintColor({
|
|
102
98
|
...theme,
|
|
103
99
|
assets: {...theme.assets, headerBackground: undefined},
|
|
@@ -105,9 +101,7 @@ const getOptions = (params: NavigationOptions, theme: Theme) => {
|
|
|
105
101
|
};
|
|
106
102
|
} else {
|
|
107
103
|
surfaceTheme = {
|
|
108
|
-
headerBackground:
|
|
109
|
-
<HeaderBackground image={theme.assets?.headerBackground} />
|
|
110
|
-
),
|
|
104
|
+
headerBackground: HeaderBackground,
|
|
111
105
|
...getTintColor(theme),
|
|
112
106
|
};
|
|
113
107
|
}
|
package/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SafeAreaProvider,
|
|
2
3
|
SafeAreaView,
|
|
3
4
|
useSafeAreaInsets,
|
|
4
|
-
SafeAreaProvider,
|
|
5
5
|
} from 'react-native-safe-area-context';
|
|
6
6
|
import LinearGradient from 'react-native-linear-gradient';
|
|
7
|
-
import Playground from './Playground';
|
|
8
|
-
export {Playground};
|
|
9
7
|
|
|
10
8
|
export {SafeAreaView, useSafeAreaInsets, SafeAreaProvider, LinearGradient};
|
|
11
9
|
|
package/package.json
CHANGED
package/Playground/index.tsx
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import React, {FC, useContext, useEffect, useState} from 'react';
|
|
2
|
-
import {FlatList, TouchableOpacity, View} from 'react-native';
|
|
3
|
-
import {CheckBox, Input, Radio, Text} from '@momo-kits/foundation';
|
|
4
|
-
import {PlaygroundProps, PropValue} from './types';
|
|
5
|
-
import styles from './styles';
|
|
6
|
-
import {Colors, Radius, Spacing} from '../Consts';
|
|
7
|
-
import {ApplicationContext} from '../Navigation';
|
|
8
|
-
import {ScreenSection, SectionItem} from '../Layout';
|
|
9
|
-
import {Icon, IconSources} from '../Icon';
|
|
10
|
-
import {string} from 'prop-types';
|
|
11
|
-
|
|
12
|
-
const ChooseOptionScreen = (
|
|
13
|
-
data: string[] = [],
|
|
14
|
-
optionType: 'color' | 'icon' | 'text' = 'text',
|
|
15
|
-
onPress: (value: string) => void,
|
|
16
|
-
) => {
|
|
17
|
-
const {theme} = useContext(ApplicationContext);
|
|
18
|
-
|
|
19
|
-
let mapData = data;
|
|
20
|
-
if (optionType === 'color') {
|
|
21
|
-
mapData = Object.values(Colors);
|
|
22
|
-
}
|
|
23
|
-
if (optionType === 'icon') {
|
|
24
|
-
mapData = Object.keys(IconSources);
|
|
25
|
-
}
|
|
26
|
-
const renderItemView = (item: string) => {
|
|
27
|
-
switch (optionType) {
|
|
28
|
-
case 'color': {
|
|
29
|
-
return (
|
|
30
|
-
<View
|
|
31
|
-
style={{
|
|
32
|
-
width: 36,
|
|
33
|
-
height: 36,
|
|
34
|
-
borderRadius: Radius.M,
|
|
35
|
-
backgroundColor: item,
|
|
36
|
-
marginRight: Spacing.S,
|
|
37
|
-
}}
|
|
38
|
-
/>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
case 'icon': {
|
|
42
|
-
return <Icon source={item} style={{marginRight: Spacing.S}} />;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const renderItem = ({item, index}) => {
|
|
48
|
-
const iconSource: {[key: string]: {uri: string}} = IconSources;
|
|
49
|
-
let key = item;
|
|
50
|
-
let chosenItem = item;
|
|
51
|
-
if (optionType === 'color') key = Object.keys(Colors)[index];
|
|
52
|
-
if (optionType === 'icon') chosenItem = iconSource[key].uri;
|
|
53
|
-
return (
|
|
54
|
-
<TouchableOpacity
|
|
55
|
-
key={`${item.toString()} ${index}`}
|
|
56
|
-
onPress={() => onPress(chosenItem)}
|
|
57
|
-
style={{
|
|
58
|
-
flexDirection: 'row',
|
|
59
|
-
alignItems: 'center',
|
|
60
|
-
marginBottom: Spacing.M,
|
|
61
|
-
borderBottomWidth: index !== mapData.length - 1 ? 1 : 0,
|
|
62
|
-
borderColor: theme.colors.border.default,
|
|
63
|
-
paddingBottom: Spacing.M,
|
|
64
|
-
}}>
|
|
65
|
-
{renderItemView(item)}
|
|
66
|
-
<Text typography={'description_default'}>{key}</Text>
|
|
67
|
-
</TouchableOpacity>
|
|
68
|
-
);
|
|
69
|
-
};
|
|
70
|
-
return (
|
|
71
|
-
<ScreenSection>
|
|
72
|
-
<SectionItem widthSpan={12}>
|
|
73
|
-
<FlatList
|
|
74
|
-
data={mapData}
|
|
75
|
-
renderItem={renderItem}
|
|
76
|
-
keyExtractor={(item, index) => `${item.toString()} ${index}`}
|
|
77
|
-
showsVerticalScrollIndicator={false}
|
|
78
|
-
/>
|
|
79
|
-
</SectionItem>
|
|
80
|
-
</ScreenSection>
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const Playground: FC<PlaygroundProps> = ({params}) => {
|
|
85
|
-
const {theme, navigator} = useContext(ApplicationContext);
|
|
86
|
-
const {props} = params;
|
|
87
|
-
const [compProps, setCompProps] = useState<{[key: string]: any}>({});
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
initProps();
|
|
90
|
-
return () => {};
|
|
91
|
-
}, [props]);
|
|
92
|
-
|
|
93
|
-
const initProps = () => {
|
|
94
|
-
let newProps = {};
|
|
95
|
-
Object.keys(props).forEach(i => {
|
|
96
|
-
newProps = {...newProps, [i]: props[i].value};
|
|
97
|
-
});
|
|
98
|
-
setCompProps(newProps);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const onChangeOptions = (
|
|
102
|
-
value: string | boolean | undefined,
|
|
103
|
-
key: string,
|
|
104
|
-
) => {
|
|
105
|
-
const newProps = {...compProps, [key]: value};
|
|
106
|
-
setCompProps(newProps);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const onCheckUndefined = (value: boolean, key: string) => {
|
|
110
|
-
let newValue = !value ? undefined : props?.[key]?.value;
|
|
111
|
-
const newProps = {...compProps, [key]: newValue};
|
|
112
|
-
setCompProps(newProps);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const showOptions = (prop: any, key: string) => {
|
|
116
|
-
navigator?.showBottomSheet({
|
|
117
|
-
options: {
|
|
118
|
-
title: 'Choose option',
|
|
119
|
-
},
|
|
120
|
-
screen: () =>
|
|
121
|
-
ChooseOptionScreen(prop.data, prop.optionType, optionValue => {
|
|
122
|
-
onChangeOptions(optionValue, key);
|
|
123
|
-
navigator?.pop();
|
|
124
|
-
}),
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const generateView = (key: string, prop: PropValue) => {
|
|
129
|
-
let PlayGroundView = <View />;
|
|
130
|
-
switch (prop.type) {
|
|
131
|
-
case 'enum': {
|
|
132
|
-
PlayGroundView = (
|
|
133
|
-
<View style={styles.radioView}>
|
|
134
|
-
{prop?.options?.map(option => {
|
|
135
|
-
return (
|
|
136
|
-
<Radio
|
|
137
|
-
label={option}
|
|
138
|
-
value={option}
|
|
139
|
-
onChange={() => onChangeOptions(option, key)}
|
|
140
|
-
groupValue={compProps?.[key]}
|
|
141
|
-
style={{marginBottom: Spacing.S}}
|
|
142
|
-
/>
|
|
143
|
-
);
|
|
144
|
-
})}
|
|
145
|
-
</View>
|
|
146
|
-
);
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
case 'string': {
|
|
150
|
-
PlayGroundView = (
|
|
151
|
-
<Input
|
|
152
|
-
size={'small'}
|
|
153
|
-
floatingValue={key}
|
|
154
|
-
value={compProps?.[key]}
|
|
155
|
-
onChangeText={text => onChangeOptions(text, key)}
|
|
156
|
-
/>
|
|
157
|
-
);
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
case 'bool': {
|
|
161
|
-
let label = compProps?.[key] === true ? 'True' : 'False';
|
|
162
|
-
if (compProps?.[key] === undefined) {
|
|
163
|
-
label = 'undefined';
|
|
164
|
-
}
|
|
165
|
-
PlayGroundView = (
|
|
166
|
-
<CheckBox
|
|
167
|
-
label={label}
|
|
168
|
-
value={compProps?.[key]}
|
|
169
|
-
onChange={value => onChangeOptions(value, key)}
|
|
170
|
-
/>
|
|
171
|
-
);
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
case 'options': {
|
|
175
|
-
PlayGroundView = (
|
|
176
|
-
<TouchableOpacity
|
|
177
|
-
style={{
|
|
178
|
-
width: '100%',
|
|
179
|
-
height: 48,
|
|
180
|
-
borderRadius: Radius.M,
|
|
181
|
-
borderColor: theme.colors.border.default,
|
|
182
|
-
borderWidth: 1,
|
|
183
|
-
justifyContent: 'center',
|
|
184
|
-
alignItems: 'center',
|
|
185
|
-
flexDirection: 'row',
|
|
186
|
-
backgroundColor: theme.colors.background.surface,
|
|
187
|
-
}}
|
|
188
|
-
onPress={() => showOptions(prop, key)}>
|
|
189
|
-
<Text typography={'description_default'}>{compProps?.[key]}</Text>
|
|
190
|
-
<View style={{position: 'absolute', right: Spacing.M}}>
|
|
191
|
-
<Icon source={'arrow_chevron_down_small'} size={24} />
|
|
192
|
-
</View>
|
|
193
|
-
</TouchableOpacity>
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return (
|
|
199
|
-
<View
|
|
200
|
-
style={[
|
|
201
|
-
styles.propView,
|
|
202
|
-
{backgroundColor: theme.colors.background.surface},
|
|
203
|
-
]}>
|
|
204
|
-
<Text style={styles.propTitle} typography={'header_default'}>
|
|
205
|
-
{key}
|
|
206
|
-
</Text>
|
|
207
|
-
{PlayGroundView}
|
|
208
|
-
{typeof compProps?.[key] !== 'boolean' && (
|
|
209
|
-
<CheckBox
|
|
210
|
-
style={{marginTop: Spacing.M}}
|
|
211
|
-
label={'Is undefined'}
|
|
212
|
-
value={!compProps?.[key]}
|
|
213
|
-
onChange={value => onCheckUndefined(!value, key)}
|
|
214
|
-
/>
|
|
215
|
-
)}
|
|
216
|
-
</View>
|
|
217
|
-
);
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const Component = params.component ?? <View />;
|
|
221
|
-
const propsKeys = Object.keys(props);
|
|
222
|
-
|
|
223
|
-
return (
|
|
224
|
-
<View>
|
|
225
|
-
<Text style={{marginBottom: Spacing.M}} typography={'title_s'}>
|
|
226
|
-
Component
|
|
227
|
-
</Text>
|
|
228
|
-
<View
|
|
229
|
-
style={[
|
|
230
|
-
styles.propView,
|
|
231
|
-
{
|
|
232
|
-
backgroundColor: theme.colors.background.surface,
|
|
233
|
-
justifyContent: 'center',
|
|
234
|
-
alignItems: 'center',
|
|
235
|
-
},
|
|
236
|
-
]}>
|
|
237
|
-
<Component {...compProps} />
|
|
238
|
-
</View>
|
|
239
|
-
<Text style={{marginBottom: Spacing.M}} typography={'title_s'}>
|
|
240
|
-
Props
|
|
241
|
-
</Text>
|
|
242
|
-
{propsKeys.map(prop => {
|
|
243
|
-
return generateView(prop, props[prop]);
|
|
244
|
-
})}
|
|
245
|
-
</View>
|
|
246
|
-
);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
export default Playground;
|
package/Playground/styles.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {StyleSheet} from 'react-native';
|
|
2
|
-
import {Colors, Radius, Spacing} from '../Consts';
|
|
3
|
-
|
|
4
|
-
export default StyleSheet.create({
|
|
5
|
-
radioView: {
|
|
6
|
-
flexDirection: 'row',
|
|
7
|
-
flexWrap: 'wrap',
|
|
8
|
-
alignItems: 'center',
|
|
9
|
-
},
|
|
10
|
-
propView: {
|
|
11
|
-
borderRadius: Radius.M,
|
|
12
|
-
padding: Spacing.M,
|
|
13
|
-
marginBottom: Spacing.M,
|
|
14
|
-
},
|
|
15
|
-
propTitle: {marginBottom: Spacing.S, textTransform: 'capitalize'},
|
|
16
|
-
});
|
package/Playground/types.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {ReactElement} from 'react';
|
|
2
|
-
|
|
3
|
-
export type PropValue = {
|
|
4
|
-
value: any;
|
|
5
|
-
options?: string[];
|
|
6
|
-
type: 'string' | 'options' | 'enum' | 'bool';
|
|
7
|
-
description?: string;
|
|
8
|
-
data?: {[key: string]: string}[];
|
|
9
|
-
optionType?: 'icon' | 'color';
|
|
10
|
-
};
|
|
11
|
-
export type PlaygroundProps = {
|
|
12
|
-
params: {
|
|
13
|
-
component: ReactElement;
|
|
14
|
-
props: {[key: string]: PropValue};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
File without changes
|