@sledge-app/react-instant-search 2.0.14 → 2.0.16

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.
@@ -4146,10 +4146,11 @@ const addToCartTrigger = async (data) => {
4146
4146
  });
4147
4147
  };
4148
4148
  const VariantSelector = (props) => {
4149
- const { data, setSelectedVariantId, setSelectedVariantStock, setSelectedVariantInventoryManagement, setSelectedVariantInventoryPolicy } = props;
4149
+ var _a;
4150
+ const { data, setSelectedVariantId, setSelectedVariantStock, setSelectedVariantInventoryManagement, setSelectedVariantInventoryPolicy, sourceApp } = props;
4150
4151
  const { product } = data || {};
4151
4152
  const { variants } = product || {};
4152
- const { id, handle } = product || {};
4153
+ const { id, handle, url } = product || {};
4153
4154
  const options = (product == null ? void 0 : product.options) ? Object.entries(product.options) : [];
4154
4155
  const images = (product == null ? void 0 : product.images) ?? [];
4155
4156
  const defaultSelected = {};
@@ -4194,7 +4195,7 @@ const VariantSelector = (props) => {
4194
4195
  }
4195
4196
  }
4196
4197
  function setSelectedVariant(element, value, optionIndex) {
4197
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4198
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
4198
4199
  const parentCard = element.target.offsetParent;
4199
4200
  const selectedInput = parentCard.querySelector(`.sledge__product-grid-card-selected-option[data-product-id='${id}']`);
4200
4201
  setElementAttribute({
@@ -4202,7 +4203,7 @@ const VariantSelector = (props) => {
4202
4203
  attributeName: `data-selected-option${optionIndex}`,
4203
4204
  value
4204
4205
  });
4205
- const option1 = `[data-option-1="${stringToSlug((_b = (_a = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _a["data-selected-option1"]) == null ? void 0 : _b.value)}"]`;
4206
+ const option1 = `[data-option-1="${stringToSlug((_b = (_a2 = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _a2["data-selected-option1"]) == null ? void 0 : _b.value)}"]`;
4206
4207
  const option2 = `${((_c = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _c["data-selected-option2"]) ? `[data-option-2="${stringToSlug((_e = (_d = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _d["data-selected-option2"]) == null ? void 0 : _e.value)}"]` : ""}`;
4207
4208
  const selectOption = parentCard.querySelector(`select option${option1}${option2}`);
4208
4209
  const variantId = selectOption.attributes["data-graphql-id"].value;
@@ -4211,11 +4212,11 @@ const VariantSelector = (props) => {
4211
4212
  const inventoryManagement = (_h = selectOption.attributes["data-inventory-management"]) == null ? void 0 : _h.value;
4212
4213
  const inventoryPolicy = (_i = selectOption.attributes["data-inventory-policy"]) == null ? void 0 : _i.value;
4213
4214
  const setOther = () => {
4214
- var _a2, _b2;
4215
+ var _a3, _b2;
4215
4216
  setElementAttribute({
4216
4217
  element: selectedInput,
4217
4218
  attributeName: "data-variant-id",
4218
- value: ((_b2 = (_a2 = selectOption == null ? void 0 : selectOption.attributes) == null ? void 0 : _a2["data-graphql-id"]) == null ? void 0 : _b2.value) || ""
4219
+ value: ((_b2 = (_a3 = selectOption == null ? void 0 : selectOption.attributes) == null ? void 0 : _a3["data-graphql-id"]) == null ? void 0 : _b2.value) || ""
4219
4220
  });
4220
4221
  setElementAttribute({
4221
4222
  element: selectedInput,
@@ -4268,37 +4269,76 @@ const VariantSelector = (props) => {
4268
4269
  return /* @__PURE__ */ jsxRuntimeExports.jsx("option", { ...optionAttributes, children: title }, id2);
4269
4270
  }) }),
4270
4271
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-variant-images", children: images == null ? void 0 : images.map((image) => /* @__PURE__ */ jsxRuntimeExports.jsx("input", { type: "hidden", id: image == null ? void 0 : image.id, value: image == null ? void 0 : image.src }, image == null ? void 0 : image.id)) }),
4271
- options == null ? void 0 : options.map((option, optionParentIndex) => {
4272
+ (_a = options == null ? void 0 : options.map) == null ? void 0 : _a.call(options, (option, optionParentIndex) => {
4273
+ var _a2;
4272
4274
  const optionName = option[0];
4273
4275
  const optionValues = option[1];
4274
4276
  let selectedOption = optionValues[0];
4275
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: optionValues[0] !== "Default Title" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__product-variant-size-swatch-flex options-button-${stringToSlug(optionName)}`, children: optionValues.map((item, index) => {
4276
- var _a;
4277
- const defaultOptionClass = `
4277
+ const initialVisibleCount = 2;
4278
+ const hiddenOptionsCount = optionValues.length - initialVisibleCount;
4279
+ const showMoreText = `${hiddenOptionsCount}+`;
4280
+ const showMoreButton = /* @__PURE__ */ jsxRuntimeExports.jsx(
4281
+ "a",
4282
+ {
4283
+ className: `${optionName === "Color" ? "sledge__product-variant-color-swatch" : "sledge__product-variant-size-swatch"}`,
4284
+ href: url,
4285
+ onClick: () => {
4286
+ if (sourceApp === "instant-search") {
4287
+ productClickTrigger$1({
4288
+ productId: id
4289
+ });
4290
+ } else if (productRecommendationSourceApps.includes(sourceApp)) {
4291
+ productClickTrigger({
4292
+ productId: id,
4293
+ sourceApp
4294
+ });
4295
+ }
4296
+ },
4297
+ "data-show-more": true,
4298
+ children: showMoreText
4299
+ }
4300
+ );
4301
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: optionValues[0] !== "Default Title" ? optionName === "Color" ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `sledge__product-variant-size-swatch-flex options-button-${stringToSlug(optionName)}`, children: [
4302
+ (_a2 = optionValues == null ? void 0 : optionValues.slice(0, initialVisibleCount)) == null ? void 0 : _a2.map((item, index) => {
4303
+ var _a3;
4304
+ const defaultOptionClass = `
4278
4305
  ${selectedOption === item ? "sledge__product-variant-size-swatch-active" : ""} sledge__product-variant-size-swatch`;
4279
- const colorOptionClass = `${selectedOption === item ? "sledge__product-variant-color-swatch-active" : ""} sledge__product-variant-color-swatch`;
4280
- const colorDataSettings = ((_a = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING))) == null ? void 0 : _a.colors) || [];
4281
- const getColorSwatch = (colorDataSettings == null ? void 0 : colorDataSettings.filter(({ name }) => name === item)[0]) || {};
4282
- const colorSwatch = (getColorSwatch == null ? void 0 : getColorSwatch.image) ? `url(${getColorSwatch == null ? void 0 : getColorSwatch.image})` : (getColorSwatch == null ? void 0 : getColorSwatch.rgb) || item;
4283
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
4284
- "button",
4285
- {
4286
- type: "button",
4287
- className: optionName === "Color" ? colorOptionClass : defaultOptionClass,
4288
- style: {
4289
- background: optionName === "Color" ? colorSwatch : null,
4290
- backgroundSize: "contain"
4291
- },
4292
- onClick: (el) => {
4293
- setSelectedVariant(el, item, optionParentIndex + 1);
4294
- setSelectedOption(el, optionName);
4306
+ const colorOptionClass = `${selectedOption === item ? "sledge__product-variant-color-swatch-active" : ""} sledge__product-variant-color-swatch`;
4307
+ const colorDataSettings = ((_a3 = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING))) == null ? void 0 : _a3.colors) || [];
4308
+ const getColorSwatch = (colorDataSettings == null ? void 0 : colorDataSettings.filter(({ name }) => name === item)[0]) || {};
4309
+ const colorSwatch = (getColorSwatch == null ? void 0 : getColorSwatch.image) ? `url(${getColorSwatch == null ? void 0 : getColorSwatch.image})` : (getColorSwatch == null ? void 0 : getColorSwatch.rgb) || item;
4310
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
4311
+ "button",
4312
+ {
4313
+ type: "button",
4314
+ className: optionName === "Color" ? colorOptionClass : defaultOptionClass,
4315
+ style: {
4316
+ background: optionName === "Color" ? colorSwatch : null,
4317
+ backgroundSize: "contain"
4318
+ },
4319
+ onClick: (el) => {
4320
+ setSelectedVariant(el, item, optionParentIndex + 1);
4321
+ setSelectedOption(el, optionName);
4322
+ },
4323
+ title: optionName === "Color" ? null : item,
4324
+ children: optionName === "Color" ? null : item
4295
4325
  },
4296
- title: optionName === "Color" ? null : item,
4297
- children: optionName === "Color" ? null : item
4326
+ index
4327
+ );
4328
+ }),
4329
+ hiddenOptionsCount > 0 && showMoreButton
4330
+ ] }, optionParentIndex) : /* @__PURE__ */ jsxRuntimeExports.jsx(
4331
+ "select",
4332
+ {
4333
+ className: "sledge__product-variant-size-swatch-select",
4334
+ onChange: (el) => {
4335
+ let { value } = el.target;
4336
+ setSelectedVariant(el, value, optionParentIndex + 1);
4337
+ setSelectedOption(el, optionName);
4298
4338
  },
4299
- index
4300
- );
4301
- }) }, optionParentIndex) });
4339
+ children: optionValues.map((item, index) => /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: item, children: item }, index))
4340
+ }
4341
+ ) : "" });
4302
4342
  })
4303
4343
  ] });
4304
4344
  };
@@ -4652,7 +4692,8 @@ const ProductCard = React__default.memo((props) => {
4652
4692
  setSelectedVariantId,
4653
4693
  setSelectedVariantStock,
4654
4694
  setSelectedVariantInventoryManagement,
4655
- setSelectedVariantInventoryPolicy
4695
+ setSelectedVariantInventoryPolicy,
4696
+ sourceApp
4656
4697
  }
4657
4698
  )
4658
4699
  ] })
@@ -8377,7 +8418,7 @@ const YuvaLayout = (props) => {
8377
8418
  ((_e = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _e.hide_limit_options) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: limit })
8378
8419
  ] })
8379
8420
  ] }),
8380
- /* @__PURE__ */ jsxRuntimeExports.jsxs(ResultData, { children: [
8421
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(ResultData, { className: openFilterToggle ? "" : "sledge__has-closed-filter-toggle", children: [
8381
8422
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge-instant-search__result-filter-toggle-panel ${""}`, "data-filter-toggle": openFilterToggle ? "open" : "closed", children: filterVertical == null ? void 0 : filterVertical({
8382
8423
  filterLayoutType: "standard",
8383
8424
  isSkeleton: Boolean(!isAllowedFilterTree && isFirstLoading || isAllowedFilterTree && isLoadingProduct || isLoadingSetting)