@useblu/ocean-react 1.54.0 → 1.55.0

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/index.js CHANGED
@@ -46430,13 +46430,17 @@ var CardListItem = function (_a) {
46430
46430
  };
46431
46431
 
46432
46432
  var Options = function (_a) {
46433
- var options = _a.options, _b = _a.selectedOptions, selectedOptions = _b === void 0 ? [] : _b, clearLabel = _a.clearLabel, filterLabel = _a.filterLabel, multiChoice = _a.multiChoice, onSelect = _a.onSelect, filterOptions = _a.filterOptions, clearOptions = _a.clearOptions;
46433
+ var options = _a.options, selectedOptions = _a.selectedOptions, clearLabel = _a.clearLabel, filterLabel = _a.filterLabel, multiChoice = _a.multiChoice, onSelect = _a.onSelect, filterOptions = _a.filterOptions, clearOptions = _a.clearOptions;
46434
46434
  var columns = multiChoice ? Math.ceil(10 / 5) : 1;
46435
46435
  return (e__default["default"].createElement("div", { className: "ods-chips__options", "data-testid": "ods-chips-option" },
46436
46436
  e__default["default"].createElement("div", { className: classNames('ods-chips__options--content', "ods-chips__options--content--columns-".concat(columns)) }, options.map(function (_a) {
46437
46437
  var label = _a.label, value = _a.value;
46438
- return (e__default["default"].createElement("button", { key: label, type: "button", value: value, onClick: function () { return onSelect(label, value); }, className: "ods-chips__options--option" },
46439
- multiChoice && (e__default["default"].createElement(Checkbox, { checked: !!selectedOptions.find(function (option) { return option.value === value; }), readOnly: true })),
46438
+ return (e__default["default"].createElement("button", { key: label, type: "button", value: value, onClick: function () { return onSelect(label, value); }, className: classNames('ods-chips__options--option', {
46439
+ 'ods-chips__options--option--selected': !multiChoice &&
46440
+ !Array.isArray(selectedOptions) &&
46441
+ selectedOptions.value === value
46442
+ }) },
46443
+ multiChoice && Array.isArray(selectedOptions) && (e__default["default"].createElement(Checkbox, { checked: !!selectedOptions.find(function (option) { return option.value === value; }), readOnly: true })),
46440
46444
  label));
46441
46445
  })),
46442
46446
  multiChoice && (e__default["default"].createElement("div", { className: "ods-chips__options--footer" },
@@ -46445,7 +46449,7 @@ var Options = function (_a) {
46445
46449
  };
46446
46450
 
46447
46451
  var Chips = function (_a) {
46448
- var label = _a.label, icon = _a.icon, disabled = _a.disabled, defaultValue = _a.defaultValue, _b = _a.options, options = _b === void 0 ? [] : _b, _c = _a.multiChoice, multiChoice = _c === void 0 ? false : _c, _d = _a.clearLabel, clearLabel = _d === void 0 ? 'Limpar' : _d, _e = _a.filterLabel, filterLabel = _e === void 0 ? 'Filtrar' : _e, initialCounter = _a.initialCounter, onClick = _a.onClick, onChange = _a.onChange;
46452
+ var label = _a.label, icon = _a.icon, disabled = _a.disabled, defaultValue = _a.defaultValue, _b = _a.options, options = _b === void 0 ? [] : _b, _c = _a.multiChoice, multiChoice = _c === void 0 ? false : _c, _d = _a.clearLabel, clearLabel = _d === void 0 ? 'Limpar' : _d, _e = _a.filterLabel, filterLabel = _e === void 0 ? 'Filtrar' : _e, initialCounter = _a.initialCounter, selectedValue = _a.selectedValue, onClick = _a.onClick, onChange = _a.onChange, onClose = _a.onClose;
46449
46453
  var wrapperRef = e.useRef(null);
46450
46454
  var _f = e__default["default"].useState(0), counter = _f[0], setCounter = _f[1];
46451
46455
  var _g = e__default["default"].useState(false), selectionIsOpen = _g[0], setSelectionIsOpen = _g[1];
@@ -46455,7 +46459,14 @@ var Chips = function (_a) {
46455
46459
  if (wrapperRef.current && !wrapperRef.current.contains(target)) {
46456
46460
  setSelectionIsOpen(false);
46457
46461
  }
46462
+ if (onClose)
46463
+ onClose();
46458
46464
  }
46465
+ e.useEffect(function () {
46466
+ if (selectedValue && selectedValue !== selectedOptions && !multiChoice) {
46467
+ setSelectedOptions(selectedValue);
46468
+ }
46469
+ }, [selectedValue]);
46459
46470
  e.useEffect(function () {
46460
46471
  document.addEventListener('mousedown', handleClickOutside);
46461
46472
  return function () {
@@ -46510,9 +46521,8 @@ var Chips = function (_a) {
46510
46521
  };
46511
46522
  var filterOptions = function () {
46512
46523
  setSelectionIsOpen(false);
46513
- if (onChange) {
46514
- onChange(selectedOptions);
46515
- }
46524
+ if (onClose)
46525
+ onClose();
46516
46526
  };
46517
46527
  return (e__default["default"].createElement("div", { className: "ods-chips", ref: wrapperRef },
46518
46528
  e__default["default"].createElement("button", { type: "button", onClick: handleClickChips, disabled: disabled, className: classNames('ods-chips__button', {
@@ -46527,7 +46537,7 @@ var Chips = function (_a) {
46527
46537
  (counter > 0 || initialCounter) && (e__default["default"].createElement(Badge, { color: "brand", className: "ods-chips__badge" }, initialCounter !== null && initialCounter !== void 0 ? initialCounter : counter)),
46528
46538
  options && (options === null || options === void 0 ? void 0 : options.length) > 0 && !selectionIsOpen && e__default["default"].createElement(J, null),
46529
46539
  options && (options === null || options === void 0 ? void 0 : options.length) > 0 && selectionIsOpen && e__default["default"].createElement(re, null)),
46530
- selectionIsOpen && options && (e__default["default"].createElement(Options, { options: options, onSelect: handleSelectOption, selectedOptions: Array.isArray(selectedOptions) ? selectedOptions : undefined, clearLabel: clearLabel, filterLabel: filterLabel, multiChoice: multiChoice, clearOptions: clearOptions, filterOptions: filterOptions }))));
46540
+ selectionIsOpen && options && (e__default["default"].createElement(Options, { options: options, onSelect: handleSelectOption, selectedOptions: selectedOptions, clearLabel: clearLabel, filterLabel: filterLabel, multiChoice: multiChoice, clearOptions: clearOptions, filterOptions: filterOptions }))));
46531
46541
  };
46532
46542
  Chips.displayName = 'Chips';
46533
46543