@northlight/ui 2.33.14 → 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.
- package/dist/es/northlight.d.ts +2 -1
- package/dist/es/northlight.js +21 -30
- package/dist/es/northlight.js.map +1 -1
- package/dist/umd/northlight.cjs +20 -29
- package/dist/umd/northlight.cjs.map +1 -1
- package/dist/umd/northlight.min.cjs +2 -2
- package/dist/umd/northlight.min.cjs.map +1 -1
- package/package.json +2 -2
package/dist/es/northlight.d.ts
CHANGED
|
@@ -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;
|
package/dist/es/northlight.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
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
|
-
|
|
3793
|
-
|
|
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
|
|
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
|
-
|
|
3812
|
-
|
|
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 ((
|
|
3817
|
-
const newOption = { value:
|
|
3805
|
+
const trimmedInputValue = inputValue.trim();
|
|
3806
|
+
if (isValidNewOption(trimmedInputValue, selectedOptions)) {
|
|
3807
|
+
const newOption = { value: trimmedInputValue, label: trimmedInputValue };
|
|
3818
3808
|
addNewOption(newOption);
|
|
3819
|
-
|
|
3820
|
-
|
|
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);
|