@useblu/ocean-react 1.54.1 → 1.55.1

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;
46434
- var columns = multiChoice ? Math.ceil(10 / 5) : 1;
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
+ var columns = multiChoice ? Math.ceil(options.length / 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, onClose = _a.onClose;
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, actived = _a.actived, 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];
@@ -46454,10 +46458,15 @@ var Chips = function (_a) {
46454
46458
  var target = event.target;
46455
46459
  if (wrapperRef.current && !wrapperRef.current.contains(target)) {
46456
46460
  setSelectionIsOpen(false);
46461
+ if (onClose)
46462
+ onClose();
46457
46463
  }
46458
- if (onClose)
46459
- onClose();
46460
46464
  }
46465
+ e.useEffect(function () {
46466
+ if (selectedValue && selectedValue !== selectedOptions && !multiChoice) {
46467
+ setSelectedOptions(selectedValue);
46468
+ }
46469
+ }, [selectedValue]);
46461
46470
  e.useEffect(function () {
46462
46471
  document.addEventListener('mousedown', handleClickOutside);
46463
46472
  return function () {
@@ -46476,6 +46485,8 @@ var Chips = function (_a) {
46476
46485
  if (!multiChoice) {
46477
46486
  setSelectedOptions({ label: labelProp, value: value });
46478
46487
  setSelectionIsOpen(false);
46488
+ if (onClose)
46489
+ onClose();
46479
46490
  if (onChange) {
46480
46491
  onChange({ label: labelProp, value: value });
46481
46492
  }
@@ -46506,9 +46517,10 @@ var Chips = function (_a) {
46506
46517
  setSelectedOptions([]);
46507
46518
  setCounter(0);
46508
46519
  setSelectionIsOpen(false);
46509
- if (onChange) {
46520
+ if (onClose)
46521
+ onClose();
46522
+ if (onChange)
46510
46523
  onChange([]);
46511
- }
46512
46524
  };
46513
46525
  var filterOptions = function () {
46514
46526
  setSelectionIsOpen(false);
@@ -46521,14 +46533,15 @@ var Chips = function (_a) {
46521
46533
  'ods-chips__button--active': selectionIsOpen ||
46522
46534
  (Array.isArray(selectedOptions)
46523
46535
  ? selectedOptions.length > 0
46524
- : selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.value)
46536
+ : selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.value) ||
46537
+ actived
46525
46538
  }) },
46526
46539
  icon || undefined,
46527
46540
  e__default["default"].createElement("p", { className: "ods-chips__label" }, displayValue()),
46528
46541
  (counter > 0 || initialCounter) && (e__default["default"].createElement(Badge, { color: "brand", className: "ods-chips__badge" }, initialCounter !== null && initialCounter !== void 0 ? initialCounter : counter)),
46529
46542
  options && (options === null || options === void 0 ? void 0 : options.length) > 0 && !selectionIsOpen && e__default["default"].createElement(J, null),
46530
46543
  options && (options === null || options === void 0 ? void 0 : options.length) > 0 && selectionIsOpen && e__default["default"].createElement(re, null)),
46531
- 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 }))));
46544
+ selectionIsOpen && options && (e__default["default"].createElement(Options, { options: options, onSelect: handleSelectOption, selectedOptions: selectedOptions, clearLabel: clearLabel, filterLabel: filterLabel, multiChoice: multiChoice, clearOptions: clearOptions, filterOptions: filterOptions }))));
46532
46545
  };
46533
46546
  Chips.displayName = 'Chips';
46534
46547