@true-engineering/true-react-common-ui-kit 1.4.1 → 1.5.1

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.
@@ -1,13 +1,14 @@
1
- import React from 'react';
1
+ import { FormEvent } from 'react';
2
2
  import { IInputProps } from '../Input';
3
3
  export interface INumberInputProps extends Omit<IInputProps, 'value' | 'onChange' | 'type'> {
4
4
  value?: number;
5
- canBeFloat?: boolean;
6
5
  precision?: number;
7
6
  intPartPrecision?: number;
8
7
  defaultValue?: number;
8
+ canBeFloat?: boolean;
9
+ canBeNegative?: boolean;
9
10
  min?: number;
10
11
  max?: number;
11
- onChange: (value: number | undefined, event?: React.FormEvent<HTMLInputElement>) => void;
12
+ onChange(value: number | undefined, event?: FormEvent<HTMLInputElement>): void;
12
13
  }
13
- export declare const NumberInput: React.ForwardRefExoticComponent<INumberInputProps & React.RefAttributes<HTMLInputElement>>;
14
+ export declare const NumberInput: import("react").ForwardRefExoticComponent<INumberInputProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -1,2 +1,4 @@
1
+ import { INumberInputProps } from './NumberInput';
1
2
  export declare const getNewCaretPosition: (defaultPosition: number, oldValue: string, newValue: string, isDeleteForwardAction?: boolean) => number;
2
3
  export declare const formatNumberWithDefault: (value: number | undefined, defaultValue?: number) => string;
4
+ export declare const constructRegExp: ({ canBeFloat, canBeNegative, intPartPrecision, precision, }: Pick<INumberInputProps, 'canBeFloat' | 'canBeNegative' | 'intPartPrecision' | 'precision'>) => string;
@@ -7711,6 +7711,10 @@ function Select(_param) {
7711
7711
  handleListOpen();
7712
7712
  };
7713
7713
  var handleBlur = function(event) {
7714
+ if (isListOpen && !isOpen) {
7715
+ handleListClose(event);
7716
+ return;
7717
+ }
7714
7718
  if (!isNotEmpty(event.relatedTarget) || !isNotEmpty(list.current)) {
7715
7719
  return;
7716
7720
  }
@@ -7955,7 +7959,7 @@ function Select(_param) {
7955
7959
  event.preventDefault();
7956
7960
  },
7957
7961
  onClick: onArrowClick,
7958
- className: clsx(classes.arrow, isListOpen && classes.activeArrow),
7962
+ className: clsx(classes.arrow, isOpen && classes.activeArrow),
7959
7963
  children: /* @__PURE__ */ jsx(Icon, {
7960
7964
  type: dropdownIcon
7961
7965
  })
@@ -10245,6 +10249,13 @@ var formatNumberWithDefault = function(value, defaultValue) {
10245
10249
  var val = formatNumber(value);
10246
10250
  return isNotEmpty(val) ? val : formatNumber(defaultValue);
10247
10251
  };
10252
+ var constructRegExp = function(param) {
10253
+ var canBeFloat = param.canBeFloat, canBeNegative = param.canBeNegative, intPartPrecision = param.intPartPrecision, precision = param.precision;
10254
+ var basePart = "\\d{0,".concat(intPartPrecision, "}");
10255
+ var floatPart = "(\\.\\d{0,".concat(precision, "})?");
10256
+ var negativePart = "(\\-)?";
10257
+ return "^".concat(canBeNegative ? negativePart : "").concat(basePart).concat(canBeFloat ? floatPart : "", "$");
10258
+ };
10248
10259
  function _array_like_to_array$e(arr, len) {
10249
10260
  if (len == null || len > arr.length)
10250
10261
  len = arr.length;
@@ -10495,9 +10506,10 @@ var __generator$2 = globalThis && globalThis.__generator || function(thisArg, bo
10495
10506
  }
10496
10507
  };
10497
10508
  var NumberInput = /* @__PURE__ */ forwardRef(function(_param, ref) {
10498
- var value = _param.value, _param_canBeFloat = _param.canBeFloat, canBeFloat = _param_canBeFloat === void 0 ? false : _param_canBeFloat, defaultValue = _param.defaultValue, _param_precision = _param.precision, precision = _param_precision === void 0 ? 3 : _param_precision, _param_intPartPrecision = _param.intPartPrecision, intPartPrecision = _param_intPartPrecision === void 0 ? 7 : _param_intPartPrecision, onChange = _param.onChange, onBlur = _param.onBlur, min2 = _param.min, max2 = _param.max, props = _object_without_properties$3(_param, [
10509
+ var value = _param.value, _param_canBeFloat = _param.canBeFloat, canBeFloat = _param_canBeFloat === void 0 ? false : _param_canBeFloat, _param_canBeNegative = _param.canBeNegative, canBeNegative = _param_canBeNegative === void 0 ? false : _param_canBeNegative, defaultValue = _param.defaultValue, _param_precision = _param.precision, precision = _param_precision === void 0 ? 3 : _param_precision, _param_intPartPrecision = _param.intPartPrecision, intPartPrecision = _param_intPartPrecision === void 0 ? 7 : _param_intPartPrecision, onChange = _param.onChange, onBlur = _param.onBlur, min2 = _param.min, max2 = _param.max, props = _object_without_properties$3(_param, [
10499
10510
  "value",
10500
10511
  "canBeFloat",
10512
+ "canBeNegative",
10501
10513
  "defaultValue",
10502
10514
  "precision",
10503
10515
  "intPartPrecision",
@@ -10518,7 +10530,7 @@ var NumberInput = /* @__PURE__ */ forwardRef(function(_param, ref) {
10518
10530
  };
10519
10531
  var handleChange = function() {
10520
10532
  var _ref = _async_to_generator$2(function(inputValue, event) {
10521
- var oldValue, target, _target_selectionStart, defaultCaretPos, numString, intRegexp, floatRegexp, numberRegexp, hasDot, formattedValue, newValue;
10533
+ var oldValue, target, _target_selectionStart, defaultCaretPos, numString, numberRegexp, hasDot, formattedValue, newValue;
10522
10534
  return __generator$2(this, function(_state) {
10523
10535
  switch (_state.label) {
10524
10536
  case 0:
@@ -10533,10 +10545,13 @@ var NumberInput = /* @__PURE__ */ forwardRef(function(_param, ref) {
10533
10545
  2
10534
10546
  ];
10535
10547
  }
10536
- intRegexp = new RegExp("^\\d{0,".concat(intPartPrecision, "}$"));
10537
- floatRegexp = new RegExp("^\\d{0,".concat(intPartPrecision, "}(\\.\\d{0,").concat(precision, "})?$"));
10538
- numberRegexp = canBeFloat && precision > 0 ? floatRegexp : intRegexp;
10539
- if (!!numString.match(numberRegexp))
10548
+ numberRegexp = new RegExp(constructRegExp({
10549
+ precision,
10550
+ intPartPrecision,
10551
+ canBeNegative,
10552
+ canBeFloat
10553
+ }));
10554
+ if (!!numberRegexp.test(numString))
10540
10555
  return [
10541
10556
  3,
10542
10557
  2
@@ -10552,7 +10567,7 @@ var NumberInput = /* @__PURE__ */ forwardRef(function(_param, ref) {
10552
10567
  2
10553
10568
  ];
10554
10569
  case 2:
10555
- hasDot = canBeFloat && inputValue.match(/^[\d\s]*[.,]$/);
10570
+ hasDot = canBeFloat && /^[-]*[\d\s]*[.,]$/.test(inputValue);
10556
10571
  formattedValue = formatStringNumber(numString);
10557
10572
  newValue = hasDot ? "".concat(formattedValue, ".") : formattedValue;
10558
10573
  return [