instantsearch-ui-components 0.11.2 → 0.13.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/dist/cjs/components/Button.js +29 -0
- package/dist/cjs/components/Carousel.js +26 -6
- package/dist/cjs/components/autocomplete/Autocomplete.js +23 -0
- package/dist/cjs/components/autocomplete/AutocompleteIndex.js +44 -0
- package/dist/cjs/components/autocomplete/AutocompletePanel.js +25 -0
- package/dist/cjs/components/autocomplete/AutocompleteSearch.js +70 -0
- package/dist/cjs/components/autocomplete/AutocompleteSuggestion.js +20 -0
- package/dist/cjs/components/autocomplete/createAutocompletePropGetters.js +222 -0
- package/dist/cjs/components/autocomplete/icons.js +56 -0
- package/dist/cjs/components/autocomplete/index.js +71 -0
- package/dist/cjs/components/chat/Chat.js +79 -0
- package/dist/cjs/components/chat/ChatHeader.js +89 -0
- package/dist/cjs/components/chat/ChatMessage.js +138 -0
- package/dist/cjs/components/chat/ChatMessageError.js +57 -0
- package/dist/cjs/components/chat/ChatMessageLoader.js +47 -0
- package/dist/cjs/components/chat/ChatMessages.js +192 -0
- package/dist/cjs/components/chat/ChatPrompt.js +179 -0
- package/dist/cjs/components/chat/ChatToggleButton.js +46 -0
- package/dist/cjs/components/chat/icons.js +375 -0
- package/dist/cjs/components/chat/types.js +1 -0
- package/dist/cjs/components/index.js +132 -0
- package/dist/cjs/lib/index.js +22 -0
- package/dist/cjs/lib/stickToBottom.js +481 -0
- package/dist/cjs/lib/utils/find.js +15 -0
- package/dist/cjs/lib/utils/index.js +27 -0
- package/dist/cjs/lib/utils/startsWith.js +9 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/warn.js +40 -0
- package/dist/es/components/Button.d.ts +38 -0
- package/dist/es/components/Button.js +22 -0
- package/dist/es/components/Carousel.d.ts +11 -0
- package/dist/es/components/Carousel.js +26 -6
- package/dist/es/components/autocomplete/Autocomplete.d.ts +13 -0
- package/dist/es/components/autocomplete/Autocomplete.js +16 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.d.ts +38 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.js +37 -0
- package/dist/es/components/autocomplete/AutocompletePanel.d.ts +17 -0
- package/dist/es/components/autocomplete/AutocompletePanel.js +18 -0
- package/dist/es/components/autocomplete/AutocompleteSearch.d.ts +8 -0
- package/dist/es/components/autocomplete/AutocompleteSearch.js +63 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.d.ts +16 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.js +14 -0
- package/dist/es/components/autocomplete/createAutocompletePropGetters.d.ts +49 -0
- package/dist/es/components/autocomplete/createAutocompletePropGetters.js +215 -0
- package/dist/es/components/autocomplete/icons.d.ts +7 -0
- package/dist/es/components/autocomplete/icons.js +48 -0
- package/dist/es/components/autocomplete/index.d.ts +6 -0
- package/dist/es/components/autocomplete/index.js +6 -0
- package/dist/es/components/chat/Chat.d.ts +42 -0
- package/dist/es/components/chat/Chat.js +72 -0
- package/dist/es/components/chat/ChatHeader.d.ts +99 -0
- package/dist/es/components/chat/ChatHeader.js +82 -0
- package/dist/es/components/chat/ChatMessage.d.ts +124 -0
- package/dist/es/components/chat/ChatMessage.js +131 -0
- package/dist/es/components/chat/ChatMessageError.d.ts +27 -0
- package/dist/es/components/chat/ChatMessageError.js +50 -0
- package/dist/es/components/chat/ChatMessageLoader.d.ts +15 -0
- package/dist/es/components/chat/ChatMessageLoader.js +40 -0
- package/dist/es/components/chat/ChatMessages.d.ts +139 -0
- package/dist/es/components/chat/ChatMessages.js +185 -0
- package/dist/es/components/chat/ChatPrompt.d.ts +119 -0
- package/dist/es/components/chat/ChatPrompt.js +172 -0
- package/dist/es/components/chat/ChatToggleButton.d.ts +29 -0
- package/dist/es/components/chat/ChatToggleButton.js +39 -0
- package/dist/es/components/chat/icons.d.ts +22 -0
- package/dist/es/components/chat/icons.js +355 -0
- package/dist/es/components/chat/types.d.ts +29 -0
- package/dist/es/components/chat/types.js +1 -0
- package/dist/es/components/index.d.ts +12 -0
- package/dist/es/components/index.js +12 -0
- package/dist/es/lib/index.d.ts +2 -0
- package/dist/es/lib/index.js +3 -1
- package/dist/es/lib/stickToBottom.d.ts +114 -0
- package/dist/es/lib/stickToBottom.js +474 -0
- package/dist/es/lib/utils/find.d.ts +1 -0
- package/dist/es/lib/utils/find.js +9 -0
- package/dist/es/lib/utils/index.d.ts +2 -0
- package/dist/es/lib/utils/index.js +2 -0
- package/dist/es/lib/utils/startsWith.d.ts +1 -0
- package/dist/es/lib/utils/startsWith.js +3 -0
- package/dist/es/types/Renderer.d.ts +1 -1
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/es/warn.d.ts +10 -0
- package/dist/es/warn.js +33 -0
- package/package.json +7 -3
package/dist/cjs/version.js
CHANGED
package/dist/cjs/warn.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.warn = warn;
|
|
7
|
+
exports.warnCache = void 0;
|
|
8
|
+
/* eslint-disable no-console, no-empty */
|
|
9
|
+
|
|
10
|
+
var warnCache = exports.warnCache = {
|
|
11
|
+
current: {}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Logs a warning if the condition is not met.
|
|
16
|
+
* This is used to log issues in development environment only.
|
|
17
|
+
*/
|
|
18
|
+
function warn(condition, message) {
|
|
19
|
+
if (!(process.env.NODE_ENV === 'development')) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (condition) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
var sanitizedMessage = message.trim();
|
|
26
|
+
var hasAlreadyPrinted = warnCache.current[sanitizedMessage];
|
|
27
|
+
if (!hasAlreadyPrinted) {
|
|
28
|
+
warnCache.current[sanitizedMessage] = true;
|
|
29
|
+
var warning = "[instantsearch-ui-components] ".concat(sanitizedMessage);
|
|
30
|
+
console.warn(warning);
|
|
31
|
+
try {
|
|
32
|
+
// Welcome to debugging InstantSearch.
|
|
33
|
+
//
|
|
34
|
+
// This error was thrown as a convenience so that you can find the source
|
|
35
|
+
// of the warning that appears in the console by enabling "Pause on exceptions"
|
|
36
|
+
// in your debugger.
|
|
37
|
+
throw new Error(warning);
|
|
38
|
+
} catch (error) {}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ComponentChildren, ComponentProps, Renderer } from '../types';
|
|
2
|
+
export type ButtonVariant = 'primary' | 'ghost' | 'outline';
|
|
3
|
+
export type ButtonSize = 'sm' | 'md';
|
|
4
|
+
export type ButtonProps = Omit<ComponentProps<'button'>, 'children'> & {
|
|
5
|
+
/**
|
|
6
|
+
* The button variant
|
|
7
|
+
* @default 'primary'
|
|
8
|
+
*/
|
|
9
|
+
variant?: ButtonVariant;
|
|
10
|
+
/**
|
|
11
|
+
* The button size
|
|
12
|
+
* @default 'md'
|
|
13
|
+
*/
|
|
14
|
+
size?: ButtonSize;
|
|
15
|
+
/**
|
|
16
|
+
* Whether the button contains only an icon (applies square padding)
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
iconOnly?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the button is disabled
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The button class name
|
|
27
|
+
*/
|
|
28
|
+
className?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The button content
|
|
31
|
+
*/
|
|
32
|
+
children?: ComponentChildren;
|
|
33
|
+
/**
|
|
34
|
+
* Click event handler
|
|
35
|
+
*/
|
|
36
|
+
onClick?: (event: any) => void;
|
|
37
|
+
};
|
|
38
|
+
export declare function createButtonComponent({ createElement, }: Pick<Renderer, 'createElement'>): (userProps: ButtonProps) => JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["variant", "size", "iconOnly", "className", "children"];
|
|
4
|
+
import { cx } from "../lib/cx.js";
|
|
5
|
+
export function createButtonComponent(_ref) {
|
|
6
|
+
var createElement = _ref.createElement;
|
|
7
|
+
return function Button(userProps) {
|
|
8
|
+
var _userProps$variant = userProps.variant,
|
|
9
|
+
variant = _userProps$variant === void 0 ? 'primary' : _userProps$variant,
|
|
10
|
+
_userProps$size = userProps.size,
|
|
11
|
+
size = _userProps$size === void 0 ? 'md' : _userProps$size,
|
|
12
|
+
_userProps$iconOnly = userProps.iconOnly,
|
|
13
|
+
iconOnly = _userProps$iconOnly === void 0 ? false : _userProps$iconOnly,
|
|
14
|
+
className = userProps.className,
|
|
15
|
+
children = userProps.children,
|
|
16
|
+
props = _objectWithoutProperties(userProps, _excluded);
|
|
17
|
+
return createElement("button", _extends({
|
|
18
|
+
type: "button",
|
|
19
|
+
className: cx('ais-Button', "ais-Button--".concat(variant), "ais-Button--".concat(size), iconOnly && 'ais-Button--icon-only', className)
|
|
20
|
+
}, props), children);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -4,10 +4,21 @@ export type CarouselProps<TObject, TComponentProps extends Record<string, unknow
|
|
|
4
4
|
nextButtonRef: MutableRef<HTMLButtonElement | null>;
|
|
5
5
|
previousButtonRef: MutableRef<HTMLButtonElement | null>;
|
|
6
6
|
carouselIdRef: MutableRef<string>;
|
|
7
|
+
canScrollLeft: boolean;
|
|
8
|
+
canScrollRight: boolean;
|
|
9
|
+
setCanScrollLeft: (canScrollLeft: boolean) => void;
|
|
10
|
+
setCanScrollRight: (canScrollRight: boolean) => void;
|
|
7
11
|
items: Array<RecordWithObjectID<TObject>>;
|
|
8
12
|
itemComponent?: (props: RecommendItemComponentProps<RecordWithObjectID<TObject>> & TComponentProps) => JSX.Element;
|
|
9
13
|
previousIconComponent?: () => JSX.Element;
|
|
10
14
|
nextIconComponent?: () => JSX.Element;
|
|
15
|
+
headerComponent?: (props: {
|
|
16
|
+
canScrollLeft: boolean;
|
|
17
|
+
canScrollRight: boolean;
|
|
18
|
+
scrollLeft: () => void;
|
|
19
|
+
scrollRight: () => void;
|
|
20
|
+
}) => JSX.Element;
|
|
21
|
+
showNavigation?: boolean;
|
|
11
22
|
classNames?: Partial<CarouselClassNames>;
|
|
12
23
|
translations?: Partial<CarouselTranslations>;
|
|
13
24
|
sendEvent: SendEventForHits;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["listRef", "nextButtonRef", "previousButtonRef", "carouselIdRef", "classNames", "itemComponent", "previousIconComponent", "nextIconComponent", "items", "translations", "sendEvent"];
|
|
4
|
+
var _excluded = ["listRef", "nextButtonRef", "previousButtonRef", "carouselIdRef", "canScrollLeft", "canScrollRight", "setCanScrollLeft", "setCanScrollRight", "classNames", "itemComponent", "previousIconComponent", "nextIconComponent", "headerComponent", "showNavigation", "items", "translations", "sendEvent"];
|
|
5
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
7
|
import { cx } from "../lib/index.js";
|
|
@@ -46,6 +46,10 @@ export function createCarouselComponent(_ref3) {
|
|
|
46
46
|
nextButtonRef = userProps.nextButtonRef,
|
|
47
47
|
previousButtonRef = userProps.previousButtonRef,
|
|
48
48
|
carouselIdRef = userProps.carouselIdRef,
|
|
49
|
+
canScrollLeft = userProps.canScrollLeft,
|
|
50
|
+
canScrollRight = userProps.canScrollRight,
|
|
51
|
+
setCanScrollLeft = userProps.setCanScrollLeft,
|
|
52
|
+
setCanScrollRight = userProps.setCanScrollRight,
|
|
49
53
|
_userProps$classNames = userProps.classNames,
|
|
50
54
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
51
55
|
_userProps$itemCompon = userProps.itemComponent,
|
|
@@ -57,6 +61,9 @@ export function createCarouselComponent(_ref3) {
|
|
|
57
61
|
PreviousIconComponent = _userProps$previousIc === void 0 ? PreviousIconDefaultComponent : _userProps$previousIc,
|
|
58
62
|
_userProps$nextIconCo = userProps.nextIconComponent,
|
|
59
63
|
NextIconComponent = _userProps$nextIconCo === void 0 ? NextIconDefaultComponent : _userProps$nextIconCo,
|
|
64
|
+
HeaderComponent = userProps.headerComponent,
|
|
65
|
+
_userProps$showNaviga = userProps.showNavigation,
|
|
66
|
+
showNavigation = _userProps$showNaviga === void 0 ? true : _userProps$showNaviga,
|
|
60
67
|
items = userProps.items,
|
|
61
68
|
userTranslations = userProps.translations,
|
|
62
69
|
sendEvent = userProps.sendEvent,
|
|
@@ -87,18 +94,31 @@ export function createCarouselComponent(_ref3) {
|
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
function updateNavigationButtonsProps() {
|
|
90
|
-
if (!listRef.current
|
|
97
|
+
if (!listRef.current) {
|
|
91
98
|
return;
|
|
92
99
|
}
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
var isLeftHidden = listRef.current.scrollLeft <= 0;
|
|
101
|
+
var isRightHidden = listRef.current.scrollLeft + listRef.current.clientWidth >= listRef.current.scrollWidth;
|
|
102
|
+
setCanScrollLeft(!isLeftHidden);
|
|
103
|
+
setCanScrollRight(!isRightHidden);
|
|
104
|
+
if (previousButtonRef.current) {
|
|
105
|
+
previousButtonRef.current.hidden = isLeftHidden;
|
|
106
|
+
}
|
|
107
|
+
if (nextButtonRef.current) {
|
|
108
|
+
nextButtonRef.current.hidden = isRightHidden;
|
|
109
|
+
}
|
|
95
110
|
}
|
|
96
111
|
if (items.length === 0) {
|
|
97
112
|
return null;
|
|
98
113
|
}
|
|
99
114
|
return createElement("div", _extends({}, props, {
|
|
100
115
|
className: cx(cssClasses.root)
|
|
101
|
-
}), createElement(
|
|
116
|
+
}), HeaderComponent && createElement(HeaderComponent, {
|
|
117
|
+
canScrollLeft: canScrollLeft,
|
|
118
|
+
canScrollRight: canScrollRight,
|
|
119
|
+
scrollLeft: scrollLeft,
|
|
120
|
+
scrollRight: scrollRight
|
|
121
|
+
}), showNavigation && createElement("button", {
|
|
102
122
|
ref: previousButtonRef,
|
|
103
123
|
title: translations.previousButtonTitle,
|
|
104
124
|
"aria-label": translations.previousButtonLabel,
|
|
@@ -145,7 +165,7 @@ export function createCarouselComponent(_ref3) {
|
|
|
145
165
|
item: item,
|
|
146
166
|
sendEvent: sendEvent
|
|
147
167
|
}));
|
|
148
|
-
})), createElement("button", {
|
|
168
|
+
})), showNavigation && createElement("button", {
|
|
149
169
|
ref: nextButtonRef,
|
|
150
170
|
title: translations.nextButtonTitle,
|
|
151
171
|
"aria-label": translations.nextButtonLabel,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentChildren, ComponentProps, Renderer } from '../../types';
|
|
3
|
+
export type AutocompleteProps = Omit<ComponentProps<'div'>, 'children'> & {
|
|
4
|
+
children?: ComponentChildren;
|
|
5
|
+
classNames?: Partial<AutocompleteClassNames>;
|
|
6
|
+
};
|
|
7
|
+
export type AutocompleteClassNames = {
|
|
8
|
+
/**
|
|
9
|
+
* Class names to apply to the root element
|
|
10
|
+
*/
|
|
11
|
+
root: string | string[];
|
|
12
|
+
};
|
|
13
|
+
export declare function createAutocompleteComponent({ createElement }: Renderer): (userProps: AutocompleteProps) => JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["children", "classNames"];
|
|
4
|
+
import { cx } from "../../lib/cx.js";
|
|
5
|
+
export function createAutocompleteComponent(_ref) {
|
|
6
|
+
var createElement = _ref.createElement;
|
|
7
|
+
return function Autocomplete(userProps) {
|
|
8
|
+
var children = userProps.children,
|
|
9
|
+
_userProps$classNames = userProps.classNames,
|
|
10
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
11
|
+
props = _objectWithoutProperties(userProps, _excluded);
|
|
12
|
+
return createElement("div", _extends({
|
|
13
|
+
className: cx('ais-Autocomplete', classNames.root)
|
|
14
|
+
}, props), children);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentProps, Renderer } from '../../types';
|
|
3
|
+
export type AutocompleteIndexProps<T = {
|
|
4
|
+
objectID: string;
|
|
5
|
+
__indexName: string;
|
|
6
|
+
} & Record<string, unknown>> = {
|
|
7
|
+
items: T[];
|
|
8
|
+
HeaderComponent?: (props: {
|
|
9
|
+
items: T[];
|
|
10
|
+
}) => JSX.Element;
|
|
11
|
+
ItemComponent: (props: {
|
|
12
|
+
item: T;
|
|
13
|
+
onSelect: () => void;
|
|
14
|
+
}) => JSX.Element;
|
|
15
|
+
getItemProps: (item: T, index: number) => Omit<ComponentProps<'li'>, 'onSelect'> & {
|
|
16
|
+
onSelect: () => void;
|
|
17
|
+
};
|
|
18
|
+
classNames?: Partial<AutocompleteIndexClassNames>;
|
|
19
|
+
};
|
|
20
|
+
export type AutocompleteIndexClassNames = {
|
|
21
|
+
/**
|
|
22
|
+
* Class names to apply to the root element
|
|
23
|
+
**/
|
|
24
|
+
root: string | string[];
|
|
25
|
+
/**
|
|
26
|
+
* Class names to apply to the list element
|
|
27
|
+
*/
|
|
28
|
+
list: string | string[];
|
|
29
|
+
/**
|
|
30
|
+
* Class names to apply to the header element
|
|
31
|
+
*/
|
|
32
|
+
header: string | string[];
|
|
33
|
+
/**
|
|
34
|
+
* Class names to apply to each item element
|
|
35
|
+
*/
|
|
36
|
+
item: string | string[];
|
|
37
|
+
};
|
|
38
|
+
export declare function createAutocompleteIndexComponent({ createElement }: Renderer): (userProps: AutocompleteIndexProps) => JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["className", "onSelect"];
|
|
4
|
+
import { cx } from "../../lib/cx.js";
|
|
5
|
+
export function createAutocompleteIndexComponent(_ref) {
|
|
6
|
+
var createElement = _ref.createElement;
|
|
7
|
+
return function AutocompleteIndex(userProps) {
|
|
8
|
+
var items = userProps.items,
|
|
9
|
+
HeaderComponent = userProps.HeaderComponent,
|
|
10
|
+
ItemComponent = userProps.ItemComponent,
|
|
11
|
+
getItemProps = userProps.getItemProps,
|
|
12
|
+
_userProps$classNames = userProps.classNames,
|
|
13
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
14
|
+
return createElement("div", {
|
|
15
|
+
className: cx('ais-AutocompleteIndex', classNames.root)
|
|
16
|
+
}, HeaderComponent && createElement("div", {
|
|
17
|
+
className: cx('ais-AutocompleteIndexHeader', classNames.header)
|
|
18
|
+
}, createElement(HeaderComponent, {
|
|
19
|
+
items: items
|
|
20
|
+
})), createElement("ol", {
|
|
21
|
+
className: cx('ais-AutocompleteIndexList', classNames.list)
|
|
22
|
+
}, items.map(function (item, index) {
|
|
23
|
+
var _getItemProps = getItemProps(item, index),
|
|
24
|
+
className = _getItemProps.className,
|
|
25
|
+
onSelect = _getItemProps.onSelect,
|
|
26
|
+
itemProps = _objectWithoutProperties(_getItemProps, _excluded);
|
|
27
|
+
return createElement("li", _extends({
|
|
28
|
+
key: item.objectID
|
|
29
|
+
}, itemProps, {
|
|
30
|
+
className: cx('ais-AutocompleteIndexItem', classNames.item, className)
|
|
31
|
+
}), createElement(ItemComponent, {
|
|
32
|
+
item: item,
|
|
33
|
+
onSelect: onSelect
|
|
34
|
+
}));
|
|
35
|
+
})));
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentChildren, ComponentProps, Renderer } from '../../types';
|
|
3
|
+
export type AutocompletePanelProps = Omit<ComponentProps<'div'>, 'children'> & {
|
|
4
|
+
children?: ComponentChildren;
|
|
5
|
+
classNames?: Partial<AutocompletePanelClassNames>;
|
|
6
|
+
};
|
|
7
|
+
export type AutocompletePanelClassNames = {
|
|
8
|
+
/**
|
|
9
|
+
* Class names to apply to the root element
|
|
10
|
+
*/
|
|
11
|
+
root: string | string[];
|
|
12
|
+
/**
|
|
13
|
+
* Class names to apply to the layout element
|
|
14
|
+
*/
|
|
15
|
+
layout: string | string[];
|
|
16
|
+
};
|
|
17
|
+
export declare function createAutocompletePanelComponent({ createElement }: Renderer): (userProps: AutocompletePanelProps) => JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["children", "classNames"];
|
|
4
|
+
import { cx } from "../../lib/cx.js";
|
|
5
|
+
export function createAutocompletePanelComponent(_ref) {
|
|
6
|
+
var createElement = _ref.createElement;
|
|
7
|
+
return function AutocompletePanel(userProps) {
|
|
8
|
+
var children = userProps.children,
|
|
9
|
+
_userProps$classNames = userProps.classNames,
|
|
10
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
11
|
+
props = _objectWithoutProperties(userProps, _excluded);
|
|
12
|
+
return createElement("div", _extends({}, props, {
|
|
13
|
+
className: cx('ais-AutocompletePanel', classNames.root, props.className)
|
|
14
|
+
}), createElement("div", {
|
|
15
|
+
className: cx('ais-AutocompletePanelLayout', classNames.layout)
|
|
16
|
+
}, children));
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComponentProps, Renderer } from '../..';
|
|
2
|
+
export type AutocompleteSearchProps = {
|
|
3
|
+
inputProps: Partial<ComponentProps<'input'>>;
|
|
4
|
+
onClear: () => void;
|
|
5
|
+
query: string;
|
|
6
|
+
isSearchStalled: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function createAutocompleteSearchComponent({ createElement }: Renderer): ({ inputProps, onClear, query, isSearchStalled, }: AutocompleteSearchProps) => JSX.Element;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import { AutocompleteClearIcon, AutocompleteLoadingIcon, AutocompleteSubmitIcon } from "./icons.js";
|
|
3
|
+
export function createAutocompleteSearchComponent(_ref) {
|
|
4
|
+
var createElement = _ref.createElement;
|
|
5
|
+
return function AutocompleteSearch(_ref2) {
|
|
6
|
+
var inputProps = _ref2.inputProps,
|
|
7
|
+
onClear = _ref2.onClear,
|
|
8
|
+
query = _ref2.query,
|
|
9
|
+
isSearchStalled = _ref2.isSearchStalled;
|
|
10
|
+
return createElement("form", {
|
|
11
|
+
className: "ais-AutocompleteForm",
|
|
12
|
+
action: "",
|
|
13
|
+
noValidate: true,
|
|
14
|
+
role: "search",
|
|
15
|
+
onSubmit: function onSubmit(e) {
|
|
16
|
+
return e.preventDefault();
|
|
17
|
+
}
|
|
18
|
+
}, createElement("div", {
|
|
19
|
+
className: "ais-AutocompleteInputWrapperPrefix"
|
|
20
|
+
}, createElement("label", {
|
|
21
|
+
className: "ais-AutocompleteLabel",
|
|
22
|
+
"aria-label": "Submit",
|
|
23
|
+
htmlFor: inputProps.id,
|
|
24
|
+
id: "".concat(inputProps.id, "-label")
|
|
25
|
+
}, createElement("button", {
|
|
26
|
+
className: "ais-AutocompleteSubmitButton",
|
|
27
|
+
type: "submit",
|
|
28
|
+
title: "Submit"
|
|
29
|
+
}, createElement(AutocompleteSubmitIcon, {
|
|
30
|
+
createElement: createElement
|
|
31
|
+
}))), createElement("div", {
|
|
32
|
+
className: "ais-AutocompleteLoadingIndicator",
|
|
33
|
+
hidden: !isSearchStalled
|
|
34
|
+
}, createElement(AutocompleteLoadingIcon, {
|
|
35
|
+
createElement: createElement
|
|
36
|
+
}))), createElement("div", {
|
|
37
|
+
className: "ais-AutocompleteInputWrapper"
|
|
38
|
+
}, createElement("input", _extends({
|
|
39
|
+
className: "ais-AutocompleteInput",
|
|
40
|
+
"aria-autocomplete": "both",
|
|
41
|
+
"aria-labelledby": "".concat(inputProps.id, "-label"),
|
|
42
|
+
autoComplete: "off",
|
|
43
|
+
autoCorrect: "off",
|
|
44
|
+
autoCapitalize: "off",
|
|
45
|
+
enterKeyHint: "search",
|
|
46
|
+
spellCheck: "false",
|
|
47
|
+
placeholder: "",
|
|
48
|
+
maxLength: 512,
|
|
49
|
+
type: "search",
|
|
50
|
+
value: query
|
|
51
|
+
}, inputProps))), createElement("div", {
|
|
52
|
+
className: "ais-AutocompleteInputWrapperSuffix"
|
|
53
|
+
}, createElement("button", {
|
|
54
|
+
className: "ais-AutocompleteClearButton",
|
|
55
|
+
type: "reset",
|
|
56
|
+
title: "Clear",
|
|
57
|
+
hidden: query.length === 0 || isSearchStalled,
|
|
58
|
+
onClick: onClear
|
|
59
|
+
}, createElement(AutocompleteClearIcon, {
|
|
60
|
+
createElement: createElement
|
|
61
|
+
}))));
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { Renderer } from '../../types';
|
|
3
|
+
export type AutocompleteSuggestionProps<T = {
|
|
4
|
+
query: string;
|
|
5
|
+
} & Record<string, unknown>> = {
|
|
6
|
+
item: T;
|
|
7
|
+
onSelect: () => void;
|
|
8
|
+
classNames?: Partial<AutocompleteSuggestionClassNames>;
|
|
9
|
+
};
|
|
10
|
+
export type AutocompleteSuggestionClassNames = {
|
|
11
|
+
/**
|
|
12
|
+
* Class names to apply to the root element
|
|
13
|
+
**/
|
|
14
|
+
root: string | string[];
|
|
15
|
+
};
|
|
16
|
+
export declare function createAutocompleteSuggestionComponent({ createElement, }: Renderer): ({ item, onSelect, classNames, }: AutocompleteSuggestionProps) => JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { cx } from "../../lib/index.js";
|
|
2
|
+
export function createAutocompleteSuggestionComponent(_ref) {
|
|
3
|
+
var createElement = _ref.createElement;
|
|
4
|
+
return function AutocompleteSuggestion(_ref2) {
|
|
5
|
+
var item = _ref2.item,
|
|
6
|
+
onSelect = _ref2.onSelect,
|
|
7
|
+
_ref2$classNames = _ref2.classNames,
|
|
8
|
+
classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames;
|
|
9
|
+
return createElement("div", {
|
|
10
|
+
onClick: onSelect,
|
|
11
|
+
className: cx('ais-AutocompleteSuggestion', classNames.root)
|
|
12
|
+
}, item.query);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ComponentProps } from '../../types';
|
|
2
|
+
type BaseHit = Record<string, unknown>;
|
|
3
|
+
export type AutocompleteIndexConfig<TItem extends BaseHit> = {
|
|
4
|
+
indexName: string;
|
|
5
|
+
getQuery?: (item: TItem) => string;
|
|
6
|
+
getURL?: (item: TItem) => string;
|
|
7
|
+
onSelect?: (params: {
|
|
8
|
+
item: TItem;
|
|
9
|
+
query: string;
|
|
10
|
+
setQuery: (query: string) => void;
|
|
11
|
+
url?: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
};
|
|
14
|
+
type GetInputProps = () => Partial<ComponentProps<'input'>>;
|
|
15
|
+
type GetItemProps = (item: {
|
|
16
|
+
__indexName: string;
|
|
17
|
+
} & Record<string, unknown>, index: number) => Pick<ComponentProps<'li'>, 'id' | 'role' | 'aria-selected'> & {
|
|
18
|
+
onSelect: () => void;
|
|
19
|
+
};
|
|
20
|
+
type GetPanelProps = () => Pick<ComponentProps<'div'>, 'id' | 'hidden' | 'role' | 'aria-labelledby'>;
|
|
21
|
+
type GetRootProps = () => Pick<ComponentProps<'div'>, 'ref'>;
|
|
22
|
+
type CreateAutocompletePropGettersParams = {
|
|
23
|
+
useEffect: (effect: () => void, inputs?: readonly unknown[]) => void;
|
|
24
|
+
useId: () => string;
|
|
25
|
+
useMemo: <TType>(factory: () => TType, inputs: readonly unknown[]) => TType;
|
|
26
|
+
useRef: <TType>(initialValue: TType | null) => {
|
|
27
|
+
current: TType | null;
|
|
28
|
+
};
|
|
29
|
+
useState: <TType>(initialState: TType) => [TType, (newState: TType) => unknown];
|
|
30
|
+
};
|
|
31
|
+
type UsePropGetters<TItem extends BaseHit> = (params: {
|
|
32
|
+
indices: Array<{
|
|
33
|
+
indexName: string;
|
|
34
|
+
indexId: string;
|
|
35
|
+
hits: Array<{
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}>;
|
|
38
|
+
}>;
|
|
39
|
+
indicesConfig: Array<AutocompleteIndexConfig<TItem>>;
|
|
40
|
+
onRefine: (query: string) => void;
|
|
41
|
+
onSelect: NonNullable<AutocompleteIndexConfig<TItem>['onSelect']>;
|
|
42
|
+
}) => {
|
|
43
|
+
getInputProps: GetInputProps;
|
|
44
|
+
getItemProps: GetItemProps;
|
|
45
|
+
getPanelProps: GetPanelProps;
|
|
46
|
+
getRootProps: GetRootProps;
|
|
47
|
+
};
|
|
48
|
+
export declare function createAutocompletePropGetters({ useEffect, useId, useMemo, useRef, useState, }: CreateAutocompletePropGettersParams): <TItem extends BaseHit>({ indices, indicesConfig, onRefine, onSelect: globalOnSelect, }: Parameters<UsePropGetters<TItem>>[0]) => ReturnType<UsePropGetters<TItem>>;
|
|
49
|
+
export {};
|