@momo-kits/foundation 0.76.1-beta.2 → 0.77.1-optimize.2
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/Application/BottomTab/BottomTabBar.tsx +478 -0
- package/Application/BottomTab/index.tsx +134 -0
- package/Application/Components.tsx +339 -161
- package/Application/ModalScreen.tsx +113 -99
- package/Application/Navigation.ts +22 -16
- package/Application/NavigationContainer.tsx +99 -48
- package/Application/Navigator.ts +110 -41
- package/Application/StackScreen.tsx +126 -8
- package/Application/index.ts +23 -4
- package/Application/types.ts +84 -33
- package/Application/utils.tsx +90 -50
- package/Assets/DotAnimation.json +256 -0
- package/Assets/SpinnerAnimation.json +1027 -0
- package/Assets/icon.json +83 -5
- package/Assets/icon_bank.json +506 -0
- package/Assets/language.json +202 -0
- package/Badge/Badge.tsx +56 -0
- package/Badge/BadgeDot.tsx +11 -0
- package/Badge/BadgeRibbon.tsx +125 -0
- package/Badge/Shape.tsx +29 -0
- package/Badge/index.tsx +7 -0
- package/Badge/styles.ts +58 -0
- package/Badge/types.ts +63 -0
- package/Button/index.tsx +90 -39
- package/Button/styles.ts +19 -0
- package/CheckBox/index.tsx +58 -43
- package/CheckBox/styles.ts +1 -1
- package/CheckBox/types.ts +6 -4
- package/Consts/colors+spacing+radius.ts +18 -0
- package/Consts/styles.ts +0 -26
- package/Consts/theme.ts +4 -0
- package/Divider/index.tsx +2 -0
- package/Icon/index.tsx +13 -9
- package/Icon/types.ts +4 -3
- package/IconButton/index.tsx +24 -15
- package/Image/index.tsx +60 -48
- package/Image/styles.ts +1 -9
- package/Image/types.ts +5 -1
- package/Input/Input.tsx +227 -116
- package/Input/InputDropDown.tsx +132 -0
- package/Input/InputMoney.tsx +174 -111
- package/Input/InputOTP.tsx +257 -0
- package/Input/InputSearch.tsx +160 -132
- package/Input/InputTextArea.tsx +150 -123
- package/Input/common.tsx +42 -17
- package/Input/index.tsx +204 -18
- package/Input/styles.ts +44 -7
- package/Input/utils.ts +2 -2
- package/Layout/Card.tsx +67 -29
- package/Layout/FloatingButton.tsx +128 -0
- package/Layout/GridSystem.tsx +31 -21
- package/Layout/Item.tsx +21 -25
- package/Layout/ItemList.tsx +55 -0
- package/Layout/ItemSectionList.tsx +39 -0
- package/Layout/Screen.tsx +348 -153
- package/Layout/Section.tsx +66 -34
- package/Layout/index.ts +13 -3
- package/Layout/styles.ts +101 -0
- package/Layout/types.ts +1 -39
- package/Layout/utils.ts +27 -52
- package/Loader/DotLoader.tsx +37 -0
- package/Loader/Loader.tsx +13 -0
- package/Loader/ProgressBar.tsx +44 -0
- package/Loader/Spinner.tsx +29 -0
- package/Loader/index.tsx +4 -0
- package/Loader/styles.ts +10 -0
- package/Loader/types.ts +35 -0
- package/Loader/utils.ts +25 -0
- package/Pagination/PaginationDot.tsx +7 -2
- package/Pagination/PaginationNumber.tsx +8 -6
- package/Pagination/PaginationScroll.tsx +0 -1
- package/Pagination/PaginationWhiteDot.tsx +8 -5
- package/Pagination/styles.ts +3 -0
- package/Pagination/types.ts +2 -0
- package/Popup/PopupNotify.tsx +102 -44
- package/Popup/PopupPromotion.tsx +63 -22
- package/Popup/types.ts +15 -4
- package/Radio/index.tsx +35 -21
- package/Radio/types.ts +7 -5
- package/Skeleton/index.tsx +1 -1
- package/Skeleton/types.ts +3 -0
- package/Switch/index.tsx +35 -24
- package/Switch/types.ts +5 -3
- package/Tag/index.tsx +2 -4
- package/Text/index.tsx +27 -22
- package/Text/styles.ts +38 -0
- package/Text/types.ts +25 -13
- package/Text/utils.ts +1 -1
- package/Title/index.tsx +186 -0
- package/Title/styles.ts +79 -0
- package/Title/types.ts +20 -0
- package/code-scanner.js +143 -0
- package/index.ts +8 -1
- package/migrate_typo.js +56 -0
- package/package.json +14 -9
- package/tsconfig.json +24 -0
- package/verify.js +47 -0
- package/Application/BottomTab.tsx +0 -52
- package/Application/NavigationButton.tsx +0 -54
- package/Assets/header-background.png +0 -0
package/Image/index.tsx
CHANGED
|
@@ -1,82 +1,94 @@
|
|
|
1
|
-
import React, {useContext, useState} from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import FastImage from 'react-native-fast-image';
|
|
1
|
+
import React, {useContext, useEffect, useRef, useState} from 'react';
|
|
2
|
+
import {StyleSheet, View} from 'react-native';
|
|
3
|
+
import FastImage, {Source} from 'react-native-fast-image';
|
|
4
4
|
import styles from './styles';
|
|
5
|
-
import {ApplicationContext} from '../Application';
|
|
5
|
+
import {ApplicationContext, ComponentContext, MiniAppContext} from '../Application';
|
|
6
6
|
import {Skeleton} from '../Skeleton';
|
|
7
7
|
import {Icon} from '../Icon';
|
|
8
8
|
import {Styles} from '../Consts';
|
|
9
|
-
import {
|
|
9
|
+
import {ImageProps} from './types';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
style?: StyleProp<ViewStyle>;
|
|
13
|
-
loading?: boolean;
|
|
14
|
-
accessibilityLabel?: string;
|
|
15
|
-
}
|
|
11
|
+
type Status = 'success' | 'loading' | 'error';
|
|
16
12
|
|
|
17
13
|
const Image: React.FC<ImageProps> = ({
|
|
18
14
|
style,
|
|
19
15
|
source,
|
|
16
|
+
loading = true,
|
|
17
|
+
children,
|
|
18
|
+
params,
|
|
20
19
|
accessibilityLabel,
|
|
21
20
|
...rest
|
|
22
21
|
}) => {
|
|
23
22
|
const {theme} = useContext(ApplicationContext);
|
|
24
|
-
const
|
|
25
|
-
const
|
|
23
|
+
const app = useContext<any>(MiniAppContext);
|
|
24
|
+
const component = useContext<any>(ComponentContext);
|
|
25
|
+
const error = useRef(false);
|
|
26
|
+
const [status, setStatus] = useState<Status>('success');
|
|
27
|
+
|
|
28
|
+
const test: any = {
|
|
29
|
+
accessibilityLabel: accessibilityLabel || `img|${(source as Source).uri}`,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if(app.enableAutoId){
|
|
34
|
+
component?.addChildren?.(test.accessibilityLabel, 'add');
|
|
35
|
+
return () => component?.addChildren(test.accessibilityLabel, 'remove');
|
|
36
|
+
}
|
|
37
|
+
}, []);
|
|
26
38
|
|
|
27
39
|
/**
|
|
28
40
|
* render content loading | fail | rendered
|
|
29
|
-
* @returns {JSX.Element}
|
|
30
41
|
*/
|
|
31
42
|
const renderContent = () => {
|
|
32
|
-
if (loading ||
|
|
33
|
-
let content =
|
|
34
|
-
|
|
35
|
-
);
|
|
36
|
-
if (fail) {
|
|
43
|
+
if (status === 'loading' || status === 'error') {
|
|
44
|
+
let content = <Skeleton />;
|
|
45
|
+
if (status === 'error') {
|
|
37
46
|
content = (
|
|
38
|
-
<
|
|
39
|
-
<Icon source="media_fail" color={theme.colors.text.disable} />
|
|
40
|
-
</View>
|
|
47
|
+
<Icon source="media_fail" color={theme.colors.text.disable} />
|
|
41
48
|
);
|
|
42
49
|
}
|
|
43
50
|
return (
|
|
44
|
-
<View
|
|
45
|
-
style={[
|
|
46
|
-
StyleSheet.absoluteFill,
|
|
47
|
-
styles.image,
|
|
48
|
-
{backgroundColor: theme.colors.background.disable},
|
|
49
|
-
]}>
|
|
51
|
+
<View style={[StyleSheet.absoluteFill, Styles.flexCenter]}>
|
|
50
52
|
{content}
|
|
51
53
|
</View>
|
|
52
54
|
);
|
|
53
55
|
}
|
|
56
|
+
return children;
|
|
54
57
|
};
|
|
55
58
|
|
|
56
59
|
return (
|
|
57
|
-
<View
|
|
58
|
-
style={[styles.container, style]}
|
|
59
|
-
accessibilityLabel={`Image/${
|
|
60
|
-
accessibilityLabel ?? (typeof source === 'number' ? source : source.uri)
|
|
61
|
-
}`}>
|
|
62
60
|
<FastImage
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
{...rest}
|
|
62
|
+
{...test}
|
|
63
|
+
source={source}
|
|
64
|
+
style={[styles.container, style]}
|
|
65
|
+
onProgress={() => {
|
|
66
|
+
error.current = false;
|
|
67
|
+
if (status !== 'loading' && loading) {
|
|
68
|
+
setStatus('loading');
|
|
69
|
+
}
|
|
70
|
+
}}
|
|
71
|
+
onLoadStart={() => {
|
|
72
|
+
error.current = false;
|
|
73
|
+
}}
|
|
74
|
+
onLoad={() => {
|
|
75
|
+
error.current = false;
|
|
76
|
+
}}
|
|
77
|
+
onLoadEnd={() => {
|
|
78
|
+
let current: Status = 'success';
|
|
79
|
+
if (error.current) {
|
|
80
|
+
current = 'error';
|
|
81
|
+
}
|
|
82
|
+
if (status !== current) {
|
|
83
|
+
setStatus(current);
|
|
84
|
+
}
|
|
85
|
+
}}
|
|
86
|
+
onError={() => {
|
|
87
|
+
error.current = true;
|
|
88
|
+
}}>
|
|
89
|
+
{renderContent()}
|
|
90
|
+
</FastImage>
|
|
75
91
|
);
|
|
76
92
|
};
|
|
77
93
|
|
|
78
|
-
Image.defaultProps = {
|
|
79
|
-
loading: true,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
94
|
export {Image};
|
package/Image/styles.ts
CHANGED
package/Image/types.ts
CHANGED
package/Input/Input.tsx
CHANGED
|
@@ -1,137 +1,248 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useContext,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import {
|
|
3
9
|
NativeSyntheticEvent,
|
|
10
|
+
Platform,
|
|
4
11
|
TextInput,
|
|
5
12
|
TextInputFocusEventData,
|
|
6
13
|
TouchableOpacity,
|
|
7
14
|
View,
|
|
8
15
|
} from 'react-native';
|
|
9
|
-
import {ApplicationContext} from '../Application';
|
|
10
|
-
import
|
|
16
|
+
import {ApplicationContext, ComponentContext} from '../Application';
|
|
17
|
+
import {Icon} from '../Icon';
|
|
18
|
+
import {Loader} from '../Loader';
|
|
11
19
|
import {ErrorView, FloatingView, getBorderColor, getSizeStyle} from './common';
|
|
12
20
|
import {InputProps} from './index';
|
|
13
|
-
import
|
|
21
|
+
import styles from './styles';
|
|
14
22
|
import {checkTyping} from './utils';
|
|
15
23
|
|
|
16
|
-
const Input
|
|
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
|
-
|
|
24
|
+
const Input = forwardRef(
|
|
25
|
+
(
|
|
26
|
+
{
|
|
27
|
+
value,
|
|
28
|
+
onChangeText,
|
|
29
|
+
floatingValue,
|
|
30
|
+
floatingIcon,
|
|
31
|
+
size = 'small',
|
|
32
|
+
placeholder,
|
|
33
|
+
onBlur,
|
|
34
|
+
onFocus,
|
|
35
|
+
errorMessage,
|
|
36
|
+
icon,
|
|
37
|
+
disabled = false,
|
|
38
|
+
floatingIconColor,
|
|
39
|
+
iconColor,
|
|
40
|
+
required = false,
|
|
41
|
+
errorSpacing,
|
|
42
|
+
loading = false,
|
|
43
|
+
leadingIcon,
|
|
44
|
+
leadingIconColor,
|
|
45
|
+
fontWeight = 'Regular',
|
|
46
|
+
onPressIcon,
|
|
47
|
+
secureTextEntry,
|
|
48
|
+
keyboardType,
|
|
49
|
+
style,
|
|
50
|
+
params,
|
|
51
|
+
hintText,
|
|
52
|
+
accessibilityLabel,
|
|
53
|
+
editable = true,
|
|
54
|
+
...props
|
|
55
|
+
}: InputProps,
|
|
56
|
+
ref,
|
|
57
|
+
) => {
|
|
58
|
+
const {theme} = useContext(ApplicationContext);
|
|
59
|
+
const [focused, setFocused] = useState(false);
|
|
60
|
+
const [haveValue, setHaveValue] = useState(!!value || !!props.defaultValue);
|
|
61
|
+
const [secureTextInput, setSecureTextInput] = useState(secureTextEntry);
|
|
62
|
+
const inputRef = useRef<TextInput | null>(null);
|
|
63
|
+
|
|
64
|
+
const onClearText = () => {
|
|
65
|
+
inputRef?.current?.clear();
|
|
66
|
+
_onChangeText('');
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const _onChangeText = (text: string) => {
|
|
70
|
+
checkTyping(text, haveValue, setHaveValue);
|
|
71
|
+
onChangeText?.(text);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const _onFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
75
|
+
setFocused(true);
|
|
76
|
+
onFocus?.(e);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const _onBlur = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
80
|
+
setFocused(false);
|
|
81
|
+
onBlur?.(e);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
useImperativeHandle(ref, () => {
|
|
85
|
+
return {
|
|
86
|
+
clear: onClearText,
|
|
87
|
+
focus: () => inputRef.current?.focus(),
|
|
88
|
+
blur: () => inputRef.current?.blur(),
|
|
89
|
+
setText: (text: string) => _onChangeText(text),
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const renderIcon = (color: string | undefined) => {
|
|
94
|
+
if (loading) {
|
|
95
|
+
return <Loader type={'spinner'} color={color} style={styles.icon} />;
|
|
96
|
+
}
|
|
97
|
+
if (secureTextEntry) {
|
|
98
|
+
return (
|
|
99
|
+
<TouchableOpacity
|
|
100
|
+
onPress={() => setSecureTextInput(!secureTextInput)}
|
|
101
|
+
style={styles.icon}>
|
|
102
|
+
<Icon
|
|
103
|
+
color={color}
|
|
104
|
+
size={24}
|
|
105
|
+
source={
|
|
106
|
+
secureTextInput ? '24_security_eye_off' : '24_security_eye_open'
|
|
107
|
+
}
|
|
108
|
+
/>
|
|
109
|
+
</TouchableOpacity>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (icon) {
|
|
113
|
+
return (
|
|
114
|
+
<TouchableOpacity
|
|
115
|
+
onPress={onPressIcon}
|
|
116
|
+
disabled={!onPressIcon}
|
|
117
|
+
style={styles.icon}>
|
|
118
|
+
<Icon color={color} source={icon} size={24} />
|
|
119
|
+
</TouchableOpacity>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const renderInputView = () => {
|
|
125
|
+
const disabledColor = theme.colors.text.disable;
|
|
126
|
+
const secure = secureTextInput && secureTextEntry;
|
|
127
|
+
let textColor = theme.colors.text.default;
|
|
128
|
+
let placeholderColor = theme.colors.text.hint;
|
|
129
|
+
let iconTintColor = iconColor;
|
|
130
|
+
|
|
131
|
+
if (disabled) {
|
|
132
|
+
textColor = disabledColor;
|
|
133
|
+
placeholderColor = disabledColor;
|
|
134
|
+
iconTintColor = disabledColor;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (secureTextEntry) {
|
|
138
|
+
keyboardType = Platform.select({
|
|
139
|
+
ios: 'ascii-capable',
|
|
140
|
+
android: 'visible-password',
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<View
|
|
146
|
+
style={[
|
|
147
|
+
styles.inputWrapper,
|
|
148
|
+
{backgroundColor: theme.colors.background.surface},
|
|
149
|
+
getSizeStyle(size),
|
|
150
|
+
getBorderColor(theme, focused, errorMessage, disabled),
|
|
151
|
+
]}>
|
|
152
|
+
<FloatingView
|
|
153
|
+
floatingValue={floatingValue}
|
|
154
|
+
floatingIconColor={floatingIconColor}
|
|
155
|
+
disabled={disabled}
|
|
156
|
+
required={required}
|
|
157
|
+
floatingIcon={floatingIcon}
|
|
158
|
+
/>
|
|
159
|
+
<View style={styles.inputView}>
|
|
160
|
+
{!!leadingIcon && (
|
|
161
|
+
<View style={styles.leadingIconContainer}>
|
|
162
|
+
<Icon
|
|
163
|
+
color={leadingIconColor}
|
|
164
|
+
source={leadingIcon}
|
|
165
|
+
size={size === 'small' ? 24 : 32}
|
|
166
|
+
/>
|
|
167
|
+
</View>
|
|
168
|
+
)}
|
|
169
|
+
<TextInput
|
|
170
|
+
{...props}
|
|
171
|
+
accessibilityLabel={accessibilityLabel}
|
|
172
|
+
editable={editable && !disabled}
|
|
173
|
+
secureTextEntry={secure}
|
|
174
|
+
textAlignVertical="center"
|
|
175
|
+
ref={inputRef}
|
|
176
|
+
style={[
|
|
177
|
+
styles.input,
|
|
178
|
+
{
|
|
179
|
+
color: textColor,
|
|
180
|
+
fontFamily: `${theme.font}-${fontWeight}`,
|
|
181
|
+
},
|
|
182
|
+
secure && haveValue && {fontSize: size === 'small' ? 18 : 22},
|
|
183
|
+
]}
|
|
184
|
+
textBreakStrategy="highQuality"
|
|
185
|
+
value={value}
|
|
186
|
+
onChangeText={_onChangeText}
|
|
187
|
+
onFocus={_onFocus}
|
|
188
|
+
onBlur={_onBlur}
|
|
189
|
+
placeholder={placeholder}
|
|
190
|
+
selectionColor={theme.colors.primary}
|
|
191
|
+
placeholderTextColor={placeholderColor}
|
|
192
|
+
keyboardType={keyboardType}
|
|
193
|
+
/>
|
|
194
|
+
</View>
|
|
195
|
+
<View style={styles.iconView}>
|
|
196
|
+
{focused && haveValue && (
|
|
197
|
+
<TouchableOpacity
|
|
198
|
+
style={styles.iconWrapper}
|
|
199
|
+
onPress={onClearText}>
|
|
200
|
+
<Icon
|
|
201
|
+
source="24_navigation_close_circle_full"
|
|
202
|
+
size={16}
|
|
203
|
+
color={theme.colors.text.hint}
|
|
204
|
+
/>
|
|
205
|
+
</TouchableOpacity>
|
|
206
|
+
)}
|
|
207
|
+
{renderIcon(iconTintColor)}
|
|
208
|
+
</View>
|
|
209
|
+
</View>
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
let inputState = 'active';
|
|
214
|
+
|
|
215
|
+
if (value && value?.length > 0) {
|
|
216
|
+
inputState = 'filled';
|
|
217
|
+
}
|
|
218
|
+
if (errorMessage && errorMessage?.length > 0) {
|
|
219
|
+
inputState = 'error';
|
|
220
|
+
}
|
|
64
221
|
|
|
65
222
|
if (disabled) {
|
|
66
|
-
|
|
67
|
-
placeholderColor = disabledColor;
|
|
68
|
-
iconTintColor = disabledColor;
|
|
223
|
+
inputState = 'disabled';
|
|
69
224
|
}
|
|
70
225
|
|
|
71
226
|
return (
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<View style={styles.inputView}>
|
|
87
|
-
<TextInput
|
|
88
|
-
{...props}
|
|
89
|
-
accessibilityLabel={`TextInput`}
|
|
90
|
-
editable={!disabled}
|
|
91
|
-
textAlignVertical="top"
|
|
92
|
-
ref={inputRef}
|
|
93
|
-
style={[
|
|
94
|
-
styles.input,
|
|
95
|
-
{
|
|
96
|
-
color: textColor,
|
|
97
|
-
},
|
|
98
|
-
]}
|
|
99
|
-
textBreakStrategy="highQuality"
|
|
100
|
-
value={value}
|
|
101
|
-
onChangeText={_onChangeText}
|
|
102
|
-
onFocus={_onFocus}
|
|
103
|
-
onBlur={_onBlur}
|
|
104
|
-
placeholder={placeholder}
|
|
105
|
-
selectionColor={theme.colors.primary}
|
|
106
|
-
placeholderTextColor={placeholderColor}
|
|
227
|
+
<ComponentContext.Provider
|
|
228
|
+
value={{
|
|
229
|
+
componentName: 'Input',
|
|
230
|
+
params,
|
|
231
|
+
componentLabel: floatingValue,
|
|
232
|
+
state: inputState,
|
|
233
|
+
componentId: accessibilityLabel,
|
|
234
|
+
}}>
|
|
235
|
+
<View style={[style, styles.wrapper]}>
|
|
236
|
+
{renderInputView()}
|
|
237
|
+
<ErrorView
|
|
238
|
+
errorMessage={errorMessage}
|
|
239
|
+
errorSpacing={errorSpacing}
|
|
240
|
+
hintText={hintText}
|
|
107
241
|
/>
|
|
108
242
|
</View>
|
|
109
|
-
|
|
110
|
-
{focused && haveValue && (
|
|
111
|
-
<TouchableOpacity style={styles.iconWrapper} onPress={onClearText}>
|
|
112
|
-
<Icon
|
|
113
|
-
source="24_navigation_close_circle_full"
|
|
114
|
-
size={16}
|
|
115
|
-
color={theme.colors.text.hint}
|
|
116
|
-
/>
|
|
117
|
-
</TouchableOpacity>
|
|
118
|
-
)}
|
|
119
|
-
{!!icon && <Icon color={iconTintColor} source={icon} size={24} />}
|
|
120
|
-
</View>
|
|
121
|
-
</View>
|
|
243
|
+
</ComponentContext.Provider>
|
|
122
244
|
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return (
|
|
126
|
-
<View style={styles.wrapper} accessibilityLabel={`Input`}>
|
|
127
|
-
{renderInputView()}
|
|
128
|
-
<ErrorView errorMessage={errorMessage} />
|
|
129
|
-
</View>
|
|
130
|
-
);
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
Input.defaultProps = {
|
|
134
|
-
size: 'small',
|
|
135
|
-
};
|
|
245
|
+
},
|
|
246
|
+
);
|
|
136
247
|
|
|
137
248
|
export default Input;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React, {useContext} from 'react';
|
|
2
|
+
import {TextInput, TouchableOpacity, View} from 'react-native';
|
|
3
|
+
import {ApplicationContext, ComponentContext} from '../Application';
|
|
4
|
+
import {Styles} from '../Consts';
|
|
5
|
+
import {Icon} from '../Icon';
|
|
6
|
+
import {Loader} from '../Loader';
|
|
7
|
+
import {ErrorView, FloatingView, getBorderColor, getSizeStyle} from './common';
|
|
8
|
+
import {InputDropDownProps} from './index';
|
|
9
|
+
import styles from './styles';
|
|
10
|
+
|
|
11
|
+
const InputDropDown = ({
|
|
12
|
+
value,
|
|
13
|
+
floatingValue,
|
|
14
|
+
floatingIcon,
|
|
15
|
+
size = 'small',
|
|
16
|
+
onPress,
|
|
17
|
+
placeholder,
|
|
18
|
+
errorMessage,
|
|
19
|
+
icon = 'arrow_chevron_down_small',
|
|
20
|
+
disabled = false,
|
|
21
|
+
floatingIconColor,
|
|
22
|
+
iconColor,
|
|
23
|
+
required = false,
|
|
24
|
+
errorSpacing,
|
|
25
|
+
loading = false,
|
|
26
|
+
leadingIcon,
|
|
27
|
+
leadingIconColor,
|
|
28
|
+
style,
|
|
29
|
+
params,
|
|
30
|
+
accessibilityLabel,
|
|
31
|
+
hintText,
|
|
32
|
+
...props
|
|
33
|
+
}: InputDropDownProps) => {
|
|
34
|
+
const {theme} = useContext(ApplicationContext);
|
|
35
|
+
const full = !!value || !!placeholder;
|
|
36
|
+
|
|
37
|
+
const renderIcon = (color: string | undefined) => {
|
|
38
|
+
if (loading) {
|
|
39
|
+
return <Loader type={'spinner'} color={color} />;
|
|
40
|
+
}
|
|
41
|
+
if (icon) {
|
|
42
|
+
return <Icon color={color} source={icon} size={24} />;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const renderInputView = () => {
|
|
47
|
+
const disabledColor = theme.colors.text.disable;
|
|
48
|
+
let textColor = theme.colors.text.default;
|
|
49
|
+
let placeholderColor = theme.colors.text.hint;
|
|
50
|
+
let iconTintColor = iconColor;
|
|
51
|
+
|
|
52
|
+
if (disabled) {
|
|
53
|
+
textColor = disabledColor;
|
|
54
|
+
placeholderColor = disabledColor;
|
|
55
|
+
iconTintColor = disabledColor;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<View
|
|
60
|
+
style={[
|
|
61
|
+
styles.inputWrapper,
|
|
62
|
+
{backgroundColor: theme.colors.background.surface},
|
|
63
|
+
getSizeStyle(size),
|
|
64
|
+
getBorderColor(theme, false, errorMessage, disabled),
|
|
65
|
+
]}>
|
|
66
|
+
<FloatingView
|
|
67
|
+
floatingValue={floatingValue}
|
|
68
|
+
floatingIconColor={floatingIconColor}
|
|
69
|
+
disabled={disabled}
|
|
70
|
+
required={required}
|
|
71
|
+
floatingIcon={floatingIcon}
|
|
72
|
+
/>
|
|
73
|
+
<View style={full ? styles.inputView : Styles.row}>
|
|
74
|
+
{!!leadingIcon && (
|
|
75
|
+
<View style={styles.leadingIconContainer}>
|
|
76
|
+
<Icon
|
|
77
|
+
color={leadingIconColor}
|
|
78
|
+
source={leadingIcon}
|
|
79
|
+
size={size === 'small' ? 24 : 32}
|
|
80
|
+
/>
|
|
81
|
+
</View>
|
|
82
|
+
)}
|
|
83
|
+
{full && (
|
|
84
|
+
<TextInput
|
|
85
|
+
{...props}
|
|
86
|
+
accessibilityLabel={accessibilityLabel}
|
|
87
|
+
onPressIn={onPress}
|
|
88
|
+
editable={false}
|
|
89
|
+
style={[
|
|
90
|
+
styles.input,
|
|
91
|
+
{
|
|
92
|
+
color: textColor,
|
|
93
|
+
fontFamily: `${theme.font}-Regular`,
|
|
94
|
+
},
|
|
95
|
+
]}
|
|
96
|
+
textBreakStrategy="highQuality"
|
|
97
|
+
value={value}
|
|
98
|
+
placeholder={placeholder}
|
|
99
|
+
selectionColor={theme.colors.primary}
|
|
100
|
+
placeholderTextColor={placeholderColor}
|
|
101
|
+
/>
|
|
102
|
+
)}
|
|
103
|
+
</View>
|
|
104
|
+
<View style={styles.iconView}>{renderIcon(iconTintColor)}</View>
|
|
105
|
+
</View>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<ComponentContext.Provider
|
|
111
|
+
value={{
|
|
112
|
+
componentName: 'InputDropDown',
|
|
113
|
+
params,
|
|
114
|
+
state: 'enabled',
|
|
115
|
+
componentLabel: floatingValue,
|
|
116
|
+
componentId: accessibilityLabel,
|
|
117
|
+
}}>
|
|
118
|
+
<TouchableOpacity
|
|
119
|
+
onPress={onPress}
|
|
120
|
+
style={[style, full && styles.wrapper]}>
|
|
121
|
+
{renderInputView()}
|
|
122
|
+
<ErrorView
|
|
123
|
+
errorMessage={errorMessage}
|
|
124
|
+
errorSpacing={errorSpacing}
|
|
125
|
+
hintText={hintText}
|
|
126
|
+
/>
|
|
127
|
+
</TouchableOpacity>
|
|
128
|
+
</ComponentContext.Provider>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export default InputDropDown;
|