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
|
@@ -8,6 +8,8 @@ export interface NumberKeyboardProps {
|
|
|
8
8
|
onChangeText?: (value: string) => void;
|
|
9
9
|
/** Giá trị tối đa cho phép */
|
|
10
10
|
maxValue?: number;
|
|
11
|
+
/** Giá trị tối thiểu cho phép */
|
|
12
|
+
minValue?: number;
|
|
11
13
|
/** Loại input: integer hoặc float */
|
|
12
14
|
type?: "integer" | "float";
|
|
13
15
|
/** Số chữ số thập phân cho phép */
|
|
@@ -13,7 +13,6 @@ export interface SelectionFieldProps extends TouchableOpacityProps {
|
|
|
13
13
|
textProps?: IText;
|
|
14
14
|
textColor?: string;
|
|
15
15
|
labelColor?: string;
|
|
16
|
-
size?: number;
|
|
17
16
|
textStyle?: TextStyle;
|
|
18
17
|
labelStyle?: TextStyle;
|
|
19
18
|
disabled?: boolean;
|
|
@@ -21,5 +20,5 @@ export interface SelectionFieldProps extends TouchableOpacityProps {
|
|
|
21
20
|
theme?: ThemeProp;
|
|
22
21
|
required?: boolean;
|
|
23
22
|
}
|
|
24
|
-
declare const _default: React.MemoExoticComponent<({ style, content, label, error, borderColor, left, right, textStyle, labelStyle, textProps, onPress, disabled, textColor, labelColor,
|
|
23
|
+
declare const _default: React.MemoExoticComponent<({ style, content, label, error, borderColor, left, right, textStyle, labelStyle, textProps, onPress, disabled, textColor, labelColor, theme: themeOverrides, required, ...props }: SelectionFieldProps) => React.JSX.Element>;
|
|
25
24
|
export default _default;
|
package/dist/index.esm.js
CHANGED
|
@@ -5984,8 +5984,15 @@ var TextInputNumber = function (_a) {
|
|
|
5984
5984
|
setInputValue(function (prev) { return prev.slice(0, -1); });
|
|
5985
5985
|
}
|
|
5986
5986
|
else if (key === "000") {
|
|
5987
|
-
if (type === "integer"
|
|
5988
|
-
|
|
5987
|
+
if (type === "integer") {
|
|
5988
|
+
var newInputValue = inputValue + "000";
|
|
5989
|
+
var newValue = Number(newInputValue);
|
|
5990
|
+
var maxValueNumber = Number(maxValue);
|
|
5991
|
+
if (!isNaN(newValue) &&
|
|
5992
|
+
!isNaN(maxValueNumber) &&
|
|
5993
|
+
newValue <= maxValueNumber) {
|
|
5994
|
+
setInputValue(newInputValue);
|
|
5995
|
+
}
|
|
5989
5996
|
setIsFirstInput(false);
|
|
5990
5997
|
}
|
|
5991
5998
|
}
|
|
@@ -6007,6 +6014,20 @@ var TextInputNumber = function (_a) {
|
|
|
6007
6014
|
setIsFirstInput(false);
|
|
6008
6015
|
}
|
|
6009
6016
|
else {
|
|
6017
|
+
// Kiểm tra nếu input bắt đầu bằng 0 và không có dấu chấm
|
|
6018
|
+
if (inputValue === "0") {
|
|
6019
|
+
if (key === ".") {
|
|
6020
|
+
setInputValue("0.");
|
|
6021
|
+
return;
|
|
6022
|
+
}
|
|
6023
|
+
else if (key >= "1" && key <= "9") {
|
|
6024
|
+
setInputValue(key);
|
|
6025
|
+
return;
|
|
6026
|
+
}
|
|
6027
|
+
else {
|
|
6028
|
+
return;
|
|
6029
|
+
}
|
|
6030
|
+
}
|
|
6010
6031
|
var newInputValue = inputValue + key;
|
|
6011
6032
|
var newValue = Number(newInputValue);
|
|
6012
6033
|
var maxValueNumber = Number(maxValue);
|
|
@@ -6014,16 +6035,16 @@ var TextInputNumber = function (_a) {
|
|
|
6014
6035
|
!isNaN(maxValueNumber) &&
|
|
6015
6036
|
newValue <= maxValueNumber) {
|
|
6016
6037
|
if (inputValue.includes(".")) {
|
|
6017
|
-
var _a = inputValue.split(".")
|
|
6018
|
-
if (
|
|
6038
|
+
var _a = inputValue.split("."); _a[0]; var _b = _a[1], decimalPart = _b === void 0 ? "" : _b;
|
|
6039
|
+
if (newInputValue.length <= 12 && decimalPart.length === 0) {
|
|
6019
6040
|
setInputValue(function (prev) { return prev + key; });
|
|
6020
6041
|
}
|
|
6021
|
-
else if (decimalPart.length < 3) {
|
|
6042
|
+
else if (newInputValue.length <= 12 && decimalPart.length < 3) {
|
|
6022
6043
|
setInputValue(function (prev) { return prev + key; });
|
|
6023
6044
|
}
|
|
6024
6045
|
}
|
|
6025
6046
|
else {
|
|
6026
|
-
if (
|
|
6047
|
+
if (newInputValue.length <= 12) {
|
|
6027
6048
|
setInputValue(function (prev) { return prev + key; });
|
|
6028
6049
|
}
|
|
6029
6050
|
}
|
|
@@ -6078,7 +6099,14 @@ var TextInputNumber = function (_a) {
|
|
|
6078
6099
|
{
|
|
6079
6100
|
borderRadius: BORDER_RADIUS_6,
|
|
6080
6101
|
},
|
|
6081
|
-
[
|
|
6102
|
+
[
|
|
6103
|
+
styles$b.border,
|
|
6104
|
+
{
|
|
6105
|
+
borderColor: isShowModalKeyboard
|
|
6106
|
+
? colors.borderBrandDefault
|
|
6107
|
+
: colors.borderPrimaryDefault,
|
|
6108
|
+
},
|
|
6109
|
+
],
|
|
6082
6110
|
textError.length > 0 && [
|
|
6083
6111
|
{
|
|
6084
6112
|
borderColor: colors.borderErrorDefault,
|
|
@@ -7184,7 +7212,7 @@ var styles$3 = StyleSheet.create({
|
|
|
7184
7212
|
});
|
|
7185
7213
|
|
|
7186
7214
|
var SelectionField = function (_a) {
|
|
7187
|
-
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
|
|
7215
|
+
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"]);
|
|
7188
7216
|
var theme = useInternalTheme();
|
|
7189
7217
|
var colors = theme.colors;
|
|
7190
7218
|
var disabledTextStyle = {
|
|
@@ -7237,7 +7265,7 @@ var SelectionField = function (_a) {
|
|
|
7237
7265
|
] },
|
|
7238
7266
|
label,
|
|
7239
7267
|
required && React__default.createElement(Text$1, { color: colors.textErrorDefault }, " *"))),
|
|
7240
|
-
React__default.createElement(Text$1, __assign({ numberOfLines: 1, color: getColor(),
|
|
7268
|
+
React__default.createElement(Text$1, __assign({ numberOfLines: 1, color: getColor(), style: [disabled && disabledTextStyle, textStyle] }, textProps),
|
|
7241
7269
|
content.toString() === "" ? label : content,
|
|
7242
7270
|
required && content.toString() === "" && (React__default.createElement(Text$1, { color: colors.textErrorDefault }, " *")))),
|
|
7243
7271
|
right || React__default.createElement(Icon$1, { name: "IconArrowDown", type: "Svg", size: 24 }),
|
|
@@ -7334,17 +7362,25 @@ var formatNumberInput = function (value, formatDecimal) {
|
|
|
7334
7362
|
return result;
|
|
7335
7363
|
};
|
|
7336
7364
|
var NumberKeyboard = function (_a) {
|
|
7337
|
-
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 =
|
|
7365
|
+
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;
|
|
7338
7366
|
var theme = useInternalTheme();
|
|
7339
7367
|
var colors = theme.colors;
|
|
7340
|
-
var
|
|
7341
|
-
var
|
|
7368
|
+
var _h = useState((value === null || value === void 0 ? void 0 : value.toString()) || ""), inputValue = _h[0], setInputValue = _h[1];
|
|
7369
|
+
var _j = useState(true), isFirstInput = _j[0], setIsFirstInput = _j[1];
|
|
7370
|
+
var _k = useState(true), canSave = _k[0], setCanSave = _k[1];
|
|
7342
7371
|
useEffect(function () {
|
|
7343
7372
|
if (visible) {
|
|
7344
7373
|
setInputValue((value === null || value === void 0 ? void 0 : value.toString()) || "");
|
|
7345
7374
|
setIsFirstInput(true);
|
|
7346
7375
|
}
|
|
7347
7376
|
}, [visible, value]);
|
|
7377
|
+
useEffect(function () {
|
|
7378
|
+
var currentValue = Number(inputValue);
|
|
7379
|
+
var minValueNumber = Number(minValue);
|
|
7380
|
+
setCanSave(!isNaN(currentValue) &&
|
|
7381
|
+
!isNaN(minValueNumber) &&
|
|
7382
|
+
currentValue >= minValueNumber);
|
|
7383
|
+
}, [inputValue, minValue]);
|
|
7348
7384
|
var handleKeyPress = useCallback(function (key) {
|
|
7349
7385
|
if (key === "del") {
|
|
7350
7386
|
setInputValue(function (prev) { return prev.slice(0, -1); });
|
|
@@ -7353,14 +7389,20 @@ var NumberKeyboard = function (_a) {
|
|
|
7353
7389
|
}
|
|
7354
7390
|
if (key === "000") {
|
|
7355
7391
|
if (type === "integer" && inputValue.length > 0) {
|
|
7356
|
-
|
|
7392
|
+
var newInputValue_1 = inputValue + "000";
|
|
7393
|
+
var newValue_1 = Number(newInputValue_1);
|
|
7394
|
+
var maxValueNumber_1 = Number(maxValue);
|
|
7395
|
+
if (!isNaN(newValue_1) &&
|
|
7396
|
+
!isNaN(maxValueNumber_1) &&
|
|
7397
|
+
newValue_1 <= maxValueNumber_1) {
|
|
7398
|
+
setInputValue(newInputValue_1);
|
|
7399
|
+
}
|
|
7357
7400
|
setIsFirstInput(false);
|
|
7358
7401
|
}
|
|
7359
7402
|
return;
|
|
7360
7403
|
}
|
|
7361
7404
|
if (key === ".") {
|
|
7362
7405
|
if (type === "float" && !inputValue.includes(".")) {
|
|
7363
|
-
// Nếu inputValue là "0" hoặc rỗng, giữ lại số 0 và thêm dấu "."
|
|
7364
7406
|
if (inputValue === "0" || inputValue === "") {
|
|
7365
7407
|
setInputValue("0.");
|
|
7366
7408
|
}
|
|
@@ -7376,6 +7418,20 @@ var NumberKeyboard = function (_a) {
|
|
|
7376
7418
|
setIsFirstInput(false);
|
|
7377
7419
|
return;
|
|
7378
7420
|
}
|
|
7421
|
+
// Kiểm tra nếu input bắt đầu bằng 0 và không có dấu chấm
|
|
7422
|
+
if (inputValue === "0") {
|
|
7423
|
+
if (key === ".") {
|
|
7424
|
+
setInputValue("0.");
|
|
7425
|
+
return;
|
|
7426
|
+
}
|
|
7427
|
+
else if (key >= "1" && key <= "9") {
|
|
7428
|
+
setInputValue(key);
|
|
7429
|
+
return;
|
|
7430
|
+
}
|
|
7431
|
+
else {
|
|
7432
|
+
return;
|
|
7433
|
+
}
|
|
7434
|
+
}
|
|
7379
7435
|
var newInputValue = inputValue + key;
|
|
7380
7436
|
var newValue = Number(newInputValue);
|
|
7381
7437
|
var maxValueNumber = Number(maxValue);
|
|
@@ -7399,17 +7455,19 @@ var NumberKeyboard = function (_a) {
|
|
|
7399
7455
|
}
|
|
7400
7456
|
}, [inputValue, maxValue, type, formatDecimal, isFirstInput]);
|
|
7401
7457
|
var handleClear = useCallback(function () {
|
|
7402
|
-
setInputValue("
|
|
7458
|
+
setInputValue("");
|
|
7403
7459
|
setIsFirstInput(true);
|
|
7404
7460
|
}, []);
|
|
7405
7461
|
var handleSave = useCallback(function () {
|
|
7462
|
+
if (!canSave)
|
|
7463
|
+
return;
|
|
7406
7464
|
var finalValue = inputValue;
|
|
7407
7465
|
if (inputValue.endsWith(".")) {
|
|
7408
7466
|
finalValue = inputValue.slice(0, -1);
|
|
7409
7467
|
}
|
|
7410
7468
|
onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(finalValue);
|
|
7411
7469
|
onClose();
|
|
7412
|
-
}, [inputValue, onChangeText, onClose]);
|
|
7470
|
+
}, [inputValue, onChangeText, onClose, canSave]);
|
|
7413
7471
|
var handleClose = useCallback(function () {
|
|
7414
7472
|
onClose();
|
|
7415
7473
|
setIsFirstInput(true);
|