@adam-milo/ui 1.0.19 → 1.0.21
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/index.cjs +1 -1
- package/dist/index.js +53 -53
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +38 -36
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +82 -76
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +50 -49
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +30 -30
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +348 -209
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +92 -82
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +32 -31
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +10 -7
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +26 -26
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +84 -66
- package/dist/index31.cjs +1 -0
- package/dist/index31.js +9 -0
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +71 -64
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +130 -104
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +136 -107
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +76 -61
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +68 -54
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +47 -43
- package/dist/src/lib/dev-utils.d.ts +41 -0
- package/dist/src/lib/dev-utils.d.ts.map +1 -0
- package/dist/src/lib/index.d.ts +13 -2
- package/dist/src/lib/index.d.ts.map +1 -1
- package/package.json +4 -2
package/dist/index14.js
CHANGED
|
@@ -1,186 +1,297 @@
|
|
|
1
|
-
import { jsxs
|
|
2
|
-
import { forwardRef
|
|
3
|
-
import { cn
|
|
4
|
-
import { Chip
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useRef, useState, useCallback, useEffect } from "react";
|
|
3
|
+
import { cn } from "./index17.js";
|
|
4
|
+
import { Chip } from "./index13.js";
|
|
5
5
|
/* empty css */
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
import { devWarn } from "./index31.js";
|
|
7
|
+
import { Icon } from "@adam-milo/icons";
|
|
8
|
+
const parseGapValue = (gapString, rootFontSize, containerFontSize) => {
|
|
9
|
+
if (!gapString) return 0.5 * rootFontSize;
|
|
10
|
+
const match = gapString.match(/^([\d.]+)(px|rem|em)?/);
|
|
11
|
+
if (!match) return 0.5 * rootFontSize;
|
|
12
|
+
const value = parseFloat(match[1]);
|
|
13
|
+
const unit = match[2] || "px";
|
|
14
|
+
switch (unit) {
|
|
13
15
|
case "px":
|
|
14
|
-
return
|
|
16
|
+
return value;
|
|
15
17
|
case "rem":
|
|
16
|
-
return
|
|
18
|
+
return value * rootFontSize;
|
|
17
19
|
case "em":
|
|
18
|
-
return
|
|
20
|
+
return value * containerFontSize;
|
|
19
21
|
default:
|
|
20
|
-
return 0.5 *
|
|
22
|
+
return 0.5 * rootFontSize;
|
|
21
23
|
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
};
|
|
25
|
+
const calculateFittingChips = (items, chipWidths, containerWidth, gap, overflowChipWidth) => {
|
|
26
|
+
let totalWidth = 0;
|
|
27
|
+
let count = 0;
|
|
28
|
+
for (let i = 0; i < items.length; i++) {
|
|
29
|
+
const item = items[i];
|
|
30
|
+
const chipWidth = chipWidths.get(item.value) || 0;
|
|
31
|
+
if (chipWidth === 0) {
|
|
32
|
+
count++;
|
|
28
33
|
break;
|
|
29
34
|
}
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const gapBeforeThisChip = i > 0 ? gap : 0;
|
|
36
|
+
const widthWithThisChip = totalWidth + gapBeforeThisChip + chipWidth;
|
|
37
|
+
const hasMoreItems = i < items.length - 1;
|
|
38
|
+
if (hasMoreItems) {
|
|
39
|
+
const widthWithOverflow = widthWithThisChip + gap + overflowChipWidth;
|
|
40
|
+
if (widthWithOverflow > containerWidth && count > 0) break;
|
|
41
|
+
} else {
|
|
42
|
+
if (widthWithThisChip > containerWidth && count > 0) break;
|
|
43
|
+
}
|
|
44
|
+
totalWidth = widthWithThisChip;
|
|
45
|
+
count++;
|
|
35
46
|
}
|
|
36
|
-
return Math.max(1,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
return Math.max(1, count);
|
|
48
|
+
};
|
|
49
|
+
const useDebounce = (callback, delay) => {
|
|
50
|
+
const timeoutRef = useRef();
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
return () => {
|
|
53
|
+
if (timeoutRef.current) {
|
|
54
|
+
clearTimeout(timeoutRef.current);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}, []);
|
|
58
|
+
const debouncedFn = useCallback(
|
|
59
|
+
(...args) => {
|
|
60
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
61
|
+
timeoutRef.current = setTimeout(() => callback(...args), delay);
|
|
44
62
|
},
|
|
45
|
-
[
|
|
63
|
+
[callback, delay]
|
|
46
64
|
);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
65
|
+
return debouncedFn;
|
|
66
|
+
};
|
|
67
|
+
const useChipOverflow = (items, containerRef, chipRefs, chipWidths, maxVisible) => {
|
|
68
|
+
const [visibleCount, setVisibleCount] = useState(items.length);
|
|
69
|
+
const calculateVisibleChips = useCallback(() => {
|
|
70
|
+
if (maxVisible !== void 0) {
|
|
71
|
+
setVisibleCount(Math.min(maxVisible, items.length));
|
|
51
72
|
return;
|
|
52
73
|
}
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
const container = containerRef.current;
|
|
75
|
+
if (!container) return;
|
|
76
|
+
const containerWidth = container.clientWidth;
|
|
77
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
78
|
+
const computedStyle = window.getComputedStyle(container);
|
|
79
|
+
const gapString = computedStyle.gap;
|
|
80
|
+
const containerFontSize = parseFloat(computedStyle.fontSize) || 16;
|
|
81
|
+
const gap = parseGapValue(gapString, rootFontSize, containerFontSize);
|
|
82
|
+
const OVERFLOW_CHIP_WIDTH_REM = 3.75;
|
|
83
|
+
const overflowChipWidth = OVERFLOW_CHIP_WIDTH_REM * rootFontSize;
|
|
84
|
+
for (let i = 0; i < items.length; i++) {
|
|
85
|
+
const item = items[i];
|
|
86
|
+
const chip = chipRefs.current[i];
|
|
87
|
+
if (chip) {
|
|
88
|
+
chipWidths.current.set(item.value, chip.offsetWidth);
|
|
89
|
+
}
|
|
59
90
|
}
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
91
|
+
const count = calculateFittingChips(
|
|
92
|
+
items,
|
|
93
|
+
chipWidths.current,
|
|
94
|
+
containerWidth,
|
|
95
|
+
gap,
|
|
96
|
+
overflowChipWidth
|
|
66
97
|
);
|
|
67
|
-
|
|
68
|
-
}, [
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
D();
|
|
98
|
+
setVisibleCount(count);
|
|
99
|
+
}, [items, maxVisible, containerRef, chipRefs, chipWidths]);
|
|
100
|
+
const debouncedCalculate = useDebounce(calculateVisibleChips, 100);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (chipRefs.current.length > items.length) {
|
|
103
|
+
chipRefs.current = chipRefs.current.slice(0, items.length);
|
|
104
|
+
}
|
|
105
|
+
const currentValues = new Set(items.map((item) => item.value));
|
|
106
|
+
chipWidths.current.forEach((_, value) => {
|
|
107
|
+
if (!currentValues.has(value)) {
|
|
108
|
+
chipWidths.current.delete(value);
|
|
109
|
+
}
|
|
80
110
|
});
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
if (maxVisible === void 0) {
|
|
112
|
+
const hasUnmeasuredItems = items.some((item) => !chipWidths.current.has(item.value));
|
|
113
|
+
if (hasUnmeasuredItems) {
|
|
114
|
+
setVisibleCount(items.length);
|
|
115
|
+
} else {
|
|
116
|
+
setTimeout(calculateVisibleChips, 0);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}, [items, maxVisible, calculateVisibleChips, chipRefs, chipWidths]);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const container = containerRef.current;
|
|
122
|
+
if (!container) return;
|
|
123
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
124
|
+
debouncedCalculate();
|
|
125
|
+
});
|
|
126
|
+
resizeObserver.observe(container);
|
|
127
|
+
setTimeout(calculateVisibleChips, 0);
|
|
128
|
+
return () => {
|
|
129
|
+
resizeObserver.disconnect();
|
|
83
130
|
};
|
|
84
|
-
}, [
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
131
|
+
}, [calculateVisibleChips, debouncedCalculate, containerRef]);
|
|
132
|
+
const visibleItems = items.slice(0, visibleCount);
|
|
133
|
+
const hiddenItems = items.slice(visibleCount);
|
|
134
|
+
const hasOverflow = hiddenItems.length > 0;
|
|
135
|
+
return { visibleCount, visibleItems, hiddenItems, hasOverflow };
|
|
136
|
+
};
|
|
137
|
+
const ChipGroup = forwardRef(
|
|
88
138
|
({
|
|
89
|
-
items
|
|
90
|
-
selectedValue
|
|
91
|
-
onSelectionChange
|
|
92
|
-
removable
|
|
93
|
-
onRemove
|
|
94
|
-
variant
|
|
95
|
-
disabled
|
|
96
|
-
maxVisible
|
|
97
|
-
className
|
|
98
|
-
"data-testid":
|
|
99
|
-
"data-cy":
|
|
100
|
-
...
|
|
101
|
-
},
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
139
|
+
items,
|
|
140
|
+
selectedValue,
|
|
141
|
+
onSelectionChange,
|
|
142
|
+
removable = false,
|
|
143
|
+
onRemove,
|
|
144
|
+
variant = "primary",
|
|
145
|
+
disabled = false,
|
|
146
|
+
maxVisible,
|
|
147
|
+
className,
|
|
148
|
+
"data-testid": dataTestId,
|
|
149
|
+
"data-cy": dataCy,
|
|
150
|
+
...props
|
|
151
|
+
}, ref) => {
|
|
152
|
+
const normalizedItems = items && Array.isArray(items) ? items : [];
|
|
153
|
+
const validItems = normalizedItems.filter((item) => {
|
|
154
|
+
return item !== null && item !== void 0 && typeof item === "object";
|
|
155
|
+
});
|
|
156
|
+
const containerRef = useRef(null);
|
|
157
|
+
const chipRefs = useRef([]);
|
|
158
|
+
const chipWidths = useRef(/* @__PURE__ */ new Map());
|
|
159
|
+
const dropdownRef = useRef(null);
|
|
160
|
+
const [showTooltip, setShowTooltip] = useState(false);
|
|
161
|
+
const [showDropdown, setShowDropdown] = useState(false);
|
|
162
|
+
const dropdownItemRefs = useRef([]);
|
|
163
|
+
const { visibleItems, hiddenItems, hasOverflow } = useChipOverflow(
|
|
164
|
+
validItems,
|
|
165
|
+
containerRef,
|
|
166
|
+
chipRefs,
|
|
167
|
+
chipWidths,
|
|
168
|
+
maxVisible
|
|
169
|
+
);
|
|
170
|
+
const handleChipClick = useCallback(
|
|
171
|
+
(value, itemDisabled, event) => {
|
|
172
|
+
if (disabled || itemDisabled) return;
|
|
173
|
+
if (onSelectionChange) {
|
|
174
|
+
const newValue = selectedValue === value ? null : value;
|
|
175
|
+
onSelectionChange(newValue, event);
|
|
176
|
+
}
|
|
111
177
|
},
|
|
112
|
-
[
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
|
|
178
|
+
[disabled, selectedValue, onSelectionChange]
|
|
179
|
+
);
|
|
180
|
+
const handleRemove = useCallback(
|
|
181
|
+
(e, value) => {
|
|
182
|
+
e.stopPropagation();
|
|
183
|
+
if (disabled) return;
|
|
184
|
+
if (onRemove) {
|
|
185
|
+
onRemove(value, e);
|
|
186
|
+
}
|
|
116
187
|
},
|
|
117
|
-
[
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
|
|
188
|
+
[disabled, onRemove]
|
|
189
|
+
);
|
|
190
|
+
const handleKeyDown = useCallback(
|
|
191
|
+
(e, value, itemDisabled) => {
|
|
192
|
+
if (disabled || itemDisabled) return;
|
|
193
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
handleChipClick(value, itemDisabled, e);
|
|
196
|
+
}
|
|
121
197
|
},
|
|
122
|
-
[
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
(
|
|
127
|
-
|
|
198
|
+
[disabled, handleChipClick]
|
|
199
|
+
);
|
|
200
|
+
const handleOverflowClick = useCallback((e) => {
|
|
201
|
+
e.stopPropagation();
|
|
202
|
+
setShowDropdown((prev) => !prev);
|
|
203
|
+
setShowTooltip(false);
|
|
204
|
+
}, []);
|
|
205
|
+
const handleDropdownKeyDown = useCallback(
|
|
206
|
+
(e, index) => {
|
|
207
|
+
var _a, _b, _c, _d;
|
|
128
208
|
switch (e.key) {
|
|
129
209
|
case "ArrowDown":
|
|
130
|
-
e.preventDefault()
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
if (index < hiddenItems.length - 1) {
|
|
212
|
+
(_a = dropdownItemRefs.current[index + 1]) == null ? void 0 : _a.focus();
|
|
213
|
+
}
|
|
131
214
|
break;
|
|
132
215
|
case "ArrowUp":
|
|
133
|
-
e.preventDefault()
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
if (index > 0) {
|
|
218
|
+
(_b = dropdownItemRefs.current[index - 1]) == null ? void 0 : _b.focus();
|
|
219
|
+
}
|
|
134
220
|
break;
|
|
135
221
|
case "Home":
|
|
136
|
-
e.preventDefault()
|
|
222
|
+
e.preventDefault();
|
|
223
|
+
(_c = dropdownItemRefs.current[0]) == null ? void 0 : _c.focus();
|
|
137
224
|
break;
|
|
138
225
|
case "End":
|
|
139
|
-
e.preventDefault()
|
|
226
|
+
e.preventDefault();
|
|
227
|
+
(_d = dropdownItemRefs.current[hiddenItems.length - 1]) == null ? void 0 : _d.focus();
|
|
140
228
|
break;
|
|
141
229
|
}
|
|
142
230
|
},
|
|
143
|
-
[
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
231
|
+
[hiddenItems.length]
|
|
232
|
+
);
|
|
233
|
+
const handleClickOutsideRef = useRef();
|
|
234
|
+
const handleEscapeRef = useRef();
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
handleClickOutsideRef.current = (event) => {
|
|
237
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
238
|
+
setShowDropdown(false);
|
|
239
|
+
}
|
|
150
240
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
241
|
+
handleEscapeRef.current = (event) => {
|
|
242
|
+
if (event.key === "Escape") {
|
|
243
|
+
setShowDropdown(false);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
useEffect(() => {
|
|
248
|
+
if (!showDropdown) return;
|
|
249
|
+
const handleClickOutside = (e) => {
|
|
250
|
+
var _a;
|
|
251
|
+
return (_a = handleClickOutsideRef.current) == null ? void 0 : _a.call(handleClickOutsideRef, e);
|
|
252
|
+
};
|
|
253
|
+
const handleEscape = (e) => {
|
|
254
|
+
var _a;
|
|
255
|
+
return (_a = handleEscapeRef.current) == null ? void 0 : _a.call(handleEscapeRef, e);
|
|
159
256
|
};
|
|
160
|
-
|
|
161
|
-
|
|
257
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
258
|
+
document.addEventListener("keydown", handleEscape);
|
|
259
|
+
return () => {
|
|
260
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
261
|
+
document.removeEventListener("keydown", handleEscape);
|
|
162
262
|
};
|
|
163
|
-
}, [
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
)
|
|
263
|
+
}, [showDropdown]);
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
if (process.env.NODE_ENV === "development" && validItems.length > 0) {
|
|
266
|
+
const values = validItems.map((item) => item.value);
|
|
267
|
+
const uniqueValues = new Set(values);
|
|
268
|
+
if (values.length !== uniqueValues.size) {
|
|
269
|
+
devWarn(
|
|
270
|
+
"[ChipGroup] Duplicate values detected in items array. Each item should have a unique value."
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}, [validItems]);
|
|
275
|
+
useEffect(() => {
|
|
276
|
+
if (dropdownItemRefs.current.length > hiddenItems.length) {
|
|
277
|
+
dropdownItemRefs.current = dropdownItemRefs.current.slice(0, hiddenItems.length);
|
|
169
278
|
}
|
|
170
|
-
}, [
|
|
171
|
-
|
|
172
|
-
|
|
279
|
+
}, [hiddenItems]);
|
|
280
|
+
if (!items || !Array.isArray(items)) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
return /* @__PURE__ */ jsxs(
|
|
173
284
|
"div",
|
|
174
285
|
{
|
|
175
|
-
ref
|
|
176
|
-
className:
|
|
286
|
+
ref,
|
|
287
|
+
className: cn("chip-group", disabled && "chip-group--disabled", className),
|
|
177
288
|
role: "group",
|
|
178
289
|
"aria-label": "Chip group",
|
|
179
|
-
"data-testid":
|
|
180
|
-
"data-cy":
|
|
181
|
-
...
|
|
290
|
+
"data-testid": dataTestId || "chip-group",
|
|
291
|
+
"data-cy": dataCy || "chip-group",
|
|
292
|
+
...props,
|
|
182
293
|
children: [
|
|
183
|
-
|
|
294
|
+
hasOverflow && /* @__PURE__ */ jsxs(
|
|
184
295
|
"div",
|
|
185
296
|
{
|
|
186
297
|
className: "sr-only",
|
|
@@ -190,141 +301,169 @@ const Q = (t, c, n) => {
|
|
|
190
301
|
"data-testid": "chip-group-live-region",
|
|
191
302
|
"data-cy": "chip-group-live-region",
|
|
192
303
|
children: [
|
|
193
|
-
|
|
304
|
+
hiddenItems.length,
|
|
194
305
|
" additional ",
|
|
195
|
-
|
|
306
|
+
hiddenItems.length === 1 ? "chip" : "chips",
|
|
196
307
|
" hidden"
|
|
197
308
|
]
|
|
198
309
|
}
|
|
199
310
|
),
|
|
200
|
-
/* @__PURE__ */
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
|
|
311
|
+
/* @__PURE__ */ jsxs("div", { ref: containerRef, className: "chip-group__container", children: [
|
|
312
|
+
visibleItems.map((item) => {
|
|
313
|
+
const isSelected = selectedValue === item.value;
|
|
314
|
+
const itemVariant = item.variant || variant;
|
|
315
|
+
const itemDisabled = disabled || item.disabled || false;
|
|
316
|
+
const itemIndexInFullArray = validItems.findIndex((i) => i.value === item.value);
|
|
317
|
+
return /* @__PURE__ */ jsx(
|
|
204
318
|
"div",
|
|
205
319
|
{
|
|
206
|
-
ref: (
|
|
207
|
-
|
|
320
|
+
ref: (el) => {
|
|
321
|
+
if (el) {
|
|
322
|
+
chipRefs.current[itemIndexInFullArray] = el;
|
|
323
|
+
} else {
|
|
324
|
+
chipRefs.current[itemIndexInFullArray] = null;
|
|
325
|
+
}
|
|
208
326
|
},
|
|
209
327
|
className: "chip-group__item-wrapper",
|
|
210
|
-
"data-cy": `chip-group-item-wrapper-${
|
|
211
|
-
"data-testid": `chip-group-item-wrapper-${
|
|
212
|
-
children: /* @__PURE__ */
|
|
328
|
+
"data-cy": `chip-group-item-wrapper-${item.value}`,
|
|
329
|
+
"data-testid": `chip-group-item-wrapper-${item.value}`,
|
|
330
|
+
children: /* @__PURE__ */ jsxs(
|
|
213
331
|
"div",
|
|
214
332
|
{
|
|
215
333
|
className: "chip-group__item",
|
|
216
|
-
onClick: (
|
|
217
|
-
onKeyDown: (
|
|
218
|
-
tabIndex:
|
|
334
|
+
onClick: (e) => handleChipClick(item.value, itemDisabled, e),
|
|
335
|
+
onKeyDown: (e) => handleKeyDown(e, item.value, itemDisabled),
|
|
336
|
+
tabIndex: itemDisabled ? -1 : 0,
|
|
219
337
|
role: "button",
|
|
220
|
-
"aria-pressed":
|
|
221
|
-
"aria-disabled":
|
|
222
|
-
"data-cy": `chip-group-item-${
|
|
223
|
-
"data-testid": `chip-group-item-${
|
|
338
|
+
"aria-pressed": isSelected ? "true" : "false",
|
|
339
|
+
"aria-disabled": itemDisabled ? "true" : "false",
|
|
340
|
+
"data-cy": `chip-group-item-${item.value}`,
|
|
341
|
+
"data-testid": `chip-group-item-${item.value}`,
|
|
224
342
|
children: [
|
|
225
|
-
/* @__PURE__ */
|
|
226
|
-
|
|
343
|
+
/* @__PURE__ */ jsx(
|
|
344
|
+
Chip,
|
|
227
345
|
{
|
|
228
|
-
variant:
|
|
229
|
-
selected:
|
|
230
|
-
disabled:
|
|
231
|
-
"data-cy": `chip-${
|
|
232
|
-
"data-testid": `chip-${
|
|
233
|
-
children:
|
|
346
|
+
variant: itemVariant,
|
|
347
|
+
selected: isSelected,
|
|
348
|
+
disabled: itemDisabled,
|
|
349
|
+
"data-cy": `chip-${item.value}`,
|
|
350
|
+
"data-testid": `chip-${item.value}`,
|
|
351
|
+
children: item.label
|
|
234
352
|
}
|
|
235
353
|
),
|
|
236
|
-
|
|
354
|
+
removable && !disabled && !itemDisabled && /* @__PURE__ */ jsx(
|
|
237
355
|
"button",
|
|
238
356
|
{
|
|
239
357
|
className: "chip-group__remove",
|
|
240
|
-
onClick: (
|
|
241
|
-
"aria-label": `Remove ${
|
|
242
|
-
"data-cy": `chip-remove-${
|
|
243
|
-
"data-testid": `chip-remove-${
|
|
358
|
+
onClick: (e) => handleRemove(e, item.value),
|
|
359
|
+
"aria-label": `Remove ${item.label}`,
|
|
360
|
+
"data-cy": `chip-remove-${item.value}`,
|
|
361
|
+
"data-testid": `chip-remove-${item.value}`,
|
|
244
362
|
type: "button",
|
|
245
|
-
children: /* @__PURE__ */
|
|
363
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "Cross2Icon", size: "sm", decorative: true })
|
|
246
364
|
}
|
|
247
365
|
)
|
|
248
366
|
]
|
|
249
367
|
}
|
|
250
368
|
)
|
|
251
369
|
},
|
|
252
|
-
|
|
370
|
+
item.value
|
|
253
371
|
);
|
|
254
372
|
}),
|
|
255
|
-
|
|
373
|
+
hasOverflow && /* @__PURE__ */ jsxs(
|
|
256
374
|
"div",
|
|
257
375
|
{
|
|
258
|
-
ref:
|
|
376
|
+
ref: dropdownRef,
|
|
259
377
|
className: "chip-group__overflow",
|
|
260
378
|
role: "button",
|
|
261
379
|
tabIndex: 0,
|
|
262
|
-
"aria-expanded":
|
|
380
|
+
"aria-expanded": showDropdown ? "true" : "false",
|
|
263
381
|
"aria-haspopup": "menu",
|
|
264
|
-
"aria-label": `Show ${
|
|
265
|
-
onMouseEnter: () => !
|
|
266
|
-
onMouseLeave: () =>
|
|
267
|
-
onClick:
|
|
382
|
+
"aria-label": `Show ${hiddenItems.length} more ${hiddenItems.length === 1 ? "chip" : "chips"}`,
|
|
383
|
+
onMouseEnter: () => !showDropdown && setShowTooltip(true),
|
|
384
|
+
onMouseLeave: () => setShowTooltip(false),
|
|
385
|
+
onClick: handleOverflowClick,
|
|
268
386
|
onKeyDown: (e) => {
|
|
269
|
-
(e.key === "Enter" || e.key === " ")
|
|
387
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
388
|
+
e.preventDefault();
|
|
389
|
+
e.stopPropagation();
|
|
390
|
+
setShowDropdown(!showDropdown);
|
|
391
|
+
setShowTooltip(false);
|
|
392
|
+
}
|
|
270
393
|
},
|
|
271
394
|
"data-cy": "chip-group-overflow",
|
|
272
395
|
"data-testid": "chip-group-overflow",
|
|
273
396
|
children: [
|
|
274
|
-
/* @__PURE__ */
|
|
397
|
+
/* @__PURE__ */ jsxs(Chip, { variant, "data-cy": "chip-overflow", "data-testid": "chip-overflow", children: [
|
|
275
398
|
"+",
|
|
276
|
-
|
|
399
|
+
hiddenItems.length
|
|
277
400
|
] }),
|
|
278
|
-
|
|
401
|
+
showTooltip && !showDropdown && /* @__PURE__ */ jsx(
|
|
279
402
|
"div",
|
|
280
403
|
{
|
|
281
404
|
className: "chip-group__tooltip chip-group__tooltip--hover",
|
|
282
405
|
role: "tooltip",
|
|
283
406
|
"data-cy": "chip-group-tooltip",
|
|
284
407
|
"data-testid": "chip-group-tooltip",
|
|
285
|
-
children:
|
|
408
|
+
children: hiddenItems.map((item) => /* @__PURE__ */ jsx(
|
|
286
409
|
"div",
|
|
287
410
|
{
|
|
288
411
|
className: "chip-group__tooltip-item",
|
|
289
|
-
"data-cy": `chip-group-tooltip-item-${
|
|
290
|
-
"data-testid": `chip-group-tooltip-item-${
|
|
291
|
-
children:
|
|
412
|
+
"data-cy": `chip-group-tooltip-item-${item.value}`,
|
|
413
|
+
"data-testid": `chip-group-tooltip-item-${item.value}`,
|
|
414
|
+
children: item.label
|
|
292
415
|
},
|
|
293
|
-
|
|
416
|
+
item.value
|
|
294
417
|
))
|
|
295
418
|
}
|
|
296
419
|
),
|
|
297
|
-
|
|
420
|
+
showDropdown && /* @__PURE__ */ jsx(
|
|
298
421
|
"div",
|
|
299
422
|
{
|
|
300
423
|
className: "chip-group__dropdown",
|
|
301
424
|
role: "menu",
|
|
302
425
|
"data-cy": "chip-group-dropdown",
|
|
303
426
|
"data-testid": "chip-group-dropdown",
|
|
304
|
-
children:
|
|
427
|
+
children: hiddenItems.map((item, index) => /* @__PURE__ */ jsx(
|
|
305
428
|
"div",
|
|
306
429
|
{
|
|
307
|
-
ref: (
|
|
308
|
-
|
|
430
|
+
ref: (el) => {
|
|
431
|
+
if (el) {
|
|
432
|
+
dropdownItemRefs.current[index] = el;
|
|
433
|
+
} else {
|
|
434
|
+
dropdownItemRefs.current[index] = null;
|
|
435
|
+
}
|
|
309
436
|
},
|
|
310
|
-
className:
|
|
437
|
+
className: cn(
|
|
311
438
|
"chip-group__dropdown-item",
|
|
312
|
-
|
|
439
|
+
item.disabled && "chip-group__dropdown-item--disabled"
|
|
313
440
|
),
|
|
314
441
|
role: "menuitem",
|
|
315
|
-
tabIndex:
|
|
316
|
-
"aria-disabled":
|
|
317
|
-
onClick: (
|
|
318
|
-
|
|
442
|
+
tabIndex: item.disabled ? -1 : 0,
|
|
443
|
+
"aria-disabled": item.disabled ? "true" : "false",
|
|
444
|
+
onClick: (e) => {
|
|
445
|
+
e.stopPropagation();
|
|
446
|
+
if (!item.disabled) {
|
|
447
|
+
handleChipClick(item.value, false, e);
|
|
448
|
+
setShowDropdown(false);
|
|
449
|
+
}
|
|
319
450
|
},
|
|
320
|
-
onKeyDown: (
|
|
321
|
-
|
|
451
|
+
onKeyDown: (e) => {
|
|
452
|
+
handleDropdownKeyDown(e, index);
|
|
453
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
454
|
+
e.preventDefault();
|
|
455
|
+
e.stopPropagation();
|
|
456
|
+
if (!item.disabled) {
|
|
457
|
+
handleChipClick(item.value, false, e);
|
|
458
|
+
setShowDropdown(false);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
322
461
|
},
|
|
323
|
-
"data-cy": `chip-group-dropdown-item-${
|
|
324
|
-
"data-testid": `chip-group-dropdown-item-${
|
|
325
|
-
children:
|
|
462
|
+
"data-cy": `chip-group-dropdown-item-${item.value}`,
|
|
463
|
+
"data-testid": `chip-group-dropdown-item-${item.value}`,
|
|
464
|
+
children: item.label
|
|
326
465
|
},
|
|
327
|
-
|
|
466
|
+
item.value
|
|
328
467
|
))
|
|
329
468
|
}
|
|
330
469
|
)
|
|
@@ -337,7 +476,7 @@ const Q = (t, c, n) => {
|
|
|
337
476
|
);
|
|
338
477
|
}
|
|
339
478
|
);
|
|
340
|
-
|
|
479
|
+
ChipGroup.displayName = "ChipGroup";
|
|
341
480
|
export {
|
|
342
|
-
|
|
481
|
+
ChipGroup
|
|
343
482
|
};
|