@adam-milo/ui 1.0.33 → 1.0.34
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 +57 -23
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +94 -56
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +199 -40
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +305 -105
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +260 -74
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +135 -27
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +52 -469
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +57 -111
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +101 -20
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +76 -21
- package/dist/index19.cjs +1 -1
- package/dist/index19.js +25 -29
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +6 -4
- package/dist/index20.cjs +1 -1
- package/dist/index20.js +468 -31
- package/dist/index21.cjs +1 -1
- package/dist/index21.js +155 -39
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +16 -27
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +36 -12
- package/dist/index24.cjs +1 -0
- package/dist/index24.js +46 -0
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +80 -263
- package/dist/index26.cjs +1 -1
- package/dist/index26.js +52 -13
- package/dist/index27.cjs +1 -0
- package/dist/index27.js +45 -0
- package/dist/index28.cjs +1 -0
- package/dist/index28.js +53 -0
- package/dist/index29.cjs +1 -0
- package/dist/index29.js +55 -0
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +33 -33
- package/dist/index30.cjs +1 -0
- package/dist/index30.js +72 -0
- package/dist/index31.cjs +1 -0
- package/dist/index31.js +14 -0
- package/dist/index32.cjs +1 -0
- package/dist/index32.js +332 -0
- package/dist/index36.cjs +1 -1
- package/dist/index36.js +383 -6
- package/dist/index37.cjs +1 -0
- package/dist/index37.js +16 -0
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +59 -11
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +19 -35
- package/dist/index50.cjs +1 -0
- package/dist/index50.js +9 -0
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +11 -101
- package/dist/index62.cjs +1 -0
- package/dist/index62.js +502 -0
- package/dist/index64.cjs +1 -0
- package/dist/index64.js +11 -0
- package/dist/index65.cjs +1 -0
- package/dist/index65.js +39 -0
- package/dist/index66.cjs +1 -0
- package/dist/index66.js +64 -0
- package/dist/index67.cjs +1 -0
- package/dist/index67.js +212 -0
- package/dist/index68.cjs +1 -0
- package/dist/index68.js +14 -0
- package/dist/index69.cjs +1 -0
- package/dist/index69.js +293 -0
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +46 -97
- package/dist/index70.cjs +1 -0
- package/dist/index70.js +18 -0
- package/dist/index71.cjs +1 -0
- package/dist/index71.js +129 -0
- package/dist/index72.cjs +1 -0
- package/dist/index72.js +43 -0
- package/dist/index73.cjs +1 -0
- package/dist/index73.js +99 -0
- package/dist/index74.cjs +1 -0
- package/dist/index74.js +71 -0
- package/dist/index75.cjs +1 -0
- package/dist/index75.js +36 -0
- package/dist/index76.cjs +1 -0
- package/dist/index76.js +14 -0
- package/dist/index77.cjs +1 -0
- package/dist/index77.js +17 -0
- package/dist/index78.cjs +1 -0
- package/dist/index78.js +6 -0
- package/dist/index79.cjs +1 -0
- package/dist/index79.js +297 -0
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +97 -88
- package/dist/index80.cjs +1 -0
- package/dist/index80.js +25 -0
- package/dist/index81.cjs +1 -0
- package/dist/index81.js +39 -0
- package/dist/index82.cjs +1 -0
- package/dist/index82.js +625 -0
- package/dist/index83.cjs +1 -0
- package/dist/index83.js +721 -0
- package/dist/index84.cjs +1 -0
- package/dist/index84.js +154 -0
- package/dist/index85.cjs +1 -0
- package/dist/index85.js +173 -0
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +55 -197
- package/dist/src/components/core/button/Button.component.d.ts +13 -7
- package/dist/src/components/core/button/Button.component.d.ts.map +1 -1
- package/dist/src/components/core/icon/Icon.component.d.ts +1 -1
- package/dist/src/components/core/icon/Icon.component.d.ts.map +1 -1
- package/dist/src/components/core/icon-button/IconButton.component.d.ts +36 -0
- package/dist/src/components/core/icon-button/IconButton.component.d.ts.map +1 -0
- package/dist/src/components/core/menu-icon-button/MenuIconButton.component.d.ts +79 -0
- package/dist/src/components/core/menu-icon-button/MenuIconButton.component.d.ts.map +1 -0
- package/dist/src/components/feedback/spinner/Spinner.component.d.ts +62 -0
- package/dist/src/components/feedback/spinner/Spinner.component.d.ts.map +1 -0
- package/dist/src/components/forms/input/Input.component.d.ts +5 -0
- package/dist/src/components/forms/input/Input.component.d.ts.map +1 -1
- package/dist/src/components/forms/otp-input/OTPInput.component.d.ts +82 -0
- package/dist/src/components/forms/otp-input/OTPInput.component.d.ts.map +1 -0
- package/dist/src/components/forms/phone-input/PhoneInput.component.d.ts +96 -0
- package/dist/src/components/forms/phone-input/PhoneInput.component.d.ts.map +1 -0
- package/dist/src/components/forms/phone-input/countries.d.ts +93 -0
- package/dist/src/components/forms/phone-input/countries.d.ts.map +1 -0
- package/dist/src/components/forms/select/Select.component.d.ts +5 -1
- package/dist/src/components/forms/select/Select.component.d.ts.map +1 -1
- package/dist/src/components/forms/toggle/Toggle.component.d.ts +80 -0
- package/dist/src/components/forms/toggle/Toggle.component.d.ts.map +1 -0
- package/dist/src/components/layout/auth-layout/AuthLayout.component.d.ts +86 -0
- package/dist/src/components/layout/auth-layout/AuthLayout.component.d.ts.map +1 -0
- package/dist/src/components/overlays/dialog/Dialog.component.d.ts +36 -2
- package/dist/src/components/overlays/dialog/Dialog.component.d.ts.map +1 -1
- package/dist/src/components/typography/heading/Heading.component.d.ts +3 -2
- package/dist/src/components/typography/heading/Heading.component.d.ts.map +1 -1
- package/dist/src/components/typography/link/Link.component.d.ts +80 -0
- package/dist/src/components/typography/link/Link.component.d.ts.map +1 -0
- package/dist/src/index.d.ts +22 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -1
- /package/dist/{index44.cjs → index61.cjs} +0 -0
- /package/dist/{index44.js → index61.js} +0 -0
package/dist/index20.js
CHANGED
|
@@ -1,45 +1,482 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from "react";
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useRef, useState, useCallback, useEffect } from "react";
|
|
3
|
+
import { cn } from "./index31.js";
|
|
4
|
+
import { Chip } from "./index19.js";
|
|
3
5
|
/* empty css */
|
|
4
|
-
|
|
6
|
+
import { devWarn } from "./index50.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) {
|
|
15
|
+
case "px":
|
|
16
|
+
return value;
|
|
17
|
+
case "rem":
|
|
18
|
+
return value * rootFontSize;
|
|
19
|
+
case "em":
|
|
20
|
+
return value * containerFontSize;
|
|
21
|
+
default:
|
|
22
|
+
return 0.5 * rootFontSize;
|
|
23
|
+
}
|
|
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++;
|
|
33
|
+
break;
|
|
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++;
|
|
46
|
+
}
|
|
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);
|
|
62
|
+
},
|
|
63
|
+
[callback, delay]
|
|
64
|
+
);
|
|
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));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
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
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const count = calculateFittingChips(
|
|
92
|
+
items,
|
|
93
|
+
chipWidths.current,
|
|
94
|
+
containerWidth,
|
|
95
|
+
gap,
|
|
96
|
+
overflowChipWidth
|
|
97
|
+
);
|
|
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
|
+
}
|
|
110
|
+
});
|
|
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();
|
|
130
|
+
};
|
|
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(
|
|
5
138
|
({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
139
|
+
items,
|
|
140
|
+
selectedValue,
|
|
141
|
+
onSelectionChange,
|
|
142
|
+
removable = false,
|
|
143
|
+
onRemove,
|
|
144
|
+
variant = "primary",
|
|
145
|
+
disabled = false,
|
|
146
|
+
maxVisible,
|
|
147
|
+
className,
|
|
14
148
|
"data-testid": dataTestId,
|
|
15
|
-
|
|
149
|
+
"data-cy": dataCy,
|
|
16
150
|
...props
|
|
17
151
|
}, ref) => {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|
|
177
|
+
},
|
|
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
|
+
}
|
|
187
|
+
},
|
|
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
|
+
}
|
|
197
|
+
},
|
|
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;
|
|
208
|
+
switch (e.key) {
|
|
209
|
+
case "ArrowDown":
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
if (index < hiddenItems.length - 1) {
|
|
212
|
+
(_a = dropdownItemRefs.current[index + 1]) == null ? void 0 : _a.focus();
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
case "ArrowUp":
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
if (index > 0) {
|
|
218
|
+
(_b = dropdownItemRefs.current[index - 1]) == null ? void 0 : _b.focus();
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
case "Home":
|
|
222
|
+
e.preventDefault();
|
|
223
|
+
(_c = dropdownItemRefs.current[0]) == null ? void 0 : _c.focus();
|
|
224
|
+
break;
|
|
225
|
+
case "End":
|
|
226
|
+
e.preventDefault();
|
|
227
|
+
(_d = dropdownItemRefs.current[hiddenItems.length - 1]) == null ? void 0 : _d.focus();
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
},
|
|
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
|
+
}
|
|
240
|
+
};
|
|
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);
|
|
256
|
+
};
|
|
257
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
258
|
+
document.addEventListener("keydown", handleEscape);
|
|
259
|
+
return () => {
|
|
260
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
261
|
+
document.removeEventListener("keydown", handleEscape);
|
|
262
|
+
};
|
|
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);
|
|
278
|
+
}
|
|
279
|
+
}, [hiddenItems]);
|
|
280
|
+
if (!items || !Array.isArray(items)) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
return /* @__PURE__ */ jsxs(
|
|
284
|
+
"div",
|
|
31
285
|
{
|
|
32
286
|
ref,
|
|
33
|
-
className:
|
|
34
|
-
"
|
|
35
|
-
"
|
|
287
|
+
className: cn("chip-group", disabled && "chip-group--disabled", className),
|
|
288
|
+
role: "group",
|
|
289
|
+
"aria-label": "Chip group",
|
|
290
|
+
"data-testid": dataTestId || "chip-group",
|
|
291
|
+
"data-cy": dataCy || "chip-group",
|
|
36
292
|
...props,
|
|
37
|
-
children
|
|
293
|
+
children: [
|
|
294
|
+
hasOverflow && /* @__PURE__ */ jsxs(
|
|
295
|
+
"div",
|
|
296
|
+
{
|
|
297
|
+
className: "sr-only",
|
|
298
|
+
role: "status",
|
|
299
|
+
"aria-live": "polite",
|
|
300
|
+
"aria-atomic": "true",
|
|
301
|
+
"data-testid": "chip-group-live-region",
|
|
302
|
+
"data-cy": "chip-group-live-region",
|
|
303
|
+
children: [
|
|
304
|
+
hiddenItems.length,
|
|
305
|
+
" additional ",
|
|
306
|
+
hiddenItems.length === 1 ? "chip" : "chips",
|
|
307
|
+
" hidden"
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
),
|
|
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(
|
|
318
|
+
"div",
|
|
319
|
+
{
|
|
320
|
+
ref: (el) => {
|
|
321
|
+
if (el) {
|
|
322
|
+
chipRefs.current[itemIndexInFullArray] = el;
|
|
323
|
+
} else {
|
|
324
|
+
chipRefs.current[itemIndexInFullArray] = null;
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
className: "chip-group__item-wrapper",
|
|
328
|
+
"data-cy": `chip-group-item-wrapper-${item.value}`,
|
|
329
|
+
"data-testid": `chip-group-item-wrapper-${item.value}`,
|
|
330
|
+
children: /* @__PURE__ */ jsxs(
|
|
331
|
+
"div",
|
|
332
|
+
{
|
|
333
|
+
className: "chip-group__item",
|
|
334
|
+
onClick: (e) => handleChipClick(item.value, itemDisabled, e),
|
|
335
|
+
onKeyDown: (e) => handleKeyDown(e, item.value, itemDisabled),
|
|
336
|
+
tabIndex: itemDisabled ? -1 : 0,
|
|
337
|
+
role: "button",
|
|
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}`,
|
|
342
|
+
children: [
|
|
343
|
+
/* @__PURE__ */ jsx(
|
|
344
|
+
Chip,
|
|
345
|
+
{
|
|
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
|
|
352
|
+
}
|
|
353
|
+
),
|
|
354
|
+
removable && !disabled && !itemDisabled && /* @__PURE__ */ jsx(
|
|
355
|
+
"button",
|
|
356
|
+
{
|
|
357
|
+
className: "chip-group__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}`,
|
|
362
|
+
type: "button",
|
|
363
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "Cross2Icon", size: "sm", decorative: true })
|
|
364
|
+
}
|
|
365
|
+
)
|
|
366
|
+
]
|
|
367
|
+
}
|
|
368
|
+
)
|
|
369
|
+
},
|
|
370
|
+
item.value
|
|
371
|
+
);
|
|
372
|
+
}),
|
|
373
|
+
hasOverflow && /* @__PURE__ */ jsxs(
|
|
374
|
+
"div",
|
|
375
|
+
{
|
|
376
|
+
ref: dropdownRef,
|
|
377
|
+
className: "chip-group__overflow",
|
|
378
|
+
role: "button",
|
|
379
|
+
tabIndex: 0,
|
|
380
|
+
"aria-expanded": showDropdown ? "true" : "false",
|
|
381
|
+
"aria-haspopup": "menu",
|
|
382
|
+
"aria-label": `Show ${hiddenItems.length} more ${hiddenItems.length === 1 ? "chip" : "chips"}`,
|
|
383
|
+
onMouseEnter: () => !showDropdown && setShowTooltip(true),
|
|
384
|
+
onMouseLeave: () => setShowTooltip(false),
|
|
385
|
+
onClick: handleOverflowClick,
|
|
386
|
+
onKeyDown: (e) => {
|
|
387
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
388
|
+
e.preventDefault();
|
|
389
|
+
e.stopPropagation();
|
|
390
|
+
setShowDropdown(!showDropdown);
|
|
391
|
+
setShowTooltip(false);
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
"data-cy": "chip-group-overflow",
|
|
395
|
+
"data-testid": "chip-group-overflow",
|
|
396
|
+
children: [
|
|
397
|
+
/* @__PURE__ */ jsxs(Chip, { variant, "data-cy": "chip-overflow", "data-testid": "chip-overflow", children: [
|
|
398
|
+
"+",
|
|
399
|
+
hiddenItems.length
|
|
400
|
+
] }),
|
|
401
|
+
showTooltip && !showDropdown && /* @__PURE__ */ jsx(
|
|
402
|
+
"div",
|
|
403
|
+
{
|
|
404
|
+
className: "chip-group__tooltip chip-group__tooltip--hover",
|
|
405
|
+
role: "tooltip",
|
|
406
|
+
"data-cy": "chip-group-tooltip",
|
|
407
|
+
"data-testid": "chip-group-tooltip",
|
|
408
|
+
children: hiddenItems.map((item) => /* @__PURE__ */ jsx(
|
|
409
|
+
"div",
|
|
410
|
+
{
|
|
411
|
+
className: "chip-group__tooltip-item",
|
|
412
|
+
"data-cy": `chip-group-tooltip-item-${item.value}`,
|
|
413
|
+
"data-testid": `chip-group-tooltip-item-${item.value}`,
|
|
414
|
+
children: item.label
|
|
415
|
+
},
|
|
416
|
+
item.value
|
|
417
|
+
))
|
|
418
|
+
}
|
|
419
|
+
),
|
|
420
|
+
showDropdown && /* @__PURE__ */ jsx(
|
|
421
|
+
"div",
|
|
422
|
+
{
|
|
423
|
+
className: "chip-group__dropdown",
|
|
424
|
+
role: "menu",
|
|
425
|
+
"data-cy": "chip-group-dropdown",
|
|
426
|
+
"data-testid": "chip-group-dropdown",
|
|
427
|
+
children: hiddenItems.map((item, index) => /* @__PURE__ */ jsx(
|
|
428
|
+
"div",
|
|
429
|
+
{
|
|
430
|
+
ref: (el) => {
|
|
431
|
+
if (el) {
|
|
432
|
+
dropdownItemRefs.current[index] = el;
|
|
433
|
+
} else {
|
|
434
|
+
dropdownItemRefs.current[index] = null;
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
className: cn(
|
|
438
|
+
"chip-group__dropdown-item",
|
|
439
|
+
item.disabled && "chip-group__dropdown-item--disabled"
|
|
440
|
+
),
|
|
441
|
+
role: "menuitem",
|
|
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
|
+
}
|
|
450
|
+
},
|
|
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
|
+
}
|
|
461
|
+
},
|
|
462
|
+
"data-cy": `chip-group-dropdown-item-${item.value}`,
|
|
463
|
+
"data-testid": `chip-group-dropdown-item-${item.value}`,
|
|
464
|
+
children: item.label
|
|
465
|
+
},
|
|
466
|
+
item.value
|
|
467
|
+
))
|
|
468
|
+
}
|
|
469
|
+
)
|
|
470
|
+
]
|
|
471
|
+
}
|
|
472
|
+
)
|
|
473
|
+
] })
|
|
474
|
+
]
|
|
38
475
|
}
|
|
39
476
|
);
|
|
40
477
|
}
|
|
41
478
|
);
|
|
42
|
-
|
|
479
|
+
ChipGroup.displayName = "ChipGroup";
|
|
43
480
|
export {
|
|
44
|
-
|
|
481
|
+
ChipGroup
|
|
45
482
|
};
|
package/dist/index21.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),e=require("react"),t=require("@radix-ui/react-dialog"),o=require("./index31.cjs");;/* empty css */const i=require("@adam-milo/icons");function s(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a)for(const t in a)if("default"!==t){const o=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>a[t]})}return e.default=a,Object.freeze(e)}const d=s(t),r=d.Root,l=d.Trigger,c=d.Portal,n=d.Close,g=e.forwardRef(({className:e,"data-cy":t,"data-testid":s,...r},l)=>{const c=t||"dialog-close-button",n=s||"dialog-close-button";return a.jsx(d.Close,{ref:l,className:o.cn("dialog-close-button",e),"data-cy":c,"data-testid":n,"aria-label":"Close dialog",...r,children:a.jsx(i.Icon,{name:"Cross2Icon",size:"sm",decorative:!0})})});g.displayName="DialogCloseButton";const y=({children:e,variant:t="default",className:i,"data-cy":s,"data-testid":d,...r})=>{const l=s||"dialog-icon",c=d||"dialog-icon";return a.jsx("div",{className:o.cn("dialog-icon",`dialog-icon--${t}`,i),"data-cy":l,"data-testid":c,"aria-hidden":"true",...r,children:e})};y.displayName="DialogIcon";const m=e.forwardRef(({className:e,"data-cy":t,"data-testid":i,...s},r)=>{const l=t||"dialog-overlay",c=i||"dialog-overlay";return a.jsx(d.Overlay,{ref:r,className:o.cn("dialog-overlay",e),"data-cy":l,"data-testid":c,...s})});m.displayName=d.Overlay.displayName;const p=e.forwardRef(({className:e,children:t,"data-cy":i,"data-testid":s,...r},l)=>{const n=i||"dialog-content",g=s||"dialog-content";return a.jsxs(c,{children:[a.jsx(m,{}),a.jsx(d.Content,{ref:l,className:o.cn("dialog-content",e),"data-cy":n,"data-testid":g,...r,children:t})]})});p.displayName=d.Content.displayName;const u=({centered:e=!1,className:t,"data-cy":i,"data-testid":s,...d})=>{const r=i||"dialog-header",l=s||"dialog-header";return a.jsx("div",{className:o.cn("dialog-header",e&&"dialog-header--centered",t),"data-cy":r,"data-testid":l,...d})};u.displayName="DialogHeader";const f=({className:e,"data-cy":t,"data-testid":i,...s})=>{const d=t||"dialog-footer",r=i||"dialog-footer";return a.jsx("div",{className:o.cn("dialog-footer",e),"data-cy":d,"data-testid":r,...s})};f.displayName="DialogFooter";const x=e.forwardRef(({className:e,"data-cy":t,"data-testid":i,...s},r)=>{const l=t||"dialog-title",c=i||"dialog-title";return a.jsx(d.Title,{ref:r,className:o.cn("dialog-title",e),"data-cy":l,"data-testid":c,...s})});x.displayName=d.Title.displayName;const N=e.forwardRef(({className:e,"data-cy":t,"data-testid":i,...s},r)=>{const l=t||"dialog-description",c=i||"dialog-description";return a.jsx(d.Description,{ref:r,className:o.cn("dialog-description",e),"data-cy":l,"data-testid":c,...s})});N.displayName=d.Description.displayName,exports.Dialog=r,exports.DialogClose=n,exports.DialogCloseButton=g,exports.DialogContent=p,exports.DialogDescription=N,exports.DialogFooter=f,exports.DialogHeader=u,exports.DialogIcon=y,exports.DialogOverlay=m,exports.DialogPortal=c,exports.DialogTitle=x,exports.DialogTrigger=l;
|