@momo-kits/foundation 0.114.1-beta.9 → 0.114.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.
@@ -6,7 +6,7 @@ import {
6
6
  TouchableOpacity,
7
7
  View,
8
8
  } from 'react-native';
9
- import {ApplicationContext, MiniAppContext} from '../index';
9
+ import {ApplicationContext, MiniAppContext, setAutomationID} from '../index';
10
10
  import {exportFontFamily, scaleSize, Text} from '../../Text';
11
11
  import {Colors, Radius, Spacing, Styles} from '../../Consts';
12
12
  import {TitleJourneyProps, TitleLocationProps, TitleUserProps} from '../types';
@@ -30,7 +30,7 @@ const HeaderTitle: React.FC<any> = props => {
30
30
  <View pointerEvents={'none'} style={styles.headerTitleContainer}>
31
31
  <Animated.Text
32
32
  {...props}
33
- accessibilityLabel={'title_navigation_header'}
33
+ {...setAutomationID('title_navigation_header')}
34
34
  style={[
35
35
  styles.title,
36
36
  {
@@ -28,12 +28,11 @@ import {
28
28
  } from './common';
29
29
  import {InputMoneyProps} from './index';
30
30
  import styles from './styles';
31
- import {formatNumberToMoney} from './utils';
31
+ import {formatMoneyToNumber, formatNumberToMoney} from './utils';
32
32
 
33
33
  const InputMoney = forwardRef(
34
34
  (
35
35
  {
36
- value,
37
36
  onChangeText,
38
37
  floatingValue,
39
38
  floatingIcon,
@@ -51,20 +50,22 @@ const InputMoney = forwardRef(
51
50
  errorSpacing,
52
51
  style,
53
52
  params,
53
+ defaultValue = '',
54
54
  hintText,
55
+ value: _value,
55
56
  onPressFloatingIcon,
56
57
  placeholder = '0đ',
58
+ currency = 'đ',
57
59
  showClearIcon = true,
58
60
  ...props
59
61
  }: InputMoneyProps,
60
62
  ref
61
63
  ) => {
62
64
  const {theme} = useContext(ApplicationContext);
65
+
63
66
  const [focused, setFocused] = useState(false);
64
- const [displayValue, setDisplayValue] = useState('');
65
- const [numericValue, setNumericValue] = useState('');
66
- const [lastDisplayValue, setLastDisplayValue] = useState('');
67
67
  const inputRef = useRef<TextInput>(null);
68
+
68
69
  const componentName = 'InputMoney';
69
70
 
70
71
  const {componentId} = useComponentId(
@@ -73,70 +74,44 @@ const InputMoney = forwardRef(
73
74
  );
74
75
 
75
76
  useEffect(() => {
76
- if (value !== undefined && typeof value === 'string') {
77
- const cleanValue = value.replace(/\D/g, '');
78
- if (cleanValue !== numericValue) {
79
- setNumericValue(cleanValue);
80
- updateDisplayValue(cleanValue);
81
- }
77
+ if (_value) {
78
+ setValue(validateText(_value));
79
+ onChangeText?.(formatMoneyToNumber(_value, currency).toString());
82
80
  }
83
- }, [value]);
84
-
85
- useEffect(() => {
86
- setLastDisplayValue(displayValue);
87
- }, [displayValue]);
81
+ }, [_value]);
88
82
 
89
- const updateDisplayValue = (numeric: string) => {
90
- if (!numeric) {
91
- setDisplayValue('');
92
- return;
93
- }
94
- const formatted = formatNumberToMoney(Number(numeric));
95
- setDisplayValue(formatted ? `${formatted}đ` : '');
83
+ const validateText = (text: string) => {
84
+ const valueFormat = formatMoneyToNumber(text, currency);
85
+ return formatNumberToMoney(valueFormat, currency);
96
86
  };
97
87
 
88
+ const [value, setValue] = useState(
89
+ defaultValue ? validateText(defaultValue) : ''
90
+ );
91
+
98
92
  const onClearText = () => {
99
- setDisplayValue('');
100
- setNumericValue('');
93
+ inputRef?.current?.clear();
94
+ setValue('');
101
95
  onChangeText?.('');
102
- inputRef?.current?.focus();
103
96
  };
104
97
 
105
98
  const _onChangeText = (text: string) => {
106
- if (!text) {
107
- setDisplayValue('');
108
- setNumericValue('');
109
- onChangeText?.('');
110
- return;
111
- }
112
-
113
- if (text.length < lastDisplayValue.length) {
114
- const lastChar = lastDisplayValue.charAt(lastDisplayValue.length - 1);
115
- const isRemovingDong = lastChar === 'đ' || lastChar === ' ';
116
- const isRemovingDot = lastChar === '.';
117
-
118
- if (isRemovingDong || isRemovingDot) {
119
- const currentNumericValue = numericValue;
120
- if (currentNumericValue.length > 0) {
121
- const newNumericValue = currentNumericValue.slice(0, -1);
122
- setNumericValue(newNumericValue);
123
- updateDisplayValue(newNumericValue);
124
- onChangeText?.(newNumericValue);
125
- return;
126
- }
127
- }
128
- }
129
-
130
- const textWithoutCurrency = text.replace(/ đ$/g, '').trim();
131
- const newNumericValue = textWithoutCurrency.replace(/[^\d]/g, '');
132
-
133
- if (/^\d*$/.test(newNumericValue)) {
134
- setNumericValue(newNumericValue);
135
- updateDisplayValue(newNumericValue);
136
- onChangeText?.(newNumericValue);
99
+ if (text.length < value.length && value.indexOf(text) === 0) {
100
+ text = value.slice(0, -2) + currency;
137
101
  }
102
+ setValue(validateText(text));
103
+ onChangeText?.(formatMoneyToNumber(text, currency).toString());
138
104
  };
139
105
 
106
+ useImperativeHandle(ref, () => {
107
+ return {
108
+ clear: onClearText,
109
+ focus: () => inputRef.current?.focus(),
110
+ blur: () => inputRef.current?.blur(),
111
+ setText: _onChangeText,
112
+ };
113
+ });
114
+
140
115
  const _onFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
141
116
  setFocused(true);
142
117
  onFocus?.(e);
@@ -147,19 +122,6 @@ const InputMoney = forwardRef(
147
122
  onBlur?.(e);
148
123
  };
149
124
 
150
- const _setText = (text: string) => {
151
- _onChangeText(text);
152
- };
153
-
154
- useImperativeHandle(ref, () => {
155
- return {
156
- clear: onClearText,
157
- focus: () => inputRef.current?.focus(),
158
- blur: () => inputRef.current?.blur(),
159
- setText: _setText,
160
- };
161
- });
162
-
163
125
  const renderInputView = () => {
164
126
  const disabledColor = theme.colors.text.disable;
165
127
  let textColor = theme.colors.text.default;
@@ -192,33 +154,32 @@ const InputMoney = forwardRef(
192
154
  <View style={styles.inputView}>
193
155
  <TextInput
194
156
  {...props}
195
- accessibilityLabel={`${componentId}`}
196
- textAlignVertical="center"
157
+ editable={!disabled}
197
158
  ref={inputRef}
198
- accessibilityState={{
199
- disabled: disabled,
200
- ...props.accessibilityState,
201
- }}
159
+ keyboardType={'number-pad'}
160
+ allowFontScaling={false}
202
161
  style={[
203
162
  styles.moneyInput,
204
163
  {
205
164
  color: textColor,
206
165
  },
207
166
  ]}
208
- allowFontScaling={false}
209
- textBreakStrategy="highQuality"
210
- value={displayValue}
167
+ accessibilityState={{
168
+ disabled: disabled,
169
+ ...props.accessibilityState,
170
+ }}
171
+ value={value}
211
172
  onChangeText={_onChangeText}
212
173
  onFocus={_onFocus}
213
174
  onBlur={_onBlur}
214
- placeholder={'0đ'}
215
175
  selectionColor={theme.colors.primary}
216
176
  placeholderTextColor={placeholderColor}
217
- keyboardType={'numeric'}
177
+ placeholder={placeholder}
178
+ accessibilityLabel={`${componentId}`}
218
179
  />
219
180
  </View>
220
181
  <View style={styles.iconView}>
221
- {showClearIcon && focused && displayValue ? (
182
+ {showClearIcon && focused && (
222
183
  <TouchableOpacity
223
184
  accessibilityLabel={`${componentId}|clear-icon-touch`}
224
185
  style={styles.iconWrapper}
@@ -230,7 +191,7 @@ const InputMoney = forwardRef(
230
191
  accessibilityLabel={`${componentId}|clear-icon`}
231
192
  />
232
193
  </TouchableOpacity>
233
- ) : null}
194
+ )}
234
195
  <RenderTrailing
235
196
  color={iconTintColor}
236
197
  icon={trailing}
@@ -244,12 +205,14 @@ const InputMoney = forwardRef(
244
205
  };
245
206
 
246
207
  let inputState = 'active';
247
- if (displayValue) {
208
+
209
+ if (value && value?.length > 0) {
248
210
  inputState = 'filled';
249
211
  }
250
212
  if (errorMessage && errorMessage?.length > 0) {
251
213
  inputState = 'error';
252
214
  }
215
+
253
216
  if (disabled) {
254
217
  inputState = 'disabled';
255
218
  }
package/Input/styles.ts CHANGED
@@ -210,5 +210,4 @@ export default StyleSheet.create({
210
210
  borderRadius: Radius.XS,
211
211
  overflow: 'hidden',
212
212
  },
213
- currency: {fontSize: scaleSize(20), fontWeight: 'bold'},
214
213
  });
@@ -210,16 +210,12 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
210
210
  ]}>
211
211
  {!!image && <Image source={{uri: image}} style={styles.image} />}
212
212
  <View style={styles.content}>
213
- <Text
214
- typography={'header_default_bold'}
215
- numberOfLines={3}
216
- accessibilityLabel={'title_popup_notify'}>
213
+ <Text typography={'header_default_bold'} numberOfLines={3}>
217
214
  {title}
218
215
  </Text>
219
216
  <Description style={[styles.description, descriptionStyle]}>
220
217
  {typeof description === 'string' ? (
221
218
  <Text
222
- accessibilityLabel={'description_popup_notify'}
223
219
  typography={'body_default_regular'}
224
220
  onTextLayout={({nativeEvent: {lines}}) => {
225
221
  const enableScroll = lines.length > 3;
@@ -236,7 +232,6 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
236
232
  {!!error && (
237
233
  <View style={styles.information}>
238
234
  <Text
239
- accessibilityLabel={'description_popup_notify'}
240
235
  typography={'description_xs_regular'}
241
236
  color={theme.colors.text.hint}
242
237
  numberOfLines={1}>
package/Switch/index.tsx CHANGED
@@ -3,7 +3,7 @@ import {TouchableOpacity, View} from 'react-native';
3
3
  import {SwitchProps} from './types';
4
4
  import styles from './styles';
5
5
  import {Colors} from '../Consts';
6
- import {ComponentContext, useComponentId} from '../Application';
6
+ import {ComponentContext} from '../Application';
7
7
 
8
8
  const Switch: FC<SwitchProps> = ({
9
9
  value = false,
@@ -11,14 +11,10 @@ const Switch: FC<SwitchProps> = ({
11
11
  disabled = false,
12
12
  style,
13
13
  params,
14
- accessibilityLabel,
15
14
  ...props
16
15
  }) => {
17
16
  const circleBackgroundColor = value ? Colors.black_01 : Colors.black_03;
18
17
  const circleAlign = value ? 'flex-end' : 'flex-start';
19
- const componentName = 'Switch';
20
-
21
- const {componentId} = useComponentId(componentName, accessibilityLabel);
22
18
 
23
19
  let backgroundColor = value ? Colors.green_03 : Colors.black_07;
24
20
  if (disabled) {
@@ -28,7 +24,7 @@ const Switch: FC<SwitchProps> = ({
28
24
  return (
29
25
  <ComponentContext.Provider
30
26
  value={{
31
- componentName,
27
+ componentName: 'Switch',
32
28
  params,
33
29
  state: disabled ? 'disabled' : 'enabled',
34
30
  action: 'click',
@@ -36,12 +32,6 @@ const Switch: FC<SwitchProps> = ({
36
32
  <TouchableOpacity
37
33
  {...props}
38
34
  disabled={disabled}
39
- accessibilityState={{
40
- checked: value,
41
- disabled: disabled === null ? false : disabled,
42
- ...props.accessibilityState,
43
- }}
44
- accessibilityLabel={componentId}
45
35
  onPress={() => onChange?.(!value)}
46
36
  style={[
47
37
  style,
package/Title/index.tsx CHANGED
@@ -2,7 +2,11 @@ import React, {FC, useContext, useState} from 'react';
2
2
  import {Text as RNText, TouchableOpacity, View, ViewStyle} from 'react-native';
3
3
  import {Icon} from '../Icon';
4
4
  import {scaleSize, Text} from '../Text';
5
- import {ApplicationContext, useComponentId} from '../Application';
5
+ import {
6
+ ApplicationContext,
7
+ setAutomationID,
8
+ useComponentId,
9
+ } from '../Application';
6
10
  import {Badge} from '../Badge';
7
11
  import {Colors} from '../Consts';
8
12
  import styles from './styles';
@@ -82,7 +86,7 @@ const Title: FC<TitleProps> = ({
82
86
  }}
83
87
  style={[styles.iconLeftView, flexStyle]}>
84
88
  <RNText
85
- accessibilityLabel={componentId + '|title-text'}
89
+ {...setAutomationID(componentId + '|title-text')}
86
90
  numberOfLines={numberOfLines}
87
91
  style={[
88
92
  styleSheet[typography],
@@ -201,7 +205,7 @@ const Title: FC<TitleProps> = ({
201
205
  return (
202
206
  <View style={isSection && styles.margin}>
203
207
  <RNText
204
- accessibilityLabel={componentId + '|title-text'}
208
+ {...setAutomationID(componentId + '|title-text')}
205
209
  numberOfLines={numberOfLines}
206
210
  style={[styleSheet[typography], styles.title]}>
207
211
  {title}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.114.1-beta.9",
3
+ "version": "0.114.2",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -14,13 +14,13 @@
14
14
  "react-native-linear-gradient": "2.8.3",
15
15
  "react-native-gesture-handler": "1.10.3",
16
16
  "react-native-fast-image": "8.1.5",
17
- "@react-navigation/bottom-tabs": "https://gitlab.mservice.com.vn/momo-platform/react-native-bottom-tabs.git",
18
17
  "@react-navigation/core": "5.16.1",
19
18
  "@react-navigation/native": "5.9.8",
20
19
  "@react-navigation/routers": "5.7.4",
21
- "react-native-reanimated": "git+https://gitlab.mservice.com.vn/momo-platform/react-native-reanimated.git#v1.13.4_gradle_7",
22
- "lottie-react-native": "git+https://gitlab.mservice.com.vn/momo-platform/momo-lottie-react-native.git",
23
- "@react-navigation/stack": "https://gitlab.mservice.com.vn/momo-platform/react-navigation-stack.git"
20
+ "react-native-reanimated": "git+https://oauth2:q9C8ByV3vnsw_vjwrDay@gitlab.mservice.com.vn/momo-platform/react-native-reanimated.git#v1.13.4_gradle_7",
21
+ "lottie-react-native": "git+https://oauth2:oZFuaMKUc7GV7HeP8xq6@gitlab.mservice.com.vn/momo-platform/momo-lottie-react-native.git",
22
+ "@react-navigation/stack": "git+https://oauth2:ntR45Ct8MSUKVd52rG7a@gitlab.mservice.com.vn/momo-platform/react-navigation-stack.git",
23
+ "@react-navigation/bottom-tabs": "git+https://oauth2:RQq-YxRT5sme7Hx3xkKk@gitlab.mservice.com.vn/momo-platform/react-native-bottom-tabs.git"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react-native": "*"