@trafilea/afrodita-components 5.0.0-beta.19 → 5.0.0-beta.21

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
@@ -101,7 +101,10 @@ declare type Filter = {
101
101
  title: string;
102
102
  columns: number;
103
103
  isOpenByDefault?: boolean;
104
- items: string[];
104
+ items: Array<{
105
+ label: string;
106
+ checked?: boolean;
107
+ }>;
105
108
  };
106
109
  declare type FilterChange = {
107
110
  sectionIndex: number;
@@ -1585,8 +1588,9 @@ interface SearchBarProps {
1585
1588
  onSearch: (term: string) => void;
1586
1589
  resultsPanelDataTestId?: string;
1587
1590
  allResults?: number;
1591
+ initialTerm?: string;
1588
1592
  }
1589
- declare const SearchBar: ({ suggestions, resultOptions, onChange, onSearch, resultsPanelDataTestId, allResults, }: SearchBarProps) => JSX.Element;
1593
+ declare const SearchBar: ({ suggestions, resultOptions, onChange, onSearch, resultsPanelDataTestId, allResults, initialTerm, }: SearchBarProps) => JSX.Element;
1590
1594
 
1591
1595
  interface ProductGalleryMobileProps {
1592
1596
  images: ImageType[];
@@ -1706,8 +1710,8 @@ interface PackSelectorProps {
1706
1710
  declare const PackSelector: FC<PackSelectorProps>;
1707
1711
 
1708
1712
  interface FiltersProps {
1709
- filters: Filter[];
1710
- onChange: (update: FilterChange) => void;
1713
+ values: Filter[];
1714
+ onChange: (newValues: Filter[], filtersState?: FilterChange) => void;
1711
1715
  tagsColor?: string;
1712
1716
  filterByText: string;
1713
1717
  clearAllText: string;
@@ -1718,7 +1722,7 @@ interface FiltersProps {
1718
1722
  mobileApplyButtonClick: () => void;
1719
1723
  onResetValues: () => void;
1720
1724
  }
1721
- declare const Filters: ({ filters, onChange, tagsColor, filterByText, clearAllText, isMobile, filtersSelectText, applyText, mobileApplyButtonClick, mobileBackArrowClick, onResetValues, }: FiltersProps) => JSX.Element;
1725
+ declare const Filters: ({ values, onChange, tagsColor, filterByText, clearAllText, isMobile, filtersSelectText, applyText, mobileApplyButtonClick, mobileBackArrowClick, onResetValues, }: FiltersProps) => JSX.Element;
1722
1726
 
1723
1727
  interface SearchNavigationProps {
1724
1728
  returnText?: string;
@@ -10616,8 +10616,11 @@ var Container$8 = newStyled.div({
10616
10616
  display: 'flex',
10617
10617
  });
10618
10618
  var SearchBar = function (_a) {
10619
- var suggestions = _a.suggestions, resultOptions = _a.resultOptions, onChange = _a.onChange, onSearch = _a.onSearch, resultsPanelDataTestId = _a.resultsPanelDataTestId, allResults = _a.allResults;
10619
+ var suggestions = _a.suggestions, resultOptions = _a.resultOptions, onChange = _a.onChange, onSearch = _a.onSearch, resultsPanelDataTestId = _a.resultsPanelDataTestId, allResults = _a.allResults, initialTerm = _a.initialTerm;
10620
10620
  var theme = useTheme();
10621
+ if (initialTerm) {
10622
+ initialState$1.term = initialTerm;
10623
+ }
10621
10624
  var _b = useReducer(reducer, initialState$1), state = _b[0], dispatch = _b[1];
10622
10625
  var ref = useRef(null);
10623
10626
  var shouldDisplaySuggestion = function () {
@@ -15053,17 +15056,39 @@ var MobileClearContainer = newStyled.div(templateObject_8 || (templateObject_8 =
15053
15056
  var templateObject_1$1, templateObject_2$1, templateObject_3$1, templateObject_4$1, templateObject_5$1, templateObject_6, templateObject_7, templateObject_8;
15054
15057
 
15055
15058
  var Filters = function (_a) {
15056
- var filters = _a.filters, onChange = _a.onChange, _b = _a.tagsColor, tagsColor = _b === void 0 ? '#fff6ef' : _b, filterByText = _a.filterByText, clearAllText = _a.clearAllText, isMobile = _a.isMobile, filtersSelectText = _a.filtersSelectText, applyText = _a.applyText, mobileApplyButtonClick = _a.mobileApplyButtonClick, mobileBackArrowClick = _a.mobileBackArrowClick, onResetValues = _a.onResetValues;
15059
+ var values = _a.values, onChange = _a.onChange, _b = _a.tagsColor, tagsColor = _b === void 0 ? '#fff6ef' : _b, filterByText = _a.filterByText, clearAllText = _a.clearAllText, isMobile = _a.isMobile, filtersSelectText = _a.filtersSelectText, applyText = _a.applyText, mobileApplyButtonClick = _a.mobileApplyButtonClick, mobileBackArrowClick = _a.mobileBackArrowClick, onResetValues = _a.onResetValues;
15057
15060
  var theme = useTheme();
15058
- var _c = React__default.useState([]), checkedItems = _c[0], setCheckedItems = _c[1];
15061
+ var _c = useState(values), filters = _c[0], setFilter = _c[1];
15062
+ var _d = useState([]), checkedItems = _d[0], setCheckedItems = _d[1];
15063
+ var _e = useState(), filterState = _e[0], setFilterSection = _e[1];
15064
+ useEffect(function () {
15065
+ if (filters.length && filterState) {
15066
+ onChange(filters, filterState);
15067
+ }
15068
+ }, [filterState, filters, onChange]);
15059
15069
  var handleCheckboxClick = useCallback(function (_a) {
15060
15070
  var sectionIndex = _a.sectionIndex, itemIndex = _a.itemIndex, checked = _a.checked;
15061
- onChange({ sectionIndex: sectionIndex, itemIndex: itemIndex, checked: checked });
15071
+ setFilterSection({ sectionIndex: sectionIndex, itemIndex: itemIndex, checked: checked });
15062
15072
  setCheckedItems(function (prev) {
15063
15073
  return checked
15064
- ? __spreadArray(__spreadArray([], prev, true), [{ sectionIndex: sectionIndex, itemIndex: itemIndex, label: filters[sectionIndex].items[itemIndex] }], false) : prev.filter(function (item) { return item.sectionIndex !== sectionIndex || item.itemIndex !== itemIndex; });
15074
+ ? __spreadArray(__spreadArray([], prev, true), [
15075
+ { sectionIndex: sectionIndex, itemIndex: itemIndex, label: filters[sectionIndex].items[itemIndex].label },
15076
+ ], false) : prev.filter(function (item) { return item.sectionIndex !== sectionIndex || item.itemIndex !== itemIndex; });
15077
+ });
15078
+ setFilter(function (prev) {
15079
+ return prev.map(function (filter, indexSection) {
15080
+ if (sectionIndex !== indexSection)
15081
+ return filter;
15082
+ return __assign$1(__assign$1({}, filter), { items: filter.items.map(function (value, indexItems) {
15083
+ return {
15084
+ label: value.label,
15085
+ checked: itemIndex === indexItems ? checked : value.checked,
15086
+ };
15087
+ }) });
15088
+ });
15065
15089
  });
15066
- }, [filters, onChange]);
15090
+ // eslint-disable-next-line react-hooks/exhaustive-deps
15091
+ }, []);
15067
15092
  var handleCloseClick = function (_a) {
15068
15093
  var sectionIndex = _a.sectionIndex, itemIndex = _a.itemIndex;
15069
15094
  var element = document.getElementById("filter[".concat(sectionIndex, ",").concat(itemIndex, "]"));
@@ -15074,16 +15099,30 @@ var Filters = function (_a) {
15074
15099
  var sectionIndex = item.sectionIndex, itemIndex = item.itemIndex;
15075
15100
  handleCloseClick({ sectionIndex: sectionIndex, itemIndex: itemIndex });
15076
15101
  });
15102
+ setFilter(function (prev) {
15103
+ return prev.map(function (filter) {
15104
+ return __assign$1(__assign$1({}, filter), { items: filter.items.map(function (value) {
15105
+ return {
15106
+ label: value.label,
15107
+ checked: false,
15108
+ };
15109
+ }) });
15110
+ });
15111
+ });
15077
15112
  onResetValues();
15078
15113
  };
15079
- return (jsxs$1(Fragment$1, { children: [!isMobile ? (jsxs$1("div", __assign$1({ "data-testid": "DesktopHeader" }, { children: [jsxs$1(Header, { children: [jsxs$1(H4, __assign$1({ color: theme.colors.shades['700'].color }, { children: [filterByText, " (", checkedItems.length, ")"] }), void 0), jsx$1(ClearAll, __assign$1({ onClick: handleClearAllClick, color: theme.colors.shades['700'].color, "data-testid": "desktop-clear-all" }, { children: clearAllText }), void 0)] }, void 0), jsx$1(Tags, { color: tagsColor, items: checkedItems.map(function (item) { return item.label; }), onCloseClick: function (index) { return handleCloseClick(checkedItems[index]); } }, void 0)] }), void 0)) : (jsxs$1(MobileHeader, __assign$1({ "data-testid": "MobileHeader" }, { children: [jsx$1(MobileIconsContainer, __assign$1({ onClick: mobileBackArrowClick, "data-testid": "mobileBackArrow" }, { children: jsx$1(Icon.Arrows.ChevronRightVariant, { fill: theme.colors.shades['700'].color }, void 0) }), void 0), jsxs$1(H4, __assign$1({ color: theme.colors.shades['700'].color }, { children: [filtersSelectText, " (", checkedItems.length, ")"] }), void 0)] }), void 0)), filters.map(function (filter, sectionIndex) { return (jsx$1(Accordion, __assign$1({ title: filter.title, isOpenByDefault: filter.isOpenByDefault }, { children: jsx$1(SectionContent, __assign$1({ cols: filter.columns }, { children: filter.items.map(function (item, itemIndex) { return (jsx$1(FilterCheckbox, { onChange: handleCheckboxClick, text: item, itemIndex: itemIndex, sectionIndex: sectionIndex }, itemIndex)); }) }), void 0) }), sectionIndex)); }), isMobile && (jsxs$1(MobileFooter, __assign$1({ "data-testid": "MobileFooter" }, { children: [jsxs$1(MobileClearContainer, __assign$1({ onClick: handleClearAllClick }, { children: [jsx$1(MobileIconsContainer, { children: jsx$1(Icon.Actions.Trash, { fill: theme.colors.shades['700'].color }, void 0) }, void 0), jsx$1(ClearAll, __assign$1({ color: theme.colors.shades['700'].color }, { children: clearAllText }), void 0)] }), void 0), jsx$1(ButtonSecondary, { text: applyText, onClick: mobileApplyButtonClick }, void 0)] }), void 0))] }, void 0));
15114
+ return (jsxs$1(Fragment$1, { children: [!isMobile ? (jsxs$1("div", __assign$1({ "data-testid": "DesktopHeader" }, { children: [jsxs$1(Header, { children: [jsxs$1(H4, __assign$1({ color: theme.colors.shades['700'].color }, { children: [filterByText, " (", checkedItems.length, ")"] }), void 0), jsx$1(ClearAll, __assign$1({ onClick: handleClearAllClick, color: theme.colors.shades['700'].color, "data-testid": "desktop-clear-all" }, { children: clearAllText }), void 0)] }, void 0), jsx$1(Tags, { color: tagsColor, items: checkedItems.map(function (item) { return item.label; }), onCloseClick: function (index) { return handleCloseClick(checkedItems[index]); } }, void 0)] }), void 0)) : (jsxs$1(MobileHeader, __assign$1({ "data-testid": "MobileHeader" }, { children: [jsx$1(MobileIconsContainer, __assign$1({ onClick: mobileBackArrowClick, "data-testid": "mobileBackArrow" }, { children: jsx$1(Icon.Arrows.ChevronRightVariant, { fill: theme.colors.shades['700'].color }, void 0) }), void 0), jsxs$1(H4, __assign$1({ color: theme.colors.shades['700'].color }, { children: [filtersSelectText, " (", checkedItems.length, ")"] }), void 0)] }), void 0)), filters.map(function (filter, sectionIndex) { return (jsx$1(Accordion, __assign$1({ title: filter.title, isOpenByDefault: filter.isOpenByDefault }, { children: jsx$1(SectionContent, __assign$1({ cols: filter.columns }, { children: filter.items.map(function (item, itemIndex) { return (jsx$1(FilterCheckbox, { onChange: handleCheckboxClick, text: item.label, checked: item.checked, itemIndex: itemIndex, sectionIndex: sectionIndex }, itemIndex)); }) }), void 0) }), sectionIndex)); }), isMobile && (jsxs$1(MobileFooter, __assign$1({ "data-testid": "MobileFooter" }, { children: [jsxs$1(MobileClearContainer, __assign$1({ onClick: handleClearAllClick }, { children: [jsx$1(MobileIconsContainer, { children: jsx$1(Icon.Actions.Trash, { fill: theme.colors.shades['700'].color }, void 0) }, void 0), jsx$1(ClearAll, __assign$1({ color: theme.colors.shades['700'].color }, { children: clearAllText }), void 0)] }), void 0), jsx$1(ButtonSecondary, { text: applyText, onClick: mobileApplyButtonClick }, void 0)] }), void 0))] }, void 0));
15080
15115
  };
15081
15116
  var FilterCheckbox = function (_a) {
15082
- var sectionIndex = _a.sectionIndex, text = _a.text, itemIndex = _a.itemIndex, onChangeProp = _a.onChange;
15117
+ var sectionIndex = _a.sectionIndex, text = _a.text, itemIndex = _a.itemIndex, onChangeProp = _a.onChange, checked = _a.checked;
15118
+ var _b = React__default.useState(checked), defaultChecked = _b[0], setDefaultChecked = _b[1];
15083
15119
  var onChange = useCallback(function (checked) {
15084
- onChangeProp({ sectionIndex: sectionIndex, itemIndex: itemIndex, checked: checked });
15085
- }, [sectionIndex, itemIndex, onChangeProp]);
15086
- return (jsx$1(Checkbox, { onChange: onChange, text: text, id: "filter[".concat(sectionIndex, ",").concat(itemIndex, "]"), size: ComponentSize.Small, variant: "secondary" }, itemIndex));
15120
+ setDefaultChecked(checked);
15121
+ }, []);
15122
+ React__default.useEffect(function () {
15123
+ onChangeProp({ sectionIndex: sectionIndex, itemIndex: itemIndex, checked: defaultChecked });
15124
+ }, [sectionIndex, itemIndex, onChangeProp, defaultChecked]);
15125
+ return (jsx$1(Checkbox, { onChange: onChange, checked: defaultChecked, text: text, id: "filter[".concat(sectionIndex, ",").concat(itemIndex, "]"), size: ComponentSize.Small, variant: "secondary" }, itemIndex));
15087
15126
  };
15088
15127
 
15089
15128
  var Container = newStyled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-wrap: wrap;\n padding: 0 1rem 1rem;\n"], ["\n display: flex;\n flex-wrap: wrap;\n padding: 0 1rem 1rem;\n"])));