@glob-ui/combobox 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/index.d.mts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +320 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +294 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kevin Martínez E
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glob-ui/combobox
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A text input with a filtered list: type to search, arrows to move, Enter to choose. The API mirrors Select.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @glob-ui/combobox
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
Full docs, examples and the accessibility table: [Combobox](https://github.com/kevin-martineze/GlobUI/tree/main/apps/docs/content/docs/components/combobox.mdx).
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
MIT. See [LICENSE](./LICENSE).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface ComboboxOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
/** A second, muted line under the label. Searched too. */
|
|
8
|
+
description?: string;
|
|
9
|
+
}
|
|
10
|
+
interface ComboboxProps {
|
|
11
|
+
options: ComboboxOption[];
|
|
12
|
+
/** Selected option value, or `null` for none. */
|
|
13
|
+
value?: string | null;
|
|
14
|
+
defaultValue?: string | null;
|
|
15
|
+
/** Called with the selected value, or `null` when cleared. */
|
|
16
|
+
onChange?: (value: string | null) => void;
|
|
17
|
+
/** The text in the field. Pass it (with onInputChange) to search on a server. */
|
|
18
|
+
inputValue?: string;
|
|
19
|
+
onInputChange?: (text: string) => void;
|
|
20
|
+
/** Commit the typed text as the value when no option is active (Enter), or on blur. */
|
|
21
|
+
allowCustomValue?: boolean;
|
|
22
|
+
/** `false`: the consumer filters `options` itself. A function: `(option, query) => boolean`. Default: accent-insensitive word match on label, value and description. */
|
|
23
|
+
filter?: false | ((option: ComboboxOption, query: string) => boolean);
|
|
24
|
+
/** Shows a "Loading…" row with a spinner under the options, announced to screen readers. */
|
|
25
|
+
loading?: boolean;
|
|
26
|
+
/** Shown when nothing matches. Default "No results.". */
|
|
27
|
+
emptyMessage?: React.ReactNode;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
/** Submitted with native forms through a hidden input. */
|
|
31
|
+
name?: string;
|
|
32
|
+
/** Shows an X button while there is text. Default true. */
|
|
33
|
+
clearable?: boolean;
|
|
34
|
+
size?: "sm" | "md" | "lg";
|
|
35
|
+
className?: string;
|
|
36
|
+
id?: string;
|
|
37
|
+
"aria-invalid"?: boolean | "true" | "false";
|
|
38
|
+
"aria-describedby"?: string;
|
|
39
|
+
"aria-labelledby"?: string;
|
|
40
|
+
"aria-label"?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An editable combobox (WAI-ARIA list autocomplete). Focus stays in the input; the active option is
|
|
44
|
+
* announced through aria-activedescendant.
|
|
45
|
+
*/
|
|
46
|
+
declare function Combobox({ options, value, defaultValue, onChange, inputValue, onInputChange, allowCustomValue, filter, loading, emptyMessage, placeholder, disabled, name, clearable, size, className, id, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, "aria-labelledby": ariaLabelledBy, "aria-label": ariaLabel, }: ComboboxProps): react_jsx_runtime.JSX.Element;
|
|
47
|
+
|
|
48
|
+
export { Combobox, type ComboboxOption, type ComboboxProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface ComboboxOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
/** A second, muted line under the label. Searched too. */
|
|
8
|
+
description?: string;
|
|
9
|
+
}
|
|
10
|
+
interface ComboboxProps {
|
|
11
|
+
options: ComboboxOption[];
|
|
12
|
+
/** Selected option value, or `null` for none. */
|
|
13
|
+
value?: string | null;
|
|
14
|
+
defaultValue?: string | null;
|
|
15
|
+
/** Called with the selected value, or `null` when cleared. */
|
|
16
|
+
onChange?: (value: string | null) => void;
|
|
17
|
+
/** The text in the field. Pass it (with onInputChange) to search on a server. */
|
|
18
|
+
inputValue?: string;
|
|
19
|
+
onInputChange?: (text: string) => void;
|
|
20
|
+
/** Commit the typed text as the value when no option is active (Enter), or on blur. */
|
|
21
|
+
allowCustomValue?: boolean;
|
|
22
|
+
/** `false`: the consumer filters `options` itself. A function: `(option, query) => boolean`. Default: accent-insensitive word match on label, value and description. */
|
|
23
|
+
filter?: false | ((option: ComboboxOption, query: string) => boolean);
|
|
24
|
+
/** Shows a "Loading…" row with a spinner under the options, announced to screen readers. */
|
|
25
|
+
loading?: boolean;
|
|
26
|
+
/** Shown when nothing matches. Default "No results.". */
|
|
27
|
+
emptyMessage?: React.ReactNode;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
/** Submitted with native forms through a hidden input. */
|
|
31
|
+
name?: string;
|
|
32
|
+
/** Shows an X button while there is text. Default true. */
|
|
33
|
+
clearable?: boolean;
|
|
34
|
+
size?: "sm" | "md" | "lg";
|
|
35
|
+
className?: string;
|
|
36
|
+
id?: string;
|
|
37
|
+
"aria-invalid"?: boolean | "true" | "false";
|
|
38
|
+
"aria-describedby"?: string;
|
|
39
|
+
"aria-labelledby"?: string;
|
|
40
|
+
"aria-label"?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An editable combobox (WAI-ARIA list autocomplete). Focus stays in the input; the active option is
|
|
44
|
+
* announced through aria-activedescendant.
|
|
45
|
+
*/
|
|
46
|
+
declare function Combobox({ options, value, defaultValue, onChange, inputValue, onInputChange, allowCustomValue, filter, loading, emptyMessage, placeholder, disabled, name, clearable, size, className, id, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, "aria-labelledby": ariaLabelledBy, "aria-label": ariaLabel, }: ComboboxProps): react_jsx_runtime.JSX.Element;
|
|
47
|
+
|
|
48
|
+
export { Combobox, type ComboboxOption, type ComboboxProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
Combobox: () => Combobox
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/combobox.tsx
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
var import_utils = require("@glob-ui/utils");
|
|
31
|
+
var import_hooks = require("@glob-ui/hooks");
|
|
32
|
+
var import_input = require("@glob-ui/input");
|
|
33
|
+
var import_spinner = require("@glob-ui/spinner");
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
var CUSTOM_KEY = "\0custom";
|
|
36
|
+
function highlight(label, query) {
|
|
37
|
+
const q = query.trim();
|
|
38
|
+
if (!q) return label;
|
|
39
|
+
const index = label.toLowerCase().indexOf(q.toLowerCase());
|
|
40
|
+
if (index < 0) return label;
|
|
41
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
42
|
+
label.slice(0, index),
|
|
43
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("mark", { className: "bg-transparent font-semibold text-glob-text", children: label.slice(index, index + q.length) }),
|
|
44
|
+
label.slice(index + q.length)
|
|
45
|
+
] });
|
|
46
|
+
}
|
|
47
|
+
function Combobox({
|
|
48
|
+
options,
|
|
49
|
+
value,
|
|
50
|
+
defaultValue = null,
|
|
51
|
+
onChange,
|
|
52
|
+
inputValue,
|
|
53
|
+
onInputChange,
|
|
54
|
+
allowCustomValue = false,
|
|
55
|
+
filter,
|
|
56
|
+
loading = false,
|
|
57
|
+
emptyMessage = "No results.",
|
|
58
|
+
placeholder,
|
|
59
|
+
disabled = false,
|
|
60
|
+
name,
|
|
61
|
+
clearable = true,
|
|
62
|
+
size,
|
|
63
|
+
className,
|
|
64
|
+
id,
|
|
65
|
+
"aria-invalid": ariaInvalid,
|
|
66
|
+
"aria-describedby": ariaDescribedBy,
|
|
67
|
+
"aria-labelledby": ariaLabelledBy,
|
|
68
|
+
"aria-label": ariaLabel
|
|
69
|
+
}) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
const baseId = (0, import_react.useId)();
|
|
72
|
+
const inputId = id != null ? id : `${baseId}-input`;
|
|
73
|
+
const listId = `${baseId}-listbox`;
|
|
74
|
+
const inputRef = (0, import_react.useRef)(null);
|
|
75
|
+
const [selected, setSelected] = (0, import_hooks.useControllableState)(value, defaultValue, onChange);
|
|
76
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
77
|
+
const [typed, setTyped] = (0, import_react.useState)(null);
|
|
78
|
+
const controlledText = inputValue !== void 0;
|
|
79
|
+
const selectedOption = options.find((o) => o.value === selected);
|
|
80
|
+
const selectedLabel = (_b = (_a = selectedOption == null ? void 0 : selectedOption.label) != null ? _a : selected) != null ? _b : "";
|
|
81
|
+
const text = controlledText ? inputValue : typed != null ? typed : selectedLabel;
|
|
82
|
+
const query = controlledText ? inputValue : typed != null ? typed : "";
|
|
83
|
+
function setText(next) {
|
|
84
|
+
if (!controlledText) setTyped(next);
|
|
85
|
+
onInputChange == null ? void 0 : onInputChange(next);
|
|
86
|
+
}
|
|
87
|
+
const visible = (0, import_react.useMemo)(() => {
|
|
88
|
+
if (filter === false) return options;
|
|
89
|
+
const match = filter != null ? filter : ((o, q) => {
|
|
90
|
+
var _a2;
|
|
91
|
+
return (0, import_utils.matchesSearch)(q, o.label, o.value, (_a2 = o.description) != null ? _a2 : "");
|
|
92
|
+
});
|
|
93
|
+
return options.filter((o) => match(o, query));
|
|
94
|
+
}, [options, filter, query]);
|
|
95
|
+
const trimmed = text.trim();
|
|
96
|
+
const hasExact = options.some((o) => (0, import_utils.normalizeText)(o.label) === (0, import_utils.normalizeText)(trimmed));
|
|
97
|
+
const rows = [
|
|
98
|
+
...visible.map((option) => ({ key: option.value, label: option.label, disabled: option.disabled, option })),
|
|
99
|
+
...allowCustomValue && trimmed !== "" && !hasExact ? [{ key: CUSTOM_KEY, label: trimmed }] : []
|
|
100
|
+
];
|
|
101
|
+
const listbox = (0, import_hooks.useListbox)({
|
|
102
|
+
id: baseId,
|
|
103
|
+
items: rows,
|
|
104
|
+
getKey: (row) => row.key,
|
|
105
|
+
getText: (row) => row.label,
|
|
106
|
+
isDisabled: (row) => Boolean(row.disabled),
|
|
107
|
+
open
|
|
108
|
+
});
|
|
109
|
+
const { setTrigger, setPanel, floatingStyles } = (0, import_hooks.useFloatingPanel)({
|
|
110
|
+
open,
|
|
111
|
+
onOpenChange: setOpen,
|
|
112
|
+
placement: "bottom-start",
|
|
113
|
+
offset: 4,
|
|
114
|
+
matchTriggerWidth: true,
|
|
115
|
+
// Focus stays in the input, so the browser must not return focus on close.
|
|
116
|
+
restoreFocus: false
|
|
117
|
+
});
|
|
118
|
+
function openList(active) {
|
|
119
|
+
if (disabled) return;
|
|
120
|
+
listbox.setActiveKey(active);
|
|
121
|
+
setOpen(true);
|
|
122
|
+
}
|
|
123
|
+
function commitValue(next, label) {
|
|
124
|
+
setSelected(next);
|
|
125
|
+
setTyped(null);
|
|
126
|
+
setOpen(false);
|
|
127
|
+
if (controlledText) onInputChange == null ? void 0 : onInputChange(label);
|
|
128
|
+
}
|
|
129
|
+
function commitRow(row) {
|
|
130
|
+
if (row.key === CUSTOM_KEY) commitValue(row.label, row.label);
|
|
131
|
+
else if (row.option) commitValue(row.option.value, row.option.label);
|
|
132
|
+
}
|
|
133
|
+
function clear() {
|
|
134
|
+
var _a2;
|
|
135
|
+
setSelected(null);
|
|
136
|
+
setText("");
|
|
137
|
+
setOpen(false);
|
|
138
|
+
(_a2 = inputRef.current) == null ? void 0 : _a2.focus();
|
|
139
|
+
}
|
|
140
|
+
function onBlur() {
|
|
141
|
+
setOpen(false);
|
|
142
|
+
if (allowCustomValue) {
|
|
143
|
+
if (trimmed === "") {
|
|
144
|
+
if (selected !== null) commitValue(null, "");
|
|
145
|
+
else setText("");
|
|
146
|
+
} else if (trimmed !== selected) {
|
|
147
|
+
commitValue(trimmed, trimmed);
|
|
148
|
+
} else {
|
|
149
|
+
setTyped(null);
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
setTyped(null);
|
|
154
|
+
if (controlledText && text !== selectedLabel) onInputChange == null ? void 0 : onInputChange(selectedLabel);
|
|
155
|
+
}
|
|
156
|
+
function onKeyDown(e) {
|
|
157
|
+
if (disabled) return;
|
|
158
|
+
if (!open) {
|
|
159
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
openList(selected);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
} else if (listbox.navigate(e, { homeEnd: false })) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (e.key === "Enter" && open) {
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
if (listbox.activeItem) commitRow(listbox.activeItem);
|
|
170
|
+
else if (allowCustomValue && trimmed !== "") commitValue(trimmed, trimmed);
|
|
171
|
+
else setOpen(false);
|
|
172
|
+
} else if (e.key === "Escape") {
|
|
173
|
+
if (open) {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
setOpen(false);
|
|
176
|
+
} else if (text !== "" || selected !== null) {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
clear();
|
|
179
|
+
}
|
|
180
|
+
} else if ((0, import_hooks.isPrintable)(e) && !open) {
|
|
181
|
+
setOpen(true);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const hasText = text !== "";
|
|
185
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_utils.cn)("relative w-full", className), children: [
|
|
186
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref: setTrigger, className: "relative w-full", children: [
|
|
187
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
188
|
+
"input",
|
|
189
|
+
{
|
|
190
|
+
ref: inputRef,
|
|
191
|
+
id: inputId,
|
|
192
|
+
type: "text",
|
|
193
|
+
role: "combobox",
|
|
194
|
+
autoComplete: "off",
|
|
195
|
+
"aria-autocomplete": "list",
|
|
196
|
+
"aria-expanded": open,
|
|
197
|
+
"aria-controls": listId,
|
|
198
|
+
"aria-activedescendant": open ? listbox.activeDescendant : void 0,
|
|
199
|
+
"aria-invalid": ariaInvalid,
|
|
200
|
+
"aria-describedby": ariaDescribedBy,
|
|
201
|
+
"aria-labelledby": ariaLabelledBy,
|
|
202
|
+
"aria-label": ariaLabel,
|
|
203
|
+
"aria-disabled": disabled || void 0,
|
|
204
|
+
disabled,
|
|
205
|
+
placeholder,
|
|
206
|
+
value: text,
|
|
207
|
+
onChange: (e) => {
|
|
208
|
+
setText(e.target.value);
|
|
209
|
+
setOpen(true);
|
|
210
|
+
listbox.setActiveKey(null);
|
|
211
|
+
},
|
|
212
|
+
onClick: () => {
|
|
213
|
+
if (!open) openList(selected);
|
|
214
|
+
},
|
|
215
|
+
onKeyDown,
|
|
216
|
+
onBlur,
|
|
217
|
+
className: (0, import_utils.cn)((0, import_input.inputVariants)({ size }), "pr-16")
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
clearable && hasText && !disabled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
221
|
+
"button",
|
|
222
|
+
{
|
|
223
|
+
type: "button",
|
|
224
|
+
"aria-label": "Clear",
|
|
225
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
226
|
+
onClick: clear,
|
|
227
|
+
className: "absolute right-8 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-glob-sm text-glob-text-secondary hover:bg-glob-surface-hover hover:text-glob-text focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring",
|
|
228
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "h-3.5 w-3.5", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M18 6L6 18M6 6l12 12" }) })
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
232
|
+
"button",
|
|
233
|
+
{
|
|
234
|
+
type: "button",
|
|
235
|
+
"aria-label": "Show options",
|
|
236
|
+
tabIndex: -1,
|
|
237
|
+
disabled,
|
|
238
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
239
|
+
onClick: () => {
|
|
240
|
+
var _a2;
|
|
241
|
+
if (open) setOpen(false);
|
|
242
|
+
else openList(selected);
|
|
243
|
+
(_a2 = inputRef.current) == null ? void 0 : _a2.focus();
|
|
244
|
+
},
|
|
245
|
+
className: "absolute right-2 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center text-glob-text-secondary disabled:opacity-50",
|
|
246
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
247
|
+
"svg",
|
|
248
|
+
{
|
|
249
|
+
"aria-hidden": "true",
|
|
250
|
+
viewBox: "0 0 24 24",
|
|
251
|
+
fill: "none",
|
|
252
|
+
stroke: "currentColor",
|
|
253
|
+
strokeWidth: "2",
|
|
254
|
+
className: (0, import_utils.cn)("h-4 w-4 transition-transform", open && "rotate-180"),
|
|
255
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 9l6 6 6-6" })
|
|
256
|
+
}
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
] }),
|
|
261
|
+
name !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "hidden", name, value: selected != null ? selected : "" }),
|
|
262
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
263
|
+
"div",
|
|
264
|
+
{
|
|
265
|
+
ref: setPanel,
|
|
266
|
+
popover: "manual",
|
|
267
|
+
style: floatingStyles,
|
|
268
|
+
className: (0, import_utils.cn)(
|
|
269
|
+
// Reset the UA popover box (inset:0 + margin:auto would center it).
|
|
270
|
+
"m-0 overflow-visible rounded-glob-md border border-glob-border bg-glob-surface text-sm text-glob-text shadow-glob-md outline-none",
|
|
271
|
+
"opacity-0 transition-[opacity,overlay,display] transition-discrete duration-150 open:opacity-100 starting:open:opacity-0 motion-reduce:transition-none"
|
|
272
|
+
),
|
|
273
|
+
children: [
|
|
274
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { id: listId, role: "listbox", "aria-labelledby": ariaLabelledBy != null ? ariaLabelledBy : inputId, className: "max-h-60 overflow-y-auto p-1", children: rows.map((row) => {
|
|
275
|
+
var _a2;
|
|
276
|
+
const isSelected = row.key !== CUSTOM_KEY && row.key === selected;
|
|
277
|
+
const isActive = listbox.activeKey === row.key;
|
|
278
|
+
const isCustom = row.key === CUSTOM_KEY;
|
|
279
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
280
|
+
"div",
|
|
281
|
+
{
|
|
282
|
+
id: listbox.optionId(row.key),
|
|
283
|
+
role: "option",
|
|
284
|
+
"aria-selected": isSelected,
|
|
285
|
+
"aria-disabled": row.disabled || void 0,
|
|
286
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
287
|
+
onPointerMove: () => {
|
|
288
|
+
if (!row.disabled) listbox.setActiveKey(row.key);
|
|
289
|
+
},
|
|
290
|
+
onClick: () => {
|
|
291
|
+
if (!row.disabled) commitRow(row);
|
|
292
|
+
},
|
|
293
|
+
className: (0, import_utils.cn)(
|
|
294
|
+
"flex w-full cursor-pointer items-center gap-2 rounded-glob-sm px-2 py-2 text-left text-sm select-none",
|
|
295
|
+
row.disabled && "cursor-not-allowed opacity-50",
|
|
296
|
+
isActive && !row.disabled && "bg-glob-surface-hover",
|
|
297
|
+
isSelected && "font-medium"
|
|
298
|
+
),
|
|
299
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "min-w-0 flex-1", children: [
|
|
300
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block truncate", children: isCustom ? `Use "${row.label}"` : highlight(row.label, query) }),
|
|
301
|
+
((_a2 = row.option) == null ? void 0 : _a2.description) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block truncate text-xs text-glob-text-secondary", children: row.option.description })
|
|
302
|
+
] })
|
|
303
|
+
},
|
|
304
|
+
row.key
|
|
305
|
+
);
|
|
306
|
+
}) }),
|
|
307
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { role: "status", "aria-live": "polite", className: "empty:hidden", children: loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2 px-3 py-3 text-sm text-glob-text-secondary", children: [
|
|
308
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { size: "sm", "aria-hidden": "true" }),
|
|
309
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Loading\u2026" })
|
|
310
|
+
] }) : rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-3 py-3 text-sm text-glob-text-secondary", children: emptyMessage }) : null })
|
|
311
|
+
]
|
|
312
|
+
}
|
|
313
|
+
)
|
|
314
|
+
] });
|
|
315
|
+
}
|
|
316
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
317
|
+
0 && (module.exports = {
|
|
318
|
+
Combobox
|
|
319
|
+
});
|
|
320
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/combobox.tsx"],"sourcesContent":["export { Combobox } from \"./combobox\"\nexport type { ComboboxProps, ComboboxOption } from \"./combobox\"\n","\"use client\"\n\nimport { useId, useMemo, useRef, useState } from \"react\"\nimport { cn, matchesSearch, normalizeText } from \"@glob-ui/utils\"\nimport { useControllableState, useFloatingPanel, useListbox, isPrintable } from \"@glob-ui/hooks\"\nimport { inputVariants } from \"@glob-ui/input\"\nimport { Spinner } from \"@glob-ui/spinner\"\n\nexport interface ComboboxOption {\n value: string\n label: string\n disabled?: boolean\n /** A second, muted line under the label. Searched too. */\n description?: string\n}\n\nexport interface ComboboxProps {\n options: ComboboxOption[]\n /** Selected option value, or `null` for none. */\n value?: string | null\n defaultValue?: string | null\n /** Called with the selected value, or `null` when cleared. */\n onChange?: (value: string | null) => void\n /** The text in the field. Pass it (with onInputChange) to search on a server. */\n inputValue?: string\n onInputChange?: (text: string) => void\n /** Commit the typed text as the value when no option is active (Enter), or on blur. */\n allowCustomValue?: boolean\n /** `false`: the consumer filters `options` itself. A function: `(option, query) => boolean`. Default: accent-insensitive word match on label, value and description. */\n filter?: false | ((option: ComboboxOption, query: string) => boolean)\n /** Shows a \"Loading…\" row with a spinner under the options, announced to screen readers. */\n loading?: boolean\n /** Shown when nothing matches. Default \"No results.\". */\n emptyMessage?: React.ReactNode\n placeholder?: string\n disabled?: boolean\n /** Submitted with native forms through a hidden input. */\n name?: string\n /** Shows an X button while there is text. Default true. */\n clearable?: boolean\n size?: \"sm\" | \"md\" | \"lg\"\n className?: string\n id?: string\n \"aria-invalid\"?: boolean | \"true\" | \"false\"\n \"aria-describedby\"?: string\n \"aria-labelledby\"?: string\n \"aria-label\"?: string\n}\n\nconst CUSTOM_KEY = \"\\u0000custom\"\n\ntype Row = { key: string; label: string; disabled?: boolean; option?: ComboboxOption }\n\n/** The label with the first occurrence of the query in `<mark>`. Cosmetic: the name stays the label. */\nfunction highlight(label: string, query: string) {\n const q = query.trim()\n if (!q) return label\n const index = label.toLowerCase().indexOf(q.toLowerCase())\n if (index < 0) return label\n return (\n <>\n {label.slice(0, index)}\n <mark className=\"bg-transparent font-semibold text-glob-text\">{label.slice(index, index + q.length)}</mark>\n {label.slice(index + q.length)}\n </>\n )\n}\n\n/**\n * An editable combobox (WAI-ARIA list autocomplete). Focus stays in the input; the active option is\n * announced through aria-activedescendant.\n */\nexport function Combobox({\n options,\n value,\n defaultValue = null,\n onChange,\n inputValue,\n onInputChange,\n allowCustomValue = false,\n filter,\n loading = false,\n emptyMessage = \"No results.\",\n placeholder,\n disabled = false,\n name,\n clearable = true,\n size,\n className,\n id,\n \"aria-invalid\": ariaInvalid,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-label\": ariaLabel,\n}: ComboboxProps) {\n const baseId = useId()\n const inputId = id ?? `${baseId}-input`\n const listId = `${baseId}-listbox`\n const inputRef = useRef<HTMLInputElement>(null)\n const [selected, setSelected] = useControllableState<string | null>(value, defaultValue, onChange)\n const [open, setOpen] = useState(false)\n // null: not editing, so the field shows the selected label. A string: what the user typed.\n const [typed, setTyped] = useState<string | null>(null)\n const controlledText = inputValue !== undefined\n\n const selectedOption = options.find((o) => o.value === selected)\n const selectedLabel = selectedOption?.label ?? selected ?? \"\"\n const text = controlledText ? inputValue : (typed ?? selectedLabel)\n const query = controlledText ? inputValue : (typed ?? \"\")\n\n function setText(next: string) {\n if (!controlledText) setTyped(next)\n onInputChange?.(next)\n }\n\n const visible = useMemo(() => {\n if (filter === false) return options\n const match = filter ?? ((o: ComboboxOption, q: string) => matchesSearch(q, o.label, o.value, o.description ?? \"\"))\n return options.filter((o) => match(o, query))\n }, [options, filter, query])\n\n const trimmed = text.trim()\n const hasExact = options.some((o) => normalizeText(o.label) === normalizeText(trimmed))\n // The \"Use ...\" row goes last, so with matches the first match stays the active option.\n const rows: Row[] = [\n ...visible.map((option) => ({ key: option.value, label: option.label, disabled: option.disabled, option })),\n ...(allowCustomValue && trimmed !== \"\" && !hasExact ? [{ key: CUSTOM_KEY, label: trimmed }] : []),\n ]\n\n const listbox = useListbox({\n id: baseId,\n items: rows,\n getKey: (row) => row.key,\n getText: (row) => row.label,\n isDisabled: (row) => Boolean(row.disabled),\n open,\n })\n\n const { setTrigger, setPanel, floatingStyles } = useFloatingPanel({\n open,\n onOpenChange: setOpen,\n placement: \"bottom-start\",\n offset: 4,\n matchTriggerWidth: true,\n // Focus stays in the input, so the browser must not return focus on close.\n restoreFocus: false,\n })\n\n function openList(active: string | null) {\n if (disabled) return\n listbox.setActiveKey(active)\n setOpen(true)\n }\n\n function commitValue(next: string | null, label: string) {\n setSelected(next)\n setTyped(null)\n setOpen(false)\n if (controlledText) onInputChange?.(label)\n }\n\n function commitRow(row: Row) {\n if (row.key === CUSTOM_KEY) commitValue(row.label, row.label)\n else if (row.option) commitValue(row.option.value, row.option.label)\n }\n\n function clear() {\n setSelected(null)\n setText(\"\")\n setOpen(false)\n inputRef.current?.focus()\n }\n\n function onBlur() {\n setOpen(false)\n if (allowCustomValue) {\n // The typed text is the value: never leave text that looks selected but is not.\n if (trimmed === \"\") {\n if (selected !== null) commitValue(null, \"\")\n else setText(\"\")\n } else if (trimmed !== selected) {\n commitValue(trimmed, trimmed)\n } else {\n setTyped(null)\n }\n return\n }\n // Not committed: show the selected label again (or nothing).\n setTyped(null)\n if (controlledText && text !== selectedLabel) onInputChange?.(selectedLabel)\n }\n\n function onKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n if (disabled) return\n if (!open) {\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault()\n openList(selected)\n return\n }\n } else if (listbox.navigate(e, { homeEnd: false })) {\n return\n }\n\n if (e.key === \"Enter\" && open) {\n e.preventDefault()\n if (listbox.activeItem) commitRow(listbox.activeItem)\n else if (allowCustomValue && trimmed !== \"\") commitValue(trimmed, trimmed)\n else setOpen(false)\n } else if (e.key === \"Escape\") {\n if (open) {\n e.preventDefault()\n setOpen(false)\n } else if (text !== \"\" || selected !== null) {\n e.preventDefault()\n clear()\n }\n } else if (isPrintable(e) && !open) {\n // Typing opens the list (the change handler filters it).\n setOpen(true)\n }\n }\n\n const hasText = text !== \"\"\n\n return (\n <div className={cn(\"relative w-full\", className)}>\n <div ref={setTrigger} className=\"relative w-full\">\n <input\n ref={inputRef}\n id={inputId}\n type=\"text\"\n role=\"combobox\"\n autoComplete=\"off\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={listId}\n aria-activedescendant={open ? listbox.activeDescendant : undefined}\n aria-invalid={ariaInvalid}\n aria-describedby={ariaDescribedBy}\n aria-labelledby={ariaLabelledBy}\n aria-label={ariaLabel}\n aria-disabled={disabled || undefined}\n disabled={disabled}\n placeholder={placeholder}\n value={text}\n onChange={(e) => {\n setText(e.target.value)\n setOpen(true)\n listbox.setActiveKey(null)\n }}\n onClick={() => {\n if (!open) openList(selected)\n }}\n onKeyDown={onKeyDown}\n onBlur={onBlur}\n className={cn(inputVariants({ size }), \"pr-16\")}\n />\n {clearable && hasText && !disabled && (\n <button\n type=\"button\"\n aria-label=\"Clear\"\n // Keep focus in the input while clicking.\n onMouseDown={(e) => e.preventDefault()}\n onClick={clear}\n className=\"absolute right-8 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-glob-sm text-glob-text-secondary hover:bg-glob-surface-hover hover:text-glob-text focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring\"\n >\n <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" className=\"h-3.5 w-3.5\">\n <path d=\"M18 6L6 18M6 6l12 12\" />\n </svg>\n </button>\n )}\n <button\n type=\"button\"\n aria-label=\"Show options\"\n tabIndex={-1}\n disabled={disabled}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => {\n if (open) setOpen(false)\n else openList(selected)\n inputRef.current?.focus()\n }}\n className=\"absolute right-2 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center text-glob-text-secondary disabled:opacity-50\"\n >\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n className={cn(\"h-4 w-4 transition-transform\", open && \"rotate-180\")}\n >\n <path d=\"M6 9l6 6 6-6\" />\n </svg>\n </button>\n </div>\n\n {name !== undefined && <input type=\"hidden\" name={name} value={selected ?? \"\"} />}\n\n <div\n ref={setPanel}\n popover=\"manual\"\n style={floatingStyles}\n className={cn(\n // Reset the UA popover box (inset:0 + margin:auto would center it).\n \"m-0 overflow-visible rounded-glob-md border border-glob-border bg-glob-surface text-sm text-glob-text shadow-glob-md outline-none\",\n \"opacity-0 transition-[opacity,overlay,display] transition-discrete duration-150 open:opacity-100 starting:open:opacity-0 motion-reduce:transition-none\"\n )}\n >\n <div id={listId} role=\"listbox\" aria-labelledby={ariaLabelledBy ?? inputId} className=\"max-h-60 overflow-y-auto p-1\">\n {rows.map((row) => {\n const isSelected = row.key !== CUSTOM_KEY && row.key === selected\n const isActive = listbox.activeKey === row.key\n const isCustom = row.key === CUSTOM_KEY\n return (\n <div\n key={row.key}\n id={listbox.optionId(row.key)}\n role=\"option\"\n aria-selected={isSelected}\n aria-disabled={row.disabled || undefined}\n onMouseDown={(e) => e.preventDefault()}\n onPointerMove={() => {\n if (!row.disabled) listbox.setActiveKey(row.key)\n }}\n onClick={() => {\n if (!row.disabled) commitRow(row)\n }}\n className={cn(\n \"flex w-full cursor-pointer items-center gap-2 rounded-glob-sm px-2 py-2 text-left text-sm select-none\",\n row.disabled && \"cursor-not-allowed opacity-50\",\n isActive && !row.disabled && \"bg-glob-surface-hover\",\n isSelected && \"font-medium\"\n )}\n >\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate\">\n {isCustom ? `Use \"${row.label}\"` : highlight(row.label, query)}\n </span>\n {row.option?.description && (\n <span className=\"block truncate text-xs text-glob-text-secondary\">{row.option.description}</span>\n )}\n </span>\n </div>\n )\n })}\n </div>\n {/* Always mounted, so screen readers hear loading and empty states as they appear. */}\n <div role=\"status\" aria-live=\"polite\" className=\"empty:hidden\">\n {loading ? (\n <div className=\"flex items-center gap-2 px-3 py-3 text-sm text-glob-text-secondary\">\n <Spinner size=\"sm\" aria-hidden=\"true\" />\n <span>Loading…</span>\n </div>\n ) : rows.length === 0 ? (\n <div className=\"px-3 py-3 text-sm text-glob-text-secondary\">{emptyMessage}</div>\n ) : null}\n </div>\n </div>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,mBAAiD;AACjD,mBAAiD;AACjD,mBAAgF;AAChF,mBAA8B;AAC9B,qBAAwB;AAsDpB;AAXJ,IAAM,aAAa;AAKnB,SAAS,UAAU,OAAe,OAAe;AAC/C,QAAM,IAAI,MAAM,KAAK;AACrB,MAAI,CAAC,EAAG,QAAO;AACf,QAAM,QAAQ,MAAM,YAAY,EAAE,QAAQ,EAAE,YAAY,CAAC;AACzD,MAAI,QAAQ,EAAG,QAAO;AACtB,SACE,4EACG;AAAA,UAAM,MAAM,GAAG,KAAK;AAAA,IACrB,4CAAC,UAAK,WAAU,+CAA+C,gBAAM,MAAM,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;AACb,sBAAI,CAAC,IAAI,SAAU,WAAU,GAAG;AAAA,gBAClC;AAAA,gBACA,eAAW;AAAA,kBACT;AAAA,kBACA,IAAI,YAAY;AAAA,kBAChB,YAAY,CAAC,IAAI,YAAY;AAAA,kBAC7B,cAAc;AAAA,gBAChB;AAAA,gBAEA,uDAAC,UAAK,WAAU,kBACd;AAAA,8DAAC,UAAK,WAAU,kBACb,qBAAW,QAAQ,IAAI,KAAK,MAAM,UAAU,IAAI,OAAO,KAAK,GAC/D;AAAA,oBACCA,MAAA,IAAI,WAAJ,gBAAAA,IAAY,gBACX,4CAAC,UAAK,WAAU,mDAAmD,cAAI,OAAO,aAAY;AAAA,mBAE9F;AAAA;AAAA,cA1BK,IAAI;AAAA,YA2BX;AAAA,UAEJ,CAAC,GACH;AAAA,UAEA,4CAAC,SAAI,MAAK,UAAS,aAAU,UAAS,WAAU,gBAC7C,oBACC,6CAAC,SAAI,WAAU,sEACb;AAAA,wDAAC,0BAAQ,MAAK,MAAK,eAAY,QAAO;AAAA,YACtC,4CAAC,UAAK,2BAAQ;AAAA,aAChB,IACE,KAAK,WAAW,IAClB,4CAAC,SAAI,WAAU,8CAA8C,wBAAa,IACxE,MACN;AAAA;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;","names":["_a"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// src/combobox.tsx
|
|
4
|
+
import { useId, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { cn, matchesSearch, normalizeText } from "@glob-ui/utils";
|
|
6
|
+
import { useControllableState, useFloatingPanel, useListbox, isPrintable } from "@glob-ui/hooks";
|
|
7
|
+
import { inputVariants } from "@glob-ui/input";
|
|
8
|
+
import { Spinner } from "@glob-ui/spinner";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var CUSTOM_KEY = "\0custom";
|
|
11
|
+
function highlight(label, query) {
|
|
12
|
+
const q = query.trim();
|
|
13
|
+
if (!q) return label;
|
|
14
|
+
const index = label.toLowerCase().indexOf(q.toLowerCase());
|
|
15
|
+
if (index < 0) return label;
|
|
16
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17
|
+
label.slice(0, index),
|
|
18
|
+
/* @__PURE__ */ jsx("mark", { className: "bg-transparent font-semibold text-glob-text", children: label.slice(index, index + q.length) }),
|
|
19
|
+
label.slice(index + q.length)
|
|
20
|
+
] });
|
|
21
|
+
}
|
|
22
|
+
function Combobox({
|
|
23
|
+
options,
|
|
24
|
+
value,
|
|
25
|
+
defaultValue = null,
|
|
26
|
+
onChange,
|
|
27
|
+
inputValue,
|
|
28
|
+
onInputChange,
|
|
29
|
+
allowCustomValue = false,
|
|
30
|
+
filter,
|
|
31
|
+
loading = false,
|
|
32
|
+
emptyMessage = "No results.",
|
|
33
|
+
placeholder,
|
|
34
|
+
disabled = false,
|
|
35
|
+
name,
|
|
36
|
+
clearable = true,
|
|
37
|
+
size,
|
|
38
|
+
className,
|
|
39
|
+
id,
|
|
40
|
+
"aria-invalid": ariaInvalid,
|
|
41
|
+
"aria-describedby": ariaDescribedBy,
|
|
42
|
+
"aria-labelledby": ariaLabelledBy,
|
|
43
|
+
"aria-label": ariaLabel
|
|
44
|
+
}) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const baseId = useId();
|
|
47
|
+
const inputId = id != null ? id : `${baseId}-input`;
|
|
48
|
+
const listId = `${baseId}-listbox`;
|
|
49
|
+
const inputRef = useRef(null);
|
|
50
|
+
const [selected, setSelected] = useControllableState(value, defaultValue, onChange);
|
|
51
|
+
const [open, setOpen] = useState(false);
|
|
52
|
+
const [typed, setTyped] = useState(null);
|
|
53
|
+
const controlledText = inputValue !== void 0;
|
|
54
|
+
const selectedOption = options.find((o) => o.value === selected);
|
|
55
|
+
const selectedLabel = (_b = (_a = selectedOption == null ? void 0 : selectedOption.label) != null ? _a : selected) != null ? _b : "";
|
|
56
|
+
const text = controlledText ? inputValue : typed != null ? typed : selectedLabel;
|
|
57
|
+
const query = controlledText ? inputValue : typed != null ? typed : "";
|
|
58
|
+
function setText(next) {
|
|
59
|
+
if (!controlledText) setTyped(next);
|
|
60
|
+
onInputChange == null ? void 0 : onInputChange(next);
|
|
61
|
+
}
|
|
62
|
+
const visible = useMemo(() => {
|
|
63
|
+
if (filter === false) return options;
|
|
64
|
+
const match = filter != null ? filter : ((o, q) => {
|
|
65
|
+
var _a2;
|
|
66
|
+
return matchesSearch(q, o.label, o.value, (_a2 = o.description) != null ? _a2 : "");
|
|
67
|
+
});
|
|
68
|
+
return options.filter((o) => match(o, query));
|
|
69
|
+
}, [options, filter, query]);
|
|
70
|
+
const trimmed = text.trim();
|
|
71
|
+
const hasExact = options.some((o) => normalizeText(o.label) === normalizeText(trimmed));
|
|
72
|
+
const rows = [
|
|
73
|
+
...visible.map((option) => ({ key: option.value, label: option.label, disabled: option.disabled, option })),
|
|
74
|
+
...allowCustomValue && trimmed !== "" && !hasExact ? [{ key: CUSTOM_KEY, label: trimmed }] : []
|
|
75
|
+
];
|
|
76
|
+
const listbox = useListbox({
|
|
77
|
+
id: baseId,
|
|
78
|
+
items: rows,
|
|
79
|
+
getKey: (row) => row.key,
|
|
80
|
+
getText: (row) => row.label,
|
|
81
|
+
isDisabled: (row) => Boolean(row.disabled),
|
|
82
|
+
open
|
|
83
|
+
});
|
|
84
|
+
const { setTrigger, setPanel, floatingStyles } = useFloatingPanel({
|
|
85
|
+
open,
|
|
86
|
+
onOpenChange: setOpen,
|
|
87
|
+
placement: "bottom-start",
|
|
88
|
+
offset: 4,
|
|
89
|
+
matchTriggerWidth: true,
|
|
90
|
+
// Focus stays in the input, so the browser must not return focus on close.
|
|
91
|
+
restoreFocus: false
|
|
92
|
+
});
|
|
93
|
+
function openList(active) {
|
|
94
|
+
if (disabled) return;
|
|
95
|
+
listbox.setActiveKey(active);
|
|
96
|
+
setOpen(true);
|
|
97
|
+
}
|
|
98
|
+
function commitValue(next, label) {
|
|
99
|
+
setSelected(next);
|
|
100
|
+
setTyped(null);
|
|
101
|
+
setOpen(false);
|
|
102
|
+
if (controlledText) onInputChange == null ? void 0 : onInputChange(label);
|
|
103
|
+
}
|
|
104
|
+
function commitRow(row) {
|
|
105
|
+
if (row.key === CUSTOM_KEY) commitValue(row.label, row.label);
|
|
106
|
+
else if (row.option) commitValue(row.option.value, row.option.label);
|
|
107
|
+
}
|
|
108
|
+
function clear() {
|
|
109
|
+
var _a2;
|
|
110
|
+
setSelected(null);
|
|
111
|
+
setText("");
|
|
112
|
+
setOpen(false);
|
|
113
|
+
(_a2 = inputRef.current) == null ? void 0 : _a2.focus();
|
|
114
|
+
}
|
|
115
|
+
function onBlur() {
|
|
116
|
+
setOpen(false);
|
|
117
|
+
if (allowCustomValue) {
|
|
118
|
+
if (trimmed === "") {
|
|
119
|
+
if (selected !== null) commitValue(null, "");
|
|
120
|
+
else setText("");
|
|
121
|
+
} else if (trimmed !== selected) {
|
|
122
|
+
commitValue(trimmed, trimmed);
|
|
123
|
+
} else {
|
|
124
|
+
setTyped(null);
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
setTyped(null);
|
|
129
|
+
if (controlledText && text !== selectedLabel) onInputChange == null ? void 0 : onInputChange(selectedLabel);
|
|
130
|
+
}
|
|
131
|
+
function onKeyDown(e) {
|
|
132
|
+
if (disabled) return;
|
|
133
|
+
if (!open) {
|
|
134
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
openList(selected);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
} else if (listbox.navigate(e, { homeEnd: false })) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (e.key === "Enter" && open) {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
if (listbox.activeItem) commitRow(listbox.activeItem);
|
|
145
|
+
else if (allowCustomValue && trimmed !== "") commitValue(trimmed, trimmed);
|
|
146
|
+
else setOpen(false);
|
|
147
|
+
} else if (e.key === "Escape") {
|
|
148
|
+
if (open) {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
setOpen(false);
|
|
151
|
+
} else if (text !== "" || selected !== null) {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
clear();
|
|
154
|
+
}
|
|
155
|
+
} else if (isPrintable(e) && !open) {
|
|
156
|
+
setOpen(true);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const hasText = text !== "";
|
|
160
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), children: [
|
|
161
|
+
/* @__PURE__ */ jsxs("div", { ref: setTrigger, className: "relative w-full", children: [
|
|
162
|
+
/* @__PURE__ */ jsx(
|
|
163
|
+
"input",
|
|
164
|
+
{
|
|
165
|
+
ref: inputRef,
|
|
166
|
+
id: inputId,
|
|
167
|
+
type: "text",
|
|
168
|
+
role: "combobox",
|
|
169
|
+
autoComplete: "off",
|
|
170
|
+
"aria-autocomplete": "list",
|
|
171
|
+
"aria-expanded": open,
|
|
172
|
+
"aria-controls": listId,
|
|
173
|
+
"aria-activedescendant": open ? listbox.activeDescendant : void 0,
|
|
174
|
+
"aria-invalid": ariaInvalid,
|
|
175
|
+
"aria-describedby": ariaDescribedBy,
|
|
176
|
+
"aria-labelledby": ariaLabelledBy,
|
|
177
|
+
"aria-label": ariaLabel,
|
|
178
|
+
"aria-disabled": disabled || void 0,
|
|
179
|
+
disabled,
|
|
180
|
+
placeholder,
|
|
181
|
+
value: text,
|
|
182
|
+
onChange: (e) => {
|
|
183
|
+
setText(e.target.value);
|
|
184
|
+
setOpen(true);
|
|
185
|
+
listbox.setActiveKey(null);
|
|
186
|
+
},
|
|
187
|
+
onClick: () => {
|
|
188
|
+
if (!open) openList(selected);
|
|
189
|
+
},
|
|
190
|
+
onKeyDown,
|
|
191
|
+
onBlur,
|
|
192
|
+
className: cn(inputVariants({ size }), "pr-16")
|
|
193
|
+
}
|
|
194
|
+
),
|
|
195
|
+
clearable && hasText && !disabled && /* @__PURE__ */ jsx(
|
|
196
|
+
"button",
|
|
197
|
+
{
|
|
198
|
+
type: "button",
|
|
199
|
+
"aria-label": "Clear",
|
|
200
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
201
|
+
onClick: clear,
|
|
202
|
+
className: "absolute right-8 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-glob-sm text-glob-text-secondary hover:bg-glob-surface-hover hover:text-glob-text focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring",
|
|
203
|
+
children: /* @__PURE__ */ jsx("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "h-3.5 w-3.5", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" }) })
|
|
204
|
+
}
|
|
205
|
+
),
|
|
206
|
+
/* @__PURE__ */ jsx(
|
|
207
|
+
"button",
|
|
208
|
+
{
|
|
209
|
+
type: "button",
|
|
210
|
+
"aria-label": "Show options",
|
|
211
|
+
tabIndex: -1,
|
|
212
|
+
disabled,
|
|
213
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
214
|
+
onClick: () => {
|
|
215
|
+
var _a2;
|
|
216
|
+
if (open) setOpen(false);
|
|
217
|
+
else openList(selected);
|
|
218
|
+
(_a2 = inputRef.current) == null ? void 0 : _a2.focus();
|
|
219
|
+
},
|
|
220
|
+
className: "absolute right-2 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center text-glob-text-secondary disabled:opacity-50",
|
|
221
|
+
children: /* @__PURE__ */ jsx(
|
|
222
|
+
"svg",
|
|
223
|
+
{
|
|
224
|
+
"aria-hidden": "true",
|
|
225
|
+
viewBox: "0 0 24 24",
|
|
226
|
+
fill: "none",
|
|
227
|
+
stroke: "currentColor",
|
|
228
|
+
strokeWidth: "2",
|
|
229
|
+
className: cn("h-4 w-4 transition-transform", open && "rotate-180"),
|
|
230
|
+
children: /* @__PURE__ */ jsx("path", { d: "M6 9l6 6 6-6" })
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
)
|
|
235
|
+
] }),
|
|
236
|
+
name !== void 0 && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: selected != null ? selected : "" }),
|
|
237
|
+
/* @__PURE__ */ jsxs(
|
|
238
|
+
"div",
|
|
239
|
+
{
|
|
240
|
+
ref: setPanel,
|
|
241
|
+
popover: "manual",
|
|
242
|
+
style: floatingStyles,
|
|
243
|
+
className: cn(
|
|
244
|
+
// Reset the UA popover box (inset:0 + margin:auto would center it).
|
|
245
|
+
"m-0 overflow-visible rounded-glob-md border border-glob-border bg-glob-surface text-sm text-glob-text shadow-glob-md outline-none",
|
|
246
|
+
"opacity-0 transition-[opacity,overlay,display] transition-discrete duration-150 open:opacity-100 starting:open:opacity-0 motion-reduce:transition-none"
|
|
247
|
+
),
|
|
248
|
+
children: [
|
|
249
|
+
/* @__PURE__ */ jsx("div", { id: listId, role: "listbox", "aria-labelledby": ariaLabelledBy != null ? ariaLabelledBy : inputId, className: "max-h-60 overflow-y-auto p-1", children: rows.map((row) => {
|
|
250
|
+
var _a2;
|
|
251
|
+
const isSelected = row.key !== CUSTOM_KEY && row.key === selected;
|
|
252
|
+
const isActive = listbox.activeKey === row.key;
|
|
253
|
+
const isCustom = row.key === CUSTOM_KEY;
|
|
254
|
+
return /* @__PURE__ */ jsx(
|
|
255
|
+
"div",
|
|
256
|
+
{
|
|
257
|
+
id: listbox.optionId(row.key),
|
|
258
|
+
role: "option",
|
|
259
|
+
"aria-selected": isSelected,
|
|
260
|
+
"aria-disabled": row.disabled || void 0,
|
|
261
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
262
|
+
onPointerMove: () => {
|
|
263
|
+
if (!row.disabled) listbox.setActiveKey(row.key);
|
|
264
|
+
},
|
|
265
|
+
onClick: () => {
|
|
266
|
+
if (!row.disabled) commitRow(row);
|
|
267
|
+
},
|
|
268
|
+
className: cn(
|
|
269
|
+
"flex w-full cursor-pointer items-center gap-2 rounded-glob-sm px-2 py-2 text-left text-sm select-none",
|
|
270
|
+
row.disabled && "cursor-not-allowed opacity-50",
|
|
271
|
+
isActive && !row.disabled && "bg-glob-surface-hover",
|
|
272
|
+
isSelected && "font-medium"
|
|
273
|
+
),
|
|
274
|
+
children: /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
275
|
+
/* @__PURE__ */ jsx("span", { className: "block truncate", children: isCustom ? `Use "${row.label}"` : highlight(row.label, query) }),
|
|
276
|
+
((_a2 = row.option) == null ? void 0 : _a2.description) && /* @__PURE__ */ jsx("span", { className: "block truncate text-xs text-glob-text-secondary", children: row.option.description })
|
|
277
|
+
] })
|
|
278
|
+
},
|
|
279
|
+
row.key
|
|
280
|
+
);
|
|
281
|
+
}) }),
|
|
282
|
+
/* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", className: "empty:hidden", children: loading ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 py-3 text-sm text-glob-text-secondary", children: [
|
|
283
|
+
/* @__PURE__ */ jsx(Spinner, { size: "sm", "aria-hidden": "true" }),
|
|
284
|
+
/* @__PURE__ */ jsx("span", { children: "Loading\u2026" })
|
|
285
|
+
] }) : rows.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-3 py-3 text-sm text-glob-text-secondary", children: emptyMessage }) : null })
|
|
286
|
+
]
|
|
287
|
+
}
|
|
288
|
+
)
|
|
289
|
+
] });
|
|
290
|
+
}
|
|
291
|
+
export {
|
|
292
|
+
Combobox
|
|
293
|
+
};
|
|
294
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/combobox.tsx"],"sourcesContent":["\"use client\"\n\nimport { useId, useMemo, useRef, useState } from \"react\"\nimport { cn, matchesSearch, normalizeText } from \"@glob-ui/utils\"\nimport { useControllableState, useFloatingPanel, useListbox, isPrintable } from \"@glob-ui/hooks\"\nimport { inputVariants } from \"@glob-ui/input\"\nimport { Spinner } from \"@glob-ui/spinner\"\n\nexport interface ComboboxOption {\n value: string\n label: string\n disabled?: boolean\n /** A second, muted line under the label. Searched too. */\n description?: string\n}\n\nexport interface ComboboxProps {\n options: ComboboxOption[]\n /** Selected option value, or `null` for none. */\n value?: string | null\n defaultValue?: string | null\n /** Called with the selected value, or `null` when cleared. */\n onChange?: (value: string | null) => void\n /** The text in the field. Pass it (with onInputChange) to search on a server. */\n inputValue?: string\n onInputChange?: (text: string) => void\n /** Commit the typed text as the value when no option is active (Enter), or on blur. */\n allowCustomValue?: boolean\n /** `false`: the consumer filters `options` itself. A function: `(option, query) => boolean`. Default: accent-insensitive word match on label, value and description. */\n filter?: false | ((option: ComboboxOption, query: string) => boolean)\n /** Shows a \"Loading…\" row with a spinner under the options, announced to screen readers. */\n loading?: boolean\n /** Shown when nothing matches. Default \"No results.\". */\n emptyMessage?: React.ReactNode\n placeholder?: string\n disabled?: boolean\n /** Submitted with native forms through a hidden input. */\n name?: string\n /** Shows an X button while there is text. Default true. */\n clearable?: boolean\n size?: \"sm\" | \"md\" | \"lg\"\n className?: string\n id?: string\n \"aria-invalid\"?: boolean | \"true\" | \"false\"\n \"aria-describedby\"?: string\n \"aria-labelledby\"?: string\n \"aria-label\"?: string\n}\n\nconst CUSTOM_KEY = \"\\u0000custom\"\n\ntype Row = { key: string; label: string; disabled?: boolean; option?: ComboboxOption }\n\n/** The label with the first occurrence of the query in `<mark>`. Cosmetic: the name stays the label. */\nfunction highlight(label: string, query: string) {\n const q = query.trim()\n if (!q) return label\n const index = label.toLowerCase().indexOf(q.toLowerCase())\n if (index < 0) return label\n return (\n <>\n {label.slice(0, index)}\n <mark className=\"bg-transparent font-semibold text-glob-text\">{label.slice(index, index + q.length)}</mark>\n {label.slice(index + q.length)}\n </>\n )\n}\n\n/**\n * An editable combobox (WAI-ARIA list autocomplete). Focus stays in the input; the active option is\n * announced through aria-activedescendant.\n */\nexport function Combobox({\n options,\n value,\n defaultValue = null,\n onChange,\n inputValue,\n onInputChange,\n allowCustomValue = false,\n filter,\n loading = false,\n emptyMessage = \"No results.\",\n placeholder,\n disabled = false,\n name,\n clearable = true,\n size,\n className,\n id,\n \"aria-invalid\": ariaInvalid,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-label\": ariaLabel,\n}: ComboboxProps) {\n const baseId = useId()\n const inputId = id ?? `${baseId}-input`\n const listId = `${baseId}-listbox`\n const inputRef = useRef<HTMLInputElement>(null)\n const [selected, setSelected] = useControllableState<string | null>(value, defaultValue, onChange)\n const [open, setOpen] = useState(false)\n // null: not editing, so the field shows the selected label. A string: what the user typed.\n const [typed, setTyped] = useState<string | null>(null)\n const controlledText = inputValue !== undefined\n\n const selectedOption = options.find((o) => o.value === selected)\n const selectedLabel = selectedOption?.label ?? selected ?? \"\"\n const text = controlledText ? inputValue : (typed ?? selectedLabel)\n const query = controlledText ? inputValue : (typed ?? \"\")\n\n function setText(next: string) {\n if (!controlledText) setTyped(next)\n onInputChange?.(next)\n }\n\n const visible = useMemo(() => {\n if (filter === false) return options\n const match = filter ?? ((o: ComboboxOption, q: string) => matchesSearch(q, o.label, o.value, o.description ?? \"\"))\n return options.filter((o) => match(o, query))\n }, [options, filter, query])\n\n const trimmed = text.trim()\n const hasExact = options.some((o) => normalizeText(o.label) === normalizeText(trimmed))\n // The \"Use ...\" row goes last, so with matches the first match stays the active option.\n const rows: Row[] = [\n ...visible.map((option) => ({ key: option.value, label: option.label, disabled: option.disabled, option })),\n ...(allowCustomValue && trimmed !== \"\" && !hasExact ? [{ key: CUSTOM_KEY, label: trimmed }] : []),\n ]\n\n const listbox = useListbox({\n id: baseId,\n items: rows,\n getKey: (row) => row.key,\n getText: (row) => row.label,\n isDisabled: (row) => Boolean(row.disabled),\n open,\n })\n\n const { setTrigger, setPanel, floatingStyles } = useFloatingPanel({\n open,\n onOpenChange: setOpen,\n placement: \"bottom-start\",\n offset: 4,\n matchTriggerWidth: true,\n // Focus stays in the input, so the browser must not return focus on close.\n restoreFocus: false,\n })\n\n function openList(active: string | null) {\n if (disabled) return\n listbox.setActiveKey(active)\n setOpen(true)\n }\n\n function commitValue(next: string | null, label: string) {\n setSelected(next)\n setTyped(null)\n setOpen(false)\n if (controlledText) onInputChange?.(label)\n }\n\n function commitRow(row: Row) {\n if (row.key === CUSTOM_KEY) commitValue(row.label, row.label)\n else if (row.option) commitValue(row.option.value, row.option.label)\n }\n\n function clear() {\n setSelected(null)\n setText(\"\")\n setOpen(false)\n inputRef.current?.focus()\n }\n\n function onBlur() {\n setOpen(false)\n if (allowCustomValue) {\n // The typed text is the value: never leave text that looks selected but is not.\n if (trimmed === \"\") {\n if (selected !== null) commitValue(null, \"\")\n else setText(\"\")\n } else if (trimmed !== selected) {\n commitValue(trimmed, trimmed)\n } else {\n setTyped(null)\n }\n return\n }\n // Not committed: show the selected label again (or nothing).\n setTyped(null)\n if (controlledText && text !== selectedLabel) onInputChange?.(selectedLabel)\n }\n\n function onKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n if (disabled) return\n if (!open) {\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault()\n openList(selected)\n return\n }\n } else if (listbox.navigate(e, { homeEnd: false })) {\n return\n }\n\n if (e.key === \"Enter\" && open) {\n e.preventDefault()\n if (listbox.activeItem) commitRow(listbox.activeItem)\n else if (allowCustomValue && trimmed !== \"\") commitValue(trimmed, trimmed)\n else setOpen(false)\n } else if (e.key === \"Escape\") {\n if (open) {\n e.preventDefault()\n setOpen(false)\n } else if (text !== \"\" || selected !== null) {\n e.preventDefault()\n clear()\n }\n } else if (isPrintable(e) && !open) {\n // Typing opens the list (the change handler filters it).\n setOpen(true)\n }\n }\n\n const hasText = text !== \"\"\n\n return (\n <div className={cn(\"relative w-full\", className)}>\n <div ref={setTrigger} className=\"relative w-full\">\n <input\n ref={inputRef}\n id={inputId}\n type=\"text\"\n role=\"combobox\"\n autoComplete=\"off\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={listId}\n aria-activedescendant={open ? listbox.activeDescendant : undefined}\n aria-invalid={ariaInvalid}\n aria-describedby={ariaDescribedBy}\n aria-labelledby={ariaLabelledBy}\n aria-label={ariaLabel}\n aria-disabled={disabled || undefined}\n disabled={disabled}\n placeholder={placeholder}\n value={text}\n onChange={(e) => {\n setText(e.target.value)\n setOpen(true)\n listbox.setActiveKey(null)\n }}\n onClick={() => {\n if (!open) openList(selected)\n }}\n onKeyDown={onKeyDown}\n onBlur={onBlur}\n className={cn(inputVariants({ size }), \"pr-16\")}\n />\n {clearable && hasText && !disabled && (\n <button\n type=\"button\"\n aria-label=\"Clear\"\n // Keep focus in the input while clicking.\n onMouseDown={(e) => e.preventDefault()}\n onClick={clear}\n className=\"absolute right-8 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-glob-sm text-glob-text-secondary hover:bg-glob-surface-hover hover:text-glob-text focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring\"\n >\n <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" className=\"h-3.5 w-3.5\">\n <path d=\"M18 6L6 18M6 6l12 12\" />\n </svg>\n </button>\n )}\n <button\n type=\"button\"\n aria-label=\"Show options\"\n tabIndex={-1}\n disabled={disabled}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => {\n if (open) setOpen(false)\n else openList(selected)\n inputRef.current?.focus()\n }}\n className=\"absolute right-2 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center text-glob-text-secondary disabled:opacity-50\"\n >\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n className={cn(\"h-4 w-4 transition-transform\", open && \"rotate-180\")}\n >\n <path d=\"M6 9l6 6 6-6\" />\n </svg>\n </button>\n </div>\n\n {name !== undefined && <input type=\"hidden\" name={name} value={selected ?? \"\"} />}\n\n <div\n ref={setPanel}\n popover=\"manual\"\n style={floatingStyles}\n className={cn(\n // Reset the UA popover box (inset:0 + margin:auto would center it).\n \"m-0 overflow-visible rounded-glob-md border border-glob-border bg-glob-surface text-sm text-glob-text shadow-glob-md outline-none\",\n \"opacity-0 transition-[opacity,overlay,display] transition-discrete duration-150 open:opacity-100 starting:open:opacity-0 motion-reduce:transition-none\"\n )}\n >\n <div id={listId} role=\"listbox\" aria-labelledby={ariaLabelledBy ?? inputId} className=\"max-h-60 overflow-y-auto p-1\">\n {rows.map((row) => {\n const isSelected = row.key !== CUSTOM_KEY && row.key === selected\n const isActive = listbox.activeKey === row.key\n const isCustom = row.key === CUSTOM_KEY\n return (\n <div\n key={row.key}\n id={listbox.optionId(row.key)}\n role=\"option\"\n aria-selected={isSelected}\n aria-disabled={row.disabled || undefined}\n onMouseDown={(e) => e.preventDefault()}\n onPointerMove={() => {\n if (!row.disabled) listbox.setActiveKey(row.key)\n }}\n onClick={() => {\n if (!row.disabled) commitRow(row)\n }}\n className={cn(\n \"flex w-full cursor-pointer items-center gap-2 rounded-glob-sm px-2 py-2 text-left text-sm select-none\",\n row.disabled && \"cursor-not-allowed opacity-50\",\n isActive && !row.disabled && \"bg-glob-surface-hover\",\n isSelected && \"font-medium\"\n )}\n >\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate\">\n {isCustom ? `Use \"${row.label}\"` : highlight(row.label, query)}\n </span>\n {row.option?.description && (\n <span className=\"block truncate text-xs text-glob-text-secondary\">{row.option.description}</span>\n )}\n </span>\n </div>\n )\n })}\n </div>\n {/* Always mounted, so screen readers hear loading and empty states as they appear. */}\n <div role=\"status\" aria-live=\"polite\" className=\"empty:hidden\">\n {loading ? (\n <div className=\"flex items-center gap-2 px-3 py-3 text-sm text-glob-text-secondary\">\n <Spinner size=\"sm\" aria-hidden=\"true\" />\n <span>Loading…</span>\n </div>\n ) : rows.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BAAQ;AAAA,aAChB,IACE,KAAK,WAAW,IAClB,oBAAC,SAAI,WAAU,8CAA8C,wBAAa,IACxE,MACN;AAAA;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;","names":["_a"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glob-ui/combobox",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "^19"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@glob-ui/hooks": "0.1.0",
|
|
30
|
+
"@glob-ui/input": "0.1.0",
|
|
31
|
+
"@glob-ui/spinner": "0.1.0",
|
|
32
|
+
"@glob-ui/utils": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.5.1"
|
|
36
|
+
},
|
|
37
|
+
"description": "A text input with a filtered list: type to search, arrows to move, Enter to choose. The API mirrors Select.",
|
|
38
|
+
"keywords": [
|
|
39
|
+
"react",
|
|
40
|
+
"glob-ui",
|
|
41
|
+
"components",
|
|
42
|
+
"accessible",
|
|
43
|
+
"tailwind",
|
|
44
|
+
"combobox"
|
|
45
|
+
],
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"author": "Kevin Martínez E",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/kevin-martineze/GlobUI.git",
|
|
51
|
+
"directory": "packages/combobox"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/kevin-martineze/GlobUI#readme",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/kevin-martineze/GlobUI/issues"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public",
|
|
59
|
+
"provenance": true
|
|
60
|
+
},
|
|
61
|
+
"sideEffects": false,
|
|
62
|
+
"type": "commonjs",
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=18.18"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsup",
|
|
68
|
+
"dev": "tsup --watch --no-clean"
|
|
69
|
+
}
|
|
6
70
|
}
|