@stella-source/stellasource-dsl 0.1.1 → 0.1.2

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/cjs/index.js CHANGED
@@ -17954,17 +17954,24 @@ const PasswordInput = ({ id, className, htmlProps, label, placeholder = "Enter P
17954
17954
  };
17955
17955
 
17956
17956
  const formatDynamicNumbersWithCommas = (num, decimalPlaces) => {
17957
- const onlyDigitNum = num.toString().replace(/[^0-9.]/g, "");
17957
+ const onlyDigitNum = num.toString().replace(/[^\d.-]/g, "");
17958
17958
  const decimalEnding = onlyDigitNum.endsWith(".");
17959
+ const decimalZero = onlyDigitNum.includes(".") && onlyDigitNum.endsWith("0");
17960
+ if (onlyDigitNum === "" || onlyDigitNum === "-" || onlyDigitNum === ".") {
17961
+ return onlyDigitNum;
17962
+ }
17963
+ if (isNaN(Number(onlyDigitNum))) {
17964
+ return "";
17965
+ }
17959
17966
  return onlyDigitNum
17960
17967
  ? `${Number(onlyDigitNum).toLocaleString("en-US", {
17961
17968
  minimumFractionDigits: 0,
17962
17969
  maximumFractionDigits: decimalPlaces,
17963
- })}${decimalEnding ? "." : ""}`
17970
+ })}${decimalEnding ? "." : ""}${decimalZero ? "0" : ""}`
17964
17971
  : "";
17965
17972
  };
17966
17973
 
17967
- const NumberInput = ({ id, className, htmlProps, leftCategory, rightCategory, label, onChange, onBlur, onFocus, value, isRequired, maxLength, tooltipText, helperText, endIcon, placeholder = "0", textAlign = "left", isTruncated = false, helperTextAffectLayout = true, hideLabel = false, disabled = false, isLoading = false, hasError = false, thousandSeparator = true, decimalPlaces = 0, ariaDescribedBy, }) => {
17974
+ const NumberInput = ({ id, className, htmlProps, leftCategory, rightCategory, label, onChange, onBlur, onFocus, value, isRequired, maxLength, tooltipText, helperText, endIcon, placeholder = "0", textAlign = "left", isTruncated = false, helperTextAffectLayout = true, hideLabel = false, disabled = false, isLoading = false, hasError = false, thousandSeparator = true, decimalPlaces = 0, allowNegativeNumbers = false, ariaDescribedBy, }) => {
17968
17975
  const containerProps = {
17969
17976
  id,
17970
17977
  label,
@@ -17988,16 +17995,21 @@ const NumberInput = ({ id, className, htmlProps, leftCategory, rightCategory, la
17988
17995
  if (e.key === "," ||
17989
17996
  (e.key === "." && decimalPlaces === 0) ||
17990
17997
  (e.key === "." && inputValue.includes(".")) ||
17991
- (inputValue.includes(".") &&
17992
- inputValue.split(".")[1]?.length >= decimalPlaces)) {
17998
+ (e.key === "-" && !allowNegativeNumbers) ||
17999
+ (e.key === "-" && inputValue.includes("-"))) {
17993
18000
  e.preventDefault();
17994
18001
  }
17995
18002
  };
17996
18003
  const handleChange = (e) => {
17997
18004
  const value = e.target.value;
17998
- if (e.currentTarget.checkValidity()) {
18005
+ const inputDecimalPlaces = value.includes(".")
18006
+ ? value.split(".")[1].length
18007
+ : 0;
18008
+ if (e.currentTarget.checkValidity() &&
18009
+ inputDecimalPlaces <= decimalPlaces) {
18010
+ console.log(value);
17999
18011
  setInputValue(value);
18000
- onChange(value.toString().replace(/[^0-9.]/g, ""));
18012
+ onChange(value.toString().replace(/[^\d.-]/g, ""));
18001
18013
  }
18002
18014
  };
18003
18015
  const handleBlur = (e) => {
@@ -18010,14 +18022,17 @@ const NumberInput = ({ id, className, htmlProps, leftCategory, rightCategory, la
18010
18022
  !onFocus && setPlaceholderText("");
18011
18023
  };
18012
18024
  return (a$i.createElement(TextFieldContainer, { ...containerProps },
18013
- a$i.createElement(TextFieldInput, { "aria-describedby": `${id}-helper-text ${ariaDescribedBy}`, type: "text", inputMode: "numeric", pattern: "^[\\d,.]*$", id: `${id}-text-field`, disabled: disabled || isLoading, placeholder: placeholderText, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, onKeyDown: handleKeyDown, value: thousandSeparator
18025
+ a$i.createElement(TextFieldInput, { "aria-describedby": `${id}-helper-text ${ariaDescribedBy}`, type: "text", inputMode: "numeric",
18026
+ // prettier-ignore
18027
+ pattern: allowNegativeNumbers ? "^[\\d,\\.\\-]*$" : "^[\\d,\\.]*$", id: `${id}-text-field`, disabled: disabled || isLoading, placeholder: placeholderText, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, onKeyDown: handleKeyDown, value: thousandSeparator
18014
18028
  ? formatDynamicNumbersWithCommas(valueToUse, decimalPlaces)
18015
18029
  : valueToUse, maxLength: maxLength &&
18016
18030
  maxLength +
18017
18031
  (thousandSeparator
18018
18032
  ? Math.floor(valueToUse.toString().split(".")[0].length / 4)
18019
18033
  : 0) +
18020
- (inputValue.includes(".") ? 1 : 0), "$isTruncated": isTruncated, "$textAlign": textAlign, "$isDisabled": disabled, "$isLoading": isLoading, ...htmlProps })));
18034
+ (inputValue.includes(".") ? 1 : 0) +
18035
+ (inputValue.includes("-") ? 1 : 0), "$isTruncated": isTruncated, "$textAlign": textAlign, "$isDisabled": disabled, "$isLoading": isLoading, ...htmlProps })));
18021
18036
  };
18022
18037
 
18023
18038
  exports.HelperText = HelperText;