mcr-design-systems 1.0.214 → 1.0.215
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.
|
@@ -125,6 +125,11 @@ export interface SelectProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
|
|
|
125
125
|
* Test identifier
|
|
126
126
|
*/
|
|
127
127
|
'data-testid'?: string;
|
|
128
|
+
/**
|
|
129
|
+
* All items (unfiltered) for selectedItems mapping when using search
|
|
130
|
+
* This ensures selected items always have proper labels even when filtered
|
|
131
|
+
*/
|
|
132
|
+
allItems?: (DropdownItem | DropdownGroup)[];
|
|
128
133
|
/**
|
|
129
134
|
* Custom width for select and dropdown
|
|
130
135
|
*/
|
|
@@ -1,104 +1,105 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { cn as
|
|
4
|
-
import { dataTestId as
|
|
5
|
-
import { Typography as
|
|
1
|
+
import { jsxs as g, jsx as t, Fragment as Re } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as Te, useState as ke, useRef as je, useCallback as T, useMemo as P, memo as De } from "react";
|
|
3
|
+
import { cn as d } from "../../shared/utils/cn.js";
|
|
4
|
+
import { dataTestId as Ee } from "../../shared/utils/dataTestId.js";
|
|
5
|
+
import { Typography as z } from "../Typography/index.js";
|
|
6
6
|
import C from "../Icon/Icon.js";
|
|
7
|
-
import { Dropdown as
|
|
8
|
-
import { selectVariants as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { useChipOverflow as
|
|
12
|
-
const
|
|
7
|
+
import { Dropdown as ie } from "../Dropdown/index.js";
|
|
8
|
+
import { selectVariants as Fe } from "./helper/variants.js";
|
|
9
|
+
import ce from "../Chip/index.js";
|
|
10
|
+
import Pe from "../TextField/HelperText.js";
|
|
11
|
+
import { useChipOverflow as ze } from "../../shared/hooks/useChipOverflow.js";
|
|
12
|
+
const me = Te(
|
|
13
13
|
({
|
|
14
14
|
items: M = [],
|
|
15
15
|
value: r,
|
|
16
16
|
onChange: y,
|
|
17
17
|
placeholder: b = "Select an option...",
|
|
18
18
|
disabled: a = !1,
|
|
19
|
-
readOnly:
|
|
20
|
-
loading:
|
|
21
|
-
showCheckmark:
|
|
22
|
-
emptyText:
|
|
23
|
-
state:
|
|
24
|
-
label:
|
|
25
|
-
helpText:
|
|
26
|
-
required:
|
|
27
|
-
leadingIcon:
|
|
28
|
-
trailingIcon:
|
|
19
|
+
readOnly: n = !1,
|
|
20
|
+
loading: V = !1,
|
|
21
|
+
showCheckmark: q = !1,
|
|
22
|
+
emptyText: G = "No options available",
|
|
23
|
+
state: k,
|
|
24
|
+
label: J,
|
|
25
|
+
helpText: pe,
|
|
26
|
+
required: fe = !1,
|
|
27
|
+
leadingIcon: c,
|
|
28
|
+
trailingIcon: m,
|
|
29
29
|
mode: o = "single",
|
|
30
|
-
displayType:
|
|
31
|
-
maxDisplayChips:
|
|
30
|
+
displayType: ue = "chip",
|
|
31
|
+
maxDisplayChips: Ve,
|
|
32
32
|
// eslint-disable-line @typescript-eslint/no-unused-vars -- kept for backward compatibility
|
|
33
|
-
moreItemsText:
|
|
34
|
-
trigger:
|
|
35
|
-
side:
|
|
36
|
-
align:
|
|
37
|
-
sideOffset:
|
|
38
|
-
enableVirtualization:
|
|
39
|
-
itemHeight:
|
|
40
|
-
maxHeight:
|
|
41
|
-
size:
|
|
42
|
-
variant:
|
|
43
|
-
fullWidth:
|
|
44
|
-
className:
|
|
45
|
-
iconsSize:
|
|
33
|
+
moreItemsText: he = "+{count}",
|
|
34
|
+
trigger: de,
|
|
35
|
+
side: K = "bottom",
|
|
36
|
+
align: L = "start",
|
|
37
|
+
sideOffset: Q = 4,
|
|
38
|
+
enableVirtualization: U,
|
|
39
|
+
itemHeight: W = 32,
|
|
40
|
+
maxHeight: X = 300,
|
|
41
|
+
size: s = "md",
|
|
42
|
+
variant: j = "default",
|
|
43
|
+
fullWidth: D = !1,
|
|
44
|
+
className: ge,
|
|
45
|
+
iconsSize: xe,
|
|
46
46
|
"data-testid": l,
|
|
47
47
|
width: A,
|
|
48
|
-
error:
|
|
49
|
-
haveIcon:
|
|
50
|
-
iconsCustom:
|
|
51
|
-
onBlur:
|
|
52
|
-
dropdownProps:
|
|
53
|
-
allowSearch:
|
|
54
|
-
title:
|
|
55
|
-
onSearchChange:
|
|
56
|
-
searchValue:
|
|
57
|
-
showClearButton:
|
|
58
|
-
searchPlaceholder:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
48
|
+
error: Y,
|
|
49
|
+
haveIcon: Ne,
|
|
50
|
+
iconsCustom: ve,
|
|
51
|
+
onBlur: Z,
|
|
52
|
+
dropdownProps: _,
|
|
53
|
+
allowSearch: H,
|
|
54
|
+
title: E,
|
|
55
|
+
onSearchChange: B,
|
|
56
|
+
searchValue: I,
|
|
57
|
+
showClearButton: O = !1,
|
|
58
|
+
searchPlaceholder: ee = "Search...",
|
|
59
|
+
allItems: S,
|
|
60
|
+
...Ce
|
|
61
|
+
}, ye) => {
|
|
62
|
+
const [p, $] = ke(!1), be = je(null), i = Fe({
|
|
63
|
+
size: s,
|
|
64
|
+
variant: j,
|
|
65
|
+
fullWidth: D,
|
|
66
|
+
state: k,
|
|
66
67
|
disabled: a,
|
|
67
|
-
readOnly:
|
|
68
|
-
}),
|
|
68
|
+
readOnly: n
|
|
69
|
+
}), Ae = T(
|
|
69
70
|
(e) => {
|
|
70
|
-
if (o === "multiple" && Array.isArray(r) && !a && !
|
|
71
|
-
const
|
|
72
|
-
y?.(
|
|
71
|
+
if (o === "multiple" && Array.isArray(r) && !a && !n) {
|
|
72
|
+
const u = r.filter((h) => h !== e);
|
|
73
|
+
y?.(u);
|
|
73
74
|
}
|
|
74
75
|
},
|
|
75
|
-
[o, r, y, a,
|
|
76
|
-
),
|
|
77
|
-
o === "multiple" && Array.isArray(r) && r.length > 0 && !a && !
|
|
78
|
-
}, [o, r, y, a,
|
|
76
|
+
[o, r, y, a, n]
|
|
77
|
+
), te = T(() => {
|
|
78
|
+
o === "multiple" && Array.isArray(r) && r.length > 0 && !a && !n && y?.([]);
|
|
79
|
+
}, [o, r, y, a, n]), f = P(() => {
|
|
79
80
|
if (!r) return [];
|
|
80
|
-
const e = Array.isArray(r) ? r : [r],
|
|
81
|
-
return ((
|
|
82
|
-
|
|
83
|
-
"items" in v ? v.items.forEach((
|
|
84
|
-
|
|
85
|
-
}) :
|
|
81
|
+
const e = Array.isArray(r) ? r : [r], u = S && S.length > 0 ? S : M, h = /* @__PURE__ */ new Map();
|
|
82
|
+
return ((w) => {
|
|
83
|
+
w.forEach((v) => {
|
|
84
|
+
"items" in v ? v.items.forEach((le) => {
|
|
85
|
+
h.set(le.value, le);
|
|
86
|
+
}) : h.set(v.value, v);
|
|
86
87
|
});
|
|
87
|
-
})(
|
|
88
|
-
const v =
|
|
88
|
+
})(u), e.map((w) => {
|
|
89
|
+
const v = h.get(w);
|
|
89
90
|
return v || {
|
|
90
|
-
value:
|
|
91
|
-
label:
|
|
91
|
+
value: w,
|
|
92
|
+
label: w
|
|
92
93
|
};
|
|
93
94
|
});
|
|
94
|
-
}, [r, M]),
|
|
95
|
+
}, [r, M, S]), F = P(() => {
|
|
95
96
|
if (o === "single") {
|
|
96
|
-
const e =
|
|
97
|
+
const e = f[0];
|
|
97
98
|
return e ? e.label : b;
|
|
98
99
|
}
|
|
99
|
-
return o === "multiple" ? r?.length === 0 ? b :
|
|
100
|
-
}, [o,
|
|
101
|
-
items: o === "multiple" && Array.isArray(r) ?
|
|
100
|
+
return o === "multiple" ? r?.length === 0 ? b : E ? `${E} ` : "" : "";
|
|
101
|
+
}, [o, f, b, E, r]), x = ze({
|
|
102
|
+
items: o === "multiple" && Array.isArray(r) ? f.map((e) => ({
|
|
102
103
|
value: e.value,
|
|
103
104
|
label: e.label
|
|
104
105
|
})) : [],
|
|
@@ -107,36 +108,36 @@ const ie = $e(
|
|
|
107
108
|
minChipsToShow: 1,
|
|
108
109
|
moreChipWidth: 60
|
|
109
110
|
// Estimated width for "+X more" chip
|
|
110
|
-
}),
|
|
111
|
+
}), R = P(() => {
|
|
111
112
|
if (o !== "multiple" || !Array.isArray(r))
|
|
112
113
|
return {
|
|
113
114
|
displayItems: [],
|
|
114
115
|
remainingCount: 0,
|
|
115
116
|
hasMore: !1
|
|
116
117
|
};
|
|
117
|
-
const
|
|
118
|
-
displayItems:
|
|
119
|
-
(
|
|
118
|
+
const u = {
|
|
119
|
+
displayItems: x.displayItems.map((h) => f.find(
|
|
120
|
+
(oe) => oe.value === h.value
|
|
120
121
|
) || {
|
|
121
|
-
value:
|
|
122
|
-
label:
|
|
122
|
+
value: h.value,
|
|
123
|
+
label: h.label
|
|
123
124
|
}),
|
|
124
|
-
remainingCount:
|
|
125
|
-
hasMore:
|
|
125
|
+
remainingCount: x.remainingCount,
|
|
126
|
+
hasMore: x.hasMore
|
|
126
127
|
};
|
|
127
|
-
return
|
|
128
|
-
displayItems: [
|
|
129
|
-
remainingCount: Math.max(0,
|
|
130
|
-
hasMore:
|
|
131
|
-
} :
|
|
128
|
+
return f.length > 0 && u.displayItems.length === 0 && !u.hasMore ? {
|
|
129
|
+
displayItems: [f[0]],
|
|
130
|
+
remainingCount: Math.max(0, f.length - 1),
|
|
131
|
+
hasMore: f.length > 1
|
|
132
|
+
} : u;
|
|
132
133
|
}, [
|
|
133
134
|
o,
|
|
134
135
|
r,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
]),
|
|
136
|
+
x.displayItems,
|
|
137
|
+
x.remainingCount,
|
|
138
|
+
x.hasMore,
|
|
139
|
+
f
|
|
140
|
+
]), we = A ? { width: typeof A == "number" ? `${A}px` : A } : {}, Me = d(i.container(), ge), N = (e) => {
|
|
140
141
|
switch (e) {
|
|
141
142
|
case "sm":
|
|
142
143
|
return 16;
|
|
@@ -147,7 +148,7 @@ const ie = $e(
|
|
|
147
148
|
default:
|
|
148
149
|
return 16;
|
|
149
150
|
}
|
|
150
|
-
},
|
|
151
|
+
}, re = (e) => {
|
|
151
152
|
switch (e) {
|
|
152
153
|
case "sm":
|
|
153
154
|
return "small";
|
|
@@ -158,157 +159,157 @@ const ie = $e(
|
|
|
158
159
|
default:
|
|
159
160
|
return "medium";
|
|
160
161
|
}
|
|
161
|
-
},
|
|
162
|
+
}, ae = T((e) => !!(e.closest('[data-testid*="chip"]') || e.closest('[data-testid*="clear-all"]') || e.closest('[data-no-trigger="true"]') || e.closest('[role="button"]') && e.closest('[data-testid*="chip"]')), []), ne = T(
|
|
162
163
|
(e) => {
|
|
163
|
-
const
|
|
164
|
-
return
|
|
164
|
+
const u = e.target;
|
|
165
|
+
return ae(u) ? (e.preventDefault(), e.stopPropagation(), !0) : !1;
|
|
165
166
|
},
|
|
166
|
-
[
|
|
167
|
+
[ae]
|
|
167
168
|
), se = (e) => {
|
|
168
|
-
|
|
169
|
+
$(e), !e && Z && Z(
|
|
169
170
|
new FocusEvent("blur")
|
|
170
171
|
);
|
|
171
|
-
},
|
|
172
|
+
}, Se = () => /* @__PURE__ */ g(
|
|
172
173
|
"div",
|
|
173
174
|
{
|
|
174
175
|
className: i.trigger(),
|
|
175
|
-
"data-state":
|
|
176
|
+
"data-state": p ? "open" : "closed",
|
|
176
177
|
children: [
|
|
177
|
-
|
|
178
|
+
c && /* @__PURE__ */ t("span", { className: i.leadingIcon(), children: c.node || c.name && /* @__PURE__ */ t(
|
|
178
179
|
C,
|
|
179
180
|
{
|
|
180
|
-
name:
|
|
181
|
-
size:
|
|
182
|
-
"aria-label":
|
|
181
|
+
name: c.name,
|
|
182
|
+
size: N(s),
|
|
183
|
+
"aria-label": c["aria-label"]
|
|
183
184
|
}
|
|
184
185
|
) }),
|
|
185
186
|
/* @__PURE__ */ t(
|
|
186
187
|
"span",
|
|
187
188
|
{
|
|
188
|
-
className:
|
|
189
|
+
className: d(
|
|
189
190
|
"flex-1 truncate text-left",
|
|
190
|
-
|
|
191
|
+
f.length > 0 ? "text-fg-neutral-main" : i.placeholder()
|
|
191
192
|
),
|
|
192
|
-
children:
|
|
193
|
+
children: F
|
|
193
194
|
}
|
|
194
195
|
),
|
|
195
|
-
|
|
196
|
+
m ? /* @__PURE__ */ t("span", { className: i.trailingIcon(), children: m.node || m.name && /* @__PURE__ */ t(
|
|
196
197
|
C,
|
|
197
198
|
{
|
|
198
|
-
name:
|
|
199
|
-
size:
|
|
200
|
-
"aria-label":
|
|
199
|
+
name: m.name,
|
|
200
|
+
size: N(s),
|
|
201
|
+
"aria-label": m["aria-label"]
|
|
201
202
|
}
|
|
202
203
|
) }) : /* @__PURE__ */ t(
|
|
203
204
|
C,
|
|
204
205
|
{
|
|
205
|
-
name:
|
|
206
|
-
size:
|
|
207
|
-
className:
|
|
206
|
+
name: p ? "chevron-up" : "chevron-down",
|
|
207
|
+
size: N(s),
|
|
208
|
+
className: d(i.chevron(), p && "rotate-180")
|
|
208
209
|
}
|
|
209
210
|
)
|
|
210
211
|
]
|
|
211
212
|
}
|
|
212
213
|
);
|
|
213
|
-
return /* @__PURE__ */
|
|
214
|
+
return /* @__PURE__ */ g(
|
|
214
215
|
"div",
|
|
215
216
|
{
|
|
216
|
-
ref:
|
|
217
|
-
className:
|
|
218
|
-
style:
|
|
219
|
-
...
|
|
220
|
-
...
|
|
217
|
+
ref: ye,
|
|
218
|
+
className: Me,
|
|
219
|
+
style: we,
|
|
220
|
+
...Ee(l || "select"),
|
|
221
|
+
...Ce,
|
|
221
222
|
children: [
|
|
222
|
-
|
|
223
|
-
/* @__PURE__ */ t(
|
|
224
|
-
|
|
223
|
+
J && /* @__PURE__ */ g("div", { className: "mb-1 flex items-center gap-[2px]", children: [
|
|
224
|
+
/* @__PURE__ */ t(z, { variants: "action", size: "sm", color: "fg-neutral-subtle", children: J }),
|
|
225
|
+
fe && /* @__PURE__ */ t(z, { variants: "action", size: "sm", color: "fg-accent-error", children: "*" })
|
|
225
226
|
] }),
|
|
226
227
|
/* @__PURE__ */ t("div", { className: "relative h-11", children: o === "multiple" ? /* @__PURE__ */ t(
|
|
227
|
-
|
|
228
|
+
ie,
|
|
228
229
|
{
|
|
229
|
-
...
|
|
230
|
+
..._,
|
|
230
231
|
items: M,
|
|
231
232
|
value: r,
|
|
232
233
|
onValueChange: (e) => {
|
|
233
|
-
a ||
|
|
234
|
+
a || n || y?.(Array.isArray(e) ? e : [e]);
|
|
234
235
|
},
|
|
235
236
|
fullWidthContent: !0,
|
|
236
237
|
placeholder: b,
|
|
237
238
|
disabled: a,
|
|
238
|
-
loading:
|
|
239
|
-
showCheckmark:
|
|
240
|
-
emptyText:
|
|
241
|
-
state:
|
|
242
|
-
open:
|
|
239
|
+
loading: V,
|
|
240
|
+
showCheckmark: q,
|
|
241
|
+
emptyText: G,
|
|
242
|
+
state: k,
|
|
243
|
+
open: p,
|
|
243
244
|
onOpenChange: se,
|
|
244
|
-
side:
|
|
245
|
-
align:
|
|
246
|
-
search:
|
|
247
|
-
sideOffset:
|
|
248
|
-
enableVirtualization:
|
|
245
|
+
side: K,
|
|
246
|
+
align: L,
|
|
247
|
+
search: H,
|
|
248
|
+
sideOffset: Q,
|
|
249
|
+
enableVirtualization: U,
|
|
249
250
|
selectionMode: "separated",
|
|
250
251
|
multiSelect: !0,
|
|
251
|
-
itemHeight:
|
|
252
|
-
maxHeight:
|
|
253
|
-
size:
|
|
254
|
-
variant:
|
|
255
|
-
fullWidth:
|
|
256
|
-
searchPlaceholder:
|
|
252
|
+
itemHeight: W,
|
|
253
|
+
maxHeight: X,
|
|
254
|
+
size: s,
|
|
255
|
+
variant: j,
|
|
256
|
+
fullWidth: D,
|
|
257
|
+
searchPlaceholder: ee,
|
|
257
258
|
width: A,
|
|
258
259
|
"data-testid": l ? `${l}-dropdown` : void 0,
|
|
259
|
-
showClearButton:
|
|
260
|
-
onClear:
|
|
261
|
-
searchValue:
|
|
262
|
-
onSearchChange:
|
|
260
|
+
showClearButton: O,
|
|
261
|
+
onClear: te,
|
|
262
|
+
searchValue: I,
|
|
263
|
+
onSearchChange: B,
|
|
263
264
|
className: "flex items-center",
|
|
264
|
-
children: /* @__PURE__ */
|
|
265
|
+
children: /* @__PURE__ */ g(
|
|
265
266
|
"div",
|
|
266
267
|
{
|
|
267
|
-
ref:
|
|
268
|
-
className:
|
|
268
|
+
ref: be,
|
|
269
|
+
className: d(
|
|
269
270
|
i.trigger({
|
|
270
|
-
state:
|
|
271
|
+
state: Y ? "error" : void 0
|
|
271
272
|
}),
|
|
272
273
|
"flex"
|
|
273
274
|
),
|
|
274
|
-
"data-state":
|
|
275
|
-
onPointerDown:
|
|
275
|
+
"data-state": p ? "open" : "closed",
|
|
276
|
+
onPointerDown: ne,
|
|
276
277
|
onClick: (e) => {
|
|
277
|
-
a ||
|
|
278
|
+
a || n || ne(e) || $(!p);
|
|
278
279
|
},
|
|
279
280
|
children: [
|
|
280
|
-
|
|
281
|
+
c && /* @__PURE__ */ t("span", { className: i.leadingIcon(), children: c.node || c.name && /* @__PURE__ */ t(
|
|
281
282
|
C,
|
|
282
283
|
{
|
|
283
|
-
name:
|
|
284
|
-
size:
|
|
285
|
-
"aria-label":
|
|
284
|
+
name: c.name,
|
|
285
|
+
size: N(s),
|
|
286
|
+
"aria-label": c["aria-label"],
|
|
286
287
|
className: "cursor-pointer"
|
|
287
288
|
}
|
|
288
289
|
) }),
|
|
289
290
|
/* @__PURE__ */ t(
|
|
290
291
|
"div",
|
|
291
292
|
{
|
|
292
|
-
className:
|
|
293
|
+
className: d(
|
|
293
294
|
"flex-1 flex flex-nowrap gap-1 min-h-0 overflow-hidden",
|
|
294
|
-
!a && !
|
|
295
|
+
!a && !n && "cursor-pointer"
|
|
295
296
|
),
|
|
296
|
-
children: Array.isArray(
|
|
297
|
+
children: Array.isArray(R) ? null : /* @__PURE__ */ t(Re, { children: ue === "chip" ? /* @__PURE__ */ g(
|
|
297
298
|
"div",
|
|
298
299
|
{
|
|
299
|
-
ref:
|
|
300
|
+
ref: x.containerRef,
|
|
300
301
|
className: "flex items-center gap-xs-3 flex-nowrap w-full max-w-full overflow-hidden",
|
|
301
302
|
children: [
|
|
302
|
-
|
|
303
|
-
|
|
303
|
+
R.displayItems.map((e) => /* @__PURE__ */ t(
|
|
304
|
+
ce,
|
|
304
305
|
{
|
|
305
|
-
size:
|
|
306
|
-
onRemove: !a && !
|
|
307
|
-
|
|
306
|
+
size: re(s),
|
|
307
|
+
onRemove: !a && !n ? () => {
|
|
308
|
+
Ae(e.value);
|
|
308
309
|
} : void 0,
|
|
309
310
|
className: "bg-bg-surface-level-3 flex-shrink-0",
|
|
310
311
|
variant: "neutral",
|
|
311
|
-
trailingIcon: !a && !
|
|
312
|
+
trailingIcon: !a && !n ? {
|
|
312
313
|
name: "x-close",
|
|
313
314
|
"aria-label": "Remove option"
|
|
314
315
|
} : void 0,
|
|
@@ -318,17 +319,17 @@ const ie = $e(
|
|
|
318
319
|
},
|
|
319
320
|
e.value
|
|
320
321
|
)),
|
|
321
|
-
|
|
322
|
-
|
|
322
|
+
R.hasMore && /* @__PURE__ */ t(
|
|
323
|
+
ce,
|
|
323
324
|
{
|
|
324
|
-
size:
|
|
325
|
+
size: re(s),
|
|
325
326
|
variant: "neutral",
|
|
326
327
|
className: "bg-bg-surface-level-3 flex-shrink-0",
|
|
327
328
|
dataTestIdName: `${l || "select"}-chip-more`,
|
|
328
329
|
onClick: (e) => e.stopPropagation(),
|
|
329
|
-
children:
|
|
330
|
+
children: he.replace(
|
|
330
331
|
"{count}",
|
|
331
|
-
|
|
332
|
+
R.remainingCount.toString()
|
|
332
333
|
)
|
|
333
334
|
}
|
|
334
335
|
)
|
|
@@ -339,45 +340,45 @@ const ie = $e(
|
|
|
339
340
|
/* @__PURE__ */ t(
|
|
340
341
|
"div",
|
|
341
342
|
{
|
|
342
|
-
className:
|
|
343
|
+
className: d(
|
|
343
344
|
i.placeholder(),
|
|
344
|
-
!a && !
|
|
345
|
+
!a && !n && "cursor-pointer"
|
|
345
346
|
),
|
|
346
|
-
children: Array.isArray(r) ? r?.length > 0 ? /* @__PURE__ */
|
|
347
|
-
|
|
347
|
+
children: Array.isArray(r) ? r?.length > 0 ? /* @__PURE__ */ g(
|
|
348
|
+
z,
|
|
348
349
|
{
|
|
349
350
|
variants: "body",
|
|
350
351
|
size: "md",
|
|
351
352
|
color: "fg-neutral-main",
|
|
352
353
|
children: [
|
|
353
|
-
|
|
354
|
-
/* @__PURE__ */
|
|
354
|
+
F,
|
|
355
|
+
/* @__PURE__ */ g("span", { className: "text-fg-brand-rest", children: [
|
|
355
356
|
"(",
|
|
356
357
|
r?.length,
|
|
357
358
|
")"
|
|
358
359
|
] })
|
|
359
360
|
]
|
|
360
361
|
}
|
|
361
|
-
) : b :
|
|
362
|
+
) : b : F
|
|
362
363
|
}
|
|
363
364
|
)
|
|
364
365
|
) })
|
|
365
366
|
}
|
|
366
367
|
),
|
|
367
|
-
/* @__PURE__ */
|
|
368
|
+
/* @__PURE__ */ g("div", { className: "flex items-center gap-xs", children: [
|
|
368
369
|
Array.isArray(r) && r.length > 0 && /* @__PURE__ */ t(
|
|
369
370
|
"button",
|
|
370
371
|
{
|
|
371
372
|
type: "button",
|
|
372
373
|
onClick: (e) => {
|
|
373
|
-
e.stopPropagation(),
|
|
374
|
+
e.stopPropagation(), te();
|
|
374
375
|
},
|
|
375
|
-
className:
|
|
376
|
+
className: d(
|
|
376
377
|
"flex items-center justify-center rounded-sm transition-colors",
|
|
377
|
-
!a && !
|
|
378
|
-
a ||
|
|
378
|
+
!a && !n && "cursor-pointer hover:bg-bg-neutral-subtle",
|
|
379
|
+
a || n ? "opacity-50 cursor-not-allowed" : ""
|
|
379
380
|
),
|
|
380
|
-
disabled: a ||
|
|
381
|
+
disabled: a || n,
|
|
381
382
|
"aria-label": "Clear all selections",
|
|
382
383
|
"data-testid": l ? `${l}-clear-all` : void 0,
|
|
383
384
|
"data-no-trigger": "true",
|
|
@@ -386,7 +387,7 @@ const ie = $e(
|
|
|
386
387
|
{
|
|
387
388
|
name: "x-circle",
|
|
388
389
|
variant: "solid",
|
|
389
|
-
size:
|
|
390
|
+
size: N(s),
|
|
390
391
|
className: "text-fg-neutral-subtle"
|
|
391
392
|
}
|
|
392
393
|
)
|
|
@@ -397,28 +398,28 @@ const ie = $e(
|
|
|
397
398
|
{
|
|
398
399
|
type: "button",
|
|
399
400
|
onClick: (e) => {
|
|
400
|
-
e.stopPropagation(), !a && !
|
|
401
|
+
e.stopPropagation(), !a && !n && $(!p);
|
|
401
402
|
},
|
|
402
|
-
className:
|
|
403
|
+
className: d(
|
|
403
404
|
"flex items-center justify-center dropdown-toggle-btn",
|
|
404
|
-
!a && !
|
|
405
|
+
!a && !n && "cursor-pointer"
|
|
405
406
|
),
|
|
406
407
|
"data-testid": l ? `${l}-dropdown-toggle` : "dropdown-toggle",
|
|
407
|
-
children:
|
|
408
|
+
children: m ? /* @__PURE__ */ t("span", { className: i.trailingIcon(), children: m.node || m.name && /* @__PURE__ */ t(
|
|
408
409
|
C,
|
|
409
410
|
{
|
|
410
|
-
name:
|
|
411
|
-
size:
|
|
412
|
-
"aria-label":
|
|
411
|
+
name: m.name,
|
|
412
|
+
size: N(s),
|
|
413
|
+
"aria-label": m["aria-label"]
|
|
413
414
|
}
|
|
414
415
|
) }) : /* @__PURE__ */ t(
|
|
415
416
|
C,
|
|
416
417
|
{
|
|
417
|
-
name:
|
|
418
|
-
size:
|
|
419
|
-
className:
|
|
418
|
+
name: p ? "chevron-up" : "chevron-down",
|
|
419
|
+
size: N(s),
|
|
420
|
+
className: d(
|
|
420
421
|
i.chevron(),
|
|
421
|
-
|
|
422
|
+
p && "rotate-180"
|
|
422
423
|
)
|
|
423
424
|
}
|
|
424
425
|
)
|
|
@@ -432,51 +433,51 @@ const ie = $e(
|
|
|
432
433
|
) : (
|
|
433
434
|
/* Single mode - use Dropdown normally */
|
|
434
435
|
/* @__PURE__ */ t(
|
|
435
|
-
|
|
436
|
+
ie,
|
|
436
437
|
{
|
|
437
|
-
...
|
|
438
|
+
..._,
|
|
438
439
|
items: M,
|
|
439
440
|
value: r,
|
|
440
441
|
onValueChange: (e) => {
|
|
441
|
-
a ||
|
|
442
|
+
a || n || (y?.(e), $(!1));
|
|
442
443
|
},
|
|
443
444
|
placeholder: b,
|
|
444
445
|
disabled: a,
|
|
445
|
-
loading:
|
|
446
|
-
showCheckmark:
|
|
447
|
-
emptyText:
|
|
448
|
-
state:
|
|
449
|
-
open:
|
|
446
|
+
loading: V,
|
|
447
|
+
showCheckmark: q,
|
|
448
|
+
emptyText: G,
|
|
449
|
+
state: k,
|
|
450
|
+
open: p,
|
|
450
451
|
onOpenChange: se,
|
|
451
|
-
side:
|
|
452
|
-
align:
|
|
453
|
-
sideOffset:
|
|
454
|
-
enableVirtualization:
|
|
455
|
-
itemHeight:
|
|
456
|
-
maxHeight:
|
|
457
|
-
size:
|
|
458
|
-
variant:
|
|
459
|
-
fullWidth:
|
|
452
|
+
side: K,
|
|
453
|
+
align: L,
|
|
454
|
+
sideOffset: Q,
|
|
455
|
+
enableVirtualization: U,
|
|
456
|
+
itemHeight: W,
|
|
457
|
+
maxHeight: X,
|
|
458
|
+
size: s,
|
|
459
|
+
variant: j,
|
|
460
|
+
fullWidth: D,
|
|
460
461
|
width: A,
|
|
461
462
|
"data-testid": l ? `${l}-dropdown` : void 0,
|
|
462
|
-
search:
|
|
463
|
-
searchPlaceholder:
|
|
464
|
-
searchValue:
|
|
465
|
-
onSearchChange:
|
|
466
|
-
showClearButton:
|
|
467
|
-
children:
|
|
463
|
+
search: H,
|
|
464
|
+
searchPlaceholder: ee,
|
|
465
|
+
searchValue: I,
|
|
466
|
+
onSearchChange: B,
|
|
467
|
+
showClearButton: O,
|
|
468
|
+
children: de || Se()
|
|
468
469
|
}
|
|
469
470
|
)
|
|
470
471
|
) }),
|
|
471
472
|
/* @__PURE__ */ t(
|
|
472
|
-
|
|
473
|
+
Pe,
|
|
473
474
|
{
|
|
474
475
|
className: "mt-1",
|
|
475
|
-
text:
|
|
476
|
-
error:
|
|
477
|
-
haveIcon:
|
|
478
|
-
iconsSize:
|
|
479
|
-
iconsCustom:
|
|
476
|
+
text: pe,
|
|
477
|
+
error: Y,
|
|
478
|
+
haveIcon: Ne,
|
|
479
|
+
iconsSize: xe,
|
|
480
|
+
iconsCustom: ve
|
|
480
481
|
}
|
|
481
482
|
)
|
|
482
483
|
]
|
|
@@ -484,8 +485,8 @@ const ie = $e(
|
|
|
484
485
|
);
|
|
485
486
|
}
|
|
486
487
|
);
|
|
487
|
-
|
|
488
|
-
const
|
|
488
|
+
me.displayName = "Select";
|
|
489
|
+
const _e = De(me);
|
|
489
490
|
export {
|
|
490
|
-
|
|
491
|
+
_e as default
|
|
491
492
|
};
|
|
@@ -1,99 +1,104 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
const
|
|
3
|
-
items:
|
|
4
|
-
gap:
|
|
5
|
-
minChipsToShow:
|
|
6
|
-
moreChipWidth:
|
|
1
|
+
import { useRef as W, useState as E, useEffect as C, useCallback as I } from "react";
|
|
2
|
+
const z = ({
|
|
3
|
+
items: r,
|
|
4
|
+
gap: c = 8,
|
|
5
|
+
minChipsToShow: x = 1,
|
|
6
|
+
moreChipWidth: M = 60
|
|
7
7
|
}) => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const d = W(null), [b, a] = E(r.length), m = W(r), A = W(r.length);
|
|
9
|
+
C(() => {
|
|
10
|
+
m.current = r, A.current = r.length;
|
|
11
|
+
});
|
|
12
|
+
const n = I(() => {
|
|
13
|
+
const t = m.current;
|
|
14
|
+
if (!d.current || t.length === 0) {
|
|
15
|
+
a(t.length);
|
|
11
16
|
return;
|
|
12
17
|
}
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
|
|
18
|
+
const h = d.current, i = h.clientWidth;
|
|
19
|
+
if (i === 0) {
|
|
20
|
+
a(t.length);
|
|
16
21
|
return;
|
|
17
22
|
}
|
|
18
23
|
if (t.length <= 4) {
|
|
19
|
-
const e =
|
|
24
|
+
const e = h.querySelectorAll(
|
|
20
25
|
'[data-testid*="chip"]:not([data-testid*="chip-more"])'
|
|
21
26
|
);
|
|
22
|
-
let
|
|
23
|
-
e.length > 0 && (
|
|
24
|
-
const
|
|
25
|
-
if (t.length *
|
|
26
|
-
|
|
27
|
+
let s = 75;
|
|
28
|
+
e.length > 0 && (s = e[0].offsetWidth);
|
|
29
|
+
const u = Math.max(0, t.length - 1) * c;
|
|
30
|
+
if (t.length * s + u <= i) {
|
|
31
|
+
a(t.length);
|
|
27
32
|
return;
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
const l =
|
|
35
|
+
const l = h.querySelectorAll(
|
|
31
36
|
'[data-testid*="chip"]:not([data-testid*="chip-more"])'
|
|
32
37
|
);
|
|
33
38
|
if (l.length === 0) {
|
|
34
|
-
|
|
39
|
+
a(t.length);
|
|
35
40
|
return;
|
|
36
41
|
}
|
|
37
|
-
let
|
|
38
|
-
l.length > 0 && (
|
|
39
|
-
let
|
|
42
|
+
let p = 0;
|
|
43
|
+
l.length > 0 && (p = Array.from(l).reduce((s, u) => s + u.offsetWidth, 0) / l.length), p === 0 && (p = 80);
|
|
44
|
+
let v = 0, o = 0;
|
|
40
45
|
for (let e = 0; e < t.length; e++) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
46
|
+
const s = e < l.length ? l[e].offsetWidth : p;
|
|
47
|
+
if (s === 0)
|
|
43
48
|
break;
|
|
44
|
-
const
|
|
45
|
-
let
|
|
46
|
-
if (
|
|
47
|
-
|
|
49
|
+
const u = e === t.length - 1, g = v + s + (e > 0 ? c : 0);
|
|
50
|
+
let f;
|
|
51
|
+
if (u)
|
|
52
|
+
f = i;
|
|
48
53
|
else {
|
|
49
|
-
const
|
|
50
|
-
|
|
54
|
+
const y = s;
|
|
55
|
+
g + c + y > i ? f = i - M - c : f = i;
|
|
51
56
|
}
|
|
52
|
-
if (
|
|
53
|
-
|
|
57
|
+
if (g <= f)
|
|
58
|
+
v = g, o = e + 1;
|
|
54
59
|
else
|
|
55
60
|
break;
|
|
56
61
|
}
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
}, [
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
const h = setTimeout(n, 0),
|
|
62
|
+
o = Math.max(o, Math.min(x, t.length));
|
|
63
|
+
const k = o >= t.length ? t.length : o, q = t.length > 0 ? Math.max(1, k) : 0;
|
|
64
|
+
a(q);
|
|
65
|
+
}, [c, x, M]);
|
|
66
|
+
C(() => {
|
|
67
|
+
const t = d.current;
|
|
68
|
+
if (!t) return;
|
|
69
|
+
const h = setTimeout(n, 0), i = new ResizeObserver(() => {
|
|
65
70
|
n();
|
|
66
71
|
});
|
|
67
|
-
return
|
|
68
|
-
clearTimeout(h),
|
|
72
|
+
return i.observe(t), () => {
|
|
73
|
+
clearTimeout(h), i.disconnect();
|
|
69
74
|
};
|
|
70
|
-
}, [n]),
|
|
75
|
+
}, [n]), C(() => {
|
|
71
76
|
n();
|
|
72
|
-
const
|
|
77
|
+
const t = setTimeout(() => {
|
|
73
78
|
n();
|
|
74
79
|
}, 10), h = setTimeout(() => {
|
|
75
80
|
n();
|
|
76
81
|
}, 50);
|
|
77
82
|
return () => {
|
|
78
|
-
clearTimeout(
|
|
83
|
+
clearTimeout(t), clearTimeout(h);
|
|
79
84
|
};
|
|
80
|
-
}, [
|
|
81
|
-
if (
|
|
82
|
-
const
|
|
85
|
+
}, [r.length, n]), C(() => {
|
|
86
|
+
if (r.length > 0) {
|
|
87
|
+
const t = requestAnimationFrame(() => {
|
|
83
88
|
n();
|
|
84
89
|
});
|
|
85
|
-
return () => cancelAnimationFrame(
|
|
90
|
+
return () => cancelAnimationFrame(t);
|
|
86
91
|
}
|
|
87
|
-
}, [
|
|
88
|
-
const
|
|
92
|
+
}, [r.length, n]);
|
|
93
|
+
const R = m.current.slice(0, b), T = Math.max(0, m.current.length - b), w = T > 0;
|
|
89
94
|
return {
|
|
90
|
-
containerRef:
|
|
91
|
-
displayItems:
|
|
92
|
-
remainingCount:
|
|
93
|
-
hasMore:
|
|
95
|
+
containerRef: d,
|
|
96
|
+
displayItems: R,
|
|
97
|
+
remainingCount: T,
|
|
98
|
+
hasMore: w,
|
|
94
99
|
recalculate: n
|
|
95
100
|
};
|
|
96
101
|
};
|
|
97
102
|
export {
|
|
98
|
-
|
|
103
|
+
z as useChipOverflow
|
|
99
104
|
};
|