@purpur/library 9.1.1 → 9.1.3
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/CHANGELOG.json +24 -0
- package/CHANGELOG.md +15 -1
- package/dist/LICENSE.txt +1 -1
- package/dist/components/dropdown/src/dropdown-select.d.ts.map +1 -1
- package/dist/components/dropdown/src/useDropdown.d.ts +1 -0
- package/dist/components/dropdown/src/useDropdown.d.ts.map +1 -1
- package/dist/dropdown-BQOY21kI.js +2 -0
- package/dist/dropdown-BQOY21kI.js.map +1 -0
- package/dist/dropdown-CBYTBaMW.mjs +779 -0
- package/dist/dropdown-CBYTBaMW.mjs.map +1 -0
- package/dist/dropdown.cjs.js +1 -1
- package/dist/dropdown.es.js +1 -1
- package/dist/library.cjs.js +1 -1
- package/dist/library.es.js +2 -2
- package/dist/purpur.css +1 -1
- package/dist/search-field-Bst9d-wX.js +2 -0
- package/dist/{search-field-DAktzYb0.js.map → search-field-Bst9d-wX.js.map} +1 -1
- package/dist/{search-field-Caj2dKLn.mjs → search-field-DTuEiK-M.mjs} +54 -54
- package/dist/{search-field-Caj2dKLn.mjs.map → search-field-DTuEiK-M.mjs.map} +1 -1
- package/dist/search-field.cjs.js +1 -1
- package/dist/search-field.es.js +1 -1
- package/package.json +22 -22
- package/dist/dropdown-BC6evqyq.js +0 -2
- package/dist/dropdown-BC6evqyq.js.map +0 -1
- package/dist/dropdown-C-Ze4gvG.mjs +0 -771
- package/dist/dropdown-C-Ze4gvG.mjs.map +0 -1
- package/dist/search-field-DAktzYb0.js +0 -2
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
import { jsxs as Y, jsx as a, Fragment as be } from "react/jsx-runtime";
|
|
2
|
+
import { useState as _e, forwardRef as ue, useId as ge, useRef as oe, useCallback as fe, useEffect as Oe } from "react";
|
|
3
|
+
import { L as te } from "./listbox-DG4KmQP_.mjs";
|
|
4
|
+
import { e as De } from "./use-autocomplete.es-CVv3z8t6.mjs";
|
|
5
|
+
import { C as Re } from "./checkbox-D6qWgpWR.mjs";
|
|
6
|
+
import { a as he } from "./dismissable-chip-group-D-gD93ON.mjs";
|
|
7
|
+
import { F as Ne } from "./field-error-text-CBSX8dGx.mjs";
|
|
8
|
+
import { F as Se } from "./field-helper-text-C5ee4SFV.mjs";
|
|
9
|
+
import { r as Le } from "./check-circle-filled.es-umBwOv5_.mjs";
|
|
10
|
+
import { l as Te } from "./chevron-down.es-PCIIj6oG.mjs";
|
|
11
|
+
import { L as Be } from "./label-7sJe5-pX.mjs";
|
|
12
|
+
import { a as Ee } from "./spinner-DRQN6YdK.mjs";
|
|
13
|
+
import { c as Fe } from "./bind-CU-R61T-.mjs";
|
|
14
|
+
const Pe = {
|
|
15
|
+
"purpur-dropdown": "_purpur-dropdown_ixl3j_1",
|
|
16
|
+
"purpur-dropdown--negative": "_purpur-dropdown--negative_ixl3j_11",
|
|
17
|
+
"purpur-dropdown__label": "_purpur-dropdown__label_ixl3j_14",
|
|
18
|
+
"purpur-dropdown__field-row": "_purpur-dropdown__field-row_ixl3j_19",
|
|
19
|
+
"purpur-dropdown__frame": "_purpur-dropdown__frame_ixl3j_23",
|
|
20
|
+
"purpur-dropdown__frame--negative": "_purpur-dropdown__frame--negative_ixl3j_30",
|
|
21
|
+
"purpur-dropdown__trigger-container": "_purpur-dropdown__trigger-container_ixl3j_33",
|
|
22
|
+
"purpur-dropdown__chip-group": "_purpur-dropdown__chip-group_ixl3j_45",
|
|
23
|
+
"purpur-dropdown__trigger-container--has-tags": "_purpur-dropdown__trigger-container--has-tags_ixl3j_50",
|
|
24
|
+
"purpur-dropdown__trigger-container--disabled": "_purpur-dropdown__trigger-container--disabled_ixl3j_53",
|
|
25
|
+
"purpur-dropdown__trigger-container--readonly": "_purpur-dropdown__trigger-container--readonly_ixl3j_53",
|
|
26
|
+
"purpur-dropdown__trigger-container--negative": "_purpur-dropdown__trigger-container--negative_ixl3j_60",
|
|
27
|
+
"purpur-dropdown__trigger-container--error": "_purpur-dropdown__trigger-container--error_ixl3j_63",
|
|
28
|
+
"purpur-dropdown__trigger-container--is-valid": "_purpur-dropdown__trigger-container--is-valid_ixl3j_66",
|
|
29
|
+
"purpur-dropdown__input": "_purpur-dropdown__input_ixl3j_69",
|
|
30
|
+
"purpur-dropdown__trigger": "_purpur-dropdown__trigger_ixl3j_33",
|
|
31
|
+
"purpur-dropdown__trigger--placeholder": "_purpur-dropdown__trigger--placeholder_ixl3j_117",
|
|
32
|
+
"purpur-dropdown__trigger--is-valid": "_purpur-dropdown__trigger--is-valid_ixl3j_120",
|
|
33
|
+
"purpur-dropdown__trigger--disabled": "_purpur-dropdown__trigger--disabled_ixl3j_123",
|
|
34
|
+
"purpur-dropdown__trigger--readonly": "_purpur-dropdown__trigger--readonly_ixl3j_127",
|
|
35
|
+
"purpur-dropdown__trigger--negative": "_purpur-dropdown__trigger--negative_ixl3j_131",
|
|
36
|
+
"purpur-dropdown__trigger-text": "_purpur-dropdown__trigger-text_ixl3j_144",
|
|
37
|
+
"purpur-dropdown__combobox-container": "_purpur-dropdown__combobox-container_ixl3j_150",
|
|
38
|
+
"purpur-dropdown__combobox-container--disabled": "_purpur-dropdown__combobox-container--disabled_ixl3j_160",
|
|
39
|
+
"purpur-dropdown__combobox-container--readonly": "_purpur-dropdown__combobox-container--readonly_ixl3j_167",
|
|
40
|
+
"purpur-dropdown__combobox-container--error": "_purpur-dropdown__combobox-container--error_ixl3j_174",
|
|
41
|
+
"purpur-dropdown__combobox-container--is-valid": "_purpur-dropdown__combobox-container--is-valid_ixl3j_177",
|
|
42
|
+
"purpur-dropdown__combobox-container--negative": "_purpur-dropdown__combobox-container--negative_ixl3j_180",
|
|
43
|
+
"purpur-dropdown__input--negative": "_purpur-dropdown__input--negative_ixl3j_219",
|
|
44
|
+
"purpur-dropdown__chip-group--select": "_purpur-dropdown__chip-group--select_ixl3j_236",
|
|
45
|
+
"purpur-dropdown__end-adornments": "_purpur-dropdown__end-adornments_ixl3j_239",
|
|
46
|
+
"purpur-dropdown__chevron-icon": "_purpur-dropdown__chevron-icon_ixl3j_250",
|
|
47
|
+
"purpur-dropdown__chevron-icon--open": "_purpur-dropdown__chevron-icon--open_ixl3j_255",
|
|
48
|
+
"purpur-dropdown__chevron-icon--disabled": "_purpur-dropdown__chevron-icon--disabled_ixl3j_258",
|
|
49
|
+
"purpur-dropdown__chevron-icon--readonly": "_purpur-dropdown__chevron-icon--readonly_ixl3j_261",
|
|
50
|
+
"purpur-dropdown__chevron-icon--negative": "_purpur-dropdown__chevron-icon--negative_ixl3j_264",
|
|
51
|
+
"purpur-dropdown__valid-icon": "_purpur-dropdown__valid-icon_ixl3j_267",
|
|
52
|
+
"purpur-dropdown__listbox": "_purpur-dropdown__listbox_ixl3j_270",
|
|
53
|
+
"purpur-dropdown__checkbox-item-multiple": "_purpur-dropdown__checkbox-item-multiple_ixl3j_280",
|
|
54
|
+
"purpur-dropdown__checkbox-container": "_purpur-dropdown__checkbox-container_ixl3j_283"
|
|
55
|
+
}, b = Fe.bind(Pe), o = "purpur-dropdown", me = ({
|
|
56
|
+
fieldId: r,
|
|
57
|
+
htmlForSuffix: t,
|
|
58
|
+
label: i,
|
|
59
|
+
getTestId: s,
|
|
60
|
+
disabled: d,
|
|
61
|
+
negative: n,
|
|
62
|
+
required: h
|
|
63
|
+
}) => i ? /* @__PURE__ */ Y(
|
|
64
|
+
Be,
|
|
65
|
+
{
|
|
66
|
+
htmlFor: t ? `${r}-${t}` : r,
|
|
67
|
+
className: b(`${o}__label`),
|
|
68
|
+
"data-testid": s("label"),
|
|
69
|
+
disabled: d,
|
|
70
|
+
negative: n,
|
|
71
|
+
children: [
|
|
72
|
+
h && /* @__PURE__ */ a("span", { "aria-hidden": !0, children: "*" }),
|
|
73
|
+
i
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
) : null, xe = ({
|
|
77
|
+
getTestId: r,
|
|
78
|
+
loading: t,
|
|
79
|
+
disabled: i,
|
|
80
|
+
negative: s,
|
|
81
|
+
isValid: d,
|
|
82
|
+
isOpen: n,
|
|
83
|
+
readOnly: h,
|
|
84
|
+
showChevronOpen: C
|
|
85
|
+
}) => /* @__PURE__ */ a("span", { className: b(`${o}__end-adornments`), children: t ? /* @__PURE__ */ a(
|
|
86
|
+
Ee,
|
|
87
|
+
{
|
|
88
|
+
disabled: i,
|
|
89
|
+
size: "xxs",
|
|
90
|
+
negative: s,
|
|
91
|
+
"data-testid": r("spinner")
|
|
92
|
+
}
|
|
93
|
+
) : /* @__PURE__ */ Y(be, { children: [
|
|
94
|
+
d && /* @__PURE__ */ a(
|
|
95
|
+
Le,
|
|
96
|
+
{
|
|
97
|
+
"data-testid": r("valid-icon"),
|
|
98
|
+
className: b(`${o}__valid-icon`)
|
|
99
|
+
}
|
|
100
|
+
),
|
|
101
|
+
/* @__PURE__ */ a(
|
|
102
|
+
Te,
|
|
103
|
+
{
|
|
104
|
+
className: b(`${o}__chevron-icon`, {
|
|
105
|
+
[`${o}__chevron-icon--open`]: C && n,
|
|
106
|
+
[`${o}__chevron-icon--disabled`]: i,
|
|
107
|
+
[`${o}__chevron-icon--readonly`]: h && !i,
|
|
108
|
+
[`${o}__chevron-icon--is-valid`]: d,
|
|
109
|
+
[`${o}__chevron-icon--negative`]: s
|
|
110
|
+
}),
|
|
111
|
+
"data-testid": r("dropdown-icon"),
|
|
112
|
+
size: "sm"
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
] }) }), we = ({
|
|
116
|
+
selectedItems: r,
|
|
117
|
+
getTestId: t,
|
|
118
|
+
disabled: i,
|
|
119
|
+
onRemove: s,
|
|
120
|
+
isSelect: d
|
|
121
|
+
}) => r.length ? /* @__PURE__ */ a(
|
|
122
|
+
he,
|
|
123
|
+
{
|
|
124
|
+
className: b(`${o}__chip-group`, {
|
|
125
|
+
[`${o}__chip-group--select`]: d
|
|
126
|
+
}),
|
|
127
|
+
"data-testid": t("tags"),
|
|
128
|
+
size: "sm",
|
|
129
|
+
children: r.map((n) => /* @__PURE__ */ a(
|
|
130
|
+
he.Item,
|
|
131
|
+
{
|
|
132
|
+
id: n.id,
|
|
133
|
+
"data-testid": t(`tag-${n.id}`),
|
|
134
|
+
"aria-label": `Remove ${n.label}`,
|
|
135
|
+
onDismiss: () => {
|
|
136
|
+
s(n);
|
|
137
|
+
},
|
|
138
|
+
disabled: i,
|
|
139
|
+
children: n.label
|
|
140
|
+
},
|
|
141
|
+
n.id
|
|
142
|
+
))
|
|
143
|
+
}
|
|
144
|
+
) : null, ve = ({
|
|
145
|
+
errorText: r,
|
|
146
|
+
helperText: t,
|
|
147
|
+
helperTextId: i,
|
|
148
|
+
negative: s
|
|
149
|
+
}) => /* @__PURE__ */ Y(be, { children: [
|
|
150
|
+
r && /* @__PURE__ */ a(Ne, { negative: s, children: r }),
|
|
151
|
+
t && !r && /* @__PURE__ */ a(Se, { id: i, negative: s, children: t })
|
|
152
|
+
] }), ye = ({
|
|
153
|
+
optionsToShow: r,
|
|
154
|
+
getListboxItemProps: t,
|
|
155
|
+
multiple: i,
|
|
156
|
+
fieldId: s,
|
|
157
|
+
noOptionsText: d
|
|
158
|
+
}) => d !== void 0 && !r.length ? /* @__PURE__ */ a(te.Item, { noninteractive: !0, children: d }) : r.map((n, h) => {
|
|
159
|
+
const { key: C, selected: y, ...g } = t(n, h);
|
|
160
|
+
return i ? /* @__PURE__ */ a(
|
|
161
|
+
te.Item,
|
|
162
|
+
{
|
|
163
|
+
...g,
|
|
164
|
+
className: b(`${o}__checkbox-item-multiple`),
|
|
165
|
+
selected: !!y,
|
|
166
|
+
hideSelectedIcon: !0,
|
|
167
|
+
children: /* @__PURE__ */ Y("span", { className: b(`${o}__checkbox-container`), children: [
|
|
168
|
+
/* @__PURE__ */ a(Re, { id: `${s}-checkbox-${n.id}`, checked: !!y, "aria-hidden": !0 }),
|
|
169
|
+
n.label
|
|
170
|
+
] })
|
|
171
|
+
},
|
|
172
|
+
C
|
|
173
|
+
) : /* @__PURE__ */ a(te.Item, { ...g, selected: !!y, children: n.label }, C);
|
|
174
|
+
}), Ae = (r, t, i) => {
|
|
175
|
+
if (i)
|
|
176
|
+
return r.filter((d) => i(t, d));
|
|
177
|
+
if (!t) return r;
|
|
178
|
+
const s = t.toUpperCase().split(" ");
|
|
179
|
+
return r.filter(
|
|
180
|
+
(d) => s.every((n) => (d.value || d.label).toUpperCase().includes(n))
|
|
181
|
+
);
|
|
182
|
+
}, $e = ({
|
|
183
|
+
options: r,
|
|
184
|
+
searchTerm: t,
|
|
185
|
+
filterOption: i,
|
|
186
|
+
selectedOption: s,
|
|
187
|
+
multiple: d
|
|
188
|
+
}) => !d && s && s.label === t ? r : Ae(r, t, i), Ie = ({
|
|
189
|
+
controlledInputValue: r,
|
|
190
|
+
defaultInputValue: t,
|
|
191
|
+
selectedOption: i,
|
|
192
|
+
onInputChange: s
|
|
193
|
+
}) => {
|
|
194
|
+
const [d, n] = _e(
|
|
195
|
+
(typeof r == "string" ? r : t ?? i?.label) ?? ""
|
|
196
|
+
);
|
|
197
|
+
return {
|
|
198
|
+
displayInputValue: typeof r == "string" ? r : d,
|
|
199
|
+
populateInputField: (y) => {
|
|
200
|
+
s?.(y), n(y);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}, Ce = ue((r, t) => {
|
|
204
|
+
const {
|
|
205
|
+
id: i,
|
|
206
|
+
label: s,
|
|
207
|
+
options: d,
|
|
208
|
+
className: n,
|
|
209
|
+
errorText: h,
|
|
210
|
+
helperText: C,
|
|
211
|
+
placeholder: y,
|
|
212
|
+
negative: g = !1,
|
|
213
|
+
readOnly: R = !1,
|
|
214
|
+
disabled: f = !1,
|
|
215
|
+
required: u = !1,
|
|
216
|
+
valid: j,
|
|
217
|
+
loading: m,
|
|
218
|
+
multiple: c = !1,
|
|
219
|
+
selectedOption: _,
|
|
220
|
+
selectedOptions: N = [],
|
|
221
|
+
onSelect: B,
|
|
222
|
+
openOnFocus: $ = !1,
|
|
223
|
+
listboxMaxHeight: Q,
|
|
224
|
+
listboxLabel: M,
|
|
225
|
+
filterOption: E,
|
|
226
|
+
inputValue: F,
|
|
227
|
+
defaultInputValue: p,
|
|
228
|
+
onInputChange: V,
|
|
229
|
+
noOptionsText: S,
|
|
230
|
+
highlightFirstOption: L = !1,
|
|
231
|
+
["data-testid"]: P
|
|
232
|
+
} = r, k = ge(), w = i ?? k, O = (l) => P ? `${P}-${l}` : void 0, H = !!j && !h, I = `${w}-helper-text`, v = c ? N : _ ? [_] : [], { displayInputValue: A, populateInputField: T } = Ie({
|
|
233
|
+
controlledInputValue: F,
|
|
234
|
+
defaultInputValue: p,
|
|
235
|
+
selectedOption: _,
|
|
236
|
+
onInputChange: V
|
|
237
|
+
}), q = $e({
|
|
238
|
+
options: d,
|
|
239
|
+
searchTerm: A,
|
|
240
|
+
filterOption: E,
|
|
241
|
+
selectedOption: _,
|
|
242
|
+
multiple: c
|
|
243
|
+
}), z = (l) => {
|
|
244
|
+
if (c) {
|
|
245
|
+
const e = v.some((x) => x.id === l.id) ? v.filter((x) => x.id !== l.id) : [...v, l];
|
|
246
|
+
B?.(l, e), T("");
|
|
247
|
+
} else
|
|
248
|
+
B?.(l, [l]), T(l.label);
|
|
249
|
+
}, {
|
|
250
|
+
rootRef: X,
|
|
251
|
+
inputRef: Z,
|
|
252
|
+
inputProps: G,
|
|
253
|
+
listboxProps: D,
|
|
254
|
+
getListboxItemProps: ee,
|
|
255
|
+
isOpen: U,
|
|
256
|
+
openListbox: re,
|
|
257
|
+
anchorStyle: ne
|
|
258
|
+
} = De({
|
|
259
|
+
id: w,
|
|
260
|
+
options: q,
|
|
261
|
+
listboxLabel: M || s || "Options",
|
|
262
|
+
selectedOption: c ? void 0 : _,
|
|
263
|
+
disabled: f,
|
|
264
|
+
readOnly: R,
|
|
265
|
+
openOnFocus: $,
|
|
266
|
+
listboxMaxHeight: Q,
|
|
267
|
+
highlightFirstOption: L,
|
|
268
|
+
closeOnSelect: !c,
|
|
269
|
+
noOptionsText: S,
|
|
270
|
+
onSelect: z,
|
|
271
|
+
"data-testid": P
|
|
272
|
+
}), ie = (l) => {
|
|
273
|
+
X.current = l, typeof t == "function" ? t(l) : t && (t.current = l);
|
|
274
|
+
}, de = (l, W) => {
|
|
275
|
+
const e = ee(l, W);
|
|
276
|
+
if (c) {
|
|
277
|
+
const x = v.some((J) => J.id === l.id);
|
|
278
|
+
return { ...e, selected: x, "aria-selected": x };
|
|
279
|
+
}
|
|
280
|
+
return e;
|
|
281
|
+
}, se = (l) => {
|
|
282
|
+
const W = v.filter((e) => e.id !== l.id);
|
|
283
|
+
B?.(l, W);
|
|
284
|
+
}, le = (l) => {
|
|
285
|
+
c && l.key === "Backspace" && l.currentTarget.value === "" && v.length > 0 && se(v[v.length - 1]), G?.onKeyDown?.(l);
|
|
286
|
+
}, pe = (l) => {
|
|
287
|
+
T(l.target.value), U || re();
|
|
288
|
+
}, ce = b(o, n, {
|
|
289
|
+
[`${o}--negative`]: g
|
|
290
|
+
});
|
|
291
|
+
return /* @__PURE__ */ Y("div", { ref: ie, className: ce, children: [
|
|
292
|
+
/* @__PURE__ */ a(
|
|
293
|
+
me,
|
|
294
|
+
{
|
|
295
|
+
fieldId: w,
|
|
296
|
+
htmlForSuffix: "input",
|
|
297
|
+
label: s,
|
|
298
|
+
getTestId: O,
|
|
299
|
+
disabled: f,
|
|
300
|
+
negative: g,
|
|
301
|
+
required: u
|
|
302
|
+
}
|
|
303
|
+
),
|
|
304
|
+
/* @__PURE__ */ a("div", { className: b(`${o}__field-row`), children: /* @__PURE__ */ Y(
|
|
305
|
+
"div",
|
|
306
|
+
{
|
|
307
|
+
className: b(`${o}__combobox-container`, {
|
|
308
|
+
[`${o}__combobox-container--error`]: !!h,
|
|
309
|
+
[`${o}__combobox-container--is-valid`]: H,
|
|
310
|
+
[`${o}__combobox-container--negative`]: g,
|
|
311
|
+
[`${o}__combobox-container--disabled`]: f,
|
|
312
|
+
[`${o}__combobox-container--readonly`]: R && !f
|
|
313
|
+
}),
|
|
314
|
+
style: ne,
|
|
315
|
+
children: [
|
|
316
|
+
c && /* @__PURE__ */ a(
|
|
317
|
+
we,
|
|
318
|
+
{
|
|
319
|
+
selectedItems: v,
|
|
320
|
+
getTestId: O,
|
|
321
|
+
disabled: f,
|
|
322
|
+
onRemove: se
|
|
323
|
+
}
|
|
324
|
+
),
|
|
325
|
+
/* @__PURE__ */ a(
|
|
326
|
+
"input",
|
|
327
|
+
{
|
|
328
|
+
...G,
|
|
329
|
+
ref: Z,
|
|
330
|
+
id: `${w}-input`,
|
|
331
|
+
"data-testid": O("input"),
|
|
332
|
+
onKeyDown: le,
|
|
333
|
+
onChange: pe,
|
|
334
|
+
value: A,
|
|
335
|
+
placeholder: y,
|
|
336
|
+
className: b(`${o}__input`, {
|
|
337
|
+
[`${o}__input--negative`]: g
|
|
338
|
+
}),
|
|
339
|
+
"aria-describedby": I,
|
|
340
|
+
"aria-invalid": !!h,
|
|
341
|
+
disabled: f,
|
|
342
|
+
readOnly: R
|
|
343
|
+
}
|
|
344
|
+
),
|
|
345
|
+
/* @__PURE__ */ a(
|
|
346
|
+
xe,
|
|
347
|
+
{
|
|
348
|
+
getTestId: O,
|
|
349
|
+
loading: m,
|
|
350
|
+
disabled: f,
|
|
351
|
+
negative: g,
|
|
352
|
+
isValid: H,
|
|
353
|
+
isOpen: U,
|
|
354
|
+
showChevronOpen: !0
|
|
355
|
+
}
|
|
356
|
+
),
|
|
357
|
+
/* @__PURE__ */ a(
|
|
358
|
+
"span",
|
|
359
|
+
{
|
|
360
|
+
className: b(`${o}__frame`, {
|
|
361
|
+
[`${o}__frame--negative`]: g
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
)
|
|
365
|
+
]
|
|
366
|
+
}
|
|
367
|
+
) }),
|
|
368
|
+
U && /* @__PURE__ */ a(te, { ...D, className: b(`${o}__listbox`), children: ye({
|
|
369
|
+
optionsToShow: q,
|
|
370
|
+
getListboxItemProps: de,
|
|
371
|
+
multiple: c,
|
|
372
|
+
fieldId: w,
|
|
373
|
+
noOptionsText: S
|
|
374
|
+
}) }),
|
|
375
|
+
/* @__PURE__ */ a(
|
|
376
|
+
ve,
|
|
377
|
+
{
|
|
378
|
+
errorText: h,
|
|
379
|
+
helperText: C,
|
|
380
|
+
helperTextId: I,
|
|
381
|
+
negative: g
|
|
382
|
+
}
|
|
383
|
+
)
|
|
384
|
+
] });
|
|
385
|
+
});
|
|
386
|
+
Ce.displayName = "DropdownCombobox";
|
|
387
|
+
const Ke = ({
|
|
388
|
+
options: r,
|
|
389
|
+
highlightFirstOption: t
|
|
390
|
+
}) => {
|
|
391
|
+
const i = oe(null), s = oe({}), [d, n] = _e(
|
|
392
|
+
t ? r[0] : void 0
|
|
393
|
+
), h = (u) => {
|
|
394
|
+
if (u) {
|
|
395
|
+
const j = u.getBoundingClientRect(), m = i.current?.getBoundingClientRect() || { top: 0, bottom: 0 };
|
|
396
|
+
(j.top < m.top || j.bottom > m.bottom) && u.scrollIntoView({ block: "nearest" });
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
return {
|
|
400
|
+
highlightedOption: d,
|
|
401
|
+
listboxRef: i,
|
|
402
|
+
optionRefs: s,
|
|
403
|
+
findNextOption: (u, j) => {
|
|
404
|
+
const m = j.filter((_) => !_.disabled);
|
|
405
|
+
if (!m.length) return;
|
|
406
|
+
const c = d ? m.findIndex((_) => _.id === d.id) : -1;
|
|
407
|
+
return u === "ArrowDown" ? m[(c + 1) % m.length] : m[(c - 1 + m.length) % m.length];
|
|
408
|
+
},
|
|
409
|
+
highlightOption: (u) => {
|
|
410
|
+
n(u ? { ...u } : void 0), u && h(s.current[u.id]);
|
|
411
|
+
},
|
|
412
|
+
highlightByClick: (u) => {
|
|
413
|
+
u.id !== d?.id && n({ ...u, isSetByClickEvent: !0 });
|
|
414
|
+
},
|
|
415
|
+
highlightSelected: (u, j) => {
|
|
416
|
+
requestAnimationFrame(() => {
|
|
417
|
+
n({ ...u, isSetByClickEvent: j === "CLICK" }), h(s.current[u.id]);
|
|
418
|
+
});
|
|
419
|
+
},
|
|
420
|
+
resetHighlight: () => {
|
|
421
|
+
n(void 0);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}, Ve = (r, t) => {
|
|
425
|
+
const i = fe(
|
|
426
|
+
(s) => {
|
|
427
|
+
r && !r.contains(s.target) && t();
|
|
428
|
+
},
|
|
429
|
+
[t, r]
|
|
430
|
+
);
|
|
431
|
+
Oe(() => (document.addEventListener("mousedown", i), () => {
|
|
432
|
+
document.removeEventListener("mousedown", i);
|
|
433
|
+
}), [i]);
|
|
434
|
+
}, He = ({
|
|
435
|
+
id: r,
|
|
436
|
+
variant: t,
|
|
437
|
+
options: i,
|
|
438
|
+
listboxLabel: s,
|
|
439
|
+
multiple: d = !1,
|
|
440
|
+
selectedOption: n,
|
|
441
|
+
selectedOptions: h = [],
|
|
442
|
+
onSelect: C,
|
|
443
|
+
filterOption: y,
|
|
444
|
+
inputValue: g,
|
|
445
|
+
defaultInputValue: R,
|
|
446
|
+
onInputChange: f,
|
|
447
|
+
noOptionsText: u,
|
|
448
|
+
highlightFirstOption: j = !1,
|
|
449
|
+
openOnFocus: m = !1,
|
|
450
|
+
listboxMaxHeight: c,
|
|
451
|
+
disabled: _ = !1,
|
|
452
|
+
readOnly: N = !1,
|
|
453
|
+
["data-testid"]: B
|
|
454
|
+
}) => {
|
|
455
|
+
const $ = t === "combobox", Q = ge(), M = oe(null), E = oe(null), F = oe(null), p = Ke({ options: i, highlightFirstOption: j }), { displayInputValue: V, populateInputField: S } = Ie({
|
|
456
|
+
controlledInputValue: g,
|
|
457
|
+
defaultInputValue: R,
|
|
458
|
+
selectedOption: n,
|
|
459
|
+
onInputChange: f
|
|
460
|
+
}), [L, P] = _e(!1), k = () => {
|
|
461
|
+
P(!1), p.resetHighlight();
|
|
462
|
+
};
|
|
463
|
+
Ve(M.current, k);
|
|
464
|
+
const w = ({ eventType: e }) => {
|
|
465
|
+
P(!0);
|
|
466
|
+
const x = d ? void 0 : n;
|
|
467
|
+
x && p.highlightSelected(x, e);
|
|
468
|
+
}, O = d ? h : n ? [n] : [], H = $ ? $e({
|
|
469
|
+
options: i,
|
|
470
|
+
searchTerm: V,
|
|
471
|
+
filterOption: y,
|
|
472
|
+
selectedOption: n,
|
|
473
|
+
multiple: d
|
|
474
|
+
}) : i, I = L && (!!H.length || !!u), v = (e) => B ? `${B}-${e}` : void 0, A = (e) => {
|
|
475
|
+
if (!(!e || e.disabled))
|
|
476
|
+
if (d) {
|
|
477
|
+
const J = O.some((K) => K.id === e.id) ? O.filter((K) => K.id !== e.id) : [...O, e];
|
|
478
|
+
C?.(e, J), $ && (S(""), F.current?.focus());
|
|
479
|
+
} else
|
|
480
|
+
C?.(e, [e]), $ && S(e.label), k(), ($ ? F : E).current?.focus();
|
|
481
|
+
}, T = (e) => {
|
|
482
|
+
I || w({ eventType: "KEYBOARD" });
|
|
483
|
+
const x = p.findNextOption(e, H);
|
|
484
|
+
p.highlightOption(x);
|
|
485
|
+
}, q = (e) => {
|
|
486
|
+
if (!(_ || N))
|
|
487
|
+
switch (e.key) {
|
|
488
|
+
case "ArrowUp":
|
|
489
|
+
case "ArrowDown":
|
|
490
|
+
e.preventDefault(), T(e.key);
|
|
491
|
+
break;
|
|
492
|
+
case "Enter": {
|
|
493
|
+
e.preventDefault(), I && p.highlightedOption ? A(p.highlightedOption) : I || w({ eventType: "KEYBOARD" });
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
case " ": {
|
|
497
|
+
$ || (e.preventDefault(), I && p.highlightedOption ? A(p.highlightedOption) : I || w({ eventType: "KEYBOARD" }));
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
case "Escape":
|
|
501
|
+
e.preventDefault(), k();
|
|
502
|
+
break;
|
|
503
|
+
case "Tab":
|
|
504
|
+
k();
|
|
505
|
+
break;
|
|
506
|
+
case "Home":
|
|
507
|
+
case "End":
|
|
508
|
+
$ && k();
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
}, z = (e) => {
|
|
512
|
+
S(e.target.value), p.resetHighlight(), L || w({ eventType: "KEYBOARD" });
|
|
513
|
+
}, X = () => {
|
|
514
|
+
_ || N || (L ? k() : w({ eventType: "CLICK" }));
|
|
515
|
+
}, Z = () => {
|
|
516
|
+
!L && m && !_ && !N && w({ eventType: "KEYBOARD" }), F.current?.select();
|
|
517
|
+
}, G = () => {
|
|
518
|
+
setTimeout(() => {
|
|
519
|
+
const e = document.activeElement;
|
|
520
|
+
e !== document.body && !F.current?.contains(e) && !p.listboxRef.current?.contains(e) && !M.current?.contains(e) && (k(), $ && !d && S(n ? n.label : ""));
|
|
521
|
+
});
|
|
522
|
+
}, D = () => {
|
|
523
|
+
_ || N || (L ? k() : w({ eventType: "CLICK" }));
|
|
524
|
+
}, ee = (e) => {
|
|
525
|
+
if (_ || N) return;
|
|
526
|
+
const x = e.target.closest("button");
|
|
527
|
+
x && x !== E.current || D();
|
|
528
|
+
}, U = () => {
|
|
529
|
+
!L && m && !_ && !N && w({ eventType: "KEYBOARD" });
|
|
530
|
+
}, re = `${r}-listbox`, ne = (e) => `${r}-listbox-item-${e.id}`, ie = `--purpur-dropdown-${Q.replace(/:/g, "")}`, de = { anchorName: ie }, se = $ ? null : {
|
|
531
|
+
onClick: ee
|
|
532
|
+
}, le = fe(
|
|
533
|
+
(e) => {
|
|
534
|
+
if (p.listboxRef.current = e, e && typeof e.showPopover == "function")
|
|
535
|
+
try {
|
|
536
|
+
e.showPopover();
|
|
537
|
+
} catch {
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
[p.listboxRef]
|
|
541
|
+
), pe = {
|
|
542
|
+
"aria-label": s,
|
|
543
|
+
"aria-expanded": I,
|
|
544
|
+
"data-testid": v("listbox"),
|
|
545
|
+
id: re,
|
|
546
|
+
ref: le,
|
|
547
|
+
onMouseLeave: () => p.resetHighlight(),
|
|
548
|
+
popover: "manual",
|
|
549
|
+
style: {
|
|
550
|
+
...c ? {
|
|
551
|
+
maxHeight: typeof c == "number" ? `${c}px` : c
|
|
552
|
+
} : {},
|
|
553
|
+
positionAnchor: ie
|
|
554
|
+
}
|
|
555
|
+
}, ce = (e, x) => {
|
|
556
|
+
const J = O.some((ae) => ae.id === e.id), { highlightedOption: K } = p, ke = (e.id === K?.id || j && !K && x === 0) && !K?.isSetByClickEvent;
|
|
557
|
+
return {
|
|
558
|
+
"data-testid": v(`listbox-item-${e.id}`),
|
|
559
|
+
id: ne(e),
|
|
560
|
+
key: e.id,
|
|
561
|
+
onMouseMove: () => p.highlightByClick(e),
|
|
562
|
+
onMouseUp: () => A(e),
|
|
563
|
+
ref: (ae) => {
|
|
564
|
+
ae && (p.optionRefs.current[e.id] = ae);
|
|
565
|
+
},
|
|
566
|
+
tabIndex: -1,
|
|
567
|
+
selected: J,
|
|
568
|
+
disabled: e.disabled,
|
|
569
|
+
highlighted: ke,
|
|
570
|
+
hovered: e.id === K?.id && !!K?.isSetByClickEvent,
|
|
571
|
+
"aria-selected": J
|
|
572
|
+
};
|
|
573
|
+
}, l = $ ? {} : {
|
|
574
|
+
ref: E,
|
|
575
|
+
type: "button",
|
|
576
|
+
role: "combobox",
|
|
577
|
+
"aria-haspopup": "listbox",
|
|
578
|
+
"aria-expanded": I,
|
|
579
|
+
"aria-controls": re,
|
|
580
|
+
"aria-disabled": _,
|
|
581
|
+
"data-testid": v("trigger"),
|
|
582
|
+
id: `${r}-trigger`,
|
|
583
|
+
onKeyDown: q,
|
|
584
|
+
onFocus: U,
|
|
585
|
+
disabled: _,
|
|
586
|
+
tabIndex: _ ? -1 : 0,
|
|
587
|
+
style: de
|
|
588
|
+
}, W = $ ? {
|
|
589
|
+
ref: F,
|
|
590
|
+
role: "combobox",
|
|
591
|
+
"aria-autocomplete": "list",
|
|
592
|
+
"aria-expanded": I,
|
|
593
|
+
"aria-controls": re,
|
|
594
|
+
"aria-activedescendant": p.highlightedOption ? ne(p.highlightedOption) : void 0,
|
|
595
|
+
"data-testid": v("input"),
|
|
596
|
+
autoComplete: "off",
|
|
597
|
+
id: `${r}-input`,
|
|
598
|
+
type: "text",
|
|
599
|
+
value: V,
|
|
600
|
+
onChange: z,
|
|
601
|
+
onMouseDown: X,
|
|
602
|
+
onFocus: Z,
|
|
603
|
+
onBlur: G,
|
|
604
|
+
onKeyDown: q,
|
|
605
|
+
disabled: _,
|
|
606
|
+
readOnly: N
|
|
607
|
+
} : null;
|
|
608
|
+
return {
|
|
609
|
+
rootRef: M,
|
|
610
|
+
triggerContainerProps: se,
|
|
611
|
+
triggerProps: l,
|
|
612
|
+
inputProps: W,
|
|
613
|
+
listboxProps: pe,
|
|
614
|
+
getListboxItemProps: ce,
|
|
615
|
+
optionsToShow: H,
|
|
616
|
+
isOpen: I,
|
|
617
|
+
highlightedOption: p.highlightedOption,
|
|
618
|
+
selectedItems: O,
|
|
619
|
+
anchorStyle: de
|
|
620
|
+
};
|
|
621
|
+
}, je = ue((r, t) => {
|
|
622
|
+
const {
|
|
623
|
+
id: i,
|
|
624
|
+
label: s,
|
|
625
|
+
options: d,
|
|
626
|
+
className: n,
|
|
627
|
+
errorText: h,
|
|
628
|
+
helperText: C,
|
|
629
|
+
placeholder: y,
|
|
630
|
+
negative: g = !1,
|
|
631
|
+
readOnly: R = !1,
|
|
632
|
+
disabled: f = !1,
|
|
633
|
+
required: u = !1,
|
|
634
|
+
valid: j = !1,
|
|
635
|
+
loading: m = !1,
|
|
636
|
+
multiple: c = !1,
|
|
637
|
+
selectedOption: _,
|
|
638
|
+
selectedOptions: N = [],
|
|
639
|
+
onSelect: B,
|
|
640
|
+
openOnFocus: $ = !1,
|
|
641
|
+
listboxMaxHeight: Q,
|
|
642
|
+
listboxLabel: M,
|
|
643
|
+
["data-testid"]: E
|
|
644
|
+
} = r, F = ge(), p = i ?? F, V = (D) => E ? `${E}-${D}` : void 0, S = !!j && !h, L = `${p}-helper-text`, P = He({
|
|
645
|
+
id: p,
|
|
646
|
+
variant: "select",
|
|
647
|
+
options: d,
|
|
648
|
+
listboxLabel: M || s || "Options",
|
|
649
|
+
multiple: c,
|
|
650
|
+
selectedOption: _,
|
|
651
|
+
selectedOptions: N,
|
|
652
|
+
onSelect: B,
|
|
653
|
+
openOnFocus: $,
|
|
654
|
+
listboxMaxHeight: Q,
|
|
655
|
+
disabled: f,
|
|
656
|
+
readOnly: R,
|
|
657
|
+
"data-testid": E
|
|
658
|
+
}), k = (D) => {
|
|
659
|
+
P.rootRef.current = D, typeof t == "function" ? t(D) : t && (t.current = D);
|
|
660
|
+
}, {
|
|
661
|
+
triggerContainerProps: w,
|
|
662
|
+
triggerProps: O,
|
|
663
|
+
listboxProps: H,
|
|
664
|
+
getListboxItemProps: I,
|
|
665
|
+
optionsToShow: v,
|
|
666
|
+
isOpen: A,
|
|
667
|
+
selectedItems: T,
|
|
668
|
+
anchorStyle: q
|
|
669
|
+
} = P, z = {
|
|
670
|
+
...O
|
|
671
|
+
};
|
|
672
|
+
delete z.style;
|
|
673
|
+
const X = (D) => {
|
|
674
|
+
const ee = T.filter((U) => U.id !== D.id);
|
|
675
|
+
B?.(D, ee);
|
|
676
|
+
}, Z = c ? T.length === 0 && y || "" : _?.label || y || "", G = b(o, n, {
|
|
677
|
+
[`${o}--negative`]: g
|
|
678
|
+
});
|
|
679
|
+
return /* @__PURE__ */ Y("div", { ref: k, className: G, children: [
|
|
680
|
+
/* @__PURE__ */ a(
|
|
681
|
+
me,
|
|
682
|
+
{
|
|
683
|
+
fieldId: p,
|
|
684
|
+
htmlForSuffix: "trigger",
|
|
685
|
+
label: s,
|
|
686
|
+
getTestId: V,
|
|
687
|
+
disabled: f,
|
|
688
|
+
negative: g,
|
|
689
|
+
required: u
|
|
690
|
+
}
|
|
691
|
+
),
|
|
692
|
+
/* @__PURE__ */ a("div", { className: b(`${o}__field-row`), children: /* @__PURE__ */ Y(
|
|
693
|
+
"div",
|
|
694
|
+
{
|
|
695
|
+
...w,
|
|
696
|
+
className: b(`${o}__trigger-container`, {
|
|
697
|
+
[`${o}__trigger-container--error`]: !!h,
|
|
698
|
+
[`${o}__trigger-container--is-valid`]: S,
|
|
699
|
+
[`${o}__trigger-container--negative`]: g,
|
|
700
|
+
[`${o}__trigger-container--disabled`]: f,
|
|
701
|
+
[`${o}__trigger-container--readonly`]: R && !f,
|
|
702
|
+
[`${o}__trigger-container--has-tags`]: c && T.length > 0
|
|
703
|
+
}),
|
|
704
|
+
style: q,
|
|
705
|
+
children: [
|
|
706
|
+
c && /* @__PURE__ */ a(
|
|
707
|
+
we,
|
|
708
|
+
{
|
|
709
|
+
selectedItems: T,
|
|
710
|
+
getTestId: V,
|
|
711
|
+
disabled: f,
|
|
712
|
+
onRemove: X,
|
|
713
|
+
isSelect: !0
|
|
714
|
+
}
|
|
715
|
+
),
|
|
716
|
+
/* @__PURE__ */ a(
|
|
717
|
+
"button",
|
|
718
|
+
{
|
|
719
|
+
...z,
|
|
720
|
+
className: b(`${o}__trigger`, {
|
|
721
|
+
[`${o}__trigger--is-valid`]: S,
|
|
722
|
+
[`${o}__trigger--negative`]: g,
|
|
723
|
+
[`${o}__trigger--disabled`]: f,
|
|
724
|
+
[`${o}__trigger--readonly`]: R && !f,
|
|
725
|
+
[`${o}__trigger--placeholder`]: !T.length
|
|
726
|
+
}),
|
|
727
|
+
"aria-describedby": L,
|
|
728
|
+
children: /* @__PURE__ */ a("span", { className: b(`${o}__trigger-text`), children: Z })
|
|
729
|
+
}
|
|
730
|
+
),
|
|
731
|
+
/* @__PURE__ */ a(
|
|
732
|
+
xe,
|
|
733
|
+
{
|
|
734
|
+
getTestId: V,
|
|
735
|
+
loading: m,
|
|
736
|
+
disabled: f,
|
|
737
|
+
negative: g,
|
|
738
|
+
isValid: S,
|
|
739
|
+
isOpen: A,
|
|
740
|
+
readOnly: R,
|
|
741
|
+
showChevronOpen: !0
|
|
742
|
+
}
|
|
743
|
+
),
|
|
744
|
+
/* @__PURE__ */ a(
|
|
745
|
+
"span",
|
|
746
|
+
{
|
|
747
|
+
className: b(`${o}__frame`, {
|
|
748
|
+
[`${o}__frame--negative`]: g
|
|
749
|
+
})
|
|
750
|
+
}
|
|
751
|
+
)
|
|
752
|
+
]
|
|
753
|
+
}
|
|
754
|
+
) }),
|
|
755
|
+
A && /* @__PURE__ */ a(te, { ...H, className: b(`${o}__listbox`), children: ye({
|
|
756
|
+
optionsToShow: v,
|
|
757
|
+
getListboxItemProps: I,
|
|
758
|
+
multiple: c,
|
|
759
|
+
fieldId: p
|
|
760
|
+
}) }),
|
|
761
|
+
/* @__PURE__ */ a(
|
|
762
|
+
ve,
|
|
763
|
+
{
|
|
764
|
+
errorText: h,
|
|
765
|
+
helperText: C,
|
|
766
|
+
helperTextId: L,
|
|
767
|
+
negative: g
|
|
768
|
+
}
|
|
769
|
+
)
|
|
770
|
+
] });
|
|
771
|
+
});
|
|
772
|
+
je.displayName = "DropdownSelect";
|
|
773
|
+
const Ye = ue((r, t) => r.combobox ? /* @__PURE__ */ a(Ce, { ref: t, ...r }) : /* @__PURE__ */ a(je, { ref: t, ...r }));
|
|
774
|
+
Ye.displayName = "Dropdown";
|
|
775
|
+
export {
|
|
776
|
+
Ye as D,
|
|
777
|
+
He as u
|
|
778
|
+
};
|
|
779
|
+
//# sourceMappingURL=dropdown-CBYTBaMW.mjs.map
|