sapo-components-ui-rn 1.0.70 → 1.0.72

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.
@@ -26,5 +26,5 @@ export interface ButtonProps extends TouchableOpacityProps {
26
26
  buttonSize?: "normal" | "small";
27
27
  critical?: boolean;
28
28
  }
29
- declare const _default: React.MemoExoticComponent<({ style, title, border, borderColor, isLoading, left, right, margin, textStyle, textProps, onPress, disabled, backgroundColor, textColor, bold, size, medium, mode, transparent, full, theme: themeOverrides, buttonSize, critical, ...props }: ButtonProps) => React.JSX.Element>;
29
+ declare const _default: React.MemoExoticComponent<({ style, title, border, borderColor, isLoading, left, right, margin, textStyle, textProps, onPress, disabled, backgroundColor, textColor, bold, medium, mode, transparent, full, theme: themeOverrides, buttonSize, size, critical, ...props }: ButtonProps) => React.JSX.Element>;
30
30
  export default _default;
@@ -11,6 +11,7 @@ export type Props = React.ComponentPropsWithRef<typeof NativeTextInput> & {
11
11
  suffix?: string;
12
12
  textError?: string;
13
13
  maxValue?: number;
14
+ minValue?: number;
14
15
  type?: "integer" | "float";
15
16
  formatDecimal?: 1 | 2 | 3;
16
17
  required?: boolean;
@@ -21,11 +22,11 @@ export type Props = React.ComponentPropsWithRef<typeof NativeTextInput> & {
21
22
  /**
22
23
  * The text or component to use for the floating label.
23
24
  */
24
- label: TextInputLabelProp;
25
+ label?: TextInputLabelProp;
25
26
  /**
26
27
  * Placeholder for the input.
27
28
  */
28
- placeholder: string;
29
+ placeholder?: string;
29
30
  /**
30
31
  * Whether to style the TextInput with error style.
31
32
  */
@@ -15,9 +15,10 @@ export interface TextInputNumberProps extends TouchableOpacityProps {
15
15
  clearButton?: boolean;
16
16
  theme?: ThemeProp;
17
17
  maxValue?: number;
18
+ minValue?: number;
18
19
  type?: "integer" | "float";
19
20
  formatDecimal?: 1 | 2 | 3;
20
21
  required?: boolean;
21
22
  }
22
- declare const _default: React.MemoExoticComponent<({ style, value, label, textError, left, right, onChangeText, disabled, theme: themeOverrides, prefix, suffix, clearButton, maxValue, type, formatDecimal, required, ...props }: TextInputNumberProps) => React.JSX.Element>;
23
+ declare const _default: React.MemoExoticComponent<({ style, value, label, textError, left, right, onChangeText, disabled, theme: themeOverrides, prefix, suffix, clearButton, maxValue, minValue, type, formatDecimal, required, ...props }: TextInputNumberProps) => React.JSX.Element>;
23
24
  export default _default;
package/dist/index.esm.js CHANGED
@@ -358,6 +358,7 @@ var ref = {
358
358
  borderSuccessInverseDefault: green.GREEN40,
359
359
  toggleBackgroundDefault: ink.INK10,
360
360
  toggleBackgroundActive: green.GREEN80,
361
+ overlayPrimaryDefault: ink.INK40,
361
362
  },
362
363
  },
363
364
  light: {
@@ -502,6 +503,7 @@ var ref = {
502
503
  borderSuccessInverseDefault: green.GREEN40,
503
504
  toggleBackgroundDefault: ink.INK10,
504
505
  toggleBackgroundActive: green.GREEN80,
506
+ overlayPrimaryDefault: ink.INK40,
505
507
  },
506
508
  },
507
509
  },
@@ -1272,6 +1274,7 @@ var LightTheme = {
1272
1274
  borderSuccessInverseDefault: green.GREEN40,
1273
1275
  toggleBackgroundDefault: ink.INK10,
1274
1276
  toggleBackgroundActive: green.GREEN80,
1277
+ overlayPrimaryDefault: ink.INK40,
1275
1278
  },
1276
1279
  fonts: configureFonts(),
1277
1280
  animation: {
@@ -1420,6 +1423,7 @@ var DarkTheme = __assign(__assign({}, LightTheme), { dark: true, mode: "adaptive
1420
1423
  borderSuccessInverseDefault: green.GREEN40,
1421
1424
  toggleBackgroundDefault: ink.INK10,
1422
1425
  toggleBackgroundActive: green.GREEN80,
1426
+ overlayPrimaryDefault: ink.INK40,
1423
1427
  } });
1424
1428
 
1425
1429
  var DefaultTheme = LightTheme;
@@ -5437,6 +5441,15 @@ var TextInputFlat = function (_a) {
5437
5441
  }
5438
5442
  return React$3.createElement(View$1, null);
5439
5443
  };
5444
+ var checkLineRightAction = function () {
5445
+ if (!multiline && right && inputValue) {
5446
+ return true;
5447
+ }
5448
+ if (parentState.focused && right) {
5449
+ return true;
5450
+ }
5451
+ return false;
5452
+ };
5440
5453
  return (React$3.createElement(View$1, null,
5441
5454
  React$3.createElement(View$1, { style: {
5442
5455
  flexDirection: "row",
@@ -5484,7 +5497,7 @@ var TextInputFlat = function (_a) {
5484
5497
  renderSuffix())),
5485
5498
  !disabled && clearButton && inputValue ? (React$3.createElement(TouchableOpacity, { onPress: handleClear, style: styles$d.clearButton },
5486
5499
  React$3.createElement(Icon$1, { name: "IconClearText", type: "Svg", size: 24 }))) : (React$3.createElement(Spacer, { width: SPACE_12 })),
5487
- !multiline && right && (React$3.createElement(Spacer, { width: 1, height: 30, backgroundColor: theme.colors.borderPrimaryDefault, style: {
5500
+ checkLineRightAction() && (React$3.createElement(Spacer, { width: 1, height: 24, backgroundColor: theme.colors.borderPrimaryDefault, style: {
5488
5501
  marginRight: SPACE_8,
5489
5502
  } })),
5490
5503
  React$3.createElement(View$1, { style: {
@@ -5665,6 +5678,15 @@ var TextInputDefault = function (_a) {
5665
5678
  }
5666
5679
  return React$3.createElement(View, null);
5667
5680
  };
5681
+ var checkLineRightAction = function () {
5682
+ if (!multiline && right && inputValue) {
5683
+ return true;
5684
+ }
5685
+ if (parentState.focused && right) {
5686
+ return true;
5687
+ }
5688
+ return false;
5689
+ };
5668
5690
  return (React$3.createElement(View, { style: viewStyle },
5669
5691
  React$3.createElement(View, { row: true, alignCenter: !multiline, justifyCenter: true, style: [
5670
5692
  {
@@ -5723,7 +5745,7 @@ var TextInputDefault = function (_a) {
5723
5745
  !multiline && renderSuffix()))),
5724
5746
  !disabled && clearButton && inputValue ? (React$3.createElement(TouchableOpacity, { onPress: handleClear, style: multiline ? styles$c.clearButtonMultiline : styles$c.clearButton },
5725
5747
  React$3.createElement(Icon$1, { name: "IconClearText", type: "Svg", size: 24 }))) : (React$3.createElement(Spacer, { width: CONSTANTS.SPACE_12 })),
5726
- !multiline && right && (React$3.createElement(Spacer, { width: 1, height: 30, backgroundColor: colors.borderPrimaryDefault, style: {
5748
+ checkLineRightAction() && (React$3.createElement(Spacer, { width: 1, height: 24, backgroundColor: colors.borderPrimaryDefault, style: {
5727
5749
  marginRight: CONSTANTS.SPACE_8,
5728
5750
  } })),
5729
5751
  right && !clearButton && React$3.createElement(Spacer, { width: CONSTANTS.SPACE_2 }),
@@ -5904,18 +5926,26 @@ function formatNumberInput$1(value, formatDecimal) {
5904
5926
  return result;
5905
5927
  }
5906
5928
  var TextInputNumber = function (_a) {
5907
- var style = _a.style, _b = _a.value, value = _b === void 0 ? "" : _b, _c = _a.label, label = _c === void 0 ? "" : _c, _d = _a.textError, textError = _d === void 0 ? "" : _d, left = _a.left, right = _a.right, onChangeText = _a.onChangeText, _e = _a.disabled, disabled = _e === void 0 ? false : _e; _a.theme; var _f = _a.prefix, prefix = _f === void 0 ? "" : _f, _g = _a.suffix, suffix = _g === void 0 ? "" : _g, _h = _a.clearButton, clearButton = _h === void 0 ? false : _h, _j = _a.maxValue, maxValue = _j === void 0 ? 999999999 : _j, _k = _a.type, type = _k === void 0 ? "integer" : _k, _l = _a.formatDecimal, formatDecimal = _l === void 0 ? 3 : _l, _m = _a.required, required = _m === void 0 ? false : _m, props = __rest(_a, ["style", "value", "label", "textError", "left", "right", "onChangeText", "disabled", "theme", "prefix", "suffix", "clearButton", "maxValue", "type", "formatDecimal", "required"]);
5929
+ var style = _a.style, _b = _a.value, value = _b === void 0 ? "" : _b, _c = _a.label, label = _c === void 0 ? "" : _c, _d = _a.textError, textError = _d === void 0 ? "" : _d, left = _a.left, right = _a.right, onChangeText = _a.onChangeText, _e = _a.disabled, disabled = _e === void 0 ? false : _e; _a.theme; var _f = _a.prefix, prefix = _f === void 0 ? "" : _f, _g = _a.suffix, suffix = _g === void 0 ? "" : _g, _h = _a.clearButton, clearButton = _h === void 0 ? false : _h, _j = _a.maxValue, maxValue = _j === void 0 ? 999999999 : _j, _k = _a.minValue, minValue = _k === void 0 ? 0 : _k, _l = _a.type, type = _l === void 0 ? "integer" : _l, _m = _a.formatDecimal, formatDecimal = _m === void 0 ? 3 : _m, _o = _a.required, required = _o === void 0 ? false : _o, props = __rest(_a, ["style", "value", "label", "textError", "left", "right", "onChangeText", "disabled", "theme", "prefix", "suffix", "clearButton", "maxValue", "minValue", "type", "formatDecimal", "required"]);
5908
5930
  var theme = useInternalTheme();
5909
5931
  var colors = theme.colors;
5910
- var _o = useState(false), isShowModalKeyboard = _o[0], setIsShowModalKeyboard = _o[1];
5911
- var _p = useState((value === null || value === void 0 ? void 0 : value.toString()) || ""), inputValue = _p[0], setInputValue = _p[1];
5912
- var _q = useState((value === null || value === void 0 ? void 0 : value.toString()) || ""), numberValue = _q[0], setNumberValue = _q[1];
5932
+ var _p = useState(false), isShowModalKeyboard = _p[0], setIsShowModalKeyboard = _p[1];
5933
+ var _q = useState((value === null || value === void 0 ? void 0 : value.toString()) || ""), inputValue = _q[0], setInputValue = _q[1];
5934
+ var _r = useState((value === null || value === void 0 ? void 0 : value.toString()) || ""), numberValue = _r[0], setNumberValue = _r[1];
5935
+ var _s = useState(true), canSave = _s[0], setCanSave = _s[1];
5913
5936
  var disabledTextStyle = {
5914
5937
  color: colors.textSecondary,
5915
5938
  };
5916
5939
  useEffect(function () {
5917
5940
  setInputValue((value === null || value === void 0 ? void 0 : value.toString()) || "");
5918
5941
  }, [value]);
5942
+ useEffect(function () {
5943
+ var currentValue = Number(inputValue);
5944
+ var minValueNumber = Number(minValue);
5945
+ setCanSave(!isNaN(currentValue) &&
5946
+ !isNaN(minValueNumber) &&
5947
+ currentValue >= minValueNumber);
5948
+ }, [inputValue, minValue]);
5919
5949
  var getColorValue = useMemo(function () {
5920
5950
  if (disabled) {
5921
5951
  return colors.textPlaceholder;
@@ -5964,7 +5994,7 @@ var TextInputNumber = function (_a) {
5964
5994
  }
5965
5995
  };
5966
5996
  var handleClear = function () {
5967
- setInputValue("");
5997
+ setInputValue("0");
5968
5998
  };
5969
5999
  var handleClearInput = function () {
5970
6000
  setInputValue("");
@@ -6050,7 +6080,7 @@ var TextInputNumber = function (_a) {
6050
6080
  suffix)))),
6051
6081
  clearButton && !checkValueEmpty() && (React__default.createElement(TouchableOpacity, { activeOpacity: 0.8, onPress: handleClearInput },
6052
6082
  React__default.createElement(Icon$1, { name: "IconClearText", type: "Svg", size: 24 }))),
6053
- right && (React__default.createElement(Spacer, { width: 1, height: 30, backgroundColor: theme.colors.borderPrimaryDefault, style: {
6083
+ right && numberValue && (React__default.createElement(Spacer, { width: 1, height: 24, backgroundColor: theme.colors.borderPrimaryDefault, style: {
6054
6084
  marginLeft: SPACE_4,
6055
6085
  } })),
6056
6086
  right && (React__default.createElement(View, { center: true, paddingLeft: SPACE_8, height: "100%" }, right)),
@@ -6086,10 +6116,11 @@ var TextInputNumber = function (_a) {
6086
6116
  React__default.createElement(Spacer, { style: {
6087
6117
  height: "100%",
6088
6118
  }, width: 1, backgroundColor: colors.borderPrimaryDefault }),
6089
- React__default.createElement(TouchableOpacity, { activeOpacity: 0.8, style: styles$b.actionButton, onPress: handleSave },
6119
+ React__default.createElement(TouchableOpacity, { activeOpacity: 0.8, style: [styles$b.actionButton, !canSave && { opacity: 0.5 }], onPress: handleSave, disabled: !canSave },
6090
6120
  React__default.createElement(Text$1, { style: [
6091
6121
  styles$b.actionText,
6092
6122
  { color: colors.textBrandDefault },
6123
+ !canSave && { color: colors.textSecondary },
6093
6124
  ] }, "L\u01B0u"))))))));
6094
6125
  };
6095
6126
  var styles$b = StyleSheet.create(__assign(__assign({}, containerStyles), { disabled: { opacity: 0.6 }, container: {
@@ -6191,7 +6222,7 @@ var DefaultRenderer = function (props) { return React__default.createElement(Tex
6191
6222
  * @extends TextInput props https://reactnative.dev/docs/textinput#props
6192
6223
  */
6193
6224
  var TextInput = forwardRef(function (_a, ref) {
6194
- var _b = _a.mode, mode = _b === void 0 ? "flat" : _b, _c = _a.dense, dense = _c === void 0 ? false : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.error, errorProp = _e === void 0 ? false : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, _g = _a.editable, editable = _g === void 0 ? true : _g, contentStyle = _a.contentStyle, _h = _a.render, render = _h === void 0 ? DefaultRenderer : _h; _a.theme; var placeholderTextColor = _a.placeholderTextColor, clearButton = _a.clearButton, textError = _a.textError, prefix = _a.prefix, suffix = _a.suffix, maxValue = _a.maxValue, type = _a.type, _j = _a.required, required = _j === void 0 ? false : _j, rest = __rest(_a, ["mode", "dense", "disabled", "error", "multiline", "editable", "contentStyle", "render", "theme", "placeholderTextColor", "clearButton", "textError", "prefix", "suffix", "maxValue", "type", "required"]);
6225
+ var _b = _a.mode, mode = _b === void 0 ? "flat" : _b, _c = _a.dense, dense = _c === void 0 ? false : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.error, errorProp = _e === void 0 ? false : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, _g = _a.editable, editable = _g === void 0 ? true : _g, contentStyle = _a.contentStyle, _h = _a.render, render = _h === void 0 ? DefaultRenderer : _h; _a.theme; var placeholderTextColor = _a.placeholderTextColor, clearButton = _a.clearButton, textError = _a.textError, prefix = _a.prefix, suffix = _a.suffix, maxValue = _a.maxValue, minValue = _a.minValue, type = _a.type, _j = _a.required, required = _j === void 0 ? false : _j, rest = __rest(_a, ["mode", "dense", "disabled", "error", "multiline", "editable", "contentStyle", "render", "theme", "placeholderTextColor", "clearButton", "textError", "prefix", "suffix", "maxValue", "minValue", "type", "required"]);
6195
6226
  var theme = useInternalTheme();
6196
6227
  var isControlled = rest.value !== undefined;
6197
6228
  var validInputValue = isControlled ? rest.value : rest.defaultValue;
@@ -6393,7 +6424,7 @@ var TextInput = forwardRef(function (_a, ref) {
6393
6424
  }, onFocus: handleFocus, forceFocus: forceFocus, onBlur: handleBlur, allowFontScaling: false, onChangeText: handleChangeText, onLayoutAnimatedText: handleLayoutAnimatedText, onInputLayout: handleInputContainerLayout, onLabelTextLayout: handleLabelTextLayout, onLeftAffixLayoutChange: onLeftAffixLayoutChange, onRightAffixLayoutChange: onRightAffixLayoutChange, maxFontSizeMultiplier: maxFontSizeMultiplier, contentStyle: contentStyle, scaledLabel: scaledLabel })));
6394
6425
  }
6395
6426
  if (mode === "number") {
6396
- return (React__default.createElement(TextInputNumber$1, { textError: textError, disabled: disabled, prefix: prefix, suffix: suffix, value: value, right: rest.right, left: rest.left, required: required, label: rest.label, clearButton: clearButton, onChangeText: handleChangeText, maxValue: maxValue, formatDecimal: rest.formatDecimal, type: type }));
6427
+ return (React__default.createElement(TextInputNumber$1, { textError: textError, disabled: disabled, prefix: prefix, suffix: suffix, value: value, right: rest.right, left: rest.left, required: required, label: rest.label, clearButton: clearButton, onChangeText: handleChangeText, maxValue: maxValue, minValue: minValue, formatDecimal: rest.formatDecimal, type: type }));
6397
6428
  }
6398
6429
  return (React__default.createElement(TextInputFlat, __assign({ dense: dense, disabled: disabled, error: errorProp, textError: textError, editable: editable, prefix: prefix, suffix: suffix, clearButton: clearButton, required: required, render: render }, rest, { theme: theme, value: value, parentState: {
6399
6430
  labeled: labeled,
@@ -6416,7 +6447,7 @@ var TextInput = forwardRef(function (_a, ref) {
6416
6447
  TextInput.Affix = TextInputAffix;
6417
6448
 
6418
6449
  var Button = function (_a) {
6419
- var style = _a.style, title = _a.title; _a.border; var borderColor = _a.borderColor, isLoading = _a.isLoading, left = _a.left, right = _a.right; _a.margin; var textStyle = _a.textStyle, textProps = _a.textProps, onPress = _a.onPress, disabled = _a.disabled, backgroundColor = _a.backgroundColor, textColor = _a.textColor, _b = _a.bold, bold = _b === void 0 ? true : _b, _c = _a.size, size = _c === void 0 ? 16 : _c, _d = _a.medium, medium = _d === void 0 ? false : _d, _e = _a.mode, mode = _e === void 0 ? "contained" : _e; _a.transparent; var _g = _a.full, full = _g === void 0 ? false : _g; _a.theme; var _h = _a.buttonSize, buttonSize = _h === void 0 ? "normal" : _h, _j = _a.critical, critical = _j === void 0 ? false : _j, props = __rest(_a, ["style", "title", "border", "borderColor", "isLoading", "left", "right", "margin", "textStyle", "textProps", "onPress", "disabled", "backgroundColor", "textColor", "bold", "size", "medium", "mode", "transparent", "full", "theme", "buttonSize", "critical"]);
6450
+ var style = _a.style, title = _a.title; _a.border; var borderColor = _a.borderColor, isLoading = _a.isLoading, left = _a.left, right = _a.right; _a.margin; var textStyle = _a.textStyle, textProps = _a.textProps, onPress = _a.onPress, disabled = _a.disabled, backgroundColor = _a.backgroundColor, textColor = _a.textColor, _b = _a.bold, bold = _b === void 0 ? true : _b, _c = _a.medium, medium = _c === void 0 ? false : _c, _d = _a.mode, mode = _d === void 0 ? "contained" : _d; _a.transparent; var _f = _a.full, full = _f === void 0 ? false : _f; _a.theme; var _g = _a.buttonSize, buttonSize = _g === void 0 ? "normal" : _g, _h = _a.size, size = _h === void 0 ? buttonSize === "small" ? 14 : 16 : _h, _j = _a.critical, critical = _j === void 0 ? false : _j, props = __rest(_a, ["style", "title", "border", "borderColor", "isLoading", "left", "right", "margin", "textStyle", "textProps", "onPress", "disabled", "backgroundColor", "textColor", "bold", "medium", "mode", "transparent", "full", "theme", "buttonSize", "size", "critical"]);
6420
6451
  var theme = useInternalTheme();
6421
6452
  var colors = theme.colors;
6422
6453
  var disabledTextStyle = {
@@ -7300,32 +7331,16 @@ var NumberKeyboard = function (_a) {
7300
7331
  }
7301
7332
  }, [inputValue, maxValue, type, formatDecimal]);
7302
7333
  var handleClear = useCallback(function () {
7303
- setInputValue("");
7334
+ setInputValue("0");
7304
7335
  }, []);
7305
7336
  var handleSave = useCallback(function () {
7306
7337
  var finalValue = inputValue;
7307
7338
  if (inputValue.endsWith(".")) {
7308
7339
  finalValue = inputValue.slice(0, -1);
7309
7340
  }
7310
- // Nếu giá trị rỗng hoặc chỉ dấu chấm, trả về "0"
7311
- if (!finalValue || finalValue === ".") {
7312
- onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText("0");
7313
- onClose();
7314
- return;
7315
- }
7316
- // Ép kiểu kết quả thành số theo type
7317
- if (type === "integer") {
7318
- var intValue = parseInt(finalValue, 10);
7319
- onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(intValue.toString());
7320
- }
7321
- else {
7322
- var floatValue = parseFloat(finalValue);
7323
- // Giới hạn số chữ số thập phân theo formatDecimal
7324
- var formattedFloat = floatValue.toFixed(formatDecimal);
7325
- onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(formattedFloat);
7326
- }
7341
+ onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(finalValue);
7327
7342
  onClose();
7328
- }, [inputValue, onChangeText, onClose, type, formatDecimal]);
7343
+ }, [inputValue, onChangeText, onClose]);
7329
7344
  var handleClose = useCallback(function () {
7330
7345
  onClose();
7331
7346
  setTimeout(function () {