@stella-source/stellasource-dsl 0.1.1 → 0.1.3

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