@trafilea/afrodita-components 5.0.0-beta.46 → 5.0.0-beta.47

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
@@ -102,6 +102,7 @@ declare type Filter = {
102
102
  title: string;
103
103
  columns: number;
104
104
  isOpenByDefault?: boolean;
105
+ isMultiselect: boolean;
105
106
  items: Array<{
106
107
  label: string;
107
108
  checked?: boolean;
@@ -3934,8 +3934,13 @@ var Checkbox = function (_a) {
3934
3934
  if (disabled || !mounted.current) {
3935
3935
  return;
3936
3936
  }
3937
- onChange(isChecked);
3938
- }, [isChecked, onChange, disabled]);
3937
+ if (checked !== isChecked) {
3938
+ onChange(isChecked);
3939
+ }
3940
+ }, [isChecked, onChange, disabled, checked]);
3941
+ useEffect(function () {
3942
+ setIsChecked(checked);
3943
+ }, [checked]);
3939
3944
  useEffect(function () {
3940
3945
  mounted.current = true;
3941
3946
  }, []);
@@ -16704,9 +16709,12 @@ var Filters = function (_a) {
16704
16709
  var handleCheckboxClick = useCallback(function (_a) {
16705
16710
  var sectionIndex = _a.sectionIndex, itemIndex = _a.itemIndex, checked = _a.checked;
16706
16711
  setFilterSection({ sectionIndex: sectionIndex, itemIndex: itemIndex, checked: checked });
16712
+ var currentFilter = filters[sectionIndex];
16707
16713
  setCheckedItems(function (prev) {
16714
+ if (!currentFilter.isMultiselect)
16715
+ resetCheckedItems(__spreadArray([], prev, true));
16708
16716
  return checked
16709
- ? __spreadArray(__spreadArray([], prev, true), [
16717
+ ? __spreadArray(__spreadArray([], (currentFilter.isMultiselect ? prev : []), true), [
16710
16718
  { sectionIndex: sectionIndex, itemIndex: itemIndex, label: filters[sectionIndex].items[itemIndex].label },
16711
16719
  ], false) : prev.filter(function (item) { return item.sectionIndex !== sectionIndex || item.itemIndex !== itemIndex; });
16712
16720
  });
@@ -16717,7 +16725,7 @@ var Filters = function (_a) {
16717
16725
  return __assign$1(__assign$1({}, filter), { items: filter.items.map(function (value, indexItems) {
16718
16726
  return {
16719
16727
  label: value.label,
16720
- checked: itemIndex === indexItems ? checked : value.checked,
16728
+ checked: itemIndex === indexItems ? checked : filter.isMultiselect ? value.checked : false,
16721
16729
  };
16722
16730
  }) });
16723
16731
  });
@@ -16729,11 +16737,15 @@ var Filters = function (_a) {
16729
16737
  var element = document.getElementById("filter[".concat(sectionIndex, ",").concat(itemIndex, "]"));
16730
16738
  simulateMouseClick(element);
16731
16739
  };
16732
- var handleClearAllClick = function () {
16733
- checkedItems.forEach(function (item) {
16740
+ var resetCheckedItems = function (items) {
16741
+ items.forEach(function (item) {
16734
16742
  var sectionIndex = item.sectionIndex, itemIndex = item.itemIndex;
16735
16743
  handleCloseClick({ sectionIndex: sectionIndex, itemIndex: itemIndex });
16736
16744
  });
16745
+ };
16746
+ var handleClearAllClick = function () {
16747
+ resetCheckedItems(checkedItems);
16748
+ setCheckedItems([]);
16737
16749
  setFilter(function (prev) {
16738
16750
  return prev.map(function (filter) {
16739
16751
  return __assign$1(__assign$1({}, filter), { items: filter.items.map(function (value) {
@@ -16746,18 +16758,14 @@ var Filters = function (_a) {
16746
16758
  });
16747
16759
  onResetValues();
16748
16760
  };
16749
- 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));
16761
+ 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 }, "".concat(item.checked, "-").concat(item.label))); }) }), 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));
16750
16762
  };
16751
16763
  var FilterCheckbox = function (_a) {
16752
16764
  var sectionIndex = _a.sectionIndex, text = _a.text, itemIndex = _a.itemIndex, onChangeProp = _a.onChange, checked = _a.checked;
16753
- var _b = React__default.useState(checked), defaultChecked = _b[0], setDefaultChecked = _b[1];
16754
16765
  var onChange = useCallback(function (checked) {
16755
- setDefaultChecked(checked);
16756
- }, []);
16757
- React__default.useEffect(function () {
16758
- onChangeProp({ sectionIndex: sectionIndex, itemIndex: itemIndex, checked: defaultChecked });
16759
- }, [sectionIndex, itemIndex, onChangeProp, defaultChecked]);
16760
- return (jsx$1(Checkbox, { onChange: onChange, checked: defaultChecked, text: text, id: "filter[".concat(sectionIndex, ",").concat(itemIndex, "]"), size: ComponentSize.Small, variant: "secondary" }, itemIndex));
16766
+ onChangeProp({ sectionIndex: sectionIndex, itemIndex: itemIndex, checked: checked });
16767
+ }, [sectionIndex, itemIndex, onChangeProp]);
16768
+ return (jsx$1(Checkbox, { onChange: onChange, checked: checked, text: text, id: "filter[".concat(sectionIndex, ",").concat(itemIndex, "]"), size: ComponentSize.Small, variant: "secondary" }, itemIndex));
16761
16769
  };
16762
16770
 
16763
16771
  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"])));