@asantemedia-org/edwardsvacuum-design-system 1.6.30 → 1.6.32

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/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect } from 'react';
1
+ import React, { useState, useCallback, useMemo, useEffect } from 'react';
2
2
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3
3
  import { faChevronDown, faChevronRight, faArrowRight } from '@fortawesome/pro-solid-svg-icons';
4
4
  import { v4 } from 'uuid';
@@ -245,13 +245,32 @@ var AccordionSection = function (_a) {
245
245
  _b = _a.className,
246
246
  className = _b === void 0 ? '' : _b,
247
247
  _c = _a.defaultOpen,
248
- defaultOpen = _c === void 0 ? false : _c;
249
- var _d = useState(defaultOpen),
250
- isOpen = _d[0],
251
- setIsOpen = _d[1];
252
- var toggleAccordion = function () {
253
- setIsOpen(!isOpen);
254
- };
248
+ defaultOpen = _c === void 0 ? false : _c,
249
+ _d = _a.lazyLoad,
250
+ lazyLoad = _d === void 0 ? false : _d;
251
+ var _e = useState(defaultOpen),
252
+ isOpen = _e[0],
253
+ setIsOpen = _e[1];
254
+ // Track if accordion has ever been opened (for lazy loading)
255
+ var _f = useState(defaultOpen),
256
+ hasBeenOpened = _f[0],
257
+ setHasBeenOpened = _f[1];
258
+ var toggleAccordion = useCallback(function () {
259
+ setIsOpen(function (prev) {
260
+ if (!prev && !hasBeenOpened) {
261
+ setHasBeenOpened(true);
262
+ }
263
+ return !prev;
264
+ });
265
+ }, [hasBeenOpened]);
266
+ var handleKeyDown = useCallback(function (e) {
267
+ if (e.key === 'Enter' || e.key === ' ') {
268
+ e.preventDefault();
269
+ toggleAccordion();
270
+ }
271
+ }, [toggleAccordion]);
272
+ // Only render children if not lazy loading, or if accordion has been opened
273
+ var shouldRenderChildren = !lazyLoad || hasBeenOpened;
255
274
  return /*#__PURE__*/React.createElement("div", {
256
275
  className: "accordion-section ".concat(className, " ").concat(isOpen ? 'open' : '')
257
276
  }, /*#__PURE__*/React.createElement("h4", {
@@ -259,12 +278,7 @@ var AccordionSection = function (_a) {
259
278
  onClick: toggleAccordion,
260
279
  role: "button",
261
280
  tabIndex: 0,
262
- onKeyDown: function (e) {
263
- if (e.key === 'Enter' || e.key === ' ') {
264
- e.preventDefault();
265
- toggleAccordion();
266
- }
267
- },
281
+ onKeyDown: handleKeyDown,
268
282
  "aria-expanded": isOpen
269
283
  }, /*#__PURE__*/React.createElement("span", {
270
284
  className: "accordion-section__title"
@@ -275,7 +289,7 @@ var AccordionSection = function (_a) {
275
289
  color: "#C4262EFF"
276
290
  }))), /*#__PURE__*/React.createElement("div", {
277
291
  className: "accordion-section__content ".concat(isOpen ? 'open' : '')
278
- }, children));
292
+ }, shouldRenderChildren ? children : null));
279
293
  };
280
294
 
281
295
  // Utility function to retrieve correct SCSS module class names
@@ -299,22 +313,14 @@ var cardSizeMapping = function (size) {
299
313
  }
300
314
  return classSrting;
301
315
  };
302
- var getImageUrl = function (imageUrl) {
316
+ // Static placeholder URL - avoid dynamic require() which freezes in AEM
317
+ var PLACEHOLDER_IMAGE = "/assets/edwards-webshop-placeholder.png";
318
+ var getImageUrl = function (imageUrl, placeholder) {
303
319
  if (imageUrl) {
304
- return imageUrl; // If an image URL is provided, use it.
305
- }
306
- try {
307
- // Try loading from local assets (works in Storybook)
308
- return require("../../../assets/edwards-webshop-placeholder.png").default.src;
309
- } catch (error) {
310
- // If that fails, load from node_modules (works in host app)
311
- try {
312
- return require("@asantemedia-org/edwardsvacuum-design-system/dist/assets/edwards-webshop-placeholder.png").default;
313
- } catch (error) {
314
- console.error("Placeholder image not found in either local assets or node_modules.", error);
315
- return ""; // Fallback empty string if no image is found
316
- }
320
+ return imageUrl;
317
321
  }
322
+ // Use provided placeholder or default static path
323
+ return PLACEHOLDER_IMAGE;
318
324
  };
319
325
  var Card = function (_a) {
320
326
  var contentCategoryLabel = _a.contentCategoryLabel,
@@ -455,7 +461,8 @@ var ProductDetailsCard = function (_a) {
455
461
  className: "cmp-card--type-product_details__spares-list"
456
462
  }, hit.spares && hit.spares.length > 0 && /*#__PURE__*/React.createElement(AccordionSection, {
457
463
  title: "Spares & Parts",
458
- className: "folding-spares-holder"
464
+ className: "folding-spares-holder",
465
+ lazyLoad: true
459
466
  }, /*#__PURE__*/React.createElement("ul", {
460
467
  className: "folding-spares-list"
461
468
  }, hit.spares.map(function (spare, index) {
@@ -582,48 +589,46 @@ var AlgoliaDynamicSearch = function (_a, useScopedStyles, styles) {
582
589
  placeholder = _a.placeholder,
583
590
  analytics = _a.analytics,
584
591
  facets = _a.facets;
585
- var _g = useState(isLoading),
586
- isLoadingState = _g[0],
587
- setIsLoadingState = _g[1];
588
- useEffect(function () {
589
- if (isLoading !== isLoadingState) {
590
- setIsLoadingState(isLoading);
591
- }
592
- }, [isLoading]);
593
592
  // Helper to resolve CSS module class names properly
594
- var getClass = function (suffix) {
593
+ var getClass = useCallback(function (suffix) {
595
594
  var fullClassName = "cmpAlgoliaDynamicSearchWidget".concat(suffix);
596
595
  return useScopedStyles && styles ? styles[fullClassName] : fullClassName;
597
- };
596
+ }, [useScopedStyles, styles]);
598
597
  // Helper for modifier classes (without the base prefix)
599
- var getModifierClass = function (modifier) {
598
+ var getModifierClass = useCallback(function (modifier) {
600
599
  return useScopedStyles && styles ? styles[modifier] : modifier;
601
- };
602
- // Background styling mapping
603
- var backgroundStyles = {
604
- "dark-grey": {
605
- buttonStyle: "outlineWhite",
606
- containerBackground: getModifierClass('hasStyleGreyBackground'),
607
- textColour: "white"
608
- },
609
- "silver": {
600
+ }, [useScopedStyles, styles]);
601
+ // Memoize background styling to prevent re-renders
602
+ var widgetStyleProps = useMemo(function () {
603
+ var backgroundStyles = {
604
+ "dark-grey": {
605
+ buttonStyle: "outlineWhite",
606
+ containerBackground: getModifierClass('hasStyleGreyBackground'),
607
+ textColour: "white"
608
+ },
609
+ "silver": {
610
+ buttonStyle: "primary",
611
+ containerBackground: getModifierClass('hasStyleSilverGradientBackground'),
612
+ textColour: "black"
613
+ }
614
+ };
615
+ return backgroundStyles[backgroundColour.toLowerCase()] || {
610
616
  buttonStyle: "primary",
611
- containerBackground: getModifierClass('hasStyleSilverGradientBackground'),
617
+ containerBackground: "",
612
618
  textColour: "black"
613
- }
614
- };
615
- var widgetStyleProps = backgroundStyles[backgroundColour.toLowerCase()] || {
616
- buttonStyle: "primary",
617
- containerBackground: ""};
619
+ };
620
+ }, [backgroundColour, getModifierClass]);
618
621
  if (!hits || hits.length === 0) {
619
622
  return null;
620
623
  }
621
624
  var baseClass = getClass('');
622
- // Build wrapper class names
623
- var wrapperClasses = [baseClass, widgetStyleProps.containerBackground, isLoadingState ? getModifierClass('isLoading') : '', queryType === 'content' ? getModifierClass('isQueryContent') : ''].filter(Boolean).join(' ');
625
+ // Memoize wrapper class names
626
+ var wrapperClasses = useMemo(function () {
627
+ return [baseClass, widgetStyleProps.containerBackground, isLoading ? getModifierClass('isLoading') : '', queryType === 'content' ? getModifierClass('isQueryContent') : ''].filter(Boolean).join(' ');
628
+ }, [baseClass, widgetStyleProps.containerBackground, isLoading, queryType, getModifierClass]);
624
629
  return /*#__PURE__*/React.createElement("div", {
625
630
  className: wrapperClasses
626
- }, isLoadingState && /*#__PURE__*/React.createElement("div", {
631
+ }, isLoading && /*#__PURE__*/React.createElement("div", {
627
632
  className: getClass('__placeholder')
628
633
  }, /*#__PURE__*/React.createElement("div", {
629
634
  className: getClass('__placeholder__loading')
@@ -695,6 +700,13 @@ var AlgoliaDynamicSearch = function (_a, useScopedStyles, styles) {
695
700
  default:
696
701
  return null;
697
702
  }
703
+ // Only create onClick handler if analytics is provided
704
+ var handleClick = analytics ? function () {
705
+ var objectID = hit.objectID,
706
+ __position = hit.__position,
707
+ __queryID = hit.__queryID;
708
+ analytics(objectID, __queryID, __position);
709
+ } : undefined;
698
710
  return /*#__PURE__*/React.createElement(Component, {
699
711
  key: hit.objectID || index,
700
712
  className: cardClassName,
@@ -713,13 +725,7 @@ var AlgoliaDynamicSearch = function (_a, useScopedStyles, styles) {
713
725
  cardLink: cardLink,
714
726
  city: hit.city,
715
727
  country: hit.country,
716
- onClick: function () {
717
- if (!analytics) return;
718
- var objectID = hit.objectID,
719
- __position = hit.__position,
720
- __queryID = hit.__queryID;
721
- analytics(objectID, __queryID, __position);
722
- }
728
+ onClick: handleClick
723
729
  });
724
730
  }))));
725
731
  };