@heroui/autocomplete 2.3.12 → 2.3.14
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/autocomplete.d.mts +21 -0
- package/dist/autocomplete.d.ts +21 -0
- package/dist/autocomplete.js +446 -0
- package/dist/autocomplete.mjs +8 -0
- package/dist/chunk-DNIGSRME.mjs +55 -0
- package/dist/chunk-OHYOYGT2.mjs +378 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +459 -0
- package/dist/index.mjs +16 -0
- package/dist/use-autocomplete.d.mts +229 -0
- package/dist/use-autocomplete.d.ts +229 -0
- package/dist/use-autocomplete.js +401 -0
- package/dist/use-autocomplete.mjs +7 -0
- package/package.json +14 -14
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { UseAutocompleteProps } from './use-autocomplete.mjs';
|
|
3
|
+
import 'tailwind-variants';
|
|
4
|
+
import '@react-stately/combobox';
|
|
5
|
+
import '@heroui/system';
|
|
6
|
+
import '@heroui/theme';
|
|
7
|
+
import '@heroui/react-utils';
|
|
8
|
+
import '@react-types/combobox';
|
|
9
|
+
import '@heroui/popover';
|
|
10
|
+
import '@heroui/listbox';
|
|
11
|
+
import '@heroui/input';
|
|
12
|
+
import '@heroui/scroll-shadow';
|
|
13
|
+
import '@heroui/button';
|
|
14
|
+
import '@react-types/shared';
|
|
15
|
+
|
|
16
|
+
interface Props<T> extends UseAutocompleteProps<T> {
|
|
17
|
+
}
|
|
18
|
+
type AutocompleteProps<T extends object = object> = Props<T>;
|
|
19
|
+
declare const Autocomplete: <T extends object>(props: AutocompleteProps<T>) => ReactElement;
|
|
20
|
+
|
|
21
|
+
export { type AutocompleteProps, Autocomplete as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { UseAutocompleteProps } from './use-autocomplete.js';
|
|
3
|
+
import 'tailwind-variants';
|
|
4
|
+
import '@react-stately/combobox';
|
|
5
|
+
import '@heroui/system';
|
|
6
|
+
import '@heroui/theme';
|
|
7
|
+
import '@heroui/react-utils';
|
|
8
|
+
import '@react-types/combobox';
|
|
9
|
+
import '@heroui/popover';
|
|
10
|
+
import '@heroui/listbox';
|
|
11
|
+
import '@heroui/input';
|
|
12
|
+
import '@heroui/scroll-shadow';
|
|
13
|
+
import '@heroui/button';
|
|
14
|
+
import '@react-types/shared';
|
|
15
|
+
|
|
16
|
+
interface Props<T> extends UseAutocompleteProps<T> {
|
|
17
|
+
}
|
|
18
|
+
type AutocompleteProps<T extends object = object> = Props<T>;
|
|
19
|
+
declare const Autocomplete: <T extends object>(props: AutocompleteProps<T>) => ReactElement;
|
|
20
|
+
|
|
21
|
+
export { type AutocompleteProps, Autocomplete as default };
|
|
@@ -0,0 +1,446 @@
|
|
|
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/autocomplete.tsx
|
|
22
|
+
var autocomplete_exports = {};
|
|
23
|
+
__export(autocomplete_exports, {
|
|
24
|
+
default: () => autocomplete_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(autocomplete_exports);
|
|
27
|
+
var import_system2 = require("@heroui/system");
|
|
28
|
+
var import_popover = require("@heroui/popover");
|
|
29
|
+
var import_scroll_shadow = require("@heroui/scroll-shadow");
|
|
30
|
+
var import_shared_icons = require("@heroui/shared-icons");
|
|
31
|
+
var import_listbox = require("@heroui/listbox");
|
|
32
|
+
var import_button = require("@heroui/button");
|
|
33
|
+
var import_input = require("@heroui/input");
|
|
34
|
+
var import_framer_motion = require("framer-motion");
|
|
35
|
+
|
|
36
|
+
// src/use-autocomplete.ts
|
|
37
|
+
var import_system = require("@heroui/system");
|
|
38
|
+
var import_use_safe_layout_effect = require("@heroui/use-safe-layout-effect");
|
|
39
|
+
var import_theme = require("@heroui/theme");
|
|
40
|
+
var import_i18n = require("@react-aria/i18n");
|
|
41
|
+
var import_combobox = require("@react-stately/combobox");
|
|
42
|
+
var import_react_utils = require("@heroui/react-utils");
|
|
43
|
+
var import_react = require("react");
|
|
44
|
+
var import_shared_utils = require("@heroui/shared-utils");
|
|
45
|
+
var import_utils = require("@react-aria/utils");
|
|
46
|
+
var import_combobox2 = require("@react-aria/combobox");
|
|
47
|
+
var import_form = require("@heroui/form");
|
|
48
|
+
var import_aria_utils = require("@heroui/aria-utils");
|
|
49
|
+
function useAutocomplete(originalProps) {
|
|
50
|
+
var _a, _b, _c, _d, _e;
|
|
51
|
+
const globalContext = (0, import_system.useProviderContext)();
|
|
52
|
+
const { validationBehavior: formValidationBehavior } = (0, import_form.useSlottedContext)(import_form.FormContext) || {};
|
|
53
|
+
const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.autocomplete.variantKeys);
|
|
54
|
+
const disableAnimation = (_b = (_a = originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
|
|
55
|
+
const isClearable = originalProps.disableClearable !== void 0 ? !originalProps.disableClearable : originalProps.isReadOnly ? false : originalProps.isClearable;
|
|
56
|
+
const {
|
|
57
|
+
ref,
|
|
58
|
+
as,
|
|
59
|
+
label,
|
|
60
|
+
isLoading,
|
|
61
|
+
menuTrigger = "focus",
|
|
62
|
+
filterOptions = {
|
|
63
|
+
sensitivity: "base"
|
|
64
|
+
},
|
|
65
|
+
children,
|
|
66
|
+
selectorIcon,
|
|
67
|
+
clearIcon,
|
|
68
|
+
scrollRef: scrollRefProp,
|
|
69
|
+
defaultFilter,
|
|
70
|
+
endContent,
|
|
71
|
+
allowsEmptyCollection = true,
|
|
72
|
+
shouldCloseOnBlur = true,
|
|
73
|
+
popoverProps = {},
|
|
74
|
+
inputProps: userInputProps = {},
|
|
75
|
+
scrollShadowProps = {},
|
|
76
|
+
listboxProps = {},
|
|
77
|
+
selectorButtonProps = {},
|
|
78
|
+
clearButtonProps = {},
|
|
79
|
+
showScrollIndicators = true,
|
|
80
|
+
allowsCustomValue = false,
|
|
81
|
+
isVirtualized,
|
|
82
|
+
maxListboxHeight = 256,
|
|
83
|
+
itemHeight = 32,
|
|
84
|
+
validationBehavior = (_c = formValidationBehavior != null ? formValidationBehavior : globalContext == null ? void 0 : globalContext.validationBehavior) != null ? _c : "native",
|
|
85
|
+
className,
|
|
86
|
+
classNames,
|
|
87
|
+
errorMessage,
|
|
88
|
+
onOpenChange,
|
|
89
|
+
onClose,
|
|
90
|
+
isReadOnly = false,
|
|
91
|
+
...otherProps
|
|
92
|
+
} = props;
|
|
93
|
+
const { contains } = (0, import_i18n.useFilter)(filterOptions);
|
|
94
|
+
let state = (0, import_combobox.useComboBoxState)({
|
|
95
|
+
...originalProps,
|
|
96
|
+
children,
|
|
97
|
+
menuTrigger,
|
|
98
|
+
validationBehavior,
|
|
99
|
+
shouldCloseOnBlur,
|
|
100
|
+
allowsEmptyCollection,
|
|
101
|
+
defaultFilter: defaultFilter && typeof defaultFilter === "function" ? defaultFilter : contains,
|
|
102
|
+
onOpenChange: (open, menuTrigger2) => {
|
|
103
|
+
onOpenChange == null ? void 0 : onOpenChange(open, menuTrigger2);
|
|
104
|
+
if (!open) {
|
|
105
|
+
onClose == null ? void 0 : onClose();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
state = {
|
|
110
|
+
...state,
|
|
111
|
+
...isReadOnly && {
|
|
112
|
+
disabledKeys: /* @__PURE__ */ new Set([...state.collection.getKeys()])
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const buttonRef = (0, import_react.useRef)(null);
|
|
116
|
+
const inputWrapperRef = (0, import_react.useRef)(null);
|
|
117
|
+
const listBoxRef = (0, import_react.useRef)(null);
|
|
118
|
+
const popoverRef = (0, import_react.useRef)(null);
|
|
119
|
+
const inputRef = (0, import_react_utils.useDOMRef)(ref);
|
|
120
|
+
const scrollShadowRef = (0, import_react_utils.useDOMRef)(scrollRefProp);
|
|
121
|
+
const {
|
|
122
|
+
buttonProps,
|
|
123
|
+
inputProps,
|
|
124
|
+
listBoxProps,
|
|
125
|
+
isInvalid: isAriaInvalid,
|
|
126
|
+
validationDetails,
|
|
127
|
+
validationErrors
|
|
128
|
+
} = (0, import_combobox2.useComboBox)(
|
|
129
|
+
{
|
|
130
|
+
validationBehavior,
|
|
131
|
+
...originalProps,
|
|
132
|
+
inputRef,
|
|
133
|
+
buttonRef,
|
|
134
|
+
listBoxRef,
|
|
135
|
+
popoverRef
|
|
136
|
+
},
|
|
137
|
+
state
|
|
138
|
+
);
|
|
139
|
+
const isInvalid = originalProps.isInvalid || isAriaInvalid;
|
|
140
|
+
const slotsProps = {
|
|
141
|
+
inputProps: (0, import_utils.mergeProps)(
|
|
142
|
+
{
|
|
143
|
+
label,
|
|
144
|
+
ref: inputRef,
|
|
145
|
+
wrapperRef: inputWrapperRef,
|
|
146
|
+
onClick: () => {
|
|
147
|
+
if (!state.isOpen && !!state.selectedItem) {
|
|
148
|
+
state.open();
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
isClearable: false,
|
|
152
|
+
disableAnimation
|
|
153
|
+
},
|
|
154
|
+
userInputProps
|
|
155
|
+
),
|
|
156
|
+
popoverProps: (0, import_utils.mergeProps)(
|
|
157
|
+
{
|
|
158
|
+
offset: 5,
|
|
159
|
+
placement: "bottom",
|
|
160
|
+
triggerScaleOnOpen: false,
|
|
161
|
+
disableAnimation
|
|
162
|
+
},
|
|
163
|
+
popoverProps
|
|
164
|
+
),
|
|
165
|
+
scrollShadowProps: (0, import_utils.mergeProps)(
|
|
166
|
+
{
|
|
167
|
+
ref: scrollShadowRef,
|
|
168
|
+
isEnabled: (_d = showScrollIndicators && state.collection.size > 5) != null ? _d : true,
|
|
169
|
+
hideScrollBar: true,
|
|
170
|
+
offset: 15
|
|
171
|
+
},
|
|
172
|
+
scrollShadowProps
|
|
173
|
+
),
|
|
174
|
+
listboxProps: (0, import_utils.mergeProps)(
|
|
175
|
+
{
|
|
176
|
+
hideEmptyContent: allowsCustomValue,
|
|
177
|
+
emptyContent: "No results found.",
|
|
178
|
+
disableAnimation
|
|
179
|
+
},
|
|
180
|
+
listboxProps
|
|
181
|
+
),
|
|
182
|
+
selectorButtonProps: (0, import_utils.mergeProps)(
|
|
183
|
+
{
|
|
184
|
+
isLoading,
|
|
185
|
+
size: "sm",
|
|
186
|
+
variant: "light",
|
|
187
|
+
radius: "full",
|
|
188
|
+
color: isInvalid ? "danger" : originalProps == null ? void 0 : originalProps.color,
|
|
189
|
+
isIconOnly: true,
|
|
190
|
+
disableAnimation
|
|
191
|
+
},
|
|
192
|
+
selectorButtonProps
|
|
193
|
+
),
|
|
194
|
+
clearButtonProps: (0, import_utils.mergeProps)(
|
|
195
|
+
{
|
|
196
|
+
size: "sm",
|
|
197
|
+
variant: "light",
|
|
198
|
+
radius: "full",
|
|
199
|
+
color: isInvalid ? "danger" : originalProps == null ? void 0 : originalProps.color,
|
|
200
|
+
isIconOnly: true,
|
|
201
|
+
disableAnimation
|
|
202
|
+
},
|
|
203
|
+
clearButtonProps
|
|
204
|
+
)
|
|
205
|
+
};
|
|
206
|
+
const baseStyles = (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.base, className);
|
|
207
|
+
const isOpen = ((_e = slotsProps.listboxProps) == null ? void 0 : _e.hideEmptyContent) ? state.isOpen && !!state.collection.size : state.isOpen;
|
|
208
|
+
(0, import_use_safe_layout_effect.useSafeLayoutEffect)(() => {
|
|
209
|
+
if (!inputRef.current) return;
|
|
210
|
+
const key = inputRef.current.value;
|
|
211
|
+
const item = state.collection.getItem(key);
|
|
212
|
+
if (item && state.inputValue !== item.textValue) {
|
|
213
|
+
state.setSelectedKey(key);
|
|
214
|
+
state.setInputValue(item.textValue);
|
|
215
|
+
}
|
|
216
|
+
}, [inputRef.current]);
|
|
217
|
+
(0, import_react.useEffect)(() => {
|
|
218
|
+
let key = state.collection.getFirstKey();
|
|
219
|
+
while (key && state.disabledKeys.has(key)) {
|
|
220
|
+
key = state.collection.getKeyAfter(key);
|
|
221
|
+
}
|
|
222
|
+
state.selectionManager.setFocusedKey(key);
|
|
223
|
+
}, [state.collection, state.disabledKeys]);
|
|
224
|
+
(0, import_react.useEffect)(() => {
|
|
225
|
+
if (isOpen) {
|
|
226
|
+
if (popoverRef.current && inputWrapperRef.current) {
|
|
227
|
+
let rect = inputWrapperRef.current.getBoundingClientRect();
|
|
228
|
+
let popover = popoverRef.current;
|
|
229
|
+
popover.style.width = rect.width + "px";
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}, [isOpen]);
|
|
233
|
+
if (inputProps.onKeyDown) {
|
|
234
|
+
const originalOnKeyDown = inputProps.onKeyDown;
|
|
235
|
+
inputProps.onKeyDown = (e) => {
|
|
236
|
+
if ("continuePropagation" in e) {
|
|
237
|
+
e.stopPropagation = () => {
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return originalOnKeyDown(e);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const Component = as || "div";
|
|
244
|
+
const slots = (0, import_react.useMemo)(
|
|
245
|
+
() => (0, import_theme.autocomplete)({
|
|
246
|
+
...variantProps,
|
|
247
|
+
isClearable,
|
|
248
|
+
disableAnimation
|
|
249
|
+
}),
|
|
250
|
+
[(0, import_shared_utils.objectToDeps)(variantProps), isClearable, disableAnimation]
|
|
251
|
+
);
|
|
252
|
+
const getBaseProps = () => ({
|
|
253
|
+
"data-invalid": (0, import_shared_utils.dataAttr)(isInvalid),
|
|
254
|
+
"data-open": (0, import_shared_utils.dataAttr)(state.isOpen),
|
|
255
|
+
className: slots.base({ class: baseStyles })
|
|
256
|
+
});
|
|
257
|
+
const getSelectorButtonProps = () => {
|
|
258
|
+
var _a2;
|
|
259
|
+
return {
|
|
260
|
+
ref: buttonRef,
|
|
261
|
+
...(0, import_utils.mergeProps)(buttonProps, slotsProps.selectorButtonProps),
|
|
262
|
+
"data-open": (0, import_shared_utils.dataAttr)(state.isOpen),
|
|
263
|
+
className: slots.selectorButton({
|
|
264
|
+
class: (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.selectorButton, (_a2 = slotsProps.selectorButtonProps) == null ? void 0 : _a2.className)
|
|
265
|
+
})
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
const getClearButtonProps = () => {
|
|
269
|
+
var _a2, _b2;
|
|
270
|
+
return {
|
|
271
|
+
...(0, import_utils.mergeProps)(buttonProps, slotsProps.clearButtonProps),
|
|
272
|
+
// disable original focus and state toggle from react aria
|
|
273
|
+
onPressStart: () => {
|
|
274
|
+
var _a3;
|
|
275
|
+
(_a3 = inputRef.current) == null ? void 0 : _a3.focus();
|
|
276
|
+
},
|
|
277
|
+
onPress: (e) => {
|
|
278
|
+
var _a3, _b3;
|
|
279
|
+
(_b3 = (_a3 = slotsProps.clearButtonProps) == null ? void 0 : _a3.onPress) == null ? void 0 : _b3.call(_a3, e);
|
|
280
|
+
if (state.selectedItem) {
|
|
281
|
+
state.setSelectedKey(null);
|
|
282
|
+
}
|
|
283
|
+
state.setInputValue("");
|
|
284
|
+
state.open();
|
|
285
|
+
},
|
|
286
|
+
"data-visible": !!state.selectedItem || ((_a2 = state.inputValue) == null ? void 0 : _a2.length) > 0,
|
|
287
|
+
className: slots.clearButton({
|
|
288
|
+
class: (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.clearButton, (_b2 = slotsProps.clearButtonProps) == null ? void 0 : _b2.className)
|
|
289
|
+
})
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
const hasUncommittedValidation = validationBehavior === "native" && state.displayValidation.isInvalid === false && state.realtimeValidation.isInvalid === true;
|
|
293
|
+
const getInputProps = () => ({
|
|
294
|
+
...otherProps,
|
|
295
|
+
...inputProps,
|
|
296
|
+
...slotsProps.inputProps,
|
|
297
|
+
isInvalid: hasUncommittedValidation ? void 0 : isInvalid,
|
|
298
|
+
validationBehavior,
|
|
299
|
+
errorMessage: typeof errorMessage === "function" ? errorMessage({ isInvalid, validationErrors, validationDetails }) : errorMessage || (validationErrors == null ? void 0 : validationErrors.join(" ")),
|
|
300
|
+
onClick: (0, import_utils.chain)(slotsProps.inputProps.onClick, otherProps.onClick)
|
|
301
|
+
});
|
|
302
|
+
const getListBoxProps = () => {
|
|
303
|
+
const shouldVirtualize = isVirtualized != null ? isVirtualized : state.collection.size > 50;
|
|
304
|
+
return {
|
|
305
|
+
state,
|
|
306
|
+
ref: listBoxRef,
|
|
307
|
+
isVirtualized: shouldVirtualize,
|
|
308
|
+
virtualization: shouldVirtualize ? {
|
|
309
|
+
maxListboxHeight,
|
|
310
|
+
itemHeight
|
|
311
|
+
} : void 0,
|
|
312
|
+
scrollShadowProps: slotsProps.scrollShadowProps,
|
|
313
|
+
...(0, import_utils.mergeProps)(slotsProps.listboxProps, listBoxProps, {
|
|
314
|
+
shouldHighlightOnFocus: true
|
|
315
|
+
})
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
const getPopoverProps = (props2 = {}) => {
|
|
319
|
+
var _a2, _b2, _c2;
|
|
320
|
+
const popoverProps2 = (0, import_utils.mergeProps)(slotsProps.popoverProps, props2);
|
|
321
|
+
return {
|
|
322
|
+
state,
|
|
323
|
+
ref: popoverRef,
|
|
324
|
+
triggerRef: inputWrapperRef,
|
|
325
|
+
scrollRef: listBoxRef,
|
|
326
|
+
triggerType: "listbox",
|
|
327
|
+
...popoverProps2,
|
|
328
|
+
classNames: {
|
|
329
|
+
...(_a2 = slotsProps.popoverProps) == null ? void 0 : _a2.classNames,
|
|
330
|
+
content: slots.popoverContent({
|
|
331
|
+
class: (0, import_shared_utils.clsx)(
|
|
332
|
+
classNames == null ? void 0 : classNames.popoverContent,
|
|
333
|
+
(_c2 = (_b2 = slotsProps.popoverProps) == null ? void 0 : _b2.classNames) == null ? void 0 : _c2["content"],
|
|
334
|
+
props2.className
|
|
335
|
+
)
|
|
336
|
+
})
|
|
337
|
+
},
|
|
338
|
+
shouldCloseOnInteractOutside: (popoverProps2 == null ? void 0 : popoverProps2.shouldCloseOnInteractOutside) ? popoverProps2.shouldCloseOnInteractOutside : (element) => (0, import_aria_utils.ariaShouldCloseOnInteractOutside)(element, inputWrapperRef, state),
|
|
339
|
+
// when the popover is open, the focus should be on input instead of dialog
|
|
340
|
+
// therefore, we skip dialog focus here
|
|
341
|
+
disableDialogFocus: true
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
const getEmptyPopoverProps = () => {
|
|
345
|
+
return {
|
|
346
|
+
ref: popoverRef,
|
|
347
|
+
className: "hidden"
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
const getListBoxWrapperProps = (props2 = {}) => {
|
|
351
|
+
var _a2, _b2;
|
|
352
|
+
return {
|
|
353
|
+
...(0, import_utils.mergeProps)(slotsProps.scrollShadowProps, props2),
|
|
354
|
+
className: slots.listboxWrapper({
|
|
355
|
+
class: (0, import_shared_utils.clsx)(
|
|
356
|
+
classNames == null ? void 0 : classNames.listboxWrapper,
|
|
357
|
+
(_a2 = slotsProps.scrollShadowProps) == null ? void 0 : _a2.className,
|
|
358
|
+
props2 == null ? void 0 : props2.className
|
|
359
|
+
)
|
|
360
|
+
}),
|
|
361
|
+
style: {
|
|
362
|
+
maxHeight: (_b2 = originalProps.maxListboxHeight) != null ? _b2 : 256
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
const getEndContentWrapperProps = (props2 = {}) => ({
|
|
367
|
+
className: slots.endContentWrapper({
|
|
368
|
+
class: (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.endContentWrapper, props2 == null ? void 0 : props2.className)
|
|
369
|
+
}),
|
|
370
|
+
onPointerDown: (0, import_utils.chain)(props2.onPointerDown, (e) => {
|
|
371
|
+
var _a2;
|
|
372
|
+
if (e.button === 0 && e.currentTarget === e.target) {
|
|
373
|
+
(_a2 = inputRef.current) == null ? void 0 : _a2.focus();
|
|
374
|
+
}
|
|
375
|
+
}),
|
|
376
|
+
onMouseDown: (0, import_utils.chain)(props2.onMouseDown, (e) => {
|
|
377
|
+
if (e.button === 0 && e.currentTarget === e.target) {
|
|
378
|
+
e.preventDefault();
|
|
379
|
+
}
|
|
380
|
+
})
|
|
381
|
+
});
|
|
382
|
+
return {
|
|
383
|
+
Component,
|
|
384
|
+
inputRef,
|
|
385
|
+
label,
|
|
386
|
+
state,
|
|
387
|
+
slots,
|
|
388
|
+
classNames,
|
|
389
|
+
isLoading,
|
|
390
|
+
clearIcon,
|
|
391
|
+
isOpen,
|
|
392
|
+
endContent,
|
|
393
|
+
isClearable,
|
|
394
|
+
disableAnimation,
|
|
395
|
+
allowsCustomValue,
|
|
396
|
+
selectorIcon,
|
|
397
|
+
getBaseProps,
|
|
398
|
+
getInputProps,
|
|
399
|
+
getListBoxProps,
|
|
400
|
+
getPopoverProps,
|
|
401
|
+
getEmptyPopoverProps,
|
|
402
|
+
getClearButtonProps,
|
|
403
|
+
getSelectorButtonProps,
|
|
404
|
+
getListBoxWrapperProps,
|
|
405
|
+
getEndContentWrapperProps
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/autocomplete.tsx
|
|
410
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
411
|
+
var Autocomplete = (0, import_system2.forwardRef)(function Autocomplete2(props, ref) {
|
|
412
|
+
var _a;
|
|
413
|
+
const {
|
|
414
|
+
Component,
|
|
415
|
+
isOpen,
|
|
416
|
+
disableAnimation,
|
|
417
|
+
selectorIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_shared_icons.ChevronDownIcon, {}),
|
|
418
|
+
clearIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_shared_icons.CloseIcon, {}),
|
|
419
|
+
endContent,
|
|
420
|
+
getBaseProps,
|
|
421
|
+
getSelectorButtonProps,
|
|
422
|
+
getInputProps,
|
|
423
|
+
getListBoxProps,
|
|
424
|
+
getPopoverProps,
|
|
425
|
+
getEmptyPopoverProps,
|
|
426
|
+
getClearButtonProps,
|
|
427
|
+
getListBoxWrapperProps,
|
|
428
|
+
getEndContentWrapperProps
|
|
429
|
+
} = useAutocomplete({ ...props, ref });
|
|
430
|
+
const listboxProps = getListBoxProps();
|
|
431
|
+
const popoverContent = isOpen ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_popover.FreeSoloPopover, { ...getPopoverProps(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_scroll_shadow.ScrollShadow, { ...getListBoxWrapperProps(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_listbox.Listbox, { ...listboxProps }) }) }) : ((_a = listboxProps.state) == null ? void 0 : _a.collection.size) === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ...getEmptyPopoverProps() }) : null;
|
|
432
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Component, { ...getBaseProps(), children: [
|
|
433
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
434
|
+
import_input.Input,
|
|
435
|
+
{
|
|
436
|
+
...getInputProps(),
|
|
437
|
+
endContent: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...getEndContentWrapperProps(), children: [
|
|
438
|
+
endContent || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { ...getClearButtonProps(), children: clearIcon }),
|
|
439
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { ...getSelectorButtonProps(), children: selectorIcon })
|
|
440
|
+
] })
|
|
441
|
+
}
|
|
442
|
+
),
|
|
443
|
+
disableAnimation ? popoverContent : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_framer_motion.AnimatePresence, { children: popoverContent })
|
|
444
|
+
] });
|
|
445
|
+
});
|
|
446
|
+
var autocomplete_default = Autocomplete;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useAutocomplete
|
|
4
|
+
} from "./chunk-OHYOYGT2.mjs";
|
|
5
|
+
|
|
6
|
+
// src/autocomplete.tsx
|
|
7
|
+
import { forwardRef } from "@heroui/system";
|
|
8
|
+
import { FreeSoloPopover } from "@heroui/popover";
|
|
9
|
+
import { ScrollShadow } from "@heroui/scroll-shadow";
|
|
10
|
+
import { ChevronDownIcon, CloseIcon } from "@heroui/shared-icons";
|
|
11
|
+
import { Listbox } from "@heroui/listbox";
|
|
12
|
+
import { Button } from "@heroui/button";
|
|
13
|
+
import { Input } from "@heroui/input";
|
|
14
|
+
import { AnimatePresence } from "framer-motion";
|
|
15
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
var Autocomplete = forwardRef(function Autocomplete2(props, ref) {
|
|
17
|
+
var _a;
|
|
18
|
+
const {
|
|
19
|
+
Component,
|
|
20
|
+
isOpen,
|
|
21
|
+
disableAnimation,
|
|
22
|
+
selectorIcon = /* @__PURE__ */ jsx(ChevronDownIcon, {}),
|
|
23
|
+
clearIcon = /* @__PURE__ */ jsx(CloseIcon, {}),
|
|
24
|
+
endContent,
|
|
25
|
+
getBaseProps,
|
|
26
|
+
getSelectorButtonProps,
|
|
27
|
+
getInputProps,
|
|
28
|
+
getListBoxProps,
|
|
29
|
+
getPopoverProps,
|
|
30
|
+
getEmptyPopoverProps,
|
|
31
|
+
getClearButtonProps,
|
|
32
|
+
getListBoxWrapperProps,
|
|
33
|
+
getEndContentWrapperProps
|
|
34
|
+
} = useAutocomplete({ ...props, ref });
|
|
35
|
+
const listboxProps = getListBoxProps();
|
|
36
|
+
const popoverContent = isOpen ? /* @__PURE__ */ jsx(FreeSoloPopover, { ...getPopoverProps(), children: /* @__PURE__ */ jsx(ScrollShadow, { ...getListBoxWrapperProps(), children: /* @__PURE__ */ jsx(Listbox, { ...listboxProps }) }) }) : ((_a = listboxProps.state) == null ? void 0 : _a.collection.size) === 0 ? /* @__PURE__ */ jsx("div", { ...getEmptyPopoverProps() }) : null;
|
|
37
|
+
return /* @__PURE__ */ jsxs(Component, { ...getBaseProps(), children: [
|
|
38
|
+
/* @__PURE__ */ jsx(
|
|
39
|
+
Input,
|
|
40
|
+
{
|
|
41
|
+
...getInputProps(),
|
|
42
|
+
endContent: /* @__PURE__ */ jsxs("div", { ...getEndContentWrapperProps(), children: [
|
|
43
|
+
endContent || /* @__PURE__ */ jsx(Button, { ...getClearButtonProps(), children: clearIcon }),
|
|
44
|
+
/* @__PURE__ */ jsx(Button, { ...getSelectorButtonProps(), children: selectorIcon })
|
|
45
|
+
] })
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
disableAnimation ? popoverContent : /* @__PURE__ */ jsx(AnimatePresence, { children: popoverContent })
|
|
49
|
+
] });
|
|
50
|
+
});
|
|
51
|
+
var autocomplete_default = Autocomplete;
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
autocomplete_default
|
|
55
|
+
};
|