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/dist/components/NumberKeyboard/index.d.ts +2 -0
- package/dist/components/SelectionField/index.d.ts +1 -2
- package/dist/index.esm.js +74 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +74 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/NumberKeyboard/index.tsx +42 -4
- package/src/components/SelectionField/index.tsx +0 -3
- package/src/components/TextInput/TextInputNumber.tsx +36 -6
package/dist/index.js
CHANGED
|
@@ -6017,8 +6017,15 @@ var TextInputNumber = function (_a) {
|
|
|
6017
6017
|
setInputValue(function (prev) { return prev.slice(0, -1); });
|
|
6018
6018
|
}
|
|
6019
6019
|
else if (key === "000") {
|
|
6020
|
-
if (type === "integer"
|
|
6021
|
-
|
|
6020
|
+
if (type === "integer") {
|
|
6021
|
+
var newInputValue = inputValue + "000";
|
|
6022
|
+
var newValue = Number(newInputValue);
|
|
6023
|
+
var maxValueNumber = Number(maxValue);
|
|
6024
|
+
if (!isNaN(newValue) &&
|
|
6025
|
+
!isNaN(maxValueNumber) &&
|
|
6026
|
+
newValue <= maxValueNumber) {
|
|
6027
|
+
setInputValue(newInputValue);
|
|
6028
|
+
}
|
|
6022
6029
|
setIsFirstInput(false);
|
|
6023
6030
|
}
|
|
6024
6031
|
}
|
|
@@ -6040,6 +6047,20 @@ var TextInputNumber = function (_a) {
|
|
|
6040
6047
|
setIsFirstInput(false);
|
|
6041
6048
|
}
|
|
6042
6049
|
else {
|
|
6050
|
+
// Kiểm tra nếu input bắt đầu bằng 0 và không có dấu chấm
|
|
6051
|
+
if (inputValue === "0") {
|
|
6052
|
+
if (key === ".") {
|
|
6053
|
+
setInputValue("0.");
|
|
6054
|
+
return;
|
|
6055
|
+
}
|
|
6056
|
+
else if (key >= "1" && key <= "9") {
|
|
6057
|
+
setInputValue(key);
|
|
6058
|
+
return;
|
|
6059
|
+
}
|
|
6060
|
+
else {
|
|
6061
|
+
return;
|
|
6062
|
+
}
|
|
6063
|
+
}
|
|
6043
6064
|
var newInputValue = inputValue + key;
|
|
6044
6065
|
var newValue = Number(newInputValue);
|
|
6045
6066
|
var maxValueNumber = Number(maxValue);
|
|
@@ -6047,16 +6068,16 @@ var TextInputNumber = function (_a) {
|
|
|
6047
6068
|
!isNaN(maxValueNumber) &&
|
|
6048
6069
|
newValue <= maxValueNumber) {
|
|
6049
6070
|
if (inputValue.includes(".")) {
|
|
6050
|
-
var _a = inputValue.split(".")
|
|
6051
|
-
if (
|
|
6071
|
+
var _a = inputValue.split("."); _a[0]; var _b = _a[1], decimalPart = _b === void 0 ? "" : _b;
|
|
6072
|
+
if (newInputValue.length <= 12 && decimalPart.length === 0) {
|
|
6052
6073
|
setInputValue(function (prev) { return prev + key; });
|
|
6053
6074
|
}
|
|
6054
|
-
else if (decimalPart.length < 3) {
|
|
6075
|
+
else if (newInputValue.length <= 12 && decimalPart.length < 3) {
|
|
6055
6076
|
setInputValue(function (prev) { return prev + key; });
|
|
6056
6077
|
}
|
|
6057
6078
|
}
|
|
6058
6079
|
else {
|
|
6059
|
-
if (
|
|
6080
|
+
if (newInputValue.length <= 12) {
|
|
6060
6081
|
setInputValue(function (prev) { return prev + key; });
|
|
6061
6082
|
}
|
|
6062
6083
|
}
|
|
@@ -6111,7 +6132,14 @@ var TextInputNumber = function (_a) {
|
|
|
6111
6132
|
{
|
|
6112
6133
|
borderRadius: BORDER_RADIUS_6,
|
|
6113
6134
|
},
|
|
6114
|
-
[
|
|
6135
|
+
[
|
|
6136
|
+
styles$b.border,
|
|
6137
|
+
{
|
|
6138
|
+
borderColor: isShowModalKeyboard
|
|
6139
|
+
? colors.borderBrandDefault
|
|
6140
|
+
: colors.borderPrimaryDefault,
|
|
6141
|
+
},
|
|
6142
|
+
],
|
|
6115
6143
|
textError.length > 0 && [
|
|
6116
6144
|
{
|
|
6117
6145
|
borderColor: colors.borderErrorDefault,
|
|
@@ -7217,7 +7245,7 @@ var styles$3 = reactNative.StyleSheet.create({
|
|
|
7217
7245
|
});
|
|
7218
7246
|
|
|
7219
7247
|
var SelectionField = function (_a) {
|
|
7220
|
-
var style = _a.style, _b = _a.content, content = _b === void 0 ? "" : _b, _c = _a.label, label = _c === void 0 ? "" : _c, _d = _a.error, error = _d === void 0 ? "" : _d, borderColor = _a.borderColor; _a.left; var right = _a.right, textStyle = _a.textStyle; _a.labelStyle; var textProps = _a.textProps, onPress = _a.onPress, _e = _a.disabled, disabled = _e === void 0 ? false : _e, textColor = _a.textColor, labelColor = _a.labelColor
|
|
7248
|
+
var style = _a.style, _b = _a.content, content = _b === void 0 ? "" : _b, _c = _a.label, label = _c === void 0 ? "" : _c, _d = _a.error, error = _d === void 0 ? "" : _d, borderColor = _a.borderColor; _a.left; var right = _a.right, textStyle = _a.textStyle; _a.labelStyle; var textProps = _a.textProps, onPress = _a.onPress, _e = _a.disabled, disabled = _e === void 0 ? false : _e, textColor = _a.textColor, labelColor = _a.labelColor; _a.theme; var _f = _a.required, required = _f === void 0 ? false : _f, props = __rest(_a, ["style", "content", "label", "error", "borderColor", "left", "right", "textStyle", "labelStyle", "textProps", "onPress", "disabled", "textColor", "labelColor", "theme", "required"]);
|
|
7221
7249
|
var theme = useInternalTheme();
|
|
7222
7250
|
var colors = theme.colors;
|
|
7223
7251
|
var disabledTextStyle = {
|
|
@@ -7270,7 +7298,7 @@ var SelectionField = function (_a) {
|
|
|
7270
7298
|
] },
|
|
7271
7299
|
label,
|
|
7272
7300
|
required && React__default["default"].createElement(Text$1, { color: colors.textErrorDefault }, " *"))),
|
|
7273
|
-
React__default["default"].createElement(Text$1, __assign({ numberOfLines: 1, color: getColor(),
|
|
7301
|
+
React__default["default"].createElement(Text$1, __assign({ numberOfLines: 1, color: getColor(), style: [disabled && disabledTextStyle, textStyle] }, textProps),
|
|
7274
7302
|
content.toString() === "" ? label : content,
|
|
7275
7303
|
required && content.toString() === "" && (React__default["default"].createElement(Text$1, { color: colors.textErrorDefault }, " *")))),
|
|
7276
7304
|
right || React__default["default"].createElement(Icon$1, { name: "IconArrowDown", type: "Svg", size: 24 }),
|
|
@@ -7367,17 +7395,25 @@ var formatNumberInput = function (value, formatDecimal) {
|
|
|
7367
7395
|
return result;
|
|
7368
7396
|
};
|
|
7369
7397
|
var NumberKeyboard = function (_a) {
|
|
7370
|
-
var _b = _a.value, value = _b === void 0 ? "" : _b, _c = _a.label, label = _c === void 0 ? "" : _c, onChangeText = _a.onChangeText, _d = _a.maxValue, maxValue = _d === void 0 ? 999999999999 : _d, _e = _a.type, type =
|
|
7398
|
+
var _b = _a.value, value = _b === void 0 ? "" : _b, _c = _a.label, label = _c === void 0 ? "" : _c, onChangeText = _a.onChangeText, _d = _a.maxValue, maxValue = _d === void 0 ? 999999999999 : _d, _e = _a.minValue, minValue = _e === void 0 ? 0 : _e, _f = _a.type, type = _f === void 0 ? "integer" : _f, _g = _a.formatDecimal, formatDecimal = _g === void 0 ? 3 : _g, visible = _a.visible, onClose = _a.onClose;
|
|
7371
7399
|
var theme = useInternalTheme();
|
|
7372
7400
|
var colors = theme.colors;
|
|
7373
|
-
var
|
|
7374
|
-
var
|
|
7401
|
+
var _h = React$3.useState((value === null || value === void 0 ? void 0 : value.toString()) || ""), inputValue = _h[0], setInputValue = _h[1];
|
|
7402
|
+
var _j = React$3.useState(true), isFirstInput = _j[0], setIsFirstInput = _j[1];
|
|
7403
|
+
var _k = React$3.useState(true), canSave = _k[0], setCanSave = _k[1];
|
|
7375
7404
|
React$3.useEffect(function () {
|
|
7376
7405
|
if (visible) {
|
|
7377
7406
|
setInputValue((value === null || value === void 0 ? void 0 : value.toString()) || "");
|
|
7378
7407
|
setIsFirstInput(true);
|
|
7379
7408
|
}
|
|
7380
7409
|
}, [visible, value]);
|
|
7410
|
+
React$3.useEffect(function () {
|
|
7411
|
+
var currentValue = Number(inputValue);
|
|
7412
|
+
var minValueNumber = Number(minValue);
|
|
7413
|
+
setCanSave(!isNaN(currentValue) &&
|
|
7414
|
+
!isNaN(minValueNumber) &&
|
|
7415
|
+
currentValue >= minValueNumber);
|
|
7416
|
+
}, [inputValue, minValue]);
|
|
7381
7417
|
var handleKeyPress = React$3.useCallback(function (key) {
|
|
7382
7418
|
if (key === "del") {
|
|
7383
7419
|
setInputValue(function (prev) { return prev.slice(0, -1); });
|
|
@@ -7386,14 +7422,20 @@ var NumberKeyboard = function (_a) {
|
|
|
7386
7422
|
}
|
|
7387
7423
|
if (key === "000") {
|
|
7388
7424
|
if (type === "integer" && inputValue.length > 0) {
|
|
7389
|
-
|
|
7425
|
+
var newInputValue_1 = inputValue + "000";
|
|
7426
|
+
var newValue_1 = Number(newInputValue_1);
|
|
7427
|
+
var maxValueNumber_1 = Number(maxValue);
|
|
7428
|
+
if (!isNaN(newValue_1) &&
|
|
7429
|
+
!isNaN(maxValueNumber_1) &&
|
|
7430
|
+
newValue_1 <= maxValueNumber_1) {
|
|
7431
|
+
setInputValue(newInputValue_1);
|
|
7432
|
+
}
|
|
7390
7433
|
setIsFirstInput(false);
|
|
7391
7434
|
}
|
|
7392
7435
|
return;
|
|
7393
7436
|
}
|
|
7394
7437
|
if (key === ".") {
|
|
7395
7438
|
if (type === "float" && !inputValue.includes(".")) {
|
|
7396
|
-
// Nếu inputValue là "0" hoặc rỗng, giữ lại số 0 và thêm dấu "."
|
|
7397
7439
|
if (inputValue === "0" || inputValue === "") {
|
|
7398
7440
|
setInputValue("0.");
|
|
7399
7441
|
}
|
|
@@ -7409,6 +7451,20 @@ var NumberKeyboard = function (_a) {
|
|
|
7409
7451
|
setIsFirstInput(false);
|
|
7410
7452
|
return;
|
|
7411
7453
|
}
|
|
7454
|
+
// Kiểm tra nếu input bắt đầu bằng 0 và không có dấu chấm
|
|
7455
|
+
if (inputValue === "0") {
|
|
7456
|
+
if (key === ".") {
|
|
7457
|
+
setInputValue("0.");
|
|
7458
|
+
return;
|
|
7459
|
+
}
|
|
7460
|
+
else if (key >= "1" && key <= "9") {
|
|
7461
|
+
setInputValue(key);
|
|
7462
|
+
return;
|
|
7463
|
+
}
|
|
7464
|
+
else {
|
|
7465
|
+
return;
|
|
7466
|
+
}
|
|
7467
|
+
}
|
|
7412
7468
|
var newInputValue = inputValue + key;
|
|
7413
7469
|
var newValue = Number(newInputValue);
|
|
7414
7470
|
var maxValueNumber = Number(maxValue);
|
|
@@ -7432,17 +7488,19 @@ var NumberKeyboard = function (_a) {
|
|
|
7432
7488
|
}
|
|
7433
7489
|
}, [inputValue, maxValue, type, formatDecimal, isFirstInput]);
|
|
7434
7490
|
var handleClear = React$3.useCallback(function () {
|
|
7435
|
-
setInputValue("
|
|
7491
|
+
setInputValue("");
|
|
7436
7492
|
setIsFirstInput(true);
|
|
7437
7493
|
}, []);
|
|
7438
7494
|
var handleSave = React$3.useCallback(function () {
|
|
7495
|
+
if (!canSave)
|
|
7496
|
+
return;
|
|
7439
7497
|
var finalValue = inputValue;
|
|
7440
7498
|
if (inputValue.endsWith(".")) {
|
|
7441
7499
|
finalValue = inputValue.slice(0, -1);
|
|
7442
7500
|
}
|
|
7443
7501
|
onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(finalValue);
|
|
7444
7502
|
onClose();
|
|
7445
|
-
}, [inputValue, onChangeText, onClose]);
|
|
7503
|
+
}, [inputValue, onChangeText, onClose, canSave]);
|
|
7446
7504
|
var handleClose = React$3.useCallback(function () {
|
|
7447
7505
|
onClose();
|
|
7448
7506
|
setIsFirstInput(true);
|