@sledge-app/react-instant-search 0.0.17 → 0.0.18

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.
@@ -19,7 +19,9 @@ const SEARCH_RESULT_URL = "/pages/search-result";
19
19
  const SEPARATE_COMPONENT_DISPLAY_NAME = {
20
20
  PRODUCT: {
21
21
  CARDS: "ProductCards"
22
- }
22
+ },
23
+ OTHER_INDEX_LISTS: "OtherIndexLists",
24
+ SUGGESTION_KEYWORD_LISTS: "SuggestionKeywordLists"
23
25
  };
24
26
  const SHOPIFY_GID = "gid://shopify/";
25
27
  const SHOPIFY_GID_PRODUCT_ID = `${SHOPIFY_GID}Product/`;
@@ -2200,10 +2202,19 @@ const SkeletonLoading = {
2200
2202
  const SearchIconWidget = (props) => {
2201
2203
  const { size = "sm", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props || {};
2202
2204
  let productCardsComponent = null;
2205
+ let suggestionKeywordListsComponent = null;
2206
+ let otherIndexListsComponent = null;
2203
2207
  React__default.Children.map(children, (child) => {
2204
- if (React__default.isValidElement(child) && isFunction(child.type) && child.type.name === SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS) {
2208
+ if (React__default.isValidElement(child) && isFunction(child.type)) {
2205
2209
  const { component } = (child == null ? void 0 : child.props) || {};
2206
- productCardsComponent = component;
2210
+ switch (child.type.name) {
2211
+ case SEPARATE_COMPONENT_DISPLAY_NAME.SUGGESTION_KEYWORD_LISTS:
2212
+ suggestionKeywordListsComponent = component;
2213
+ break;
2214
+ case SEPARATE_COMPONENT_DISPLAY_NAME.OTHER_INDEX_LISTS:
2215
+ otherIndexListsComponent = component;
2216
+ break;
2217
+ }
2207
2218
  }
2208
2219
  });
2209
2220
  const { isRenderApp } = React__default.useContext(SledgeContext);
@@ -2233,11 +2244,55 @@ const SearchIconWidget = (props) => {
2233
2244
  }, [isRenderApp]);
2234
2245
  const handleShowWidget = () => {
2235
2246
  if (typeof window !== "undefined" && window.sledgeInstantSearchIconWidgetPopup)
2236
- window.sledgeInstantSearchIconWidgetPopup(onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct, productCardsComponent);
2247
+ window.sledgeInstantSearchIconWidgetPopup(
2248
+ onAfterAddToCart,
2249
+ onAfterAddWishlist,
2250
+ onAfterRemoveWishlist,
2251
+ onAfterRenderProduct,
2252
+ productCardsComponent,
2253
+ suggestionKeywordListsComponent,
2254
+ otherIndexListsComponent
2255
+ );
2237
2256
  };
2238
2257
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__icon-widget", onClick: handleShowWidget, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { ...sizing, color: "currentColor" }) });
2239
2258
  };
2240
2259
  const SearchIconWidgetPopup$1 = "";
2260
+ const SuggestionKeywordLists = ({ listsComponent, keywords }) => {
2261
+ return listsComponent ? listsComponent({ keywords }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2262
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__icon-widget-search-form-result-title", children: "Suggestions" }),
2263
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "sledge-instant-search__icon-widget-search-form-result-list", children: keywords.map((keyword, index) => {
2264
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
2265
+ "a",
2266
+ {
2267
+ href: `${SEARCH_RESULT_URL}?q=${keyword}`,
2268
+ className: "sledge-instant-search__icon-widget-search-form-result-list-link sledge-instant-search__icon-widget-search-form-result-list-link-suggestion",
2269
+ children: [
2270
+ /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { width: 12, height: 12, color: "#677487" }),
2271
+ " ",
2272
+ keyword
2273
+ ]
2274
+ }
2275
+ ) }, index);
2276
+ }) })
2277
+ ] });
2278
+ };
2279
+ const OtherIndexLists = ({ listsComponent, indexUid, name, items }) => {
2280
+ console.log("OtherIndexLists listsComponent", listsComponent);
2281
+ console.log("OtherIndexLists indexUid", indexUid);
2282
+ console.log("OtherIndexLists name", name);
2283
+ console.log("OtherIndexLists items", items);
2284
+ return listsComponent ? listsComponent({ indexUid, name, items }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2285
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__icon-widget-search-form-result-title", children: name }),
2286
+ (items == null ? void 0 : items.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "sledge-instant-search__icon-widget-search-form-result-list", children: items.map((hit, index) => {
2287
+ const { title, url } = hit;
2288
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("a", { href: url, className: "sledge-instant-search__icon-widget-search-form-result-list-link", children: title }) }, index);
2289
+ }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "sledge-instant-search__icon-widget-search-form-result-list", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { className: "sledge-instant-search__icon-widget-search-form-result-item-disabled", children: [
2290
+ "No ",
2291
+ name == null ? void 0 : name.toLowerCase(),
2292
+ " were found"
2293
+ ] }) })
2294
+ ] });
2295
+ };
2241
2296
  const SearchIconWidgetPopup = () => {
2242
2297
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2243
2298
  const [isLoading, setIsLoading] = React__default.useState(true);
@@ -2260,7 +2315,9 @@ const SearchIconWidgetPopup = () => {
2260
2315
  },
2261
2316
  onAfterRenderProduct: (state) => {
2262
2317
  },
2263
- productCardsComponent: null
2318
+ productCardsComponent: null,
2319
+ otherIndexListsComponent: null,
2320
+ suggestionKeywordListsComponent: null
2264
2321
  });
2265
2322
  const searchFieldRef = React__default.useRef(null);
2266
2323
  const previousState = usePrevious({ keyword });
@@ -2350,6 +2407,8 @@ const SearchIconWidgetPopup = () => {
2350
2407
  }, onAfterRemoveWishlist = () => {
2351
2408
  }, onAfterRenderProduct = () => {
2352
2409
  }, productCardsComponent = () => {
2410
+ }, otherIndexListsComponent = () => {
2411
+ }, suggestionKeywordListsComponent = () => {
2353
2412
  }) => {
2354
2413
  setShowInfo(true);
2355
2414
  setHandleFunctions({
@@ -2357,7 +2416,9 @@ const SearchIconWidgetPopup = () => {
2357
2416
  onAfterAddWishlist,
2358
2417
  onAfterRemoveWishlist,
2359
2418
  onAfterRenderProduct,
2360
- productCardsComponent
2419
+ productCardsComponent,
2420
+ otherIndexListsComponent,
2421
+ suggestionKeywordListsComponent
2361
2422
  });
2362
2423
  setTimeout(() => {
2363
2424
  if (searchFieldRef == null ? void 0 : searchFieldRef.current) {
@@ -2438,36 +2499,10 @@ const SearchIconWidgetPopup = () => {
2438
2499
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__icon-widget-search-form-result-flex-item-product", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.ProductGrid, { count: 6, type: "medium" }) })
2439
2500
  ] }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(ScrollArea, { children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__icon-widget-search-form-result-wrapper", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__icon-widget-search-form-result-flex", children: [
2440
2501
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__icon-widget-search-form-result-flex-item-other", children: [
2441
- Object.keys(suggestionSettings).length && ((_c = (_b = suggestionSettings[suggestionIndex]) == null ? void 0 : _b.keywords) == null ? void 0 : _c.active) && ((_f = (_e = (_d = suggestionSettings[suggestionIndex]) == null ? void 0 : _d.keywords) == null ? void 0 : _e.list) == null ? void 0 : _f.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2442
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__icon-widget-search-form-result-title", children: "Suggestions" }),
2443
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "sledge-instant-search__icon-widget-search-form-result-list", children: suggestionSettings[suggestionIndex].keywords.list.map((keyword2, index) => {
2444
- return /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
2445
- "a",
2446
- {
2447
- href: `${SEARCH_RESULT_URL}?q=${keyword2}`,
2448
- className: "sledge-instant-search__icon-widget-search-form-result-list-link sledge-instant-search__icon-widget-search-form-result-list-link-suggestion",
2449
- children: [
2450
- /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { width: 12, height: 12, color: "#677487" }),
2451
- " ",
2452
- keyword2
2453
- ]
2454
- }
2455
- ) }, index);
2456
- }) })
2457
- ] }) : null,
2502
+ Object.keys(suggestionSettings).length && ((_c = (_b = suggestionSettings[suggestionIndex]) == null ? void 0 : _b.keywords) == null ? void 0 : _c.active) && ((_f = (_e = (_d = suggestionSettings[suggestionIndex]) == null ? void 0 : _d.keywords) == null ? void 0 : _e.list) == null ? void 0 : _f.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx(SuggestionKeywordLists, { listsComponent: handleFunctions.suggestionKeywordListsComponent, keywords: suggestionSettings[suggestionIndex].keywords.list }) : null,
2458
2503
  searchResultOther && searchResultOther.map((item, index) => {
2459
- const { hits, name } = item;
2460
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(React__default.Fragment, { children: [
2461
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__icon-widget-search-form-result-title", children: name }),
2462
- (hits == null ? void 0 : hits.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "sledge-instant-search__icon-widget-search-form-result-list", children: hits.map((hit, index2) => {
2463
- const { title, url } = hit;
2464
- return /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("a", { href: url, className: "sledge-instant-search__icon-widget-search-form-result-list-link", children: title }) }, index2);
2465
- }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "sledge-instant-search__icon-widget-search-form-result-list", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { className: "sledge-instant-search__icon-widget-search-form-result-item-disabled", children: [
2466
- "No ",
2467
- name.toLowerCase(),
2468
- " were found"
2469
- ] }) })
2470
- ] }, index);
2504
+ const { indexUid, hits, name } = item;
2505
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(OtherIndexLists, { listsComponent: handleFunctions.otherIndexListsComponent, indexUid, name, items: hits }) }, index);
2471
2506
  })
2472
2507
  ] }),
2473
2508
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__icon-widget-search-form-result-flex-item-product", children: [