@momo-kits/foundation 1.0.3 → 1.0.5
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/Button/index.tsx +0 -1
- package/CheckBox/index.tsx +3 -5
- package/CheckBox/styles.ts +4 -2
- package/ContentLoader/index.tsx +1 -1
- package/Icon/icon.json +3 -0
- package/Icon/index.tsx +6 -4
- package/Icon/types.ts +4 -1
- package/Image/index.tsx +8 -9
- package/Image/types.ts +1 -3
- package/Input/Input.tsx +18 -38
- package/Input/SearchInput.tsx +153 -0
- package/Input/TextArea.tsx +19 -33
- package/Input/common.tsx +37 -7
- package/Input/index.tsx +14 -9
- package/Input/styles.ts +32 -6
- package/Layout/ScreenContainer.tsx +2 -22
- package/Navigation/Components.tsx +54 -16
- package/Navigation/ModalScreen.tsx +10 -12
- package/Navigation/Navigation.ts +7 -6
- package/Navigation/NavigationContainer.tsx +22 -17
- package/Navigation/StackScreen.tsx +12 -7
- package/Navigation/types.ts +4 -8
- package/Navigation/utils.tsx +51 -27
- package/Playground/index.tsx +142 -5
- package/Playground/types.ts +3 -2
- package/Popup/PopupPromotion.tsx +1 -5
- package/Popup/types.ts +0 -1
- package/Radio/index.tsx +16 -8
- package/Radio/styles.ts +0 -1
- package/Radio/types.ts +4 -1
- package/Switch/index.tsx +6 -2
- package/Switch/types.ts +4 -1
- package/package.json +3 -2
package/Playground/index.tsx
CHANGED
|
@@ -1,13 +1,104 @@
|
|
|
1
1
|
import React, {FC, useContext, useEffect, useState} from 'react';
|
|
2
|
-
import {View} from 'react-native';
|
|
2
|
+
import {FlatList, TouchableOpacity, View} from 'react-native';
|
|
3
3
|
import {CheckBox, Input, Radio, Text} from '@momo-kits/foundation';
|
|
4
4
|
import {PlaygroundProps, PropValue} from './types';
|
|
5
5
|
import styles from './styles';
|
|
6
|
-
import {Spacing} from '../Consts';
|
|
6
|
+
import {Colors, Radius, Spacing} from '../Consts';
|
|
7
7
|
import {ApplicationContext} from '../Navigation';
|
|
8
|
+
import {ScreenSection, SectionItem} from '../Layout';
|
|
9
|
+
import {Icon, IconSources} from '../Icon';
|
|
10
|
+
import {SearchInput} from '../Input';
|
|
8
11
|
|
|
9
|
-
const
|
|
12
|
+
const ChooseOptionScreen = (
|
|
13
|
+
data: string[] = [],
|
|
14
|
+
optionType: 'color' | 'icon' | 'text' = 'text',
|
|
15
|
+
onPress: (value: string) => void,
|
|
16
|
+
) => {
|
|
10
17
|
const {theme} = useContext(ApplicationContext);
|
|
18
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
19
|
+
const [filteredData, setFilteredData] = useState<string[]>([]);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let mapData = data;
|
|
23
|
+
if (optionType === 'color') {
|
|
24
|
+
mapData = Object.values(Colors);
|
|
25
|
+
}
|
|
26
|
+
if (optionType === 'icon') {
|
|
27
|
+
mapData = Object.keys(IconSources);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setFilteredData(mapData);
|
|
31
|
+
return () => {};
|
|
32
|
+
}, [filteredData]);
|
|
33
|
+
|
|
34
|
+
const renderItemView = (item: string) => {
|
|
35
|
+
switch (optionType) {
|
|
36
|
+
case 'color': {
|
|
37
|
+
return (
|
|
38
|
+
<View
|
|
39
|
+
style={{
|
|
40
|
+
width: 36,
|
|
41
|
+
height: 36,
|
|
42
|
+
borderRadius: Radius.M,
|
|
43
|
+
backgroundColor: item,
|
|
44
|
+
marginRight: Spacing.S,
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
case 'icon': {
|
|
50
|
+
return <Icon source={item} style={{marginRight: Spacing.S}} />;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const onSearch = (text: string) => {
|
|
56
|
+
let newData = filteredData.map(i => i.includes(text));
|
|
57
|
+
if (text === '') {
|
|
58
|
+
newData = mapData;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const renderItem = ({item, index}) => {
|
|
63
|
+
const iconSource: {[key: string]: {uri: string}} = IconSources;
|
|
64
|
+
let key = item;
|
|
65
|
+
let chosenItem = item;
|
|
66
|
+
if (optionType === 'color') key = Object.keys(Colors)[index];
|
|
67
|
+
if (optionType === 'icon') chosenItem = iconSource[key].uri;
|
|
68
|
+
return (
|
|
69
|
+
<TouchableOpacity
|
|
70
|
+
key={`${item.toString()} ${index}`}
|
|
71
|
+
onPress={() => onPress(chosenItem)}
|
|
72
|
+
style={{
|
|
73
|
+
flexDirection: 'row',
|
|
74
|
+
alignItems: 'center',
|
|
75
|
+
marginBottom: Spacing.M,
|
|
76
|
+
borderBottomWidth: index !== filteredData.length - 1 ? 1 : 0,
|
|
77
|
+
borderColor: theme.colors.border.default,
|
|
78
|
+
paddingBottom: Spacing.M,
|
|
79
|
+
}}>
|
|
80
|
+
{renderItemView(item)}
|
|
81
|
+
<Text typography={'description_default'}>{key}</Text>
|
|
82
|
+
</TouchableOpacity>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
return (
|
|
86
|
+
<ScreenSection>
|
|
87
|
+
<SectionItem widthSpan={12}>
|
|
88
|
+
<SearchInput value={searchTerm} onChangeText={onSearch} />
|
|
89
|
+
<FlatList
|
|
90
|
+
data={filteredData}
|
|
91
|
+
renderItem={renderItem}
|
|
92
|
+
keyExtractor={(item, index) => `${item.toString()} ${index}`}
|
|
93
|
+
showsVerticalScrollIndicator={false}
|
|
94
|
+
/>
|
|
95
|
+
</SectionItem>
|
|
96
|
+
</ScreenSection>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const Playground: FC<PlaygroundProps> = ({params}) => {
|
|
101
|
+
const {theme, navigator} = useContext(ApplicationContext);
|
|
11
102
|
const {props} = params;
|
|
12
103
|
const [compProps, setCompProps] = useState<{[key: string]: any}>({});
|
|
13
104
|
useEffect(() => {
|
|
@@ -37,6 +128,19 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
|
|
|
37
128
|
setCompProps(newProps);
|
|
38
129
|
};
|
|
39
130
|
|
|
131
|
+
const showOptions = (prop: any, key: string) => {
|
|
132
|
+
navigator?.showBottomSheet({
|
|
133
|
+
options: {
|
|
134
|
+
title: 'Choose option',
|
|
135
|
+
},
|
|
136
|
+
screen: () =>
|
|
137
|
+
ChooseOptionScreen(prop.data, prop.optionType, optionValue => {
|
|
138
|
+
onChangeOptions(optionValue, key);
|
|
139
|
+
navigator?.pop();
|
|
140
|
+
}),
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
|
|
40
144
|
const generateView = (key: string, prop: PropValue) => {
|
|
41
145
|
let PlayGroundView = <View />;
|
|
42
146
|
switch (prop.type) {
|
|
@@ -50,6 +154,11 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
|
|
|
50
154
|
value={option}
|
|
51
155
|
onChange={() => onChangeOptions(option, key)}
|
|
52
156
|
groupValue={compProps?.[key]}
|
|
157
|
+
style={{
|
|
158
|
+
marginBottom: Spacing.S,
|
|
159
|
+
marginRight: Spacing.M,
|
|
160
|
+
width: '25%',
|
|
161
|
+
}}
|
|
53
162
|
/>
|
|
54
163
|
);
|
|
55
164
|
})}
|
|
@@ -62,6 +171,7 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
|
|
|
62
171
|
<Input
|
|
63
172
|
size={'small'}
|
|
64
173
|
floatingValue={key}
|
|
174
|
+
value={compProps?.[key]}
|
|
65
175
|
onChangeText={text => onChangeOptions(text, key)}
|
|
66
176
|
/>
|
|
67
177
|
);
|
|
@@ -79,6 +189,29 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
|
|
|
79
189
|
onChange={value => onChangeOptions(value, key)}
|
|
80
190
|
/>
|
|
81
191
|
);
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case 'options': {
|
|
195
|
+
PlayGroundView = (
|
|
196
|
+
<TouchableOpacity
|
|
197
|
+
style={{
|
|
198
|
+
width: '100%',
|
|
199
|
+
height: 48,
|
|
200
|
+
borderRadius: Radius.M,
|
|
201
|
+
borderColor: theme.colors.border.default,
|
|
202
|
+
borderWidth: 1,
|
|
203
|
+
justifyContent: 'center',
|
|
204
|
+
alignItems: 'center',
|
|
205
|
+
flexDirection: 'row',
|
|
206
|
+
backgroundColor: theme.colors.background.surface,
|
|
207
|
+
}}
|
|
208
|
+
onPress={() => showOptions(prop, key)}>
|
|
209
|
+
<Text typography={'description_default'}>{compProps?.[key]}</Text>
|
|
210
|
+
<View style={{position: 'absolute', right: Spacing.M}}>
|
|
211
|
+
<Icon source={'arrow_chevron_down_small'} size={24} />
|
|
212
|
+
</View>
|
|
213
|
+
</TouchableOpacity>
|
|
214
|
+
);
|
|
82
215
|
}
|
|
83
216
|
}
|
|
84
217
|
|
|
@@ -106,6 +239,7 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
|
|
|
106
239
|
|
|
107
240
|
const Component = params.component ?? <View />;
|
|
108
241
|
const propsKeys = Object.keys(props);
|
|
242
|
+
|
|
109
243
|
return (
|
|
110
244
|
<View>
|
|
111
245
|
<Text style={{marginBottom: Spacing.M}} typography={'title_s'}>
|
|
@@ -114,9 +248,12 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
|
|
|
114
248
|
<View
|
|
115
249
|
style={[
|
|
116
250
|
styles.propView,
|
|
117
|
-
{
|
|
251
|
+
{
|
|
252
|
+
backgroundColor: theme.colors.background.surface,
|
|
253
|
+
justifyContent: 'center',
|
|
254
|
+
alignItems: 'center',
|
|
255
|
+
},
|
|
118
256
|
]}>
|
|
119
|
-
<Text typography={'header_default'}>{params.displayName}</Text>
|
|
120
257
|
<Component {...compProps} />
|
|
121
258
|
</View>
|
|
122
259
|
<Text style={{marginBottom: Spacing.M}} typography={'title_s'}>
|
package/Playground/types.ts
CHANGED
|
@@ -3,13 +3,14 @@ import {ReactElement} from 'react';
|
|
|
3
3
|
export type PropValue = {
|
|
4
4
|
value: any;
|
|
5
5
|
options?: string[];
|
|
6
|
-
type: 'string' | 'enum' | 'bool';
|
|
6
|
+
type: 'string' | 'options' | 'enum' | 'bool';
|
|
7
7
|
description?: string;
|
|
8
|
+
data?: {[key: string]: string}[];
|
|
9
|
+
optionType?: 'icon' | 'color';
|
|
8
10
|
};
|
|
9
11
|
export type PlaygroundProps = {
|
|
10
12
|
params: {
|
|
11
13
|
component: ReactElement;
|
|
12
|
-
displayName: string;
|
|
13
14
|
props: {[key: string]: PropValue};
|
|
14
15
|
};
|
|
15
16
|
};
|
package/Popup/PopupPromotion.tsx
CHANGED
|
@@ -6,11 +6,7 @@ import {Image} from '../Image';
|
|
|
6
6
|
import {Button} from '../Button';
|
|
7
7
|
import {Spacing} from '../Consts';
|
|
8
8
|
|
|
9
|
-
const PopupPromotion: React.FC<PopupPromotionProps> = ({
|
|
10
|
-
image,
|
|
11
|
-
primary,
|
|
12
|
-
onIconClose,
|
|
13
|
-
}) => {
|
|
9
|
+
const PopupPromotion: React.FC<PopupPromotionProps> = ({image, primary}) => {
|
|
14
10
|
const {theme, navigator} = useContext(ApplicationContext);
|
|
15
11
|
|
|
16
12
|
/**
|
package/Popup/types.ts
CHANGED
package/Radio/index.tsx
CHANGED
|
@@ -13,6 +13,7 @@ const Radio: FC<RadioProps> = ({
|
|
|
13
13
|
disabled,
|
|
14
14
|
onChange,
|
|
15
15
|
label,
|
|
16
|
+
style,
|
|
16
17
|
}) => {
|
|
17
18
|
const {theme} = useContext(ApplicationContext);
|
|
18
19
|
const selected = value === groupValue;
|
|
@@ -26,15 +27,22 @@ const Radio: FC<RadioProps> = ({
|
|
|
26
27
|
|
|
27
28
|
return (
|
|
28
29
|
<TouchableOpacity
|
|
29
|
-
onPress={
|
|
30
|
+
onPress={onChange}
|
|
30
31
|
disabled={disabled}
|
|
31
|
-
style={
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
style={[
|
|
33
|
+
style,
|
|
34
|
+
{
|
|
35
|
+
flexDirection: 'row',
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
},
|
|
38
|
+
]}>
|
|
39
|
+
<View
|
|
40
|
+
style={[
|
|
41
|
+
styles.radio,
|
|
42
|
+
{borderWidth, borderColor, marginRight: !!label ? Spacing.XS : 0},
|
|
43
|
+
]}
|
|
44
|
+
/>
|
|
45
|
+
{!!label && <Text typography={'description_default'}>{label}</Text>}
|
|
38
46
|
</TouchableOpacity>
|
|
39
47
|
);
|
|
40
48
|
};
|
package/Radio/styles.ts
CHANGED
package/Radio/types.ts
CHANGED
package/Switch/index.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import {Colors} from '../Consts';
|
|
|
7
7
|
|
|
8
8
|
const Switch: FC<SwitchProps> = props => {
|
|
9
9
|
const {theme} = useContext(ApplicationContext);
|
|
10
|
-
const {value, onChange, disabled} = props;
|
|
10
|
+
const {value, onChange, disabled, style} = props;
|
|
11
11
|
const circleBackgroundColor = value ? Colors.black_01 : Colors.black_03;
|
|
12
12
|
const circleAlign = value ? 'flex-end' : 'flex-start';
|
|
13
13
|
|
|
@@ -20,7 +20,11 @@ const Switch: FC<SwitchProps> = props => {
|
|
|
20
20
|
<TouchableOpacity
|
|
21
21
|
disabled={disabled}
|
|
22
22
|
onPress={() => onChange?.(!value)}
|
|
23
|
-
style={[
|
|
23
|
+
style={[
|
|
24
|
+
style,
|
|
25
|
+
styles.container,
|
|
26
|
+
{backgroundColor, alignItems: circleAlign},
|
|
27
|
+
]}>
|
|
24
28
|
<View style={[styles.circle, {backgroundColor: circleBackgroundColor}]}>
|
|
25
29
|
<View style={[styles.circleSmall, {backgroundColor}]} />
|
|
26
30
|
</View>
|
package/Switch/types.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/foundation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "React Native Component Kits",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"react-native-safe-area-context": "3.1.4",
|
|
14
|
-
"
|
|
14
|
+
"react-native-linear-gradient": "2.5.6",
|
|
15
|
+
"@react-navigation/bottom-tabs": "git+https://gitlab.com/dung.huynh1/react-navigation-bottom-tabs.git#main",
|
|
15
16
|
"@react-navigation/core": "5.16.1",
|
|
16
17
|
"@react-navigation/native": "5.9.8",
|
|
17
18
|
"@react-navigation/routers": "5.7.4",
|