@purpurds/autocomplete 0.0.1
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/LICENSE.txt +45 -0
- package/dist/autocomplete.cjs.js +14 -0
- package/dist/autocomplete.cjs.js.map +1 -0
- package/dist/autocomplete.d.ts +25 -0
- package/dist/autocomplete.d.ts.map +1 -0
- package/dist/autocomplete.es.js +437 -0
- package/dist/autocomplete.es.js.map +1 -0
- package/dist/listbox.d.ts +22 -0
- package/dist/listbox.d.ts.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/useAutocomplete.d.ts +40 -0
- package/dist/useAutocomplete.d.ts.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +65 -0
- package/readme.mdx +164 -0
- package/src/autocomplete.module.scss +9 -0
- package/src/autocomplete.stories.tsx +202 -0
- package/src/autocomplete.test.tsx +515 -0
- package/src/autocomplete.tsx +81 -0
- package/src/global.d.ts +4 -0
- package/src/listbox.module.scss +60 -0
- package/src/listbox.tsx +96 -0
- package/src/useAutocomplete.ts +302 -0
- package/src/utils.ts +28 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { default as React, ComponentPropsWithRef, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import * as ListBox from "./listbox";
|
|
4
|
+
export declare const Autocomplete: React.ForwardRefExoticComponent<{
|
|
5
|
+
highlightFirstOption?: boolean | undefined;
|
|
6
|
+
defaultInputValue?: string | undefined;
|
|
7
|
+
inputValue?: string | undefined;
|
|
8
|
+
filterOption?: ((inputValue: string | undefined, option: ListBox.Option) => boolean) | undefined;
|
|
9
|
+
id: string;
|
|
10
|
+
listboxLabel: string;
|
|
11
|
+
listboxMaxHeight?: string | number | undefined;
|
|
12
|
+
noOptionsText?: React.ReactNode;
|
|
13
|
+
onInputChange?: ((value: string) => void) | undefined;
|
|
14
|
+
openOnFocus?: boolean | undefined;
|
|
15
|
+
onSelect?: ((option: ListBox.Option | undefined) => void) | undefined;
|
|
16
|
+
options: ListBox.Option[];
|
|
17
|
+
selectedOption?: ListBox.Option | undefined;
|
|
18
|
+
"data-testid"?: string | undefined;
|
|
19
|
+
className?: string | undefined;
|
|
20
|
+
renderInput: (props: ComponentPropsWithRef<"input">) => ReactNode;
|
|
21
|
+
renderOption?: ((option: ListBox.Option) => ReactNode) | undefined;
|
|
22
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
23
|
+
export type { Option, UseAutocompleteOptions } from './useAutocomplete';
|
|
24
|
+
export { useAutocomplete } from './useAutocomplete';
|
|
25
|
+
//# sourceMappingURL=autocomplete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../src/autocomplete.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,qBAAqB,EAA4B,SAAS,EAAE,MAAM,OAAO,CAAC;AAI1F,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAwErC,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;yBA5DA,sBAAsB,OAAO,CAAC,KAAK,SAAS;gDAInC,SAAS;wCAwDkB,CAAC;AAG9D,YAAY,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import { jsx as y, jsxs as rr } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as S, useCallback as hr, useEffect as br, useState as M, forwardRef as q, Children as vr, isValidElement as xr } from "react";
|
|
3
|
+
function gr(t) {
|
|
4
|
+
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
5
|
+
}
|
|
6
|
+
var tr = { exports: {} };
|
|
7
|
+
/*!
|
|
8
|
+
Copyright (c) 2018 Jed Watson.
|
|
9
|
+
Licensed under the MIT License (MIT), see
|
|
10
|
+
http://jedwatson.github.io/classnames
|
|
11
|
+
*/
|
|
12
|
+
(function(t) {
|
|
13
|
+
(function() {
|
|
14
|
+
var s = {}.hasOwnProperty;
|
|
15
|
+
function n() {
|
|
16
|
+
for (var r = "", e = 0; e < arguments.length; e++) {
|
|
17
|
+
var o = arguments[e];
|
|
18
|
+
o && (r = i(r, l.call(this, o)));
|
|
19
|
+
}
|
|
20
|
+
return r;
|
|
21
|
+
}
|
|
22
|
+
function l(r) {
|
|
23
|
+
if (typeof r == "string" || typeof r == "number")
|
|
24
|
+
return this && this[r] || r;
|
|
25
|
+
if (typeof r != "object")
|
|
26
|
+
return "";
|
|
27
|
+
if (Array.isArray(r))
|
|
28
|
+
return n.apply(this, r);
|
|
29
|
+
if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
|
|
30
|
+
return r.toString();
|
|
31
|
+
var e = "";
|
|
32
|
+
for (var o in r)
|
|
33
|
+
s.call(r, o) && r[o] && (e = i(e, this && this[o] || o));
|
|
34
|
+
return e;
|
|
35
|
+
}
|
|
36
|
+
function i(r, e) {
|
|
37
|
+
return e ? r ? r + " " + e : r + e : r;
|
|
38
|
+
}
|
|
39
|
+
t.exports ? (n.default = n, t.exports = n) : window.classNames = n;
|
|
40
|
+
})();
|
|
41
|
+
})(tr);
|
|
42
|
+
var yr = tr.exports;
|
|
43
|
+
const er = /* @__PURE__ */ gr(yr), wr = {
|
|
44
|
+
"purpur-autocomplete": "_purpur-autocomplete_19u9x_1",
|
|
45
|
+
"purpur-autocomplete__listbox": "_purpur-autocomplete__listbox_19u9x_4"
|
|
46
|
+
};
|
|
47
|
+
function Ar(t) {
|
|
48
|
+
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
49
|
+
}
|
|
50
|
+
var ar = { exports: {} };
|
|
51
|
+
/*!
|
|
52
|
+
Copyright (c) 2018 Jed Watson.
|
|
53
|
+
Licensed under the MIT License (MIT), see
|
|
54
|
+
http://jedwatson.github.io/classnames
|
|
55
|
+
*/
|
|
56
|
+
(function(t) {
|
|
57
|
+
(function() {
|
|
58
|
+
var s = {}.hasOwnProperty;
|
|
59
|
+
function n() {
|
|
60
|
+
for (var r = "", e = 0; e < arguments.length; e++) {
|
|
61
|
+
var o = arguments[e];
|
|
62
|
+
o && (r = i(r, l.call(this, o)));
|
|
63
|
+
}
|
|
64
|
+
return r;
|
|
65
|
+
}
|
|
66
|
+
function l(r) {
|
|
67
|
+
if (typeof r == "string" || typeof r == "number")
|
|
68
|
+
return this && this[r] || r;
|
|
69
|
+
if (typeof r != "object")
|
|
70
|
+
return "";
|
|
71
|
+
if (Array.isArray(r))
|
|
72
|
+
return n.apply(this, r);
|
|
73
|
+
if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
|
|
74
|
+
return r.toString();
|
|
75
|
+
var e = "";
|
|
76
|
+
for (var o in r)
|
|
77
|
+
s.call(r, o) && r[o] && (e = i(e, this && this[o] || o));
|
|
78
|
+
return e;
|
|
79
|
+
}
|
|
80
|
+
function i(r, e) {
|
|
81
|
+
return e ? r ? r + " " + e : r + e : r;
|
|
82
|
+
}
|
|
83
|
+
t.exports ? (n.default = n, t.exports = n) : window.classNames = n;
|
|
84
|
+
})();
|
|
85
|
+
})(ar);
|
|
86
|
+
var Rr = ar.exports;
|
|
87
|
+
const $r = /* @__PURE__ */ Ar(Rr), Ir = {
|
|
88
|
+
"purpur-icon": "_purpur-icon_8u1lq_1",
|
|
89
|
+
"purpur-icon--xxs": "_purpur-icon--xxs_8u1lq_4",
|
|
90
|
+
"purpur-icon--xs": "_purpur-icon--xs_8u1lq_8",
|
|
91
|
+
"purpur-icon--sm": "_purpur-icon--sm_8u1lq_12",
|
|
92
|
+
"purpur-icon--md": "_purpur-icon--md_8u1lq_16",
|
|
93
|
+
"purpur-icon--lg": "_purpur-icon--lg_8u1lq_20",
|
|
94
|
+
"purpur-icon--xl": "_purpur-icon--xl_8u1lq_24"
|
|
95
|
+
}, Lr = {
|
|
96
|
+
name: "checkmark",
|
|
97
|
+
svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M21.06 3.795a.9.9 0 0 1 .145 1.264l-11.5 14.5a.9.9 0 0 1-1.341.077l-6-6a.9.9 0 0 1 1.272-1.272l5.286 5.286L19.795 3.94a.9.9 0 0 1 1.264-.145Z" clip-rule="evenodd"/></svg>',
|
|
98
|
+
keywords: ["checkmark"],
|
|
99
|
+
category: "utility"
|
|
100
|
+
}, Er = $r.bind(Ir), J = "purpur-icon", Nr = "md", Pr = (t) => t.filter((s) => Object.keys(s).length >= 1).map((s) => `${s.name}="${s.value}"`).join(" "), Sr = ({ content: t = "", title: s } = {}) => {
|
|
101
|
+
const n = [
|
|
102
|
+
{ name: "xmlns", value: "http://www.w3.org/2000/svg" },
|
|
103
|
+
{ name: "fill", value: "currentColor" },
|
|
104
|
+
{ name: "viewBox", value: "0 0 24 24" },
|
|
105
|
+
s ? { name: "role", value: "img" } : { name: "aria-hidden", value: "true" }
|
|
106
|
+
], l = s ? `<title>${s}</title>` : "";
|
|
107
|
+
return `<svg ${Pr(n)}>${l}${t}</svg>`;
|
|
108
|
+
}, Cr = (t) => t.replace(/<(\/?)svg([^>]*)>/g, "").trim(), Br = ({
|
|
109
|
+
["data-testid"]: t,
|
|
110
|
+
svg: s,
|
|
111
|
+
allyTitle: n,
|
|
112
|
+
className: l = "",
|
|
113
|
+
size: i = Nr,
|
|
114
|
+
...r
|
|
115
|
+
}) => {
|
|
116
|
+
const e = Sr({
|
|
117
|
+
content: Cr(s.svg),
|
|
118
|
+
title: n
|
|
119
|
+
}), o = Er(l, J, `${J}--${i}`);
|
|
120
|
+
return /* @__PURE__ */ y(
|
|
121
|
+
"span",
|
|
122
|
+
{
|
|
123
|
+
"aria-label": n,
|
|
124
|
+
className: o,
|
|
125
|
+
"data-testid": t,
|
|
126
|
+
dangerouslySetInnerHTML: { __html: e },
|
|
127
|
+
...r
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
function Dr(t) {
|
|
132
|
+
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
133
|
+
}
|
|
134
|
+
var nr = { exports: {} };
|
|
135
|
+
/*!
|
|
136
|
+
Copyright (c) 2018 Jed Watson.
|
|
137
|
+
Licensed under the MIT License (MIT), see
|
|
138
|
+
http://jedwatson.github.io/classnames
|
|
139
|
+
*/
|
|
140
|
+
(function(t) {
|
|
141
|
+
(function() {
|
|
142
|
+
var s = {}.hasOwnProperty;
|
|
143
|
+
function n() {
|
|
144
|
+
for (var r = "", e = 0; e < arguments.length; e++) {
|
|
145
|
+
var o = arguments[e];
|
|
146
|
+
o && (r = i(r, l(o)));
|
|
147
|
+
}
|
|
148
|
+
return r;
|
|
149
|
+
}
|
|
150
|
+
function l(r) {
|
|
151
|
+
if (typeof r == "string" || typeof r == "number")
|
|
152
|
+
return r;
|
|
153
|
+
if (typeof r != "object")
|
|
154
|
+
return "";
|
|
155
|
+
if (Array.isArray(r))
|
|
156
|
+
return n.apply(null, r);
|
|
157
|
+
if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
|
|
158
|
+
return r.toString();
|
|
159
|
+
var e = "";
|
|
160
|
+
for (var o in r)
|
|
161
|
+
s.call(r, o) && r[o] && (e = i(e, o));
|
|
162
|
+
return e;
|
|
163
|
+
}
|
|
164
|
+
function i(r, e) {
|
|
165
|
+
return e ? r ? r + " " + e : r + e : r;
|
|
166
|
+
}
|
|
167
|
+
t.exports ? (n.default = n, t.exports = n) : window.classNames = n;
|
|
168
|
+
})();
|
|
169
|
+
})(nr);
|
|
170
|
+
var kr = nr.exports;
|
|
171
|
+
const Mr = /* @__PURE__ */ Dr(kr), $ = {
|
|
172
|
+
"purpur-paragraph": "_purpur-paragraph_1rh57_1",
|
|
173
|
+
"purpur-paragraph--disabled": "_purpur-paragraph--disabled_1rh57_7",
|
|
174
|
+
"purpur-paragraph--hyphens": "_purpur-paragraph--hyphens_1rh57_10",
|
|
175
|
+
"purpur-paragraph--negative": "_purpur-paragraph--negative_1rh57_13",
|
|
176
|
+
"purpur-paragraph--paragraph-100": "_purpur-paragraph--paragraph-100_1rh57_16",
|
|
177
|
+
"purpur-paragraph--paragraph-100-medium": "_purpur-paragraph--paragraph-100-medium_1rh57_22",
|
|
178
|
+
"purpur-paragraph--paragraph-100-bold": "_purpur-paragraph--paragraph-100-bold_1rh57_29",
|
|
179
|
+
"purpur-paragraph--paragraph-200": "_purpur-paragraph--paragraph-200_1rh57_36",
|
|
180
|
+
"purpur-paragraph--preamble-100": "_purpur-paragraph--preamble-100_1rh57_42",
|
|
181
|
+
"purpur-paragraph--preamble-200": "_purpur-paragraph--preamble-200_1rh57_48",
|
|
182
|
+
"purpur-paragraph--additional-100": "_purpur-paragraph--additional-100_1rh57_54",
|
|
183
|
+
"purpur-paragraph--additional-100-medium": "_purpur-paragraph--additional-100-medium_1rh57_60",
|
|
184
|
+
"purpur-paragraph--overline-100": "_purpur-paragraph--overline-100_1rh57_67",
|
|
185
|
+
"purpur-paragraph--overline-200": "_purpur-paragraph--overline-200_1rh57_75"
|
|
186
|
+
}, jr = {
|
|
187
|
+
PARAGRAPH100: "paragraph-100",
|
|
188
|
+
PARAGRAPH100MEDIUM: "paragraph-100-medium",
|
|
189
|
+
PARAGRAPH100BOLD: "paragraph-100-bold",
|
|
190
|
+
PARAGRAPH200: "paragraph-200",
|
|
191
|
+
PREAMBLE100: "preamble-100",
|
|
192
|
+
PREAMBLE200: "preamble-200",
|
|
193
|
+
ADDITIONAL100: "additional-100",
|
|
194
|
+
ADDITIONAL100MEDIUM: "additional-100-medium",
|
|
195
|
+
OVERLINE100: "overline-100",
|
|
196
|
+
OVERLINE200: "overline-200"
|
|
197
|
+
}, I = "purpur-paragraph", qr = ({
|
|
198
|
+
["data-testid"]: t,
|
|
199
|
+
children: s,
|
|
200
|
+
className: n = "",
|
|
201
|
+
disabled: l,
|
|
202
|
+
enableHyphenation: i = !1,
|
|
203
|
+
negative: r = !1,
|
|
204
|
+
variant: e = jr.PARAGRAPH100,
|
|
205
|
+
...o
|
|
206
|
+
}) => {
|
|
207
|
+
const _ = Mr([
|
|
208
|
+
n,
|
|
209
|
+
$[I],
|
|
210
|
+
$[`${I}--${e}`],
|
|
211
|
+
{
|
|
212
|
+
[$[`${I}--hyphens`]]: i,
|
|
213
|
+
[$[`${I}--disabled`]]: l,
|
|
214
|
+
[$[`${I}--negative`]]: r
|
|
215
|
+
}
|
|
216
|
+
]);
|
|
217
|
+
return /* @__PURE__ */ y("p", { ...o, className: _, "data-testid": t, children: s });
|
|
218
|
+
}, Tr = {
|
|
219
|
+
"purpur-listbox": "_purpur-listbox_qhoi7_1",
|
|
220
|
+
"purpur-listbox-item": "_purpur-listbox-item_qhoi7_15",
|
|
221
|
+
"purpur-listbox-item--hovered": "_purpur-listbox-item--hovered_qhoi7_29",
|
|
222
|
+
"purpur-listbox-item--highlighted": "_purpur-listbox-item--highlighted_qhoi7_37",
|
|
223
|
+
"purpur-listbox-item--noninteractive": "_purpur-listbox-item--noninteractive_qhoi7_41",
|
|
224
|
+
"purpur-listbox-item--disabled": "_purpur-listbox-item--disabled_qhoi7_44",
|
|
225
|
+
"purpur-listbox-item__icon": "_purpur-listbox-item__icon_qhoi7_51"
|
|
226
|
+
}, Vr = (t) => S(t), Kr = (t, s) => {
|
|
227
|
+
const n = hr(
|
|
228
|
+
(l) => {
|
|
229
|
+
t && !t.contains(l.target) && s();
|
|
230
|
+
},
|
|
231
|
+
[s, t]
|
|
232
|
+
);
|
|
233
|
+
br(() => (document.addEventListener("mousedown", n), () => {
|
|
234
|
+
document.removeEventListener("mousedown", n);
|
|
235
|
+
}), [n]);
|
|
236
|
+
}, Or = ({
|
|
237
|
+
highlightFirstOption: t,
|
|
238
|
+
defaultInputValue: s,
|
|
239
|
+
inputValue: n,
|
|
240
|
+
filterOption: l,
|
|
241
|
+
id: i,
|
|
242
|
+
listboxLabel: r,
|
|
243
|
+
listboxMaxHeight: e,
|
|
244
|
+
onInputChange: o,
|
|
245
|
+
openOnFocus: _,
|
|
246
|
+
noOptionsText: w,
|
|
247
|
+
onSelect: A,
|
|
248
|
+
options: h,
|
|
249
|
+
selectedOption: c,
|
|
250
|
+
["data-testid"]: L
|
|
251
|
+
}) => {
|
|
252
|
+
const [V, m] = M(
|
|
253
|
+
(typeof n == "string" ? n : s) || (c == null ? void 0 : c.label)
|
|
254
|
+
), E = typeof n == "string" ? n : V, [u, b] = M(t ? h[0] : void 0), C = S(null), K = Vr(null), O = S(null), N = S({}), [H, U] = M(!1);
|
|
255
|
+
function B(a) {
|
|
256
|
+
return L ? `${L}-${a}` : void 0;
|
|
257
|
+
}
|
|
258
|
+
const P = () => {
|
|
259
|
+
U(!1), b(void 0);
|
|
260
|
+
};
|
|
261
|
+
Kr(K.current, P);
|
|
262
|
+
const R = ({ eventType: a }) => {
|
|
263
|
+
U(!0), c && requestAnimationFrame(() => {
|
|
264
|
+
b({ ...c, isSetByClickEvent: a === "CLICK" }), D(N.current[c.id]);
|
|
265
|
+
});
|
|
266
|
+
}, sr = (a) => {
|
|
267
|
+
if (l)
|
|
268
|
+
return h.filter((d) => l(a, d));
|
|
269
|
+
if (!a)
|
|
270
|
+
return h;
|
|
271
|
+
const p = a.toUpperCase().split(" ") || [];
|
|
272
|
+
return h.filter(
|
|
273
|
+
(d) => p.every(
|
|
274
|
+
(f) => (d.value || d.label).toUpperCase().includes(f)
|
|
275
|
+
)
|
|
276
|
+
);
|
|
277
|
+
}, G = (a) => c && (c == null ? void 0 : c.label) === a ? h : sr(a), v = G(E), Y = (a) => {
|
|
278
|
+
o == null || o(a), m(a);
|
|
279
|
+
}, D = (a) => {
|
|
280
|
+
var p;
|
|
281
|
+
if (a) {
|
|
282
|
+
const d = a.getBoundingClientRect(), f = ((p = O.current) == null ? void 0 : p.getBoundingClientRect()) || { top: 0, bottom: 0 };
|
|
283
|
+
(d.top < f.top || d.bottom > f.bottom) && a.scrollIntoView({ block: "nearest" });
|
|
284
|
+
}
|
|
285
|
+
}, z = (a) => {
|
|
286
|
+
var p;
|
|
287
|
+
a && ((p = C.current) == null || p.focus(), Y(a.label), A == null || A(a)), P();
|
|
288
|
+
}, ur = (a) => {
|
|
289
|
+
const p = t && !u ? 0 : v.findIndex((f) => f && (u == null ? void 0 : u.id) === f.id), d = v.length;
|
|
290
|
+
return a === "ArrowDown" ? v[(p ?? -1) + 1] || v[0] : v[(p ?? d) - 1] || v[d - 1];
|
|
291
|
+
}, x = H && (!!v.length || !!w), ir = (a) => {
|
|
292
|
+
!x && R({ eventType: "KEYBOARD" });
|
|
293
|
+
const p = ur(a);
|
|
294
|
+
b(p), p && D(N.current[p.id]);
|
|
295
|
+
}, pr = (a) => {
|
|
296
|
+
switch (a.key) {
|
|
297
|
+
case "ArrowUp":
|
|
298
|
+
case "ArrowDown":
|
|
299
|
+
a.preventDefault(), ir(a.key);
|
|
300
|
+
break;
|
|
301
|
+
case "Enter": {
|
|
302
|
+
const p = u || (t ? h[0] : void 0);
|
|
303
|
+
x && z(p), !x && R({ eventType: "KEYBOARD" });
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
case "Escape":
|
|
307
|
+
case "Tab":
|
|
308
|
+
P();
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
}, lr = (a) => {
|
|
312
|
+
const p = G(a.target.value);
|
|
313
|
+
Y(a.target.value), b(void 0), !x && R({ eventType: "KEYBOARD" }), t && p[0] && D(N.current[p[0].id]);
|
|
314
|
+
}, cr = () => {
|
|
315
|
+
x ? P() : R({ eventType: "CLICK" });
|
|
316
|
+
}, dr = () => {
|
|
317
|
+
var a;
|
|
318
|
+
!H && _ && R({ eventType: "KEYBOARD" }), (a = C.current) == null || a.select();
|
|
319
|
+
}, mr = {
|
|
320
|
+
maxHeight: typeof e == "number" ? `${e}px` : e
|
|
321
|
+
}, F = {
|
|
322
|
+
"aria-label": r,
|
|
323
|
+
"aria-expanded": x,
|
|
324
|
+
"data-testid": B("listbox"),
|
|
325
|
+
id: `${i}-listbox`,
|
|
326
|
+
ref: O,
|
|
327
|
+
onMouseLeave: () => b(void 0),
|
|
328
|
+
style: e ? mr : void 0
|
|
329
|
+
}, Z = (a) => `${i}-listbox-item-${a.id}`, _r = (a, p) => {
|
|
330
|
+
const d = () => a.id !== (u == null ? void 0 : u.id) && b({ ...a, isSetByClickEvent: !0 }), f = (a.id === (u == null ? void 0 : u.id) || !!t && !u && p === 0) && !(u != null && u.isSetByClickEvent);
|
|
331
|
+
return {
|
|
332
|
+
"data-testid": B(`listbox-item-${a.id}`),
|
|
333
|
+
id: Z(a),
|
|
334
|
+
key: a.id,
|
|
335
|
+
onMouseMove: d,
|
|
336
|
+
onMouseUp: () => z(a),
|
|
337
|
+
ref: (k) => k && (N.current[a.id] = k),
|
|
338
|
+
tabIndex: -1,
|
|
339
|
+
selected: a.id === (c == null ? void 0 : c.id),
|
|
340
|
+
disabled: a.disabled,
|
|
341
|
+
highlighted: f,
|
|
342
|
+
hovered: a.id === (u == null ? void 0 : u.id) && !!(u != null && u.isSetByClickEvent)
|
|
343
|
+
};
|
|
344
|
+
}, fr = {
|
|
345
|
+
"aria-activedescendant": u ? Z(u) : void 0,
|
|
346
|
+
"aria-autocomplete": "list",
|
|
347
|
+
"aria-controls": F.id,
|
|
348
|
+
"aria-expanded": x,
|
|
349
|
+
"data-testid": B("input"),
|
|
350
|
+
autoComplete: "off",
|
|
351
|
+
id: `${i}-input`,
|
|
352
|
+
onChange: lr,
|
|
353
|
+
onMouseDown: cr,
|
|
354
|
+
onFocus: dr,
|
|
355
|
+
onKeyDown: pr,
|
|
356
|
+
ref: C,
|
|
357
|
+
role: "combobox",
|
|
358
|
+
value: E
|
|
359
|
+
};
|
|
360
|
+
return {
|
|
361
|
+
id: i,
|
|
362
|
+
inputProps: fr,
|
|
363
|
+
internalRef: K,
|
|
364
|
+
optionsToShow: v,
|
|
365
|
+
showListbox: x,
|
|
366
|
+
noOptionsText: w,
|
|
367
|
+
getListBoxItemProps: _r,
|
|
368
|
+
listboxProps: F
|
|
369
|
+
};
|
|
370
|
+
}, j = er.bind(Tr), g = "purpur-listbox", or = q(
|
|
371
|
+
({ children: t, ...s }, n) => /* @__PURE__ */ y(
|
|
372
|
+
"ul",
|
|
373
|
+
{
|
|
374
|
+
...s,
|
|
375
|
+
ref: n,
|
|
376
|
+
className: j(g, s.className),
|
|
377
|
+
role: "listbox",
|
|
378
|
+
children: vr.toArray(t).filter(Hr)
|
|
379
|
+
}
|
|
380
|
+
)
|
|
381
|
+
);
|
|
382
|
+
or.displayName = "ListBox";
|
|
383
|
+
const T = q((t, s) => {
|
|
384
|
+
const { disabled: n, highlighted: l, hovered: i, selected: r, children: e, noninteractive: o, ..._ } = t, w = j(`${g}-item`, _.className, {
|
|
385
|
+
[`${g}-item--highlighted`]: l,
|
|
386
|
+
[`${g}-item--selected`]: r,
|
|
387
|
+
[`${g}-item--hovered`]: i,
|
|
388
|
+
[`${g}-item--disabled`]: n,
|
|
389
|
+
[`${g}-item--noninteractive`]: o
|
|
390
|
+
});
|
|
391
|
+
return /* @__PURE__ */ rr(
|
|
392
|
+
"li",
|
|
393
|
+
{
|
|
394
|
+
..._,
|
|
395
|
+
ref: s,
|
|
396
|
+
className: w,
|
|
397
|
+
"aria-selected": !!r,
|
|
398
|
+
role: "option",
|
|
399
|
+
"aria-disabled": !!n,
|
|
400
|
+
children: [
|
|
401
|
+
typeof e == "string" ? /* @__PURE__ */ y(qr, { children: e }) : e,
|
|
402
|
+
r && /* @__PURE__ */ y(Br, { svg: Lr, size: "xs", className: j(`${g}-item__icon`) })
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
);
|
|
406
|
+
});
|
|
407
|
+
T.displayName = "ListBoxItem";
|
|
408
|
+
function Hr(t) {
|
|
409
|
+
return xr(t) && (t == null ? void 0 : t.type) === T;
|
|
410
|
+
}
|
|
411
|
+
const Ur = or, Q = T, W = er.bind(wr), X = "purpur-autocomplete", Gr = ({ className: t, renderInput: s, renderOption: n, ...l }, i) => {
|
|
412
|
+
const {
|
|
413
|
+
id: r,
|
|
414
|
+
inputProps: e,
|
|
415
|
+
internalRef: o,
|
|
416
|
+
optionsToShow: _,
|
|
417
|
+
showListbox: w,
|
|
418
|
+
noOptionsText: A,
|
|
419
|
+
getListBoxItemProps: h,
|
|
420
|
+
listboxProps: c
|
|
421
|
+
} = Or(l), L = (m, E) => {
|
|
422
|
+
const { key: u, ...b } = h(m, E);
|
|
423
|
+
return /* @__PURE__ */ y(Q, { ...b, children: n ? n == null ? void 0 : n(m) : m.label }, u);
|
|
424
|
+
};
|
|
425
|
+
return /* @__PURE__ */ rr("div", { id: r, ref: (m) => {
|
|
426
|
+
o.current = m, typeof i == "function" ? i(m) : i && (i.current = m);
|
|
427
|
+
}, className: W([t, X]), children: [
|
|
428
|
+
s(e),
|
|
429
|
+
w && /* @__PURE__ */ y(Ur, { ...c, className: W(`${X}__listbox`), children: _.length ? _.filter((m) => !!m).map(L) : /* @__PURE__ */ y(Q, { noninteractive: !0, children: A }) })
|
|
430
|
+
] });
|
|
431
|
+
}, Yr = q(Gr);
|
|
432
|
+
Yr.displayName = "Autocomplete";
|
|
433
|
+
export {
|
|
434
|
+
Yr as Autocomplete,
|
|
435
|
+
Or as useAutocomplete
|
|
436
|
+
};
|
|
437
|
+
//# sourceMappingURL=autocomplete.es.js.map
|