sapo-components-ui-rn 1.0.77 → 1.0.78

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sapo-components-ui-rn",
3
- "version": "1.0.77",
3
+ "version": "1.0.78",
4
4
  "description": "React Native UI Components Library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -21,6 +21,8 @@ export interface NumberKeyboardProps {
21
21
  onChangeText?: (value: string) => void;
22
22
  /** Giá trị tối đa cho phép */
23
23
  maxValue?: number;
24
+ /** Giá trị tối thiểu cho phép */
25
+ minValue?: number;
24
26
  /** Loại input: integer hoặc float */
25
27
  type?: "integer" | "float";
26
28
  /** Số chữ số thập phân cho phép */
@@ -53,6 +55,7 @@ const NumberKeyboard: React.FC<NumberKeyboardProps> = ({
53
55
  label = "",
54
56
  onChangeText,
55
57
  maxValue = 999999999999,
58
+ minValue = 0,
56
59
  type = "integer",
57
60
  formatDecimal = 3,
58
61
  visible,
@@ -63,6 +66,7 @@ const NumberKeyboard: React.FC<NumberKeyboardProps> = ({
63
66
 
64
67
  const [inputValue, setInputValue] = useState<string>(value?.toString() || "");
65
68
  const [isFirstInput, setIsFirstInput] = useState<boolean>(true);
69
+ const [canSave, setCanSave] = useState<boolean>(true);
66
70
 
67
71
  useEffect(() => {
68
72
  if (visible) {
@@ -71,6 +75,16 @@ const NumberKeyboard: React.FC<NumberKeyboardProps> = ({
71
75
  }
72
76
  }, [visible, value]);
73
77
 
78
+ useEffect(() => {
79
+ const currentValue = Number(inputValue);
80
+ const minValueNumber = Number(minValue);
81
+ setCanSave(
82
+ !isNaN(currentValue) &&
83
+ !isNaN(minValueNumber) &&
84
+ currentValue >= minValueNumber
85
+ );
86
+ }, [inputValue, minValue]);
87
+
74
88
  const handleKeyPress = useCallback(
75
89
  (key: string) => {
76
90
  if (key === "del") {
@@ -81,7 +95,17 @@ const NumberKeyboard: React.FC<NumberKeyboardProps> = ({
81
95
 
82
96
  if (key === "000") {
83
97
  if (type === "integer" && inputValue.length > 0) {
84
- setInputValue((prev) => prev + "000");
98
+ const newInputValue = inputValue + "000";
99
+ const newValue = Number(newInputValue);
100
+ const maxValueNumber = Number(maxValue);
101
+
102
+ if (
103
+ !isNaN(newValue) &&
104
+ !isNaN(maxValueNumber) &&
105
+ newValue <= maxValueNumber
106
+ ) {
107
+ setInputValue(newInputValue);
108
+ }
85
109
  setIsFirstInput(false);
86
110
  }
87
111
  return;
@@ -89,7 +113,6 @@ const NumberKeyboard: React.FC<NumberKeyboardProps> = ({
89
113
 
90
114
  if (key === ".") {
91
115
  if (type === "float" && !inputValue.includes(".")) {
92
- // Nếu inputValue là "0" hoặc rỗng, giữ lại số 0 và thêm dấu "."
93
116
  if (inputValue === "0" || inputValue === "") {
94
117
  setInputValue("0.");
95
118
  } else {
@@ -106,6 +129,19 @@ const NumberKeyboard: React.FC<NumberKeyboardProps> = ({
106
129
  return;
107
130
  }
108
131
 
132
+ // Kiểm tra nếu input bắt đầu bằng 0 và không có dấu chấm
133
+ if (inputValue === "0") {
134
+ if (key === ".") {
135
+ setInputValue("0.");
136
+ return;
137
+ } else if (key >= "1" && key <= "9") {
138
+ setInputValue(key);
139
+ return;
140
+ } else {
141
+ return;
142
+ }
143
+ }
144
+
109
145
  const newInputValue = inputValue + key;
110
146
  const newValue = Number(newInputValue);
111
147
  const maxValueNumber = Number(maxValue);
@@ -133,18 +169,20 @@ const NumberKeyboard: React.FC<NumberKeyboardProps> = ({
133
169
  );
134
170
 
135
171
  const handleClear = useCallback(() => {
136
- setInputValue("0");
172
+ setInputValue("");
137
173
  setIsFirstInput(true);
138
174
  }, []);
139
175
 
140
176
  const handleSave = useCallback(() => {
177
+ if (!canSave) return;
178
+
141
179
  let finalValue = inputValue;
142
180
  if (inputValue.endsWith(".")) {
143
181
  finalValue = inputValue.slice(0, -1);
144
182
  }
145
183
  onChangeText?.(finalValue);
146
184
  onClose();
147
- }, [inputValue, onChangeText, onClose]);
185
+ }, [inputValue, onChangeText, onClose, canSave]);
148
186
 
149
187
  const handleClose = useCallback(() => {
150
188
  onClose();
@@ -38,7 +38,6 @@ export interface SelectionFieldProps extends TouchableOpacityProps {
38
38
  textProps?: IText;
39
39
  textColor?: string;
40
40
  labelColor?: string;
41
- size?: number;
42
41
  textStyle?: TextStyle;
43
42
  labelStyle?: TextStyle;
44
43
  disabled?: boolean;
@@ -61,7 +60,6 @@ const SelectionField = ({
61
60
  disabled = false,
62
61
  textColor,
63
62
  labelColor,
64
- size = 16,
65
63
  theme: themeOverrides,
66
64
  required = false,
67
65
  ...props
@@ -138,7 +136,6 @@ const SelectionField = ({
138
136
  <Text
139
137
  numberOfLines={1}
140
138
  color={getColor()}
141
- size={size}
142
139
  style={[disabled && disabledTextStyle, textStyle]}
143
140
  {...textProps}
144
141
  >
@@ -138,8 +138,18 @@ const TextInputNumber = ({
138
138
  if (key === "del") {
139
139
  setInputValue((prev) => prev.slice(0, -1));
140
140
  } else if (key === "000") {
141
- if (type === "integer" && inputValue.length > 0) {
142
- setInputValue((prev) => prev + "000");
141
+ if (type === "integer") {
142
+ const newInputValue = inputValue + "000";
143
+ const newValue = Number(newInputValue);
144
+ const maxValueNumber = Number(maxValue);
145
+
146
+ if (
147
+ !isNaN(newValue) &&
148
+ !isNaN(maxValueNumber) &&
149
+ newValue <= maxValueNumber
150
+ ) {
151
+ setInputValue(newInputValue);
152
+ }
143
153
  setIsFirstInput(false);
144
154
  }
145
155
  } else if (key === ".") {
@@ -157,6 +167,19 @@ const TextInputNumber = ({
157
167
  setInputValue(key);
158
168
  setIsFirstInput(false);
159
169
  } else {
170
+ // Kiểm tra nếu input bắt đầu bằng 0 và không có dấu chấm
171
+ if (inputValue === "0") {
172
+ if (key === ".") {
173
+ setInputValue("0.");
174
+ return;
175
+ } else if (key >= "1" && key <= "9") {
176
+ setInputValue(key);
177
+ return;
178
+ } else {
179
+ return;
180
+ }
181
+ }
182
+
160
183
  const newInputValue = inputValue + key;
161
184
  const newValue = Number(newInputValue);
162
185
  const maxValueNumber = Number(maxValue);
@@ -168,13 +191,13 @@ const TextInputNumber = ({
168
191
  ) {
169
192
  if (inputValue.includes(".")) {
170
193
  const [intPart, decimalPart = ""] = inputValue.split(".");
171
- if (intPart.length < 12 && decimalPart.length === 0) {
194
+ if (newInputValue.length <= 12 && decimalPart.length === 0) {
172
195
  setInputValue((prev) => prev + key);
173
- } else if (decimalPart.length < 3) {
196
+ } else if (newInputValue.length <= 12 && decimalPart.length < 3) {
174
197
  setInputValue((prev) => prev + key);
175
198
  }
176
199
  } else {
177
- if (inputValue.length < 12) {
200
+ if (newInputValue.length <= 12) {
178
201
  setInputValue((prev) => prev + key);
179
202
  }
180
203
  }
@@ -246,7 +269,14 @@ const TextInputNumber = ({
246
269
  borderRadius: BORDER_RADIUS_6,
247
270
  },
248
271
 
249
- [styles.border, { borderColor: colors.borderPrimaryDefault }],
272
+ [
273
+ styles.border,
274
+ {
275
+ borderColor: isShowModalKeyboard
276
+ ? colors.borderBrandDefault
277
+ : colors.borderPrimaryDefault,
278
+ },
279
+ ],
250
280
 
251
281
  textError.length > 0 && [
252
282
  {