@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.
@@ -299,6 +299,7 @@ interface TagsInputProps<T> extends Omit<SelectProps<T, true>, 'value' | 'format
299
299
  value?: MultiValue<T>;
300
300
  formatCreateLabel?: (textInputValue: string) => string;
301
301
  isValidNewOption?: (option: string, selectOptions: MultiValue<T>) => boolean;
302
+ onError?: (message: string) => void;
302
303
  }
303
304
 
304
305
  /**
@@ -319,7 +320,7 @@ interface TagsInputProps<T> extends Omit<SelectProps<T, true>, 'value' | 'format
319
320
  * ?)
320
321
  *
321
322
  */
322
- declare function TagsInput<T extends Option>({ options, onChange, isLoading, loadingList, 'data-testid': testId, value, ...rest }: TagsInputProps<T>): JSX.Element;
323
+ declare function TagsInput<T extends Option>({ options, onChange, isLoading, loadingList, 'data-testid': testId, value, onError, ...rest }: TagsInputProps<T>): JSX.Element;
323
324
 
324
325
  interface OrganizationLogoProps extends AvatarProps$1 {
325
326
  name: string;
@@ -915,6 +916,7 @@ interface DateRangePickerProps extends Omit<AriaDateRangePickerProps<DateValue>,
915
916
  fiscalStartMonth?: number;
916
917
  fiscalStartDay?: number;
917
918
  renderInPortal?: boolean;
919
+ buttonLabel?: string;
918
920
  }
919
921
  interface DatePickerFieldProps extends Omit<InputProps, 'onChange'>, InputFieldProps {
920
922
  name: string;
@@ -933,6 +935,7 @@ interface DatePickerFieldProps extends Omit<InputProps, 'onChange'>, InputFieldP
933
935
  }
934
936
  interface DateRangePickerFieldProps extends Omit<DatePickerFieldProps, 'onChange'> {
935
937
  onChange?: (date: null | DateRange) => void;
938
+ buttonLabel?: string;
936
939
  }
937
940
  type FormBody = Record<string, DateRange>;
938
941
 
@@ -3,7 +3,7 @@ export { AbsoluteCenter, AccordionIcon, AlertDescription, AlertDialog, AlertDial
3
3
  import React, { useState, useEffect, useRef, isValidElement, cloneElement, Children, createContext, useContext, forwardRef as forwardRef$1, useImperativeHandle, memo, useMemo, useCallback } from 'react';
4
4
  import { CreatableSelect, chakraComponents, AsyncSelect, Select as Select$3 } from 'chakra-react-select';
5
5
  export { AsyncCreatableSelect, AsyncSelect, Select as ChakraReactSelect, CreatableSelect, chakraComponents as selectChakraComponents } from 'chakra-react-select';
6
- import { isNil, last, map, prop, difference, replace, split, path, T, keys, omit, merge, isEmpty, identity, any, init, append, ifElse, gt, always, defaultTo, take, inc, dec, forEach, is, trim, values, equals, mergeAll, toLower, find, times, has, not, all, filter, test, indexOf, remove, insert, intersection, findIndex, concat, head, match, length, propEq } from 'ramda';
6
+ import { isNil, last, map, prop, difference, replace, split, path, T, keys, omit, merge, isEmpty, identity, any, ifElse, gt, always, defaultTo, take, inc, dec, forEach, is, trim, values, equals, mergeAll, toLower, find, times, has, not, all, filter, test, indexOf, remove, insert, intersection, findIndex, concat, head, match, length, propEq } from 'ramda';
7
7
  import { useFocusManager, FocusScope, useFocusRing } from '@react-aria/focus';
8
8
  import { useForm, FormProvider, useFormContext, Controller } from 'react-hook-form';
9
9
  export { useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
@@ -3759,14 +3759,16 @@ function TagsInput(_a) {
3759
3759
  isLoading,
3760
3760
  loadingList = () => null,
3761
3761
  "data-testid": testId,
3762
- value = []
3762
+ value = [],
3763
+ onError
3763
3764
  } = _b, rest = __objRest$1Q(_b, [
3764
3765
  "options",
3765
3766
  "onChange",
3766
3767
  "isLoading",
3767
3768
  "loadingList",
3768
3769
  "data-testid",
3769
- "value"
3770
+ "value",
3771
+ "onError"
3770
3772
  ]);
3771
3773
  const [borderColor] = useToken$1("border.select", ["focus"]);
3772
3774
  const [menuIsOpen, setMenuIsOpen] = useState(false);
@@ -3781,44 +3783,33 @@ function TagsInput(_a) {
3781
3783
  setSelectedOptions(values);
3782
3784
  onChange(values, actionMeta);
3783
3785
  };
3784
- const isValidNewOption = (input, availableOptions) => {
3785
- const optionAlreadyExists = any(
3786
- (option) => option.value === input,
3787
- availableOptions
3788
- );
3789
- return !isEmpty(input) && !optionAlreadyExists;
3790
- };
3786
+ const isValidNewOption = (input, availableOptions) => !any(
3787
+ (option) => option.value === input,
3788
+ availableOptions
3789
+ );
3791
3790
  const addNewOption = (newOption) => {
3792
- onChange(selectedOptions, { action: "select-option", option: newOption });
3793
- setSelectedOptions(append(newOption));
3791
+ const updatedOptions = [...selectedOptions, newOption];
3792
+ onChange(updatedOptions, { action: "select-option", option: newOption });
3793
+ setSelectedOptions(updatedOptions);
3794
3794
  };
3795
- const isInputChangeValid = (newInput, event) => isValidNewOption(newInput, selectedOptions) && newInput !== "" && newInput !== "," && newInput.endsWith(",") && event.action !== "input-blur";
3796
3795
  const clearInput = () => {
3797
3796
  setInputValue("");
3798
3797
  };
3799
- const handleInputChange = (newInput, event) => {
3798
+ const handleInputChange = (newInput) => {
3800
3799
  setInputValue(newInput);
3801
- if (!isInputChangeValid(newInput, event))
3802
- return;
3803
- const newOption = {
3804
- value: init(newInput),
3805
- label: init(newInput).slice(0, -1)
3806
- };
3807
- addNewOption(newOption);
3808
- clearInput();
3809
3800
  };
3810
3801
  const handleKeyDown = (event) => {
3811
- if (!isValidNewOption(inputValue, selectedOptions) && !isEmpty(inputValue) && event.key !== " ") {
3812
- clearInput();
3813
- event.preventDefault();
3802
+ const shouldAddOption = event.key === "Enter" || event.key === "Tab" || event.key === ",";
3803
+ if (!shouldAddOption || isEmpty(inputValue))
3814
3804
  return;
3815
- }
3816
- if ((event.key === "Enter" || event.key === "Tab") && !isEmpty(inputValue)) {
3817
- const newOption = { value: inputValue, label: inputValue };
3805
+ const trimmedInputValue = inputValue.trim();
3806
+ if (isValidNewOption(trimmedInputValue, selectedOptions)) {
3807
+ const newOption = { value: trimmedInputValue, label: trimmedInputValue };
3818
3808
  addNewOption(newOption);
3819
- clearInput();
3820
- event.preventDefault();
3809
+ } else {
3810
+ onError == null ? void 0 : onError("Tag already exists");
3821
3811
  }
3812
+ clearInput();
3822
3813
  };
3823
3814
  const handleFocus = () => {
3824
3815
  setIsFocused(true);
@@ -7456,7 +7447,8 @@ const RangeCalendar = (props) => {
7456
7447
  minValue,
7457
7448
  maxValue,
7458
7449
  firstDayOfWeek,
7459
- onSave
7450
+ onSave,
7451
+ buttonLabel = "Save"
7460
7452
  } = props;
7461
7453
  const { locale } = useLocale();
7462
7454
  const ref = useRef(null);
@@ -7528,7 +7520,7 @@ const RangeCalendar = (props) => {
7528
7520
  range: value,
7529
7521
  firstDayOfWeek
7530
7522
  }
7531
- ))), /* @__PURE__ */ React.createElement(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"))))))));
7523
+ ))), /* @__PURE__ */ React.createElement(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))))))));
7532
7524
  };
7533
7525
 
7534
7526
  const isValidDateRange = (value) => is(Object, value) && has("startDate", value) && has("endDate", value) && is(String, value.startDate) && is(String, value.endDate);
@@ -7582,7 +7574,8 @@ const DateRangePicker = (props) => {
7582
7574
  maxValue,
7583
7575
  renderInPortal = false,
7584
7576
  firstDayOfWeek,
7585
- onSave
7577
+ onSave,
7578
+ buttonLabel = "Save"
7586
7579
  } = props;
7587
7580
  const ref = useRef();
7588
7581
  const { group } = useMultiStyleConfig("DatePicker");
@@ -7666,7 +7659,8 @@ const DateRangePicker = (props) => {
7666
7659
  fiscalStartDay: fiscalStartDay || 0,
7667
7660
  isClearable,
7668
7661
  firstDayOfWeek,
7669
- onSave
7662
+ onSave,
7663
+ buttonLabel
7670
7664
  })
7671
7665
  )))))
7672
7666
  );
@@ -7855,7 +7849,8 @@ const DateRangePickerField = forwardRef$1((_a, ref) => {
7855
7849
  firstDayOfWeek = "monday",
7856
7850
  onChange: onChangeCallback = identity,
7857
7851
  isClearable = true,
7858
- onSave
7852
+ onSave,
7853
+ buttonLabel = "Save"
7859
7854
  } = _b, rest = __objRest$19(_b, [
7860
7855
  "name",
7861
7856
  "minValue",
@@ -7867,7 +7862,8 @@ const DateRangePickerField = forwardRef$1((_a, ref) => {
7867
7862
  "firstDayOfWeek",
7868
7863
  "onChange",
7869
7864
  "isClearable",
7870
- "onSave"
7865
+ "onSave",
7866
+ "buttonLabel"
7871
7867
  ]);
7872
7868
  const { setValue, setError, trigger } = useFormContext();
7873
7869
  const handleChange = (dateRange) => {
@@ -7905,7 +7901,8 @@ const DateRangePickerField = forwardRef$1((_a, ref) => {
7905
7901
  minValue,
7906
7902
  maxValue,
7907
7903
  validationState: errors.name ? "invalid" : "valid",
7908
- isClearable
7904
+ isClearable,
7905
+ buttonLabel
7909
7906
  }, rest)
7910
7907
  )
7911
7908
  );