sapo-components-ui-rn 1.0.77 → 1.0.79

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.
@@ -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, size, theme: themeOverrides, required, ...props }: SelectionFieldProps) => React.JSX.Element>;
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
@@ -5279,7 +5279,7 @@ var TextInputFlat = function (_a) {
5279
5279
  var font = theme.fonts.bodyLarge;
5280
5280
  var hasActiveOutline = parentState.focused || error;
5281
5281
  var _h = getConstants(), LABEL_PADDING_TOP = _h.LABEL_PADDING_TOP, FLAT_INPUT_OFFSET = _h.FLAT_INPUT_OFFSET, MIN_HEIGHT = _h.MIN_HEIGHT;
5282
- var _j = (StyleSheet.flatten(style) || {}), fontSizeStyle = _j.fontSize, lineHeightStyle = _j.lineHeight, fontWeight = _j.fontWeight, height = _j.height, paddingHorizontal = _j.paddingHorizontal, textAlign = _j.textAlign; __rest(_j, ["fontSize", "lineHeight", "fontWeight", "height", "paddingHorizontal", "textAlign"]);
5282
+ var _j = (StyleSheet.flatten(style) || {}), fontSizeStyle = _j.fontSize, lineHeightStyle = _j.lineHeight, fontWeight = _j.fontWeight, height = _j.height, paddingHorizontal = _j.paddingHorizontal; _j.textAlign; __rest(_j, ["fontSize", "lineHeight", "fontWeight", "height", "paddingHorizontal", "textAlign"]);
5283
5283
  var fontSize = fontSizeStyle || MAXIMIZED_LABEL_FONT_SIZE;
5284
5284
  var lineHeight = lineHeightStyle || (Platform.OS === "web" ? fontSize * 1.2 : undefined);
5285
5285
  var isPaddingHorizontalPassed = paddingHorizontal !== undefined && typeof paddingHorizontal === "number";
@@ -5499,11 +5499,7 @@ var TextInputFlat = function (_a) {
5499
5499
  renderPrefix(), render === null || render === void 0 ? void 0 :
5500
5500
  render(__assign(__assign({}, rest), { ref: innerRef, onChangeText: handleChangeText, value: inputValue, placeholder: rest.placeholder, editable: !disabled && editable, selectionColor: selectionColor, cursorColor: typeof cursorColor === "undefined" ? activeColor : cursorColor, placeholderTextColor: placeholderTextColorBasedOnState, onFocus: onFocus, onBlur: onBlur, underlineColorAndroid: "transparent", multiline: multiline, style: [
5501
5501
  styles$d.input,
5502
- __assign(__assign({ paddingLeft: paddingLeft, paddingRight: paddingRight, paddingTop: parentState.focused || parentState.value ? SPACE_12 : 0 }, font), { fontSize: fontSize, lineHeight: lineHeight, fontWeight: fontWeight, color: inputTextColor, textAlignVertical: multiline ? "top" : "center", textAlign: textAlign
5503
- ? textAlign
5504
- : I18nManager.getConstants().isRTL
5505
- ? "right"
5506
- : "left", marginTop: Platform.OS === "android" ? SPACE_8 : SPACE_2 }),
5502
+ __assign(__assign({ paddingLeft: paddingLeft, paddingRight: paddingRight, paddingTop: parentState.focused || parentState.value ? SPACE_12 : 0 }, font), { fontSize: fontSize, lineHeight: lineHeight, fontWeight: fontWeight, color: inputTextColor, textAlignVertical: multiline ? "top" : "center", marginTop: Platform.OS === "android" ? SPACE_8 : SPACE_2 }),
5507
5503
  contentStyle,
5508
5504
  ] })),
5509
5505
  renderSuffix())),
@@ -5753,11 +5749,7 @@ var TextInputDefault = function (_a) {
5753
5749
  ? activeColor
5754
5750
  : cursorColor, placeholderTextColor: placeholderTextColorBasedOnState, onFocus: onFocus, onBlur: onBlur, underlineColorAndroid: "transparent", multiline: multiline, style: [
5755
5751
  styles$c.input,
5756
- __assign(__assign({}, font), { fontSize: fontSize, lineHeight: lineHeight, fontWeight: fontWeight, color: inputTextColor, textAlignVertical: multiline ? "top" : "center", textAlign: textAlign
5757
- ? textAlign
5758
- : I18nManager.getConstants().isRTL
5759
- ? "right"
5760
- : "left", height: height ? height : 48, paddingTop: getPaddingTopValue(), paddingBottom: multiline ? CONSTANTS.SPACE_4 : 0 }),
5752
+ __assign(__assign({}, font), { fontSize: fontSize, lineHeight: lineHeight, fontWeight: fontWeight, color: inputTextColor, textAlignVertical: multiline ? "top" : "center", height: height ? height : 48, paddingTop: getPaddingTopValue(), paddingBottom: multiline ? CONSTANTS.SPACE_4 : 0 }),
5761
5753
  contentStyle,
5762
5754
  ] })),
5763
5755
  !multiline && renderSuffix()))),
@@ -5984,8 +5976,15 @@ var TextInputNumber = function (_a) {
5984
5976
  setInputValue(function (prev) { return prev.slice(0, -1); });
5985
5977
  }
5986
5978
  else if (key === "000") {
5987
- if (type === "integer" && inputValue.length > 0) {
5988
- setInputValue(function (prev) { return prev + "000"; });
5979
+ if (type === "integer") {
5980
+ var newInputValue = inputValue + "000";
5981
+ var newValue = Number(newInputValue);
5982
+ var maxValueNumber = Number(maxValue);
5983
+ if (!isNaN(newValue) &&
5984
+ !isNaN(maxValueNumber) &&
5985
+ newValue <= maxValueNumber) {
5986
+ setInputValue(newInputValue);
5987
+ }
5989
5988
  setIsFirstInput(false);
5990
5989
  }
5991
5990
  }
@@ -6007,6 +6006,20 @@ var TextInputNumber = function (_a) {
6007
6006
  setIsFirstInput(false);
6008
6007
  }
6009
6008
  else {
6009
+ // Kiểm tra nếu input bắt đầu bằng 0 và không có dấu chấm
6010
+ if (inputValue === "0") {
6011
+ if (key === ".") {
6012
+ setInputValue("0.");
6013
+ return;
6014
+ }
6015
+ else if (key >= "1" && key <= "9") {
6016
+ setInputValue(key);
6017
+ return;
6018
+ }
6019
+ else {
6020
+ return;
6021
+ }
6022
+ }
6010
6023
  var newInputValue = inputValue + key;
6011
6024
  var newValue = Number(newInputValue);
6012
6025
  var maxValueNumber = Number(maxValue);
@@ -6014,16 +6027,16 @@ var TextInputNumber = function (_a) {
6014
6027
  !isNaN(maxValueNumber) &&
6015
6028
  newValue <= maxValueNumber) {
6016
6029
  if (inputValue.includes(".")) {
6017
- var _a = inputValue.split("."), intPart = _a[0], _b = _a[1], decimalPart = _b === void 0 ? "" : _b;
6018
- if (intPart.length < 12 && decimalPart.length === 0) {
6030
+ var _a = inputValue.split("."); _a[0]; var _b = _a[1], decimalPart = _b === void 0 ? "" : _b;
6031
+ if (newInputValue.length <= 12 && decimalPart.length === 0) {
6019
6032
  setInputValue(function (prev) { return prev + key; });
6020
6033
  }
6021
- else if (decimalPart.length < 3) {
6034
+ else if (newInputValue.length <= 12 && decimalPart.length < 3) {
6022
6035
  setInputValue(function (prev) { return prev + key; });
6023
6036
  }
6024
6037
  }
6025
6038
  else {
6026
- if (inputValue.length < 12) {
6039
+ if (newInputValue.length <= 12) {
6027
6040
  setInputValue(function (prev) { return prev + key; });
6028
6041
  }
6029
6042
  }
@@ -6054,7 +6067,6 @@ var TextInputNumber = function (_a) {
6054
6067
  }
6055
6068
  return false;
6056
6069
  };
6057
- console.log(value, "value");
6058
6070
  var checkLabelEmpty = function () {
6059
6071
  if (label === undefined || label === null || label.toString() === "") {
6060
6072
  return true;
@@ -6078,7 +6090,14 @@ var TextInputNumber = function (_a) {
6078
6090
  {
6079
6091
  borderRadius: BORDER_RADIUS_6,
6080
6092
  },
6081
- [styles$b.border, { borderColor: colors.borderPrimaryDefault }],
6093
+ [
6094
+ styles$b.border,
6095
+ {
6096
+ borderColor: isShowModalKeyboard
6097
+ ? colors.borderBrandDefault
6098
+ : colors.borderPrimaryDefault,
6099
+ },
6100
+ ],
6082
6101
  textError.length > 0 && [
6083
6102
  {
6084
6103
  borderColor: colors.borderErrorDefault,
@@ -6873,7 +6892,7 @@ var Toast = memoWithRef(function (_props, ref) {
6873
6892
  top: top ? top : CONSTANTS.SPACE_16,
6874
6893
  },
6875
6894
  ] },
6876
- React__default.createElement(View, { row: !options.title, center: !options.title, full: true, onPress: onPressToast, style: [
6895
+ React__default.createElement(View, { row: !options.title, center: !options.title, full: true, activeOpacity: 0.8, onPress: onPressToast, style: [
6877
6896
  styles$8.wrapContent,
6878
6897
  {
6879
6898
  shadowColor: "black",
@@ -7184,7 +7203,7 @@ var styles$3 = StyleSheet.create({
7184
7203
  });
7185
7204
 
7186
7205
  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, _f = _a.size, size = _f === void 0 ? 16 : _f; _a.theme; var _g = _a.required, required = _g === void 0 ? false : _g, props = __rest(_a, ["style", "content", "label", "error", "borderColor", "left", "right", "textStyle", "labelStyle", "textProps", "onPress", "disabled", "textColor", "labelColor", "size", "theme", "required"]);
7206
+ 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
7207
  var theme = useInternalTheme();
7189
7208
  var colors = theme.colors;
7190
7209
  var disabledTextStyle = {
@@ -7237,7 +7256,7 @@ var SelectionField = function (_a) {
7237
7256
  ] },
7238
7257
  label,
7239
7258
  required && React__default.createElement(Text$1, { color: colors.textErrorDefault }, " *"))),
7240
- React__default.createElement(Text$1, __assign({ numberOfLines: 1, color: getColor(), size: size, style: [disabled && disabledTextStyle, textStyle] }, textProps),
7259
+ React__default.createElement(Text$1, __assign({ numberOfLines: 1, color: getColor(), style: [disabled && disabledTextStyle, textStyle] }, textProps),
7241
7260
  content.toString() === "" ? label : content,
7242
7261
  required && content.toString() === "" && (React__default.createElement(Text$1, { color: colors.textErrorDefault }, " *")))),
7243
7262
  right || React__default.createElement(Icon$1, { name: "IconArrowDown", type: "Svg", size: 24 }),
@@ -7334,17 +7353,25 @@ var formatNumberInput = function (value, formatDecimal) {
7334
7353
  return result;
7335
7354
  };
7336
7355
  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 = _e === void 0 ? "integer" : _e, _f = _a.formatDecimal, formatDecimal = _f === void 0 ? 3 : _f, visible = _a.visible, onClose = _a.onClose;
7356
+ 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
7357
  var theme = useInternalTheme();
7339
7358
  var colors = theme.colors;
7340
- var _g = useState((value === null || value === void 0 ? void 0 : value.toString()) || ""), inputValue = _g[0], setInputValue = _g[1];
7341
- var _h = useState(true), isFirstInput = _h[0], setIsFirstInput = _h[1];
7359
+ var _h = useState((value === null || value === void 0 ? void 0 : value.toString()) || ""), inputValue = _h[0], setInputValue = _h[1];
7360
+ var _j = useState(true), isFirstInput = _j[0], setIsFirstInput = _j[1];
7361
+ var _k = useState(true), canSave = _k[0], setCanSave = _k[1];
7342
7362
  useEffect(function () {
7343
7363
  if (visible) {
7344
7364
  setInputValue((value === null || value === void 0 ? void 0 : value.toString()) || "");
7345
7365
  setIsFirstInput(true);
7346
7366
  }
7347
7367
  }, [visible, value]);
7368
+ useEffect(function () {
7369
+ var currentValue = Number(inputValue);
7370
+ var minValueNumber = Number(minValue);
7371
+ setCanSave(!isNaN(currentValue) &&
7372
+ !isNaN(minValueNumber) &&
7373
+ currentValue >= minValueNumber);
7374
+ }, [inputValue, minValue]);
7348
7375
  var handleKeyPress = useCallback(function (key) {
7349
7376
  if (key === "del") {
7350
7377
  setInputValue(function (prev) { return prev.slice(0, -1); });
@@ -7353,14 +7380,20 @@ var NumberKeyboard = function (_a) {
7353
7380
  }
7354
7381
  if (key === "000") {
7355
7382
  if (type === "integer" && inputValue.length > 0) {
7356
- setInputValue(function (prev) { return prev + "000"; });
7383
+ var newInputValue_1 = inputValue + "000";
7384
+ var newValue_1 = Number(newInputValue_1);
7385
+ var maxValueNumber_1 = Number(maxValue);
7386
+ if (!isNaN(newValue_1) &&
7387
+ !isNaN(maxValueNumber_1) &&
7388
+ newValue_1 <= maxValueNumber_1) {
7389
+ setInputValue(newInputValue_1);
7390
+ }
7357
7391
  setIsFirstInput(false);
7358
7392
  }
7359
7393
  return;
7360
7394
  }
7361
7395
  if (key === ".") {
7362
7396
  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
7397
  if (inputValue === "0" || inputValue === "") {
7365
7398
  setInputValue("0.");
7366
7399
  }
@@ -7376,6 +7409,20 @@ var NumberKeyboard = function (_a) {
7376
7409
  setIsFirstInput(false);
7377
7410
  return;
7378
7411
  }
7412
+ // Kiểm tra nếu input bắt đầu bằng 0 và không có dấu chấm
7413
+ if (inputValue === "0") {
7414
+ if (key === ".") {
7415
+ setInputValue("0.");
7416
+ return;
7417
+ }
7418
+ else if (key >= "1" && key <= "9") {
7419
+ setInputValue(key);
7420
+ return;
7421
+ }
7422
+ else {
7423
+ return;
7424
+ }
7425
+ }
7379
7426
  var newInputValue = inputValue + key;
7380
7427
  var newValue = Number(newInputValue);
7381
7428
  var maxValueNumber = Number(maxValue);
@@ -7399,17 +7446,19 @@ var NumberKeyboard = function (_a) {
7399
7446
  }
7400
7447
  }, [inputValue, maxValue, type, formatDecimal, isFirstInput]);
7401
7448
  var handleClear = useCallback(function () {
7402
- setInputValue("0");
7449
+ setInputValue("");
7403
7450
  setIsFirstInput(true);
7404
7451
  }, []);
7405
7452
  var handleSave = useCallback(function () {
7453
+ if (!canSave)
7454
+ return;
7406
7455
  var finalValue = inputValue;
7407
7456
  if (inputValue.endsWith(".")) {
7408
7457
  finalValue = inputValue.slice(0, -1);
7409
7458
  }
7410
7459
  onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(finalValue);
7411
7460
  onClose();
7412
- }, [inputValue, onChangeText, onClose]);
7461
+ }, [inputValue, onChangeText, onClose, canSave]);
7413
7462
  var handleClose = useCallback(function () {
7414
7463
  onClose();
7415
7464
  setIsFirstInput(true);