@momo-kits/foundation 0.75.1-beta.3
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/Assets/header-background.png +0 -0
- package/Assets/icon.json +3947 -0
- package/Button/index.tsx +247 -0
- package/Button/styles.ts +41 -0
- package/CheckBox/index.tsx +61 -0
- package/CheckBox/styles.ts +15 -0
- package/CheckBox/types.ts +10 -0
- package/Consts/colors+spacing+radius.ts +214 -0
- package/Consts/index.ts +3 -0
- package/Consts/styles.ts +78 -0
- package/Consts/theme.ts +121 -0
- package/Divider/index.tsx +19 -0
- package/Icon/index.tsx +37 -0
- package/Icon/types.ts +8 -0
- package/IconButton/index.tsx +128 -0
- package/IconButton/styles.ts +19 -0
- package/Image/index.tsx +80 -0
- package/Image/styles.ts +13 -0
- package/Image/types.ts +3 -0
- package/Input/Input.tsx +142 -0
- package/Input/InputMoney.tsx +132 -0
- package/Input/InputSearch.tsx +161 -0
- package/Input/InputTextArea.tsx +152 -0
- package/Input/common.tsx +125 -0
- package/Input/index.tsx +41 -0
- package/Input/styles.ts +122 -0
- package/Input/utils.ts +63 -0
- package/Layout/Card.tsx +87 -0
- package/Layout/GridSystem.tsx +124 -0
- package/Layout/ScreenContainer.tsx +122 -0
- package/Layout/Section.tsx +143 -0
- package/Layout/index.ts +16 -0
- package/Layout/types.ts +21 -0
- package/Layout/utils.ts +50 -0
- package/Navigation/BottomTab.tsx +39 -0
- package/Navigation/Components.tsx +329 -0
- package/Navigation/ModalScreen.tsx +207 -0
- package/Navigation/Navigation.ts +38 -0
- package/Navigation/NavigationButton.tsx +54 -0
- package/Navigation/NavigationContainer.tsx +82 -0
- package/Navigation/Navigator.ts +66 -0
- package/Navigation/Observer.ts +79 -0
- package/Navigation/StackScreen.tsx +40 -0
- package/Navigation/index.ts +14 -0
- package/Navigation/types.ts +149 -0
- package/Navigation/utils.tsx +167 -0
- package/Pagination/Dot.tsx +16 -0
- package/Pagination/PaginationDot.tsx +33 -0
- package/Pagination/PaginationNumber.tsx +23 -0
- package/Pagination/PaginationScroll.tsx +88 -0
- package/Pagination/PaginationWhiteDot.tsx +32 -0
- package/Pagination/index.tsx +25 -0
- package/Pagination/styles.ts +47 -0
- package/Pagination/types.ts +19 -0
- package/Popup/PopupNotify.tsx +215 -0
- package/Popup/PopupPromotion.tsx +77 -0
- package/Popup/index.tsx +4 -0
- package/Popup/types.ts +22 -0
- package/Radio/index.tsx +65 -0
- package/Radio/styles.ts +11 -0
- package/Radio/types.ts +10 -0
- package/Skeleton/index.tsx +72 -0
- package/Skeleton/styles.ts +5 -0
- package/Skeleton/types.ts +3 -0
- package/Switch/index.tsx +40 -0
- package/Switch/styles.ts +23 -0
- package/Switch/types.ts +8 -0
- package/Tag/index.tsx +79 -0
- package/Tag/styles.ts +24 -0
- package/Tag/types.ts +10 -0
- package/Text/index.tsx +110 -0
- package/Text/styles.ts +35 -0
- package/Text/types.ts +40 -0
- package/index.ts +38 -0
- package/package.json +41 -0
- package/publish.sh +26 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import React, {FC, useContext, useRef, useState} from 'react';
|
|
2
|
+
import {
|
|
3
|
+
NativeSyntheticEvent,
|
|
4
|
+
TextInput,
|
|
5
|
+
TextInputFocusEventData,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
View,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import {InputSearchProps} from './index';
|
|
10
|
+
import {ApplicationContext} from '../Navigation';
|
|
11
|
+
import styles from './styles';
|
|
12
|
+
import {Icon} from '../Icon';
|
|
13
|
+
import {Text} from '../Text';
|
|
14
|
+
import {checkTyping} from './common';
|
|
15
|
+
|
|
16
|
+
const InputSearch: FC<InputSearchProps> = ({
|
|
17
|
+
placeholder,
|
|
18
|
+
onFocus,
|
|
19
|
+
onBlur,
|
|
20
|
+
iconColor,
|
|
21
|
+
value,
|
|
22
|
+
onChangeText,
|
|
23
|
+
icon,
|
|
24
|
+
buttonText = 'Hủy',
|
|
25
|
+
showButtonText = true,
|
|
26
|
+
showBorder = true,
|
|
27
|
+
style,
|
|
28
|
+
defaultValue,
|
|
29
|
+
...props
|
|
30
|
+
}) => {
|
|
31
|
+
const {theme} = useContext(ApplicationContext);
|
|
32
|
+
const [focused, setFocused] = useState(false);
|
|
33
|
+
const [haveValue, setHaveValue] = useState(!!value || !!defaultValue);
|
|
34
|
+
const inputRef = useRef<any>(null);
|
|
35
|
+
let iconTintColor = iconColor;
|
|
36
|
+
|
|
37
|
+
const _onFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
38
|
+
setFocused(true);
|
|
39
|
+
onFocus?.(e);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const _onBlur = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
43
|
+
setFocused(false);
|
|
44
|
+
onBlur?.(e);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const onClearText = () => {
|
|
48
|
+
inputRef?.current?.clear();
|
|
49
|
+
_onChangeText('');
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const _onChangeText = (text: string) => {
|
|
53
|
+
checkTyping(text, haveValue, setHaveValue);
|
|
54
|
+
onChangeText?.(text);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getBorderColor = () => {
|
|
58
|
+
let borderColor = showBorder
|
|
59
|
+
? theme.colors.border.default
|
|
60
|
+
: theme.colors.background.surface;
|
|
61
|
+
|
|
62
|
+
if (focused) {
|
|
63
|
+
borderColor = theme.colors.primary;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {borderColor};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const renderInputView = () => {
|
|
70
|
+
let textColor = theme.colors.text.default;
|
|
71
|
+
let placeholderColor = theme.colors.text.hint;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<TextInput
|
|
75
|
+
{...props}
|
|
76
|
+
textAlignVertical="top"
|
|
77
|
+
ref={inputRef}
|
|
78
|
+
style={[
|
|
79
|
+
styles.searchInput,
|
|
80
|
+
{
|
|
81
|
+
color: textColor,
|
|
82
|
+
},
|
|
83
|
+
]}
|
|
84
|
+
value={value}
|
|
85
|
+
onChangeText={_onChangeText}
|
|
86
|
+
onFocus={_onFocus}
|
|
87
|
+
onBlur={_onBlur}
|
|
88
|
+
placeholder={placeholder}
|
|
89
|
+
selectionColor={theme.colors.primary}
|
|
90
|
+
placeholderTextColor={placeholderColor}
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const renderIconView = () => {
|
|
96
|
+
return (
|
|
97
|
+
<View
|
|
98
|
+
style={{
|
|
99
|
+
flexDirection: 'row',
|
|
100
|
+
}}>
|
|
101
|
+
{focused && haveValue && (
|
|
102
|
+
<TouchableOpacity style={styles.iconWrapper} onPress={onClearText}>
|
|
103
|
+
<Icon
|
|
104
|
+
source="24_navigation_close_circle_full"
|
|
105
|
+
size={16}
|
|
106
|
+
color={theme.colors.text.hint}
|
|
107
|
+
/>
|
|
108
|
+
</TouchableOpacity>
|
|
109
|
+
)}
|
|
110
|
+
{!!icon && (
|
|
111
|
+
<View style={{flexDirection: 'row'}}>
|
|
112
|
+
<View
|
|
113
|
+
style={[
|
|
114
|
+
styles.divider,
|
|
115
|
+
{
|
|
116
|
+
backgroundColor: theme.colors.primary,
|
|
117
|
+
},
|
|
118
|
+
]}
|
|
119
|
+
/>
|
|
120
|
+
<Icon
|
|
121
|
+
color={iconTintColor}
|
|
122
|
+
source={icon}
|
|
123
|
+
style={styles.iconSearchInput}
|
|
124
|
+
/>
|
|
125
|
+
</View>
|
|
126
|
+
)}
|
|
127
|
+
</View>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
return (
|
|
131
|
+
<View
|
|
132
|
+
style={[style, styles.searchInputContainer]}
|
|
133
|
+
accessibilityLabel={`InputSearch`}>
|
|
134
|
+
<View
|
|
135
|
+
style={[
|
|
136
|
+
getBorderColor(),
|
|
137
|
+
styles.searchInputWrapper,
|
|
138
|
+
{
|
|
139
|
+
backgroundColor: theme.colors.background.surface,
|
|
140
|
+
},
|
|
141
|
+
]}>
|
|
142
|
+
<Icon
|
|
143
|
+
source={'navigation_search'}
|
|
144
|
+
size={24}
|
|
145
|
+
color={theme.colors.text.hint}
|
|
146
|
+
/>
|
|
147
|
+
{renderInputView()}
|
|
148
|
+
{renderIconView()}
|
|
149
|
+
</View>
|
|
150
|
+
{showButtonText && (
|
|
151
|
+
<TouchableOpacity>
|
|
152
|
+
<Text typography={'action_default'} style={styles.textButton}>
|
|
153
|
+
{buttonText}
|
|
154
|
+
</Text>
|
|
155
|
+
</TouchableOpacity>
|
|
156
|
+
)}
|
|
157
|
+
</View>
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export default InputSearch;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React, {FC, useContext, useRef, useState} from 'react';
|
|
2
|
+
import {
|
|
3
|
+
NativeSyntheticEvent,
|
|
4
|
+
TextInput,
|
|
5
|
+
TextInputFocusEventData,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
View,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import styles from './styles';
|
|
10
|
+
import {Text} from '../Text';
|
|
11
|
+
import {ApplicationContext} from '../Navigation';
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_HEIGHT,
|
|
14
|
+
ErrorView,
|
|
15
|
+
FloatingView,
|
|
16
|
+
getBorderColor,
|
|
17
|
+
MAX_LENGTH,
|
|
18
|
+
} from './common';
|
|
19
|
+
import {InputTextAreaProps} from './index';
|
|
20
|
+
import {Icon} from '../Icon';
|
|
21
|
+
|
|
22
|
+
const InputTextArea: FC<InputTextAreaProps> = props => {
|
|
23
|
+
const {theme} = useContext(ApplicationContext);
|
|
24
|
+
const {
|
|
25
|
+
errorMessage,
|
|
26
|
+
onChangeText,
|
|
27
|
+
floatingIconColor,
|
|
28
|
+
floatingIcon,
|
|
29
|
+
floatingValue,
|
|
30
|
+
onFocus,
|
|
31
|
+
onBlur,
|
|
32
|
+
disabled,
|
|
33
|
+
value,
|
|
34
|
+
defaultValue,
|
|
35
|
+
height,
|
|
36
|
+
placeholder,
|
|
37
|
+
maxLength,
|
|
38
|
+
required,
|
|
39
|
+
} = props;
|
|
40
|
+
|
|
41
|
+
const [focused, setFocused] = useState(false);
|
|
42
|
+
const [inputValue, setInputValue] = useState(defaultValue ?? '');
|
|
43
|
+
const inputRef = useRef<any>(null);
|
|
44
|
+
|
|
45
|
+
const onClearText = () => {
|
|
46
|
+
inputRef?.current?.clear();
|
|
47
|
+
_onChangeText('');
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const _onChangeText = (text: string) => {
|
|
51
|
+
onChangeText?.(text);
|
|
52
|
+
setInputValue(text);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const _onFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
56
|
+
setFocused(true);
|
|
57
|
+
onFocus?.(e);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const _onBlur = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
61
|
+
setFocused(false);
|
|
62
|
+
onBlur?.(e);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const renderCountingView = () => {
|
|
66
|
+
return (
|
|
67
|
+
<View style={styles.countingView}>
|
|
68
|
+
<Text color={theme.colors.text.hint} typography={'description_xs'}>
|
|
69
|
+
{`${inputValue.length}/${maxLength}`}
|
|
70
|
+
</Text>
|
|
71
|
+
</View>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
const renderInputView = () => {
|
|
75
|
+
const disabledColor = theme.colors.text.disable;
|
|
76
|
+
let textColor = theme.colors.text.default;
|
|
77
|
+
let placeholderColor = theme.colors.text.hint;
|
|
78
|
+
|
|
79
|
+
if (disabled) {
|
|
80
|
+
textColor = disabledColor;
|
|
81
|
+
placeholderColor = disabledColor;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<View
|
|
86
|
+
style={[
|
|
87
|
+
getBorderColor(focused, errorMessage, disabled),
|
|
88
|
+
styles.textAreaWrapper,
|
|
89
|
+
{
|
|
90
|
+
height: height || DEFAULT_HEIGHT,
|
|
91
|
+
backgroundColor: theme.colors.background.surface,
|
|
92
|
+
},
|
|
93
|
+
]}>
|
|
94
|
+
<FloatingView
|
|
95
|
+
floatingValue={floatingValue}
|
|
96
|
+
floatingIconColor={floatingIconColor}
|
|
97
|
+
disabled={disabled}
|
|
98
|
+
floatingIcon={floatingIcon}
|
|
99
|
+
required={required}
|
|
100
|
+
/>
|
|
101
|
+
<View style={styles.rowArea}>
|
|
102
|
+
<View style={styles.textAreaView}>
|
|
103
|
+
<TextInput
|
|
104
|
+
ref={inputRef}
|
|
105
|
+
editable={!disabled}
|
|
106
|
+
textAlignVertical="top"
|
|
107
|
+
style={[
|
|
108
|
+
styles.textArea,
|
|
109
|
+
{
|
|
110
|
+
color: textColor,
|
|
111
|
+
},
|
|
112
|
+
]}
|
|
113
|
+
maxLength={maxLength}
|
|
114
|
+
textBreakStrategy="highQuality"
|
|
115
|
+
multiline={true}
|
|
116
|
+
value={value}
|
|
117
|
+
onChangeText={_onChangeText}
|
|
118
|
+
onFocus={_onFocus}
|
|
119
|
+
onBlur={_onBlur}
|
|
120
|
+
placeholder={placeholder}
|
|
121
|
+
selectionColor={theme.colors.primary}
|
|
122
|
+
placeholderTextColor={placeholderColor}
|
|
123
|
+
/>
|
|
124
|
+
</View>
|
|
125
|
+
{focused && inputValue.length > 0 && (
|
|
126
|
+
<TouchableOpacity style={styles.iconWrapper} onPress={onClearText}>
|
|
127
|
+
<Icon
|
|
128
|
+
source="24_navigation_close_circle_full"
|
|
129
|
+
size={16}
|
|
130
|
+
color={theme.colors.text.hint}
|
|
131
|
+
/>
|
|
132
|
+
</TouchableOpacity>
|
|
133
|
+
)}
|
|
134
|
+
</View>
|
|
135
|
+
{renderCountingView()}
|
|
136
|
+
</View>
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<View style={styles.wrapper} accessibilityLabel={`InputTextArea`}>
|
|
142
|
+
{renderInputView()}
|
|
143
|
+
<ErrorView errorMessage={errorMessage} />
|
|
144
|
+
</View>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
InputTextArea.defaultProps = {
|
|
149
|
+
maxLength: MAX_LENGTH,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export default InputTextArea;
|
package/Input/common.tsx
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {View} from 'react-native';
|
|
2
|
+
import styles from './styles';
|
|
3
|
+
import {Text} from '../Text';
|
|
4
|
+
import React, {FC, useContext} from 'react';
|
|
5
|
+
import {ApplicationContext} from '../Navigation';
|
|
6
|
+
import {Icon} from '../Icon';
|
|
7
|
+
import {Styles} from '../Consts';
|
|
8
|
+
|
|
9
|
+
type FloatingViewProps = {
|
|
10
|
+
floatingValue?: string;
|
|
11
|
+
floatingIconColor?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
floatingIcon?: string;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const DEFAULT_HEIGHT = 112;
|
|
18
|
+
export const MAX_LENGTH = 300;
|
|
19
|
+
|
|
20
|
+
export const getBorderColor = (
|
|
21
|
+
focused: boolean,
|
|
22
|
+
errorMessage?: string,
|
|
23
|
+
disabled?: boolean,
|
|
24
|
+
) => {
|
|
25
|
+
const {theme} = useContext(ApplicationContext);
|
|
26
|
+
|
|
27
|
+
let borderColor = theme.colors.border.default;
|
|
28
|
+
|
|
29
|
+
if (focused) {
|
|
30
|
+
borderColor = theme.colors.primary;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (errorMessage) {
|
|
34
|
+
borderColor = theme.colors.error.primary;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (disabled) {
|
|
38
|
+
borderColor = theme.colors.border.disable;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {borderColor};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const getSizeStyle = (size?: 'small' | 'large') => {
|
|
45
|
+
if (size === 'small') {
|
|
46
|
+
return styles.smallContainer;
|
|
47
|
+
}
|
|
48
|
+
return styles.container;
|
|
49
|
+
};
|
|
50
|
+
export const ErrorView: FC<{errorMessage?: string}> = ({errorMessage}) => {
|
|
51
|
+
const {theme} = useContext(ApplicationContext);
|
|
52
|
+
const errorColor = theme.colors.error.primary;
|
|
53
|
+
if (errorMessage) {
|
|
54
|
+
return (
|
|
55
|
+
<View style={styles.errorView}>
|
|
56
|
+
<View style={styles.errorIcon}>
|
|
57
|
+
<Icon color={errorColor} source="ic_error" size={16} />
|
|
58
|
+
</View>
|
|
59
|
+
<Text
|
|
60
|
+
style={Styles.flex}
|
|
61
|
+
color={errorColor}
|
|
62
|
+
numberOfLines={1}
|
|
63
|
+
typography={'description_s'}>
|
|
64
|
+
{errorMessage}
|
|
65
|
+
</Text>
|
|
66
|
+
</View>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const FloatingView: FC<FloatingViewProps> = ({
|
|
73
|
+
floatingValue,
|
|
74
|
+
floatingIconColor,
|
|
75
|
+
disabled,
|
|
76
|
+
floatingIcon,
|
|
77
|
+
required,
|
|
78
|
+
}) => {
|
|
79
|
+
const {theme} = useContext(ApplicationContext);
|
|
80
|
+
|
|
81
|
+
if (floatingValue) {
|
|
82
|
+
let floatingTextColor = theme.colors.text.hint;
|
|
83
|
+
let floatingIconTintColor = floatingIconColor;
|
|
84
|
+
if (disabled) {
|
|
85
|
+
floatingTextColor = theme.colors.text.disable;
|
|
86
|
+
floatingIconTintColor = theme.colors.text.disable;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<View
|
|
91
|
+
style={[
|
|
92
|
+
styles.floatingView,
|
|
93
|
+
{
|
|
94
|
+
backgroundColor: theme.colors.background.surface,
|
|
95
|
+
zIndex: 10,
|
|
96
|
+
},
|
|
97
|
+
]}>
|
|
98
|
+
<Text color={floatingTextColor} typography={'label_s'}>
|
|
99
|
+
{floatingValue}
|
|
100
|
+
{required && (
|
|
101
|
+
<Text typography={'label_s'} color={theme.colors.error.primary}>
|
|
102
|
+
*
|
|
103
|
+
</Text>
|
|
104
|
+
)}
|
|
105
|
+
</Text>
|
|
106
|
+
{!!floatingIcon && (
|
|
107
|
+
<Icon
|
|
108
|
+
color={floatingIconTintColor}
|
|
109
|
+
source={floatingIcon}
|
|
110
|
+
size={16}
|
|
111
|
+
style={styles.floatingIcon}
|
|
112
|
+
/>
|
|
113
|
+
)}
|
|
114
|
+
</View>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const checkTyping = (text: string, value: boolean, setValue: any) => {
|
|
121
|
+
let typing = text?.length > 0;
|
|
122
|
+
if (typing != value) {
|
|
123
|
+
setValue(typing);
|
|
124
|
+
}
|
|
125
|
+
};
|
package/Input/index.tsx
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Input from './Input';
|
|
2
|
+
import InputTextArea from './InputTextArea';
|
|
3
|
+
import InputSearch from './InputSearch';
|
|
4
|
+
import InputMoney from './InputMoney';
|
|
5
|
+
import {TextInputProps} from 'react-native';
|
|
6
|
+
|
|
7
|
+
export interface InputProps extends TextInputProps {
|
|
8
|
+
size?: 'small' | 'large';
|
|
9
|
+
floatingValue?: string;
|
|
10
|
+
floatingIcon?: string;
|
|
11
|
+
errorMessage?: string;
|
|
12
|
+
icon?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
floatingIconColor?: string;
|
|
15
|
+
iconColor?: string;
|
|
16
|
+
required?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type InputPropsWithoutSizeAndIcon = Omit<
|
|
20
|
+
InputProps,
|
|
21
|
+
'size' | 'icon' | 'iconColor'
|
|
22
|
+
>;
|
|
23
|
+
type InputPropsOmitForSearch = Omit<
|
|
24
|
+
InputProps,
|
|
25
|
+
'required' | 'size' | 'errorMessage' | 'disabled'
|
|
26
|
+
>;
|
|
27
|
+
type InputPropsWithoutPlaceholder = Omit<InputProps, 'placeholder'>;
|
|
28
|
+
|
|
29
|
+
export interface InputTextAreaProps extends InputPropsWithoutSizeAndIcon {
|
|
30
|
+
height?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface InputSearchProps extends InputPropsOmitForSearch {
|
|
34
|
+
buttonText?: string;
|
|
35
|
+
showButtonText?: boolean;
|
|
36
|
+
showBorder?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface InputMoneyProps extends InputPropsWithoutPlaceholder {}
|
|
40
|
+
|
|
41
|
+
export {Input, InputTextArea, InputSearch, InputMoney};
|
package/Input/styles.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
import {Radius, Spacing} from '../Consts';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
//input style
|
|
6
|
+
input: {width: '100%', paddingLeft: Spacing.M, height: '100%'},
|
|
7
|
+
wrapper: {
|
|
8
|
+
width: '100%',
|
|
9
|
+
},
|
|
10
|
+
container: {
|
|
11
|
+
borderWidth: 1,
|
|
12
|
+
borderRadius: Radius.S,
|
|
13
|
+
height: 56,
|
|
14
|
+
paddingVertical: 8,
|
|
15
|
+
},
|
|
16
|
+
smallContainer: {
|
|
17
|
+
borderRadius: Radius.S,
|
|
18
|
+
borderWidth: 1,
|
|
19
|
+
height: 48,
|
|
20
|
+
},
|
|
21
|
+
floatingView: {
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
top: -10,
|
|
24
|
+
left: Spacing.S,
|
|
25
|
+
paddingHorizontal: Spacing.S,
|
|
26
|
+
flexDirection: 'row',
|
|
27
|
+
},
|
|
28
|
+
floatingIcon: {marginLeft: Spacing.XS},
|
|
29
|
+
errorIcon: {marginRight: Spacing.XS},
|
|
30
|
+
errorView: {
|
|
31
|
+
flexDirection: 'row',
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
marginTop: Spacing.XS,
|
|
34
|
+
},
|
|
35
|
+
inputView: {
|
|
36
|
+
justifyContent: 'space-between',
|
|
37
|
+
flex: 1,
|
|
38
|
+
},
|
|
39
|
+
iconView: {
|
|
40
|
+
flexDirection: 'row',
|
|
41
|
+
alignItems: 'center',
|
|
42
|
+
marginLeft: Spacing.XS,
|
|
43
|
+
marginRight: Spacing.M,
|
|
44
|
+
},
|
|
45
|
+
icon: {
|
|
46
|
+
width: 24,
|
|
47
|
+
height: 24,
|
|
48
|
+
},
|
|
49
|
+
iconWrapper: {
|
|
50
|
+
width: 24,
|
|
51
|
+
height: 24,
|
|
52
|
+
justifyContent: 'center',
|
|
53
|
+
alignItems: 'center',
|
|
54
|
+
},
|
|
55
|
+
inputWrapper: {
|
|
56
|
+
flexDirection: 'row',
|
|
57
|
+
marginTop: Spacing.S,
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
//text area style
|
|
61
|
+
textAreaView: {
|
|
62
|
+
flex: 1,
|
|
63
|
+
},
|
|
64
|
+
textArea: {
|
|
65
|
+
width: '100%',
|
|
66
|
+
flex: 1,
|
|
67
|
+
paddingRight: Spacing.XS,
|
|
68
|
+
},
|
|
69
|
+
textAreaWrapper: {
|
|
70
|
+
borderWidth: 1,
|
|
71
|
+
borderRadius: Radius.S,
|
|
72
|
+
paddingVertical: Spacing.S,
|
|
73
|
+
paddingLeft: Spacing.M,
|
|
74
|
+
paddingRight: Spacing.S,
|
|
75
|
+
},
|
|
76
|
+
countingView: {
|
|
77
|
+
width: '100%',
|
|
78
|
+
alignItems: 'flex-end',
|
|
79
|
+
paddingRight: Spacing.XS,
|
|
80
|
+
},
|
|
81
|
+
rowArea: {
|
|
82
|
+
flexDirection: 'row',
|
|
83
|
+
width: '100%',
|
|
84
|
+
flex: 1,
|
|
85
|
+
marginBottom: Spacing.XS,
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
//searchInput
|
|
89
|
+
searchInputWrapper: {
|
|
90
|
+
flexDirection: 'row',
|
|
91
|
+
borderRadius: Radius.XL,
|
|
92
|
+
borderWidth: 1,
|
|
93
|
+
paddingHorizontal: Spacing.S,
|
|
94
|
+
alignItems: 'center',
|
|
95
|
+
flex: 1,
|
|
96
|
+
},
|
|
97
|
+
searchInput: {
|
|
98
|
+
height: 36,
|
|
99
|
+
marginLeft: Spacing.S,
|
|
100
|
+
flex: 1,
|
|
101
|
+
},
|
|
102
|
+
searchInputView: {
|
|
103
|
+
flexDirection: 'row',
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
},
|
|
106
|
+
iconSearchInput: {
|
|
107
|
+
marginLeft: Spacing.S,
|
|
108
|
+
},
|
|
109
|
+
searchInputContainer: {flexDirection: 'row', alignItems: 'center'},
|
|
110
|
+
textButton: {marginLeft: Spacing.L},
|
|
111
|
+
divider: {
|
|
112
|
+
width: 1,
|
|
113
|
+
marginLeft: Spacing.XS,
|
|
114
|
+
},
|
|
115
|
+
moneyInput: {
|
|
116
|
+
width: '100%',
|
|
117
|
+
paddingLeft: Spacing.M,
|
|
118
|
+
height: '100%',
|
|
119
|
+
fontSize: 20,
|
|
120
|
+
fontWeight: 'bold',
|
|
121
|
+
},
|
|
122
|
+
});
|
package/Input/utils.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const formatNumberToMoney = (number: number, currency = '') => {
|
|
2
|
+
if (!number || isNaN(number) || Number(number) === 0) {
|
|
3
|
+
return `0${currency}`;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const array = [];
|
|
7
|
+
let result = '';
|
|
8
|
+
let isNegative = false;
|
|
9
|
+
|
|
10
|
+
if (number < 0) {
|
|
11
|
+
isNegative = true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const numberString = Math.abs(number).toString();
|
|
15
|
+
if (numberString.length < 3) {
|
|
16
|
+
return numberString + currency;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let count = 0;
|
|
20
|
+
for (let i = numberString.length - 1; i >= 0; i -= 1) {
|
|
21
|
+
count += 1;
|
|
22
|
+
if (numberString[i] === '.' || numberString[i] === ',') {
|
|
23
|
+
array.push(',');
|
|
24
|
+
count = 0;
|
|
25
|
+
} else {
|
|
26
|
+
array.push(numberString[i]);
|
|
27
|
+
}
|
|
28
|
+
if (count === 3 && i >= 1) {
|
|
29
|
+
array.push('.');
|
|
30
|
+
count = 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (let i = array.length - 1; i >= 0; i -= 1) {
|
|
35
|
+
result += array[i];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isNegative) {
|
|
39
|
+
result = `-${result}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return result + currency;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const formatMoneyToNumber = (money: string, currencyUnit: string) => {
|
|
46
|
+
if (money && money.length > 0) {
|
|
47
|
+
const moneyString = money
|
|
48
|
+
.replace(currencyUnit, '')
|
|
49
|
+
.replace(/,/g, '')
|
|
50
|
+
.replace(/đ/g, '')
|
|
51
|
+
.replace(/\./g, '')
|
|
52
|
+
.replace(/ /g, '');
|
|
53
|
+
const number = Number(moneyString);
|
|
54
|
+
if (isNaN(number)) {
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
return number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return Number(money);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export {formatMoneyToNumber, formatNumberToMoney};
|