@sledge-app/react-instant-search 1.0.32 → 1.0.34

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.
@@ -30,6 +30,7 @@ const DATASET_ATTRIBUTE_KEY = {
30
30
  USER_EMAIL: "data-user-email",
31
31
  USER_FULLNAME: "data-user-fullname",
32
32
  COLLECTION_ID: "data-collection-id",
33
+ COLLECTION_NAME: "data-collection-name",
33
34
  WIDTH_ELEMENT: "data-width-element",
34
35
  ICON_SIZE: "data-icon-size",
35
36
  API_KEY: "data-api-key",
@@ -1279,7 +1280,7 @@ const Trigger = (props) => {
1279
1280
  if (typeof window !== "undefined" && window.sledgeToastNotification && show_notification)
1280
1281
  window.sledgeToastNotification({
1281
1282
  title: title_fail_add_to_wishlist || "Failed",
1282
- message: text_fail_add_to_wishlist || "failed add to wishlist",
1283
+ message: text_fail_add_to_wishlist || "Failed add to wishlist, please try again",
1283
1284
  location: location_notification,
1284
1285
  type: "failed",
1285
1286
  icon: /* @__PURE__ */ jsxRuntimeExports.jsx(HeartIcon, { width: 40, height: 40, color: "black", type: "outline" })
@@ -1394,7 +1395,7 @@ const WidgetHeaderClearTrigger = ({ buttonText, shareId, dataSettings, isFirstLo
1394
1395
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !isRequiredLogin && /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !shareId && /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isFirstLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "132px", height: "46px", color: "lighten", rounded: "md" }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-wishlist__widget-header-item", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "button", colorType: "danger", onClick: handleClick, style: display_button_clear_all_style, children: buttonText ? buttonText : button_clear_all || "Clear Wishlist" }) }) }) }) });
1395
1396
  };
1396
1397
  const WidgetHeaderShareTrigger = ({ wishlistData, buttonText, showShareTrigger, shareLink, shareId, dataSettings, isFirstLoading }) => {
1397
- var _a, _b, _c, _d, _e, _f, _g;
1398
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1398
1399
  const { triggerRenderMultipleComponent, sledgeAnonymId } = React__default.useContext(SledgeContext);
1399
1400
  const { trigger: triggerRenderWishlistBadge } = ((_a = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.wishlist) == null ? void 0 : _a.badge) || {};
1400
1401
  const { is_required_login } = ((_b = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _b.global) || {};
@@ -1413,7 +1414,8 @@ const WidgetHeaderShareTrigger = ({ wishlistData, buttonText, showShareTrigger,
1413
1414
  } = ((_d = (_c = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _c.widget) == null ? void 0 : _d.button_share) || {};
1414
1415
  const { title_share_wishlist } = ((_e = dataSettings == null ? void 0 : dataSettings.languages) == null ? void 0 : _e.popup) || {};
1415
1416
  const { button_share } = ((_f = dataSettings == null ? void 0 : dataSettings.languages) == null ? void 0 : _f.widget) || {};
1416
- const { title_added_all_to_wishlist, text_added_all_to_wishlist } = ((_g = dataSettings == null ? void 0 : dataSettings.languages) == null ? void 0 : _g.notification) || {};
1417
+ const { show: show_notification, location: location_notification } = ((_g = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _g.notification) || {};
1418
+ const { title_added_all_to_wishlist, text_added_all_to_wishlist, title_fail_add_to_wishlist, text_fail_add_to_wishlist } = ((_h = dataSettings == null ? void 0 : dataSettings.languages) == null ? void 0 : _h.notification) || {};
1417
1419
  const [isRequiredLogin, setIsRequiredLogin] = React__default.useState(false);
1418
1420
  const display_button_share_style = {
1419
1421
  ...display_button_share_text_color && { color: display_button_share_text_color },
@@ -1464,17 +1466,18 @@ const WidgetHeaderShareTrigger = ({ wishlistData, buttonText, showShareTrigger,
1464
1466
  if (window.sledgeInfoPopup)
1465
1467
  window.sledgeInfoPopup({
1466
1468
  title: title_added_all_to_wishlist,
1467
- message: text_added_all_to_wishlist,
1468
- textCancel: "Cancel"
1469
+ message: text_added_all_to_wishlist
1469
1470
  });
1470
1471
  }
1471
1472
  setIsLoadingBulkAdd(false);
1472
1473
  } else {
1473
- if (typeof window !== "undefined" && window.sledgeInfoPopup)
1474
- window.sledgeInfoPopup({
1475
- title: "Failed",
1476
- message: "Failed add to wishlist, please try again",
1477
- textCancel: "Cancel"
1474
+ if (typeof window !== "undefined" && window.sledgeToastNotification && show_notification)
1475
+ window.sledgeToastNotification({
1476
+ title: title_fail_add_to_wishlist || "Failed",
1477
+ message: text_fail_add_to_wishlist || "Failed add to wishlist, please try again",
1478
+ location: location_notification,
1479
+ type: "failed",
1480
+ icon: /* @__PURE__ */ jsxRuntimeExports.jsx(HeartIcon, { width: 40, height: 40, color: "black", type: "outline" })
1478
1481
  });
1479
1482
  }
1480
1483
  };
@@ -1522,8 +1525,7 @@ const WidgetHeaderShareTrigger = ({ wishlistData, buttonText, showShareTrigger,
1522
1525
  ${clipboardIcon}
1523
1526
  </div>
1524
1527
  <div class="sledge-wishlist__widget-box-copy-content">${shareLink}</div>
1525
- </div>` : "",
1526
- textCancel: "Cancel"
1528
+ </div>` : ""
1527
1529
  });
1528
1530
  }
1529
1531
  }
@@ -4270,7 +4272,7 @@ const ResultProduct = (props) => {
4270
4272
  setIsReplaceWidgetList
4271
4273
  } = props || {};
4272
4274
  const queryKeyword = (query == null ? void 0 : query.keyword) ? query.keyword : DEFAULT_QUERY_PARAM.KEYWORD;
4273
- const { collectionId } = params || {};
4275
+ const { collectionId, collectionName } = params || {};
4274
4276
  const [isFirstLoading, setIsFirstLoading] = React__default.useState(!propsData);
4275
4277
  const [isLoading, setIsLoading] = React__default.useState(!propsData);
4276
4278
  const [isOpenSort, setIsOpenSort] = React__default.useState(false);
@@ -4296,11 +4298,23 @@ const ResultProduct = (props) => {
4296
4298
  const [isFilterChanged, setIsFilterChanged] = React__default.useState(false);
4297
4299
  const [handleSearchResultFirstTime, setHandleSearchResultFirstTime] = React__default.useState(true);
4298
4300
  const [searchResultFacets, setSearchResultFacets] = React__default.useState({});
4299
- const summaryTextGenerator = () => {
4301
+ const {
4302
+ sort_by: language_sort_by,
4303
+ result: language_result,
4304
+ search_form_placeholder: language_search_form_placeholder,
4305
+ limit: language_limit,
4306
+ add_to_cart: language_add_to_cart,
4307
+ filter: language_filter,
4308
+ clear_filter: language_clear_filter,
4309
+ pagination_info: language_pagination_info,
4310
+ total_result_text: language_total_result_text
4311
+ } = languageSettings || {};
4312
+ const summaryTextGenerator = (totalResult) => {
4300
4313
  var _a2;
4301
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-item", children: ((_a2 = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _a2.show_total_products) ? /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "sledge-instant-search__result-data-summary-text", children: [
4302
- totalSearchResult,
4303
- " result",
4314
+ const defaultSummaryText = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
4315
+ totalResult,
4316
+ " ",
4317
+ language_result || "result",
4304
4318
  " ",
4305
4319
  (keyword == null ? void 0 : keyword.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
4306
4320
  "for ",
@@ -4310,9 +4324,17 @@ const ResultProduct = (props) => {
4310
4324
  '"'
4311
4325
  ] })
4312
4326
  ] }) : null
4313
- ] }) : null });
4327
+ ] });
4328
+ let getSummaryText = language_total_result_text[layoutType === "product-filter" ? "product_filter" : "product"];
4329
+ let isSummaryTextFromLanguage = language_total_result_text && getSummaryText;
4330
+ if (isSummaryTextFromLanguage) {
4331
+ getSummaryText = getSummaryText.replaceAll(OBJECT_DATA_STRING_KEY.TOTAL_RESULT, totalResult);
4332
+ if (layoutType === "product-filter")
4333
+ getSummaryText = getSummaryText.replaceAll(OBJECT_DATA_STRING_KEY.COLLECTION_NAME, collectionName || "");
4334
+ }
4335
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-item", children: ((_a2 = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _a2.show_total_products) ? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__result-data-summary-text", children: isSummaryTextFromLanguage ? getSummaryText : defaultSummaryText }) : null });
4314
4336
  };
4315
- const [summaryText, setSummaryText] = React__default.useState(propsData ? summaryTextGenerator() : null);
4337
+ const [summaryText, setSummaryText] = React__default.useState(propsData ? summaryTextGenerator(totalSearchResult) : null);
4316
4338
  const previousState = usePrevious({ keyword, clickedLimitId, clickedFacets, clickedTabIndexId });
4317
4339
  const { color: filter_title_color, font_size: filter_title_font_size, font_weight: filter_title_font_weight, text_transform: filter_title_text_transform } = ((_i = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _i.title) || {};
4318
4340
  const {
@@ -4334,17 +4356,6 @@ const ResultProduct = (props) => {
4334
4356
  font_weight: filter_button_font_weight,
4335
4357
  text_transform: filter_button_text_transform
4336
4358
  } = ((_k = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _k.button) || {};
4337
- const {
4338
- sort_by: language_sort_by,
4339
- result: language_result,
4340
- search_form_placeholder: language_search_form_placeholder,
4341
- limit: language_limit,
4342
- add_to_cart: language_add_to_cart,
4343
- filter: language_filter,
4344
- clear_filter: language_clear_filter,
4345
- pagination_info: language_pagination_info,
4346
- total_result_text: language_total_result_text
4347
- } = languageSettings || {};
4348
4359
  const filter_title_style = {
4349
4360
  ...filter_title_color && { color: filter_title_color },
4350
4361
  ...filter_title_font_size && { fontSize: filter_title_font_size },
@@ -4476,7 +4487,6 @@ const ResultProduct = (props) => {
4476
4487
  }, 10);
4477
4488
  };
4478
4489
  const handleSearchResultData = (result, onSearch) => {
4479
- var _a2;
4480
4490
  if (!result)
4481
4491
  return;
4482
4492
  const { hits, processingTimeMs, totalHits, totalPages, facetDistribution } = result;
@@ -4493,22 +4503,7 @@ const ResultProduct = (props) => {
4493
4503
  setSearchProcessingTimeMs(processingTimeMs || 0);
4494
4504
  setTotalPage(totalPages);
4495
4505
  setTotalSearchResult(totalHits || 0);
4496
- setSummaryText(
4497
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-item", children: ((_a2 = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _a2.show_total_products) ? /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "sledge-instant-search__result-data-summary-text", children: [
4498
- totalHits,
4499
- " ",
4500
- language_result || "result",
4501
- " ",
4502
- (keyword == null ? void 0 : keyword.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
4503
- "for ",
4504
- /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "sledge-instant-search__result-data-summary-text-keyword", children: [
4505
- '"',
4506
- keyword,
4507
- '"'
4508
- ] })
4509
- ] }) : null
4510
- ] }) : null })
4511
- );
4506
+ setSummaryText(summaryTextGenerator(totalHits));
4512
4507
  setSearchResultFacets(
4513
4508
  defaultFacetDistribution ? Object.fromEntries(
4514
4509
  Object.entries(defaultFacetDistribution).map((facet) => {
@@ -5033,6 +5028,7 @@ const ResultCategory = (props) => {
5033
5028
  clickedTabIndexId,
5034
5029
  clickedTabIndexName,
5035
5030
  clickedTabIndexType,
5031
+ displaySettings,
5036
5032
  isJsVersion,
5037
5033
  collectionCardsComponent,
5038
5034
  pageCardsComponent,
@@ -5058,7 +5054,34 @@ const ResultCategory = (props) => {
5058
5054
  const [totalSearchResult, setTotalSearchResult] = React__default.useState(0);
5059
5055
  const [summaryText, setSummaryText] = React__default.useState(null);
5060
5056
  const previousState = usePrevious({ keyword, clickedTabIndexId });
5061
- const { pagination_info: language_pagination_info, search_form_placeholder: language_search_form_placeholder } = languageSettings || {};
5057
+ const {
5058
+ pagination_info: language_pagination_info,
5059
+ search_form_placeholder: language_search_form_placeholder,
5060
+ result: language_result,
5061
+ total_result_text: language_total_result_text
5062
+ } = languageSettings || {};
5063
+ const summaryTextGenerator = (totalResult) => {
5064
+ var _a;
5065
+ const defaultSummaryText = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
5066
+ totalResult,
5067
+ " ",
5068
+ language_result || "result",
5069
+ " ",
5070
+ (keyword == null ? void 0 : keyword.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
5071
+ "for ",
5072
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "sledge-instant-search__result-data-summary-text-keyword", children: [
5073
+ '"',
5074
+ keyword,
5075
+ '"'
5076
+ ] })
5077
+ ] }) : null
5078
+ ] });
5079
+ let getSummaryText = clickedTabIndexType ? language_total_result_text[clickedTabIndexType] : null;
5080
+ let isSummaryTextFromLanguage = language_total_result_text && getSummaryText;
5081
+ if (isSummaryTextFromLanguage)
5082
+ getSummaryText = getSummaryText.replaceAll(OBJECT_DATA_STRING_KEY.TOTAL_RESULT, totalResult);
5083
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-item", children: ((_a = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _a.show_total_products) ? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__result-data-summary-text", children: isSummaryTextFromLanguage ? getSummaryText : defaultSummaryText }) : null });
5084
+ };
5062
5085
  const handleSearchResultData = (result) => {
5063
5086
  if (!result)
5064
5087
  return;
@@ -5070,21 +5093,7 @@ const ResultCategory = (props) => {
5070
5093
  setSearchProcessingTimeMs(processingTimeMs || 0);
5071
5094
  setTotalPage(totalPages);
5072
5095
  setTotalSearchResult(totalHits || 0);
5073
- setSummaryText(
5074
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-item", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "sledge-instant-search__result-data-summary-text", children: [
5075
- totalHits,
5076
- " result",
5077
- " ",
5078
- (keyword == null ? void 0 : keyword.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
5079
- "for ",
5080
- /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "sledge-instant-search__result-data-summary-text-keyword", children: [
5081
- '"',
5082
- keyword,
5083
- '"'
5084
- ] })
5085
- ] }) : null
5086
- ] }) })
5087
- );
5096
+ setSummaryText(summaryTextGenerator(totalHits));
5088
5097
  };
5089
5098
  const handleSearchResult = async (isRefreshPage = false) => {
5090
5099
  if (!clickedTabIndexId)