instantsearch-ui-components 0.15.2 → 0.16.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.
@@ -8,7 +8,7 @@ exports.createAutocompleteIndexComponent = createAutocompleteIndexComponent;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
10
  var _cx = require("../../lib/cx");
11
- var _excluded = ["className", "onSelect"];
11
+ var _excluded = ["className", "onSelect", "onApply"];
12
12
  function createAutocompleteIndexComponent(_ref) {
13
13
  var createElement = _ref.createElement;
14
14
  return function AutocompleteIndex(userProps) {
@@ -30,6 +30,7 @@ function createAutocompleteIndexComponent(_ref) {
30
30
  var _getItemProps = getItemProps(item, index),
31
31
  className = _getItemProps.className,
32
32
  onSelect = _getItemProps.onSelect,
33
+ onApply = _getItemProps.onApply,
33
34
  itemProps = (0, _objectWithoutProperties2.default)(_getItemProps, _excluded);
34
35
  return createElement("li", (0, _extends2.default)({
35
36
  key: "".concat(itemProps.id, ":").concat(item.objectID)
@@ -37,7 +38,8 @@ function createAutocompleteIndexComponent(_ref) {
37
38
  className: (0, _cx.cx)('ais-AutocompleteIndexItem', classNames.item, className)
38
39
  }), createElement(ItemComponent, {
39
40
  item: item,
40
- onSelect: onSelect
41
+ onSelect: onSelect,
42
+ onApply: onApply
41
43
  }));
42
44
  })));
43
45
  };
@@ -13,6 +13,7 @@ function createAutocompleteRecentSearchComponent(_ref) {
13
13
  children = userProps.children,
14
14
  onSelect = userProps.onSelect,
15
15
  onRemoveRecentSearch = userProps.onRemoveRecentSearch,
16
+ onApply = userProps.onApply,
16
17
  _userProps$classNames = userProps.classNames,
17
18
  classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
18
19
  return createElement("div", {
@@ -37,6 +38,15 @@ function createAutocompleteRecentSearchComponent(_ref) {
37
38
  }
38
39
  }, createElement(_icons.TrashIcon, {
39
40
  createElement: createElement
41
+ })), createElement("button", {
42
+ className: (0, _lib.cx)('ais-AutocompleteItemActionButton', 'ais-AutocompleteRecentSearchItemApplyButton', classNames.applyButton),
43
+ title: "Apply ".concat(item.query, " as search"),
44
+ onClick: function onClick(evt) {
45
+ evt.stopPropagation();
46
+ onApply();
47
+ }
48
+ }, createElement(_icons.ApplyIcon, {
49
+ createElement: createElement
40
50
  }))));
41
51
  };
42
52
  }
@@ -9,8 +9,10 @@ var _icons = require("./icons");
9
9
  function createAutocompleteSuggestionComponent(_ref) {
10
10
  var createElement = _ref.createElement;
11
11
  return function AutocompleteSuggestion(userProps) {
12
- var children = userProps.children,
12
+ var item = userProps.item,
13
+ children = userProps.children,
13
14
  onSelect = userProps.onSelect,
15
+ onApply = userProps.onApply,
14
16
  _userProps$classNames = userProps.classNames,
15
17
  classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
16
18
  return createElement("div", {
@@ -24,6 +26,18 @@ function createAutocompleteSuggestionComponent(_ref) {
24
26
  createElement: createElement
25
27
  })), createElement("div", {
26
28
  className: (0, _lib.cx)('ais-AutocompleteItemContentBody', 'ais-AutocompleteSuggestionItemContentBody', classNames.content)
27
- }, children)));
29
+ }, children)), createElement("div", {
30
+ className: (0, _lib.cx)('ais-AutocompleteItemActions', 'ais-AutocompleteSuggestionItemActions', classNames.actions)
31
+ }, createElement("button", {
32
+ className: (0, _lib.cx)('ais-AutocompleteItemActionButton', 'ais-AutocompleteSuggestionItemApplyButton', classNames.applyButton),
33
+ type: "button",
34
+ title: "Apply ".concat(item.query, " as search"),
35
+ onClick: function onClick(evt) {
36
+ evt.stopPropagation();
37
+ onApply();
38
+ }
39
+ }, createElement(_icons.ApplyIcon, {
40
+ createElement: createElement
41
+ }))));
28
42
  };
29
43
  }
@@ -18,6 +18,7 @@ function createAutocompletePropGetters(_ref) {
18
18
  indicesConfig = _ref2.indicesConfig,
19
19
  onRefine = _ref2.onRefine,
20
20
  globalOnSelect = _ref2.onSelect,
21
+ _onApply = _ref2.onApply,
21
22
  placeholder = _ref2.placeholder;
22
23
  var getElementId = createGetElementId(useId());
23
24
  var inputRef = useRef(null);
@@ -185,6 +186,13 @@ function createAutocompletePropGetters(_ref) {
185
186
  return submit({
186
187
  activeDescendant: id
187
188
  });
189
+ },
190
+ onApply: function onApply() {
191
+ var _getQuery2;
192
+ var _ref4 = items.get(id),
193
+ currentItem = _ref4.item,
194
+ getQuery = _ref4.config.getQuery;
195
+ _onApply((_getQuery2 = getQuery === null || getQuery === void 0 ? void 0 : getQuery(currentItem)) !== null && _getQuery2 !== void 0 ? _getQuery2 : '');
188
196
  }
189
197
  };
190
198
  },
@@ -204,10 +212,10 @@ function createAutocompletePropGetters(_ref) {
204
212
  };
205
213
  };
206
214
  }
207
- function buildItems(_ref4) {
208
- var indices = _ref4.indices,
209
- indicesConfig = _ref4.indicesConfig,
210
- getElementId = _ref4.getElementId;
215
+ function buildItems(_ref5) {
216
+ var indices = _ref5.indices,
217
+ indicesConfig = _ref5.indicesConfig,
218
+ getElementId = _ref5.getElementId;
211
219
  var itemsIds = [];
212
220
  var items = new Map();
213
221
  for (var i = 0; i < indicesConfig.length; i++) {
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.ApplyIcon = ApplyIcon;
6
7
  exports.ClearIcon = ClearIcon;
7
8
  exports.ClockIcon = ClockIcon;
8
9
  exports.LoadingIcon = LoadingIcon;
@@ -67,4 +68,13 @@ function TrashIcon(_ref5) {
67
68
  }, createElement("path", {
68
69
  d: "M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z"
69
70
  }));
71
+ }
72
+ function ApplyIcon(_ref6) {
73
+ var createElement = _ref6.createElement;
74
+ return createElement("svg", {
75
+ viewBox: "0 0 24 24",
76
+ fill: "currentColor"
77
+ }, createElement("path", {
78
+ d: "M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z"
79
+ }));
70
80
  }
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '0.15.2';
7
+ var _default = exports.default = '0.16.0';
@@ -11,9 +11,11 @@ export type AutocompleteIndexProps<T = {
11
11
  ItemComponent: (props: {
12
12
  item: T;
13
13
  onSelect: () => void;
14
+ onApply: () => void;
14
15
  }) => JSX.Element;
15
16
  getItemProps: (item: T, index: number) => Omit<ComponentProps<'li'>, 'onSelect'> & {
16
17
  onSelect: () => void;
18
+ onApply: () => void;
17
19
  };
18
20
  classNames?: Partial<AutocompleteIndexClassNames>;
19
21
  };
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["className", "onSelect"];
3
+ var _excluded = ["className", "onSelect", "onApply"];
4
4
  import { cx } from "../../lib/cx.js";
5
5
  export function createAutocompleteIndexComponent(_ref) {
6
6
  var createElement = _ref.createElement;
@@ -23,6 +23,7 @@ export function createAutocompleteIndexComponent(_ref) {
23
23
  var _getItemProps = getItemProps(item, index),
24
24
  className = _getItemProps.className,
25
25
  onSelect = _getItemProps.onSelect,
26
+ onApply = _getItemProps.onApply,
26
27
  itemProps = _objectWithoutProperties(_getItemProps, _excluded);
27
28
  return createElement("li", _extends({
28
29
  key: "".concat(itemProps.id, ":").concat(item.objectID)
@@ -30,7 +31,8 @@ export function createAutocompleteIndexComponent(_ref) {
30
31
  className: cx('ais-AutocompleteIndexItem', classNames.item, className)
31
32
  }), createElement(ItemComponent, {
32
33
  item: item,
33
- onSelect: onSelect
34
+ onSelect: onSelect,
35
+ onApply: onApply
34
36
  }));
35
37
  })));
36
38
  };
@@ -7,6 +7,7 @@ export type AutocompleteRecentSearchProps<T = {
7
7
  children?: ComponentChildren;
8
8
  onSelect: () => void;
9
9
  onRemoveRecentSearch: () => void;
10
+ onApply: () => void;
10
11
  classNames?: Partial<AutocompleteRecentSearchClassNames>;
11
12
  };
12
13
  export type AutocompleteRecentSearchClassNames = {
@@ -34,5 +35,9 @@ export type AutocompleteRecentSearchClassNames = {
34
35
  * Class names to apply to the delete button element
35
36
  **/
36
37
  deleteButton: string | string[];
38
+ /**
39
+ * Class names to apply to the apply button element
40
+ **/
41
+ applyButton: string | string[];
37
42
  };
38
43
  export declare function createAutocompleteRecentSearchComponent({ createElement, }: Renderer): (userProps: AutocompleteRecentSearchProps) => JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import { cx } from "../../lib/index.js";
2
- import { ClockIcon, TrashIcon } from "./icons.js";
2
+ import { ApplyIcon, ClockIcon, TrashIcon } from "./icons.js";
3
3
  export function createAutocompleteRecentSearchComponent(_ref) {
4
4
  var createElement = _ref.createElement;
5
5
  return function AutocompleteRecentSearch(userProps) {
@@ -7,6 +7,7 @@ export function createAutocompleteRecentSearchComponent(_ref) {
7
7
  children = userProps.children,
8
8
  onSelect = userProps.onSelect,
9
9
  onRemoveRecentSearch = userProps.onRemoveRecentSearch,
10
+ onApply = userProps.onApply,
10
11
  _userProps$classNames = userProps.classNames,
11
12
  classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
12
13
  return createElement("div", {
@@ -31,6 +32,15 @@ export function createAutocompleteRecentSearchComponent(_ref) {
31
32
  }
32
33
  }, createElement(TrashIcon, {
33
34
  createElement: createElement
35
+ })), createElement("button", {
36
+ className: cx('ais-AutocompleteItemActionButton', 'ais-AutocompleteRecentSearchItemApplyButton', classNames.applyButton),
37
+ title: "Apply ".concat(item.query, " as search"),
38
+ onClick: function onClick(evt) {
39
+ evt.stopPropagation();
40
+ onApply();
41
+ }
42
+ }, createElement(ApplyIcon, {
43
+ createElement: createElement
34
44
  }))));
35
45
  };
36
46
  }
@@ -5,6 +5,7 @@ export type AutocompleteSuggestionProps<T = {
5
5
  } & Record<string, unknown>> = {
6
6
  item: T;
7
7
  onSelect: () => void;
8
+ onApply: () => void;
8
9
  children: ComponentChildren;
9
10
  classNames?: Partial<AutocompleteSuggestionClassNames>;
10
11
  };
@@ -21,5 +22,7 @@ export type AutocompleteSuggestionClassNames = {
21
22
  icon: string | string[];
22
23
  /** Class names to apply to the body element **/
23
24
  body: string | string[];
25
+ /** Class names to apply to the apply button element **/
26
+ applyButton: string | string[];
24
27
  };
25
28
  export declare function createAutocompleteSuggestionComponent({ createElement, }: Renderer): (userProps: AutocompleteSuggestionProps) => JSX.Element;
@@ -1,10 +1,12 @@
1
1
  import { cx } from "../../lib/index.js";
2
- import { SubmitIcon } from "./icons.js";
2
+ import { SubmitIcon, ApplyIcon } from "./icons.js";
3
3
  export function createAutocompleteSuggestionComponent(_ref) {
4
4
  var createElement = _ref.createElement;
5
5
  return function AutocompleteSuggestion(userProps) {
6
- var children = userProps.children,
6
+ var item = userProps.item,
7
+ children = userProps.children,
7
8
  onSelect = userProps.onSelect,
9
+ onApply = userProps.onApply,
8
10
  _userProps$classNames = userProps.classNames,
9
11
  classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
10
12
  return createElement("div", {
@@ -18,6 +20,18 @@ export function createAutocompleteSuggestionComponent(_ref) {
18
20
  createElement: createElement
19
21
  })), createElement("div", {
20
22
  className: cx('ais-AutocompleteItemContentBody', 'ais-AutocompleteSuggestionItemContentBody', classNames.content)
21
- }, children)));
23
+ }, children)), createElement("div", {
24
+ className: cx('ais-AutocompleteItemActions', 'ais-AutocompleteSuggestionItemActions', classNames.actions)
25
+ }, createElement("button", {
26
+ className: cx('ais-AutocompleteItemActionButton', 'ais-AutocompleteSuggestionItemApplyButton', classNames.applyButton),
27
+ type: "button",
28
+ title: "Apply ".concat(item.query, " as search"),
29
+ onClick: function onClick(evt) {
30
+ evt.stopPropagation();
31
+ onApply();
32
+ }
33
+ }, createElement(ApplyIcon, {
34
+ createElement: createElement
35
+ }))));
22
36
  };
23
37
  }
@@ -21,6 +21,7 @@ type GetItemProps = (item: {
21
21
  'aria-selected'?: boolean;
22
22
  } & {
23
23
  onSelect: () => void;
24
+ onApply: () => void;
24
25
  };
25
26
  type GetPanelProps = () => {
26
27
  id?: string;
@@ -51,6 +52,7 @@ export type UsePropGetters<TItem extends BaseHit> = (params: {
51
52
  indicesConfig: Array<AutocompleteIndexConfig<TItem>>;
52
53
  onRefine: (query: string) => void;
53
54
  onSelect: NonNullable<AutocompleteIndexConfig<TItem>['onSelect']>;
55
+ onApply: (query: string) => void;
54
56
  placeholder?: string;
55
57
  }) => {
56
58
  getInputProps: GetInputProps;
@@ -58,5 +60,5 @@ export type UsePropGetters<TItem extends BaseHit> = (params: {
58
60
  getPanelProps: GetPanelProps;
59
61
  getRootProps: GetRootProps;
60
62
  };
61
- export declare function createAutocompletePropGetters({ useEffect, useId, useMemo, useRef, useState, }: CreateAutocompletePropGettersParams): <TItem extends BaseHit>({ indices, indicesConfig, onRefine, onSelect: globalOnSelect, placeholder, }: Parameters<UsePropGetters<TItem>>[0]) => ReturnType<UsePropGetters<TItem>>;
63
+ export declare function createAutocompletePropGetters({ useEffect, useId, useMemo, useRef, useState, }: CreateAutocompletePropGettersParams): <TItem extends BaseHit>({ indices, indicesConfig, onRefine, onSelect: globalOnSelect, onApply, placeholder, }: Parameters<UsePropGetters<TItem>>[0]) => ReturnType<UsePropGetters<TItem>>;
62
64
  export {};
@@ -11,6 +11,7 @@ export function createAutocompletePropGetters(_ref) {
11
11
  indicesConfig = _ref2.indicesConfig,
12
12
  onRefine = _ref2.onRefine,
13
13
  globalOnSelect = _ref2.onSelect,
14
+ _onApply = _ref2.onApply,
14
15
  placeholder = _ref2.placeholder;
15
16
  var getElementId = createGetElementId(useId());
16
17
  var inputRef = useRef(null);
@@ -178,6 +179,13 @@ export function createAutocompletePropGetters(_ref) {
178
179
  return submit({
179
180
  activeDescendant: id
180
181
  });
182
+ },
183
+ onApply: function onApply() {
184
+ var _getQuery2;
185
+ var _ref4 = items.get(id),
186
+ currentItem = _ref4.item,
187
+ getQuery = _ref4.config.getQuery;
188
+ _onApply((_getQuery2 = getQuery === null || getQuery === void 0 ? void 0 : getQuery(currentItem)) !== null && _getQuery2 !== void 0 ? _getQuery2 : '');
181
189
  }
182
190
  };
183
191
  },
@@ -197,10 +205,10 @@ export function createAutocompletePropGetters(_ref) {
197
205
  };
198
206
  };
199
207
  }
200
- function buildItems(_ref4) {
201
- var indices = _ref4.indices,
202
- indicesConfig = _ref4.indicesConfig,
203
- getElementId = _ref4.getElementId;
208
+ function buildItems(_ref5) {
209
+ var indices = _ref5.indices,
210
+ indicesConfig = _ref5.indicesConfig,
211
+ getElementId = _ref5.getElementId;
204
212
  var itemsIds = [];
205
213
  var items = new Map();
206
214
  for (var i = 0; i < indicesConfig.length; i++) {
@@ -6,4 +6,5 @@ export declare function LoadingIcon({ createElement }: IconProps): JSX.Element;
6
6
  export declare function ClearIcon({ createElement }: IconProps): JSX.Element;
7
7
  export declare function ClockIcon({ createElement }: IconProps): JSX.Element;
8
8
  export declare function TrashIcon({ createElement }: IconProps): JSX.Element;
9
+ export declare function ApplyIcon({ createElement }: IconProps): JSX.Element;
9
10
  export {};
@@ -57,4 +57,13 @@ export function TrashIcon(_ref5) {
57
57
  }, createElement("path", {
58
58
  d: "M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z"
59
59
  }));
60
+ }
61
+ export function ApplyIcon(_ref6) {
62
+ var createElement = _ref6.createElement;
63
+ return createElement("svg", {
64
+ viewBox: "0 0 24 24",
65
+ fill: "currentColor"
66
+ }, createElement("path", {
67
+ d: "M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z"
68
+ }));
60
69
  }
@@ -1,2 +1,2 @@
1
- declare const _default: "0.15.2";
1
+ declare const _default: "0.16.0";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '0.15.2';
1
+ export default '0.16.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch-ui-components",
3
- "version": "0.15.2",
3
+ "version": "0.16.0",
4
4
  "description": "Common UI components for InstantSearch.",
5
5
  "types": "dist/es/index.d.ts",
6
6
  "main": "dist/cjs/index.js",
@@ -53,5 +53,5 @@
53
53
  "zod": "^3.25.76 || ^4",
54
54
  "zod-to-json-schema": "3.24.6"
55
55
  },
56
- "gitHead": "00ba8af52fcf72388a8da9c1ab22079b5de9ca63"
56
+ "gitHead": "13c7c916b870f34f5f6dde9bd7b16850990dc7ea"
57
57
  }