@northlight/ui 2.33.13 → 2.33.15

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.
@@ -3721,14 +3721,16 @@
3721
3721
  isLoading,
3722
3722
  loadingList = () => null,
3723
3723
  "data-testid": testId,
3724
- value = []
3724
+ value = [],
3725
+ onError
3725
3726
  } = _b, rest = __objRest$1Q(_b, [
3726
3727
  "options",
3727
3728
  "onChange",
3728
3729
  "isLoading",
3729
3730
  "loadingList",
3730
3731
  "data-testid",
3731
- "value"
3732
+ "value",
3733
+ "onError"
3732
3734
  ]);
3733
3735
  const [borderColor] = react.useToken("border.select", ["focus"]);
3734
3736
  const [menuIsOpen, setMenuIsOpen] = React.useState(false);
@@ -3743,44 +3745,33 @@
3743
3745
  setSelectedOptions(values);
3744
3746
  onChange(values, actionMeta);
3745
3747
  };
3746
- const isValidNewOption = (input, availableOptions) => {
3747
- const optionAlreadyExists = ramda.any(
3748
- (option) => option.value === input,
3749
- availableOptions
3750
- );
3751
- return !ramda.isEmpty(input) && !optionAlreadyExists;
3752
- };
3748
+ const isValidNewOption = (input, availableOptions) => !ramda.any(
3749
+ (option) => option.value === input,
3750
+ availableOptions
3751
+ );
3753
3752
  const addNewOption = (newOption) => {
3754
- onChange(selectedOptions, { action: "select-option", option: newOption });
3755
- setSelectedOptions(ramda.append(newOption));
3753
+ const updatedOptions = [...selectedOptions, newOption];
3754
+ onChange(updatedOptions, { action: "select-option", option: newOption });
3755
+ setSelectedOptions(updatedOptions);
3756
3756
  };
3757
- const isInputChangeValid = (newInput, event) => isValidNewOption(newInput, selectedOptions) && newInput !== "" && newInput !== "," && newInput.endsWith(",") && event.action !== "input-blur";
3758
3757
  const clearInput = () => {
3759
3758
  setInputValue("");
3760
3759
  };
3761
- const handleInputChange = (newInput, event) => {
3760
+ const handleInputChange = (newInput) => {
3762
3761
  setInputValue(newInput);
3763
- if (!isInputChangeValid(newInput, event))
3764
- return;
3765
- const newOption = {
3766
- value: ramda.init(newInput),
3767
- label: ramda.init(newInput).slice(0, -1)
3768
- };
3769
- addNewOption(newOption);
3770
- clearInput();
3771
3762
  };
3772
3763
  const handleKeyDown = (event) => {
3773
- if (!isValidNewOption(inputValue, selectedOptions) && !ramda.isEmpty(inputValue) && event.key !== " ") {
3774
- clearInput();
3775
- event.preventDefault();
3764
+ const shouldAddOption = event.key === "Enter" || event.key === "Tab" || event.key === ",";
3765
+ if (!shouldAddOption || ramda.isEmpty(inputValue))
3776
3766
  return;
3777
- }
3778
- if ((event.key === "Enter" || event.key === "Tab") && !ramda.isEmpty(inputValue)) {
3779
- const newOption = { value: inputValue, label: inputValue };
3767
+ const trimmedInputValue = inputValue.trim();
3768
+ if (isValidNewOption(trimmedInputValue, selectedOptions)) {
3769
+ const newOption = { value: trimmedInputValue, label: trimmedInputValue };
3780
3770
  addNewOption(newOption);
3781
- clearInput();
3782
- event.preventDefault();
3771
+ } else {
3772
+ onError == null ? void 0 : onError("Tag already exists");
3783
3773
  }
3774
+ clearInput();
3784
3775
  };
3785
3776
  const handleFocus = () => {
3786
3777
  setIsFocused(true);
@@ -7418,7 +7409,8 @@
7418
7409
  minValue,
7419
7410
  maxValue,
7420
7411
  firstDayOfWeek,
7421
- onSave
7412
+ onSave,
7413
+ buttonLabel = "Save"
7422
7414
  } = props;
7423
7415
  const { locale } = i18n.useLocale();
7424
7416
  const ref = React.useRef(null);
@@ -7490,7 +7482,7 @@
7490
7482
  range: value,
7491
7483
  firstDayOfWeek
7492
7484
  }
7493
- ))), /* @__PURE__ */ React.createElement(react.HStack, { pt: "2", alignSelf: "end" }, isClearable && /* @__PURE__ */ React.createElement(Button, { onClick: resetDate, variant: "ghost", size: "sm" }, "Clear"), /* @__PURE__ */ React.createElement(Button, { variant: "brand", onClick: handleSave, size: "sm" }, "Save"))))))));
7485
+ ))), /* @__PURE__ */ React.createElement(react.HStack, { pt: "2", alignSelf: "end" }, isClearable && /* @__PURE__ */ React.createElement(Button, { onClick: resetDate, variant: "ghost", size: "sm" }, "Clear"), /* @__PURE__ */ React.createElement(Button, { variant: "brand", onClick: handleSave, size: "sm" }, buttonLabel))))))));
7494
7486
  };
7495
7487
 
7496
7488
  const isValidDateRange = (value) => ramda.is(Object, value) && ramda.has("startDate", value) && ramda.has("endDate", value) && ramda.is(String, value.startDate) && ramda.is(String, value.endDate);
@@ -7544,7 +7536,8 @@
7544
7536
  maxValue,
7545
7537
  renderInPortal = false,
7546
7538
  firstDayOfWeek,
7547
- onSave
7539
+ onSave,
7540
+ buttonLabel = "Save"
7548
7541
  } = props;
7549
7542
  const ref = React.useRef();
7550
7543
  const { group } = react.useMultiStyleConfig("DatePicker");
@@ -7628,7 +7621,8 @@
7628
7621
  fiscalStartDay: fiscalStartDay || 0,
7629
7622
  isClearable,
7630
7623
  firstDayOfWeek,
7631
- onSave
7624
+ onSave,
7625
+ buttonLabel
7632
7626
  })
7633
7627
  )))))
7634
7628
  );
@@ -7817,7 +7811,8 @@
7817
7811
  firstDayOfWeek = "monday",
7818
7812
  onChange: onChangeCallback = ramda.identity,
7819
7813
  isClearable = true,
7820
- onSave
7814
+ onSave,
7815
+ buttonLabel = "Save"
7821
7816
  } = _b, rest = __objRest$19(_b, [
7822
7817
  "name",
7823
7818
  "minValue",
@@ -7829,7 +7824,8 @@
7829
7824
  "firstDayOfWeek",
7830
7825
  "onChange",
7831
7826
  "isClearable",
7832
- "onSave"
7827
+ "onSave",
7828
+ "buttonLabel"
7833
7829
  ]);
7834
7830
  const { setValue, setError, trigger } = reactHookForm.useFormContext();
7835
7831
  const handleChange = (dateRange) => {
@@ -7867,7 +7863,8 @@
7867
7863
  minValue,
7868
7864
  maxValue,
7869
7865
  validationState: errors.name ? "invalid" : "valid",
7870
- isClearable
7866
+ isClearable,
7867
+ buttonLabel
7871
7868
  }, rest)
7872
7869
  )
7873
7870
  );