@thecb/components 11.1.8 → 11.1.9
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.cjs.js +62 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +62 -12
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/molecules/multiple-select-filter/MultipleSelectFilter.js +49 -10
- package/src/components/molecules/multiple-select-filter/__private__/FilterButton.js +3 -1
- package/src/components/molecules/multiple-select-filter/__private__/util.js +13 -0
- package/src/components/atoms/.DS_Store +0 -0
package/dist/index.esm.js
CHANGED
|
@@ -50732,7 +50732,8 @@ var FilterButton$1 = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
50732
50732
|
truncateBtnTextWidth = _ref.truncateBtnTextWidth,
|
|
50733
50733
|
filterLabel = _ref.filterLabel,
|
|
50734
50734
|
selectedOptions = _ref.selectedOptions,
|
|
50735
|
-
extraStyles = _ref.extraStyles
|
|
50735
|
+
extraStyles = _ref.extraStyles,
|
|
50736
|
+
dataAppliedOptions = _ref.dataAppliedOptions;
|
|
50736
50737
|
var btnTextFilterDescription = selectedOptions !== null && selectedOptions !== void 0 && selectedOptions.length ? "".concat(filterLabel ? "".concat(filterLabel, ": ") : "").concat(selectedOptions[0].name) : "".concat(filterLabel ? filterLabel : "");
|
|
50737
50738
|
var btnTextItemsDescription = selectedOptions !== null && selectedOptions !== void 0 && selectedOptions.length && (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.length) > 1 ? ", +".concat((selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.length) - 1, " More") : "";
|
|
50738
50739
|
return /*#__PURE__*/React.createElement(StyledFilterButton, {
|
|
@@ -50750,6 +50751,7 @@ var FilterButton$1 = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
50750
50751
|
dataQa: "".concat(name, "-filter-button"),
|
|
50751
50752
|
extraStyles: extraStyles,
|
|
50752
50753
|
"aria-label": "".concat(filterLabel, " Filter: ").concat(btnTextFilterDescription, " ").concat(btnTextItemsDescription),
|
|
50754
|
+
"data-applied-options": dataAppliedOptions,
|
|
50753
50755
|
contentOverride: true
|
|
50754
50756
|
}, btnContentOverride ? btnContentOverride : /*#__PURE__*/React.createElement(Center, {
|
|
50755
50757
|
as: "span",
|
|
@@ -50934,6 +50936,19 @@ var selectOption = function selectOption(option, selectedOptions, setSelectedOpt
|
|
|
50934
50936
|
setSelectedOptions(moreOptions);
|
|
50935
50937
|
}
|
|
50936
50938
|
};
|
|
50939
|
+
var mergeOptions = function mergeOptions(selectedOptions, activeOptions) {
|
|
50940
|
+
if (!activeOptions.length) return selectedOptions;
|
|
50941
|
+
if (!selectedOptions.length) return activeOptions;
|
|
50942
|
+
var mergedOptions = _toConsumableArray(selectedOptions);
|
|
50943
|
+
activeOptions.forEach(function (activeOption) {
|
|
50944
|
+
if (!mergedOptions.some(function (option) {
|
|
50945
|
+
return option.name === activeOption.name;
|
|
50946
|
+
})) {
|
|
50947
|
+
mergedOptions.push(activeOption);
|
|
50948
|
+
}
|
|
50949
|
+
});
|
|
50950
|
+
return mergedOptions;
|
|
50951
|
+
};
|
|
50937
50952
|
|
|
50938
50953
|
var useKeyboardNavigation = function useKeyboardNavigation(_ref) {
|
|
50939
50954
|
var options = _ref.options,
|
|
@@ -51134,41 +51149,75 @@ var MultipleSelectFilter = function MultipleSelectFilter(_ref) {
|
|
|
51134
51149
|
searchable = _ref$searchable === void 0 ? true : _ref$searchable,
|
|
51135
51150
|
themeValues = _ref.themeValues,
|
|
51136
51151
|
_ref$truncateBtnTextW = _ref.truncateBtnTextWidth,
|
|
51137
|
-
truncateBtnTextWidth = _ref$truncateBtnTextW === void 0 ? "15rem" : _ref$truncateBtnTextW
|
|
51152
|
+
truncateBtnTextWidth = _ref$truncateBtnTextW === void 0 ? "15rem" : _ref$truncateBtnTextW,
|
|
51153
|
+
activeAppliedOptions = _ref.activeAppliedOptions;
|
|
51154
|
+
// State to manage whether the dropdown is open or closed
|
|
51138
51155
|
var _useState = useState(false),
|
|
51139
51156
|
_useState2 = _slicedToArray(_useState, 2),
|
|
51140
51157
|
opened = _useState2[0],
|
|
51141
51158
|
setOpened = _useState2[1];
|
|
51159
|
+
|
|
51160
|
+
// State to manage the currently selected options
|
|
51142
51161
|
var _useState3 = useState([]),
|
|
51143
51162
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
51144
51163
|
selectedOptions = _useState4[0],
|
|
51145
51164
|
setSelectedOptions = _useState4[1];
|
|
51146
|
-
|
|
51165
|
+
|
|
51166
|
+
// State to manage the applied options, initialized with activeAppliedOptions or an empty array
|
|
51167
|
+
var _useState5 = useState(activeAppliedOptions || []),
|
|
51147
51168
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
51148
51169
|
appliedOptions = _useState6[0],
|
|
51149
51170
|
setAppliedOptions = _useState6[1];
|
|
51171
|
+
|
|
51172
|
+
// State to track whether the user has interacted with the component
|
|
51173
|
+
var _useState7 = useState(false),
|
|
51174
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
51175
|
+
hasInteracted = _useState8[0],
|
|
51176
|
+
setHasInteracted = _useState8[1];
|
|
51177
|
+
|
|
51178
|
+
// Reference to keep track of the opened state across renders without causing re-renders
|
|
51150
51179
|
var openedRef = useRef(opened);
|
|
51151
|
-
|
|
51152
|
-
|
|
51153
|
-
setOpened(false);
|
|
51154
|
-
actions.fields.searchTerm.set("");
|
|
51155
|
-
}
|
|
51156
|
-
};
|
|
51180
|
+
|
|
51181
|
+
// Hook to detect clicks outside the component and close the dropdown
|
|
51157
51182
|
var containerRef = useOutsideClickHook(function () {
|
|
51158
51183
|
return handleOnClose();
|
|
51159
51184
|
});
|
|
51185
|
+
|
|
51186
|
+
// References to various elements within the component
|
|
51160
51187
|
var dropdownRef = useRef(null);
|
|
51161
51188
|
var filterButtonRef = useRef(null);
|
|
51162
51189
|
var applyFilterButtonRef = useRef(null);
|
|
51190
|
+
|
|
51191
|
+
// IDs for accessibility and identification purposes
|
|
51163
51192
|
var filterDropdownID = "".concat(name, "-filter-dropdown");
|
|
51164
51193
|
var listGroupID = "".concat(name, "-list-group");
|
|
51194
|
+
var handleOnClose = function handleOnClose() {
|
|
51195
|
+
if (openedRef.current) {
|
|
51196
|
+
setOpened(false);
|
|
51197
|
+
actions.fields.searchTerm.set("");
|
|
51198
|
+
}
|
|
51199
|
+
};
|
|
51165
51200
|
useEffect$1(function () {
|
|
51166
51201
|
openedRef.current = opened;
|
|
51167
51202
|
if (!opened) {
|
|
51168
|
-
|
|
51169
|
-
|
|
51203
|
+
if (hasInteracted) {
|
|
51204
|
+
onApply(selectedOptions);
|
|
51205
|
+
setAppliedOptions(selectedOptions);
|
|
51206
|
+
}
|
|
51207
|
+
} else {
|
|
51208
|
+
setHasInteracted(true);
|
|
51170
51209
|
}
|
|
51171
51210
|
}, [opened]);
|
|
51211
|
+
useEffect$1(function () {
|
|
51212
|
+
// Update the applied options state with the current active applied options,
|
|
51213
|
+
// or an empty array if activeAppliedOptions is undefined or null.
|
|
51214
|
+
// This ensures that the current applied options are in sync with the parent component.
|
|
51215
|
+
setAppliedOptions(activeAppliedOptions || []);
|
|
51216
|
+
|
|
51217
|
+
// Merge the selected options with the active applied options.
|
|
51218
|
+
var mergedSelections = mergeOptions(selectedOptions, activeAppliedOptions);
|
|
51219
|
+
setSelectedOptions(mergedSelections);
|
|
51220
|
+
}, [activeAppliedOptions]);
|
|
51172
51221
|
useEffect$1(function () {
|
|
51173
51222
|
var handleKeyDown = function handleKeyDown(event) {
|
|
51174
51223
|
if (event.key === "Escape") {
|
|
@@ -51210,7 +51259,8 @@ var MultipleSelectFilter = function MultipleSelectFilter(_ref) {
|
|
|
51210
51259
|
truncateBtnTextWidth: truncateBtnTextWidth,
|
|
51211
51260
|
filterLabel: filterLabel,
|
|
51212
51261
|
selectedOptions: selectedOptions,
|
|
51213
|
-
extraStyles: btnExtraStyles
|
|
51262
|
+
extraStyles: btnExtraStyles,
|
|
51263
|
+
dataAppliedOptions: appliedOptions === null || appliedOptions === void 0 ? void 0 : appliedOptions.length
|
|
51214
51264
|
}), /*#__PURE__*/React.createElement(FilterDropdown, {
|
|
51215
51265
|
id: filterDropdownID,
|
|
51216
51266
|
ref: dropdownRef,
|