ab-ui-library 1.61.0 → 1.62.0

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.
@@ -56,6 +56,8 @@ var MultiTextareaWithChipsComponent = function MultiTextareaWithChipsComponent(_
56
56
  availableOptions = _ref$availableOptions === void 0 ? [] : _ref$availableOptions,
57
57
  _ref$allowCustomValue = _ref.allowCustomValues,
58
58
  allowCustomValues = _ref$allowCustomValue === void 0 ? true : _ref$allowCustomValue,
59
+ _ref$allowDuplicates = _ref.allowDuplicates,
60
+ allowDuplicates = _ref$allowDuplicates === void 0 ? false : _ref$allowDuplicates,
59
61
  searchPlaceholder = _ref.searchPlaceholder,
60
62
  chipValidationSchema = _ref.chipValidationSchema,
61
63
  chipValidationErrorMessage = _ref.chipValidationErrorMessage,
@@ -108,7 +110,7 @@ var MultiTextareaWithChipsComponent = function MultiTextareaWithChipsComponent(_
108
110
  containerRef: containerRef
109
111
  });
110
112
  var handleSelectOption = function handleSelectOption(option) {
111
- if (chipManagement.getChipTexts().includes(option)) return;
113
+ if (!allowDuplicates && chipManagement.getChipTexts().includes(option)) return;
112
114
  try {
113
115
  var valueToValidate = transformToUppercase ? option.toUpperCase() : option;
114
116
  var validatedChip = chipValidation.createValidatedChip(valueToValidate);
@@ -123,7 +125,7 @@ var MultiTextareaWithChipsComponent = function MultiTextareaWithChipsComponent(_
123
125
  }
124
126
  };
125
127
  var handleAddCustomValue = useCallback(function (value) {
126
- if (chipManagement.getChipTexts().includes(value)) return;
128
+ if (!allowDuplicates && chipManagement.getChipTexts().includes(value)) return;
127
129
  try {
128
130
  var valueToValidate = transformToUppercase ? value.toUpperCase() : value;
129
131
  var validatedChip = chipValidation.createValidatedChip(valueToValidate);
@@ -135,7 +137,7 @@ var MultiTextareaWithChipsComponent = function MultiTextareaWithChipsComponent(_
135
137
  setChipError(error instanceof Error ? error.message : 'Invalid value');
136
138
  }
137
139
  }
138
- }, [chipManagement, chipValidation, allowInvalidChips, transformToUppercase]);
140
+ }, [chipManagement, chipValidation, allowInvalidChips, transformToUppercase, allowDuplicates]);
139
141
  var onBlurLogic = useOnBlurLogic({
140
142
  inputValue: inputValue,
141
143
  disabled: disabled,
@@ -149,10 +151,9 @@ var MultiTextareaWithChipsComponent = function MultiTextareaWithChipsComponent(_
149
151
  allowInvalidChips: allowInvalidChips
150
152
  });
151
153
  var handleRemoveLastChip = function handleRemoveLastChip() {
152
- var lastChip = chipManagement.chips[chipManagement.chips.length - 1];
153
- if (lastChip) {
154
- var chipText = typeof lastChip === 'string' ? lastChip : lastChip.text;
155
- chipManagement.removeChip(chipText);
154
+ var lastChipIndex = chipManagement.chips.length - 1;
155
+ if (lastChipIndex >= 0) {
156
+ chipManagement.removeChip(lastChipIndex);
156
157
  }
157
158
  };
158
159
  var handleInputChange = function handleInputChange(e) {
@@ -225,7 +226,8 @@ var MultiTextareaWithChipsComponent = function MultiTextareaWithChipsComponent(_
225
226
  text: text,
226
227
  withAction: !disabled,
227
228
  onClick: function onClick() {
228
- chipManagement.removeChip(text);
229
+ // Pass index instead of text to remove specific chip
230
+ chipManagement.removeChip(index);
229
231
  setTimeout(function () {
230
232
  var _inputRef$current;
231
233
  (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
@@ -8,12 +8,13 @@ interface UseChipManagementProps {
8
8
  };
9
9
  setValue?: (fieldName: string, value: TFormValue) => void;
10
10
  onAddChip?: (chip: string) => void;
11
- onRemoveChip?: (chip: string) => void;
11
+ onRemoveChip?: (chip: string, index: number) => void;
12
12
  }
13
13
  export declare const useChipManagement: ({ initialChips, fieldName, formProps, setValue, onAddChip, onRemoveChip }: UseChipManagementProps) => {
14
14
  chips: ChipValue[];
15
15
  addChip: (chip: ChipValue) => void;
16
- removeChip: (chipText: string) => void;
16
+ removeChip: (index: number) => void;
17
+ removeChipByText: (chipText: string) => void;
17
18
  getChipTexts: () => string[];
18
19
  hasErrorChips: boolean;
19
20
  getErrorMessage: () => string;
@@ -41,15 +41,31 @@ var useChipManagement = function useChipManagement(_ref) {
41
41
  onAddChip === null || onAddChip === void 0 || onAddChip(chip.text);
42
42
  }
43
43
  }, [chips, updateFormValue, onAddChip]);
44
- var removeChip = useCallback(function (chipText) {
44
+ var removeChip = useCallback(function (index) {
45
45
  isUserInteraction.current = true;
46
- var newChips = chips.filter(function (chip) {
47
- var text = typeof chip === 'string' ? chip : chip.text;
48
- return text !== chipText;
46
+ var chipToRemove = chips[index];
47
+ var chipText = typeof chipToRemove === 'string' ? chipToRemove : chipToRemove.text;
48
+ var newChips = chips.filter(function (_, i) {
49
+ return i !== index;
49
50
  });
50
51
  setChips(newChips);
51
52
  updateFormValue(newChips);
52
- onRemoveChip === null || onRemoveChip === void 0 || onRemoveChip(chipText);
53
+ onRemoveChip === null || onRemoveChip === void 0 || onRemoveChip(chipText, index);
54
+ }, [chips, updateFormValue, onRemoveChip]);
55
+ var removeChipByText = useCallback(function (chipText) {
56
+ isUserInteraction.current = true;
57
+ var index = chips.findIndex(function (chip) {
58
+ var text = typeof chip === 'string' ? chip : chip.text;
59
+ return text === chipText;
60
+ });
61
+ if (index !== -1) {
62
+ var newChips = chips.filter(function (_, i) {
63
+ return i !== index;
64
+ });
65
+ setChips(newChips);
66
+ updateFormValue(newChips);
67
+ onRemoveChip === null || onRemoveChip === void 0 || onRemoveChip(chipText, index);
68
+ }
53
69
  }, [chips, updateFormValue, onRemoveChip]);
54
70
  var getChipTexts = useCallback(function () {
55
71
  return chips.map(function (chip) {
@@ -72,6 +88,7 @@ var useChipManagement = function useChipManagement(_ref) {
72
88
  chips: chips,
73
89
  addChip: addChip,
74
90
  removeChip: removeChip,
91
+ removeChipByText: removeChipByText,
75
92
  getChipTexts: getChipTexts,
76
93
  hasErrorChips: hasErrorChips,
77
94
  getErrorMessage: getErrorMessage
@@ -18,11 +18,12 @@ export interface TMultiTextareaWithChipsProps extends IFormCompProps {
18
18
  helperText?: string;
19
19
  chips?: ChipValue[];
20
20
  onAddChip?: (chip: string) => void;
21
- onRemoveChip?: (chip: string) => void;
21
+ onRemoveChip?: (chipText: string, index: number) => void;
22
22
  className?: string;
23
23
  disabled?: boolean;
24
24
  availableOptions?: string[];
25
25
  allowCustomValues?: boolean;
26
+ allowDuplicates?: boolean;
26
27
  searchPlaceholder?: string;
27
28
  chipValidationSchema?: AnySchema;
28
29
  chipValidationErrorMessage?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ab-ui-library",
3
- "version": "1.61.0",
3
+ "version": "1.62.0",
4
4
  "description": "UI library for AM",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",