@trafilea/afrodita-components 5.0.0-beta.23 → 5.0.0-beta.27

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/build/index.d.ts CHANGED
@@ -1403,8 +1403,8 @@ interface ProductItemProps {
1403
1403
  price: Pick<PriceLabelProps, 'finalPrice' | 'originalPrice' | 'color'>;
1404
1404
  rating: Pick<RatingProps, 'rating' | 'reviews'>;
1405
1405
  tags?: {
1406
- categoryTagText: string;
1407
- seasonOfferTagText: string;
1406
+ categoryTagText?: string;
1407
+ seasonOfferTagText?: string;
1408
1408
  };
1409
1409
  alignName?: 'left' | 'center';
1410
1410
  url?: string;
@@ -1413,6 +1413,7 @@ interface ProductItemProps {
1413
1413
 
1414
1414
  interface ProductItemSmallMobileProps extends ProductItemProps {
1415
1415
  size: ComponentSize.Medium | ComponentSize.Small | ComponentSize.Large;
1416
+ onClick?: () => void;
1416
1417
  }
1417
1418
 
1418
1419
  declare function withProductGrid<P extends ProductItemProps>(ProductItemComponent: React.FC<P>, data: ProductItemProps[]): {
@@ -1421,7 +1422,7 @@ declare function withProductGrid<P extends ProductItemProps>(ProductItemComponen
1421
1422
  };
1422
1423
 
1423
1424
  declare const Collection: {
1424
- ProductItemMobile: ({ title, image, price, rating, size, tags, alignName, url, className, }: ProductItemSmallMobileProps) => _emotion_react_types_jsx_namespace.EmotionJSX.Element;
1425
+ ProductItemMobile: ({ title, image, price, rating, size, tags, alignName, url, className, onClick, }: ProductItemSmallMobileProps) => _emotion_react_types_jsx_namespace.EmotionJSX.Element;
1425
1426
  withProductGrid: typeof withProductGrid;
1426
1427
  };
1427
1428
 
@@ -1587,11 +1588,13 @@ interface SearchBarProps {
1587
1588
  resultOptions: SearchBarOptionItem[];
1588
1589
  onChange: (text: string) => void;
1589
1590
  onSearch: (term: string) => void;
1591
+ onClose: () => void;
1590
1592
  resultsPanelDataTestId?: string;
1591
1593
  allResults?: number;
1592
1594
  initialTerm?: string;
1595
+ shouldClear?: boolean;
1593
1596
  }
1594
- declare const SearchBar: ({ suggestions, resultOptions, onChange, onSearch, resultsPanelDataTestId, allResults, initialTerm, }: SearchBarProps) => JSX.Element;
1597
+ declare const SearchBar: ({ suggestions, resultOptions, onChange, onSearch, onClose, resultsPanelDataTestId, allResults, initialTerm, shouldClear, }: SearchBarProps) => JSX.Element;
1595
1598
 
1596
1599
  interface ProductGalleryMobileProps {
1597
1600
  images: ImageType[];
@@ -10249,7 +10249,7 @@ var getStylesBySize = function (size) {
10249
10249
  }
10250
10250
  };
10251
10251
  var ProductItemMobile = function (_a) {
10252
- var title = _a.title, image = _a.image, price = _a.price, rating = _a.rating, size = _a.size, tags = _a.tags, _b = _a.alignName, alignName = _b === void 0 ? 'center' : _b, url = _a.url, className = _a.className;
10252
+ var title = _a.title, image = _a.image, price = _a.price, rating = _a.rating, size = _a.size, tags = _a.tags, _b = _a.alignName, alignName = _b === void 0 ? 'center' : _b, url = _a.url, className = _a.className, onClick = _a.onClick;
10253
10253
  var theme = useTheme();
10254
10254
  var styles = getStylesBySize(size);
10255
10255
  var space = useMemo(function () {
@@ -10260,7 +10260,7 @@ var ProductItemMobile = function (_a) {
10260
10260
  _a[ComponentSize.Small] = 2,
10261
10261
  _a)[size];
10262
10262
  }, [size]);
10263
- return (jsxs(Container$f, __assign$1({ as: url ? 'a' : 'div', href: url, className: className }, { children: [tags ? (jsxs(ImageContainer, __assign$1({ width: styles === null || styles === void 0 ? void 0 : styles.width, height: styles === null || styles === void 0 ? void 0 : styles.height, "data-testid": "tags-image-container" }, { children: [jsx(Image, { src: image.src, alt: image.alt, width: "100%", height: "100%" }, void 0), jsx(SeasonOfferTag, { text: tags.seasonOfferTagText, size: ComponentSize.Small, css: { position: 'absolute', top: 0, left: 0 } }, void 0), jsx(CategoryTag, { text: tags.categoryTagText, size: ComponentSize.Small, css: { position: 'absolute', bottom: '1rem', left: 0 } }, void 0)] }), void 0)) : (jsx(Image, { src: image.src, alt: image.alt, width: styles === null || styles === void 0 ? void 0 : styles.width, height: styles === null || styles === void 0 ? void 0 : styles.height }, void 0)), jsx(Spacing, { size: space }, void 0), jsx(H1, __assign$1({ theme: theme, align: alignName }, { children: title }), void 0), jsx(Spacing, { size: space }, void 0), jsx(PriceLabel, { finalPrice: price.finalPrice, originalPrice: price.originalPrice, color: price.color, size: ComponentSize.Small, testId: "volume-discount" }, void 0), jsx(Spacing, { size: space }, void 0), jsx(Rating, { size: size === ComponentSize.Large ? ComponentSize.Small : ComponentSize.XSmall, rating: rating.rating, reviews: rating.reviews, reviewsText: "", wrapWithParenthesis: true }, void 0)] }), void 0));
10263
+ return (jsxs(Container$f, __assign$1({ as: url ? 'a' : 'div', href: url, className: className, onClick: onClick }, { children: [tags ? (jsxs(ImageContainer, __assign$1({ width: styles === null || styles === void 0 ? void 0 : styles.width, height: styles === null || styles === void 0 ? void 0 : styles.height, "data-testid": "tags-image-container" }, { children: [jsx(Image, { src: image.src, alt: image.alt, width: "100%", height: "100%" }, void 0), (tags === null || tags === void 0 ? void 0 : tags.seasonOfferTagText) && (jsx(SeasonOfferTag, { text: tags.seasonOfferTagText, size: ComponentSize.Small, css: { position: 'absolute', top: 0, left: 0 } }, void 0)), (tags === null || tags === void 0 ? void 0 : tags.categoryTagText) && (jsx(CategoryTag, { text: tags.categoryTagText, size: ComponentSize.Small, css: { position: 'absolute', bottom: '1rem', left: 0 } }, void 0))] }), void 0)) : (jsx(Image, { src: image.src, alt: image.alt, width: styles === null || styles === void 0 ? void 0 : styles.width, height: styles === null || styles === void 0 ? void 0 : styles.height }, void 0)), jsx(Spacing, { size: space }, void 0), jsx(H1, __assign$1({ theme: theme, align: alignName }, { children: title }), void 0), jsx(Spacing, { size: space }, void 0), jsx(PriceLabel, { finalPrice: price.finalPrice, originalPrice: price.originalPrice, color: price.color, size: ComponentSize.Small, testId: "volume-discount" }, void 0), jsx(Spacing, { size: space }, void 0), jsx(Rating, { size: size === ComponentSize.Large ? ComponentSize.Small : ComponentSize.XSmall, rating: rating.rating, reviews: rating.reviews, reviewsText: "", wrapWithParenthesis: true }, void 0)] }), void 0));
10264
10264
  };
10265
10265
  var templateObject_1$n, templateObject_2$d;
10266
10266
 
@@ -10577,11 +10577,11 @@ var SearchIconContainer = newStyled.div({
10577
10577
  alignSelf: 'center',
10578
10578
  });
10579
10579
  var SearchControl = function (_a) {
10580
- var open = _a.open, onSearch = _a.onSearch, onClear = _a.onClear;
10580
+ var open = _a.open, onSearch = _a.onSearch, onClose = _a.onClose;
10581
10581
  var theme = useTheme();
10582
10582
  var isMobile = useWindowDimensions(theme.mediaQueries).isMobile;
10583
10583
  if (isMobile) {
10584
- return open ? (jsx(ClearButton, { onClick: onClear }, void 0)) : (jsx(SearchIconContainer, { children: jsx(Icon.Navigation.Search, { height: 1.25, width: 1.25 }, void 0) }, void 0));
10584
+ return open ? (jsx(ClearButton, { onClick: onClose }, void 0)) : (jsx(SearchIconContainer, { children: jsx(Icon.Navigation.Search, { height: 1.25, width: 1.25 }, void 0) }, void 0));
10585
10585
  }
10586
10586
  else {
10587
10587
  return (jsxs(Fragment, { children: [jsx(ButtonSecondary, { css: {
@@ -10591,7 +10591,7 @@ var SearchControl = function (_a) {
10591
10591
  borderTopLeftRadius: 0,
10592
10592
  borderBottomLeftRadius: 0,
10593
10593
  padding: '0.875rem 1.5rem',
10594
- }, text: "SEARCH", onClick: onSearch }, void 0), jsx(ClearButton, { onClick: onClear }, void 0)] }, void 0));
10594
+ }, text: "SEARCH", onClick: onSearch }, void 0), jsx(ClearButton, { onClick: onClose }, void 0)] }, void 0));
10595
10595
  }
10596
10596
  };
10597
10597
 
@@ -10601,12 +10601,12 @@ var reducer = function (state, action) {
10601
10601
  case 'UPDATE_TERM': {
10602
10602
  return __assign$1(__assign$1({}, state), { term: action.payload.term });
10603
10603
  }
10604
- case 'TOGGLE_PANEL': {
10605
- return __assign$1(__assign$1({}, state), { open: action.payload.open });
10606
- }
10607
10604
  case 'CLEAR': {
10608
10605
  return __assign$1(__assign$1({}, state), { term: '', open: false });
10609
10606
  }
10607
+ case 'TOGGLE_PANEL': {
10608
+ return __assign$1(__assign$1({}, state), { open: action.payload.open });
10609
+ }
10610
10610
  }
10611
10611
  };
10612
10612
  var Container$8 = newStyled.div({
@@ -10614,12 +10614,12 @@ var Container$8 = newStyled.div({
10614
10614
  display: 'flex',
10615
10615
  });
10616
10616
  var SearchBar = function (_a) {
10617
- var suggestions = _a.suggestions, resultOptions = _a.resultOptions, onChange = _a.onChange, onSearch = _a.onSearch, resultsPanelDataTestId = _a.resultsPanelDataTestId, allResults = _a.allResults, initialTerm = _a.initialTerm;
10617
+ var suggestions = _a.suggestions, resultOptions = _a.resultOptions, onChange = _a.onChange, onSearch = _a.onSearch, onClose = _a.onClose, resultsPanelDataTestId = _a.resultsPanelDataTestId, allResults = _a.allResults, initialTerm = _a.initialTerm, _b = _a.shouldClear, shouldClear = _b === void 0 ? false : _b;
10618
10618
  var theme = useTheme();
10619
10619
  if (initialTerm) {
10620
10620
  initialState$1.term = initialTerm;
10621
10621
  }
10622
- var _b = useReducer(reducer, initialState$1), state = _b[0], dispatch = _b[1];
10622
+ var _c = useReducer(reducer, initialState$1), state = _c[0], dispatch = _c[1];
10623
10623
  var ref = useRef(null);
10624
10624
  var shouldDisplaySuggestion = function () {
10625
10625
  return resultOptions.length === 0 && suggestions.length > 0 && !state.term;
@@ -10637,7 +10637,21 @@ var SearchBar = function (_a) {
10637
10637
  : shouldDisplaySuggestion()
10638
10638
  ? suggestions
10639
10639
  : [];
10640
- return (jsxs$1("form", __assign$1({ role: "search", onSubmit: function (e) { return e.preventDefault(); }, ref: ref, style: { position: 'relative' } }, { children: [jsxs$1(Container$8, __assign$1({ theme: theme }, { children: [jsx$1(Input, { value: state.term, placeholder: "Search for products", onChange: function (e) { return dispatch({ type: 'UPDATE_TERM', payload: { term: e.target.value } }); }, onFocus: function () { return dispatch({ type: 'TOGGLE_PANEL', payload: { open: true } }); }, id: "search", autoComplete: "off", theme: theme, "aria-label": "Search for products" }, void 0), jsx$1(SearchControl, { open: state.open, onClear: function () { return dispatch({ type: 'CLEAR', payload: {} }); }, onSearch: function () { return onSearch(state.term); } }, void 0)] }), void 0), state.open && !!options.length && (jsx$1(ResultsPanel, { testId: resultsPanelDataTestId, options: options, header: shouldDisplaySuggestion() ? 'Most popular products' : undefined, footer: allResults ? "View all results (".concat(allResults, ")") : undefined, onViewAll: function () { return onSearch(state.term); } }, void 0))] }), void 0));
10640
+ var handleOnClose = function () {
10641
+ if (shouldClear) {
10642
+ dispatch({ type: 'CLEAR', payload: {} });
10643
+ }
10644
+ else {
10645
+ onClose();
10646
+ }
10647
+ };
10648
+ return (jsxs$1("form", __assign$1({ role: "search", onSubmit: function (e) { return e.preventDefault(); }, ref: ref, style: { position: 'relative' } }, { children: [jsxs$1(Container$8, __assign$1({ theme: theme }, { children: [jsx$1(Input, { value: state.term, placeholder: "Search for products", onChange: function (e) { return dispatch({ type: 'UPDATE_TERM', payload: { term: e.target.value } }); }, onFocus: function () { return dispatch({ type: 'TOGGLE_PANEL', payload: { open: true } }); }, id: "search", autoComplete: "off", theme: theme, "aria-label": "Search for products", onKeyDown: function (e) {
10649
+ if (e.key === 'Enter') {
10650
+ e.preventDefault();
10651
+ e.stopPropagation();
10652
+ onSearch(state.term);
10653
+ }
10654
+ } }, void 0), jsx$1(SearchControl, { open: state.open, onClose: handleOnClose, onSearch: function () { return onSearch(state.term); } }, void 0)] }), void 0), state.open && !!options.length && (jsx$1(ResultsPanel, { testId: resultsPanelDataTestId, options: options, header: shouldDisplaySuggestion() ? 'Most popular products' : undefined, footer: allResults ? "View all results (".concat(allResults, ")") : undefined, onViewAll: function () { return onSearch(state.term); } }, void 0))] }), void 0));
10641
10655
  };
10642
10656
 
10643
10657
  function _extends() {