@northlight/ui 2.31.1 → 2.31.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.
@@ -4767,10 +4767,13 @@
4767
4767
  }),
4768
4768
  variants: {
4769
4769
  default: ({ theme: { colors: color } }) => ({
4770
- bgColor: "bg.tertiary.default",
4771
- color: color.text.inverted,
4772
- [$arrowBg.variable]: color.bg.tertiary.default,
4773
- [$arrowBorder.variable]: color.bg.tertiary.default
4770
+ color: color.text.default,
4771
+ bgColor: color.bg.base,
4772
+ borderWidth: "xs",
4773
+ borderColor: color.border.default,
4774
+ borderStyle: "solid",
4775
+ [$arrowBg.variable]: color.bg.base,
4776
+ [$arrowBorder.variable]: color.border.default
4774
4777
  }),
4775
4778
  success: ({ theme: { colors: color } }) => ({
4776
4779
  color: "text.over.success",
@@ -7772,7 +7775,7 @@
7772
7775
  hasArrow = true,
7773
7776
  title = "",
7774
7777
  description = "",
7775
- hasIcon = "true"
7778
+ hasIcon = false
7776
7779
  } = _b, rest = __objRest$18(_b, [
7777
7780
  "variant",
7778
7781
  "hasArrow",
@@ -7787,7 +7790,7 @@
7787
7790
  {
7788
7791
  variant: "14",
7789
7792
  sx: {
7790
- color: !variant || variant === "ai" || variant === "default" ? "text.inverted" : void 0
7793
+ color: !variant || variant === "ai" ? "text.inverted" : "text.default"
7791
7794
  }
7792
7795
  },
7793
7796
  description
@@ -13015,12 +13018,13 @@
13015
13018
  preset = "eu",
13016
13019
  isPercentage = false,
13017
13020
  onChange = ramda.identity,
13018
- value,
13021
+ value: valueProp,
13019
13022
  numberOfDecimals = 2,
13020
13023
  max = Infinity,
13021
13024
  min = -Infinity,
13022
13025
  inputLeftElement,
13023
- inputRightElement
13026
+ inputRightElement,
13027
+ onBlur
13024
13028
  } = _b, rest = __objRest$g(_b, [
13025
13029
  "preset",
13026
13030
  "isPercentage",
@@ -13030,27 +13034,37 @@
13030
13034
  "max",
13031
13035
  "min",
13032
13036
  "inputLeftElement",
13033
- "inputRightElement"
13037
+ "inputRightElement",
13038
+ "onBlur"
13034
13039
  ]);
13040
+ const [valueState, setValueState] = React.useState(valueProp);
13041
+ const isControlled = typeof valueProp !== "undefined";
13042
+ const value = isControlled ? valueProp : valueState;
13035
13043
  const props = presetMap[preset];
13036
- const [v, setV] = React.useState(value);
13044
+ const getNumberFormatValues = (number) => ({
13045
+ floatValue: number,
13046
+ formattedValue: reactNumberFormat.numericFormatter(number.toString(), props),
13047
+ value: number.toString()
13048
+ });
13037
13049
  const validateRange = () => {
13038
- if (ramda.isNil(v))
13050
+ if (ramda.isNil(value))
13039
13051
  return;
13040
- const vNum = typeof v === "string" ? parseFloat(v) : v;
13052
+ const vNum = typeof value === "string" ? parseFloat(value) : value;
13041
13053
  const factor = isPercentage ? 100 : 1;
13042
13054
  if (vNum * factor > max) {
13043
13055
  const newValue = roundToPrecision(max / factor, numberOfDecimals);
13044
- setV(newValue);
13056
+ setValueState(newValue);
13057
+ onChange(getNumberFormatValues(newValue));
13045
13058
  }
13046
13059
  if (vNum * factor < min) {
13047
13060
  const newValue = roundToPrecision(min / factor, numberOfDecimals);
13048
- setV(newValue);
13061
+ setValueState(newValue);
13062
+ onChange(getNumberFormatValues(newValue));
13049
13063
  }
13050
13064
  };
13051
13065
  const onValueChangeHandler = (values, sourceInfo) => {
13052
13066
  const newFloatValue = values.floatValue && isPercentage ? roundToPrecision(values.floatValue / 100, numberOfDecimals) : values.floatValue;
13053
- setV(newFloatValue);
13067
+ setValueState(newFloatValue);
13054
13068
  onChange(
13055
13069
  __spreadProps$3(__spreadValues$k({}, values), {
13056
13070
  floatValue: newFloatValue
@@ -13058,6 +13072,9 @@
13058
13072
  sourceInfo
13059
13073
  );
13060
13074
  };
13075
+ React.useEffect(() => {
13076
+ validateRange();
13077
+ }, [value]);
13061
13078
  return /* @__PURE__ */ React.createElement(
13062
13079
  InputGroupWrapper,
13063
13080
  {
@@ -13069,10 +13086,13 @@
13069
13086
  __spreadValues$k(__spreadValues$k({
13070
13087
  allowLeadingZeros: true,
13071
13088
  customInput: react.Input,
13072
- onBlur: validateRange,
13089
+ onBlur: (e) => {
13090
+ onBlur == null ? void 0 : onBlur(e);
13091
+ validateRange();
13092
+ },
13073
13093
  onValueChange: onValueChangeHandler,
13074
13094
  decimalScale: numberOfDecimals,
13075
- value: isPercentage ? roundToPrecision(parseFloat(`${v != null ? v : 0}`) * 100, numberOfDecimals) : v,
13095
+ value: isPercentage ? roundToPrecision(parseFloat(`${value != null ? value : 0}`) * 100, numberOfDecimals) : value,
13076
13096
  suffix: isPercentage ? "%" : ""
13077
13097
  }, props), rest)
13078
13098
  )
@@ -14236,12 +14256,15 @@
14236
14256
  onChange,
14237
14257
  options,
14238
14258
  size,
14239
- value,
14259
+ value: valueProp,
14240
14260
  placeholder,
14241
14261
  precision,
14242
14262
  formatPreset,
14243
14263
  isDisabled,
14244
- isReadOnly
14264
+ isReadOnly,
14265
+ defaultToZeroIfEmpty = true,
14266
+ max = Infinity,
14267
+ min = -Infinity
14245
14268
  } = _b, rest = __objRest$1(_b, [
14246
14269
  "onChange",
14247
14270
  "options",
@@ -14251,19 +14274,26 @@
14251
14274
  "precision",
14252
14275
  "formatPreset",
14253
14276
  "isDisabled",
14254
- "isReadOnly"
14277
+ "isReadOnly",
14278
+ "defaultToZeroIfEmpty",
14279
+ "max",
14280
+ "min"
14255
14281
  ]);
14256
14282
  var _a2;
14257
14283
  const { isOpen, onToggle, onClose } = react.useDisclosure();
14258
- const [inputValue, setInputValue] = React.useState(value == null ? void 0 : value.input);
14259
- const [selectOption, setSelectOption] = React.useState((_a2 = value == null ? void 0 : value.option) != null ? _a2 : options[0]);
14284
+ const [inputValueState, setInputValueState] = React.useState(valueProp == null ? void 0 : valueProp.input);
14285
+ const [selectOptionState, setselectOptionState] = React.useState((_a2 = valueProp == null ? void 0 : valueProp.option) != null ? _a2 : options[0]);
14260
14286
  const [enableSelectInput, setEnableSelectInput] = React.useState(false);
14287
+ const isInputValueControlled = typeof (valueProp == null ? void 0 : valueProp.input) !== "undefined";
14288
+ const inputValue = isInputValueControlled ? valueProp.input : inputValueState;
14289
+ const isOptionControlled = typeof (valueProp == null ? void 0 : valueProp.option) !== "undefined";
14290
+ const selectOption = isOptionControlled ? valueProp.option : selectOptionState;
14261
14291
  const buttonRef = React.useRef();
14262
14292
  const selectRef = React.useRef();
14263
- const getNewValue = (option, input) => input ? { input: Number(input), option } : { option };
14293
+ const getNewValue = (option, input) => ramda.is(Number, input) ? { input: Number(input), option } : { option };
14264
14294
  const handleInputChange = (newInputvalue) => {
14265
- const newValue = getNewValue(selectOption, newInputvalue.floatValue);
14266
- setInputValue(newValue.input);
14295
+ const newValue = getNewValue(selectOption, newInputvalue);
14296
+ setInputValueState(newValue.input);
14267
14297
  onChange == null ? void 0 : onChange(newValue);
14268
14298
  };
14269
14299
  const handleSelectClose = () => {
@@ -14275,9 +14305,11 @@
14275
14305
  };
14276
14306
  const handleSelectChange = (selectedOption) => {
14277
14307
  if (selectedOption) {
14278
- setSelectOption(selectedOption);
14308
+ setselectOptionState(selectedOption);
14279
14309
  onChange == null ? void 0 : onChange(getNewValue(selectedOption, inputValue));
14280
- handleSelectClose();
14310
+ if (isOpen) {
14311
+ handleSelectClose();
14312
+ }
14281
14313
  }
14282
14314
  };
14283
14315
  const handleSelectToggle = () => {
@@ -14291,18 +14323,25 @@
14291
14323
  selectRef.current.focus();
14292
14324
  }
14293
14325
  }, [enableSelectInput]);
14326
+ React.useEffect(() => {
14327
+ if (!ramda.is(Number, inputValue) && defaultToZeroIfEmpty) {
14328
+ handleInputChange(clamp(min, max, 0));
14329
+ }
14330
+ }, [valueProp == null ? void 0 : valueProp.input]);
14294
14331
  return /* @__PURE__ */ React.createElement(react.InputGroup, null, /* @__PURE__ */ React.createElement(
14295
14332
  FormattedNumberInput,
14296
14333
  __spreadValues$1({
14297
14334
  width: "100%",
14298
- onChange: handleInputChange,
14299
- defaultValue: inputValue,
14335
+ onChange: (values) => handleInputChange(values.floatValue),
14336
+ value: inputValue,
14300
14337
  placeholder,
14301
14338
  size,
14302
14339
  numberOfDecimals: precision,
14303
14340
  preset: formatPreset,
14304
14341
  disabled: isDisabled,
14305
- readOnly: isReadOnly
14342
+ readOnly: isReadOnly,
14343
+ min,
14344
+ max
14306
14345
  }, rest)
14307
14346
  ), /* @__PURE__ */ React.createElement(
14308
14347
  react.InputRightElement,