@useblu/ocean-react 1.137.1 → 1.138.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/CHANGELOG.md +6 -0
- package/Chips/Chips.d.ts +1 -0
- package/Chips/Chips.d.ts.map +1 -1
- package/Chips/MultipleChoiceOptions.d.ts +1 -0
- package/Chips/MultipleChoiceOptions.d.ts.map +1 -1
- package/Chips/hooks/useChip.d.ts +1 -1
- package/Chips/hooks/useChip.d.ts.map +1 -1
- package/Chips/types.d.ts +1 -0
- package/Chips/types.d.ts.map +1 -1
- package/index.es.js +45 -27
- package/index.es.js.map +1 -1
- package/index.js +45 -27
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -47254,7 +47254,7 @@ var CardListItem = e.forwardRef(function (_a, ref) {
|
|
|
47254
47254
|
CardListItem.displayName = 'CardListItem';
|
|
47255
47255
|
|
|
47256
47256
|
var MultipleChoiceOptions = function (_a) {
|
|
47257
|
-
var options = _a.options, selectedOptions = _a.selectedOptions, clearLabel = _a.clearLabel, filterLabel = _a.filterLabel, multiChoice = _a.multiChoice, onSelect = _a.onSelect, clearOptions = _a.clearOptions, filterOptions = _a.filterOptions, headerOptions = _a.headerOptions, selectionIsOpen = _a.selectionIsOpen, handleContextMenuOpenChange = _a.handleContextMenuOpenChange, selectAllOptions = _a.selectAllOptions;
|
|
47257
|
+
var options = _a.options, selectedOptions = _a.selectedOptions, clearLabel = _a.clearLabel, filterLabel = _a.filterLabel, multiChoice = _a.multiChoice, _b = _a.singleSelection, singleSelection = _b === void 0 ? false : _b, onSelect = _a.onSelect, clearOptions = _a.clearOptions, filterOptions = _a.filterOptions, headerOptions = _a.headerOptions, selectionIsOpen = _a.selectionIsOpen, handleContextMenuOpenChange = _a.handleContextMenuOpenChange, selectAllOptions = _a.selectAllOptions;
|
|
47258
47258
|
var isMobile = useMedia$1('(max-width: 768px)');
|
|
47259
47259
|
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
|
47260
47260
|
var selectedValues = selectedArray.map(function (option) { return option.value; });
|
|
@@ -47277,7 +47277,7 @@ var MultipleChoiceOptions = function (_a) {
|
|
|
47277
47277
|
}
|
|
47278
47278
|
});
|
|
47279
47279
|
};
|
|
47280
|
-
if (!multiChoice) {
|
|
47280
|
+
if (!multiChoice && !singleSelection) {
|
|
47281
47281
|
return null;
|
|
47282
47282
|
}
|
|
47283
47283
|
var isMultiArray = Array.isArray(selectedOptions);
|
|
@@ -47297,7 +47297,7 @@ var MultipleChoiceOptions = function (_a) {
|
|
|
47297
47297
|
e.createElement("div", { className: "ods-chips__options__responsive-header" },
|
|
47298
47298
|
e.createElement(IconButton, { size: "sm", onClick: function () { return handleContextMenuOpenChange(false); }, "aria-label": "Fechar menu" },
|
|
47299
47299
|
e.createElement(Wa, null))),
|
|
47300
|
-
selectAllOptions && (e.createElement("div", { className: "ods-chips__options__select-all" },
|
|
47300
|
+
selectAllOptions && !singleSelection && (e.createElement("div", { className: "ods-chips__options__select-all" },
|
|
47301
47301
|
e.createElement(ListSelectable, { status: "highlight", type: "text", title: "Selecionar todos", checkbox: {
|
|
47302
47302
|
id: 'select-all',
|
|
47303
47303
|
checked: allOptionsSelected || someOptionsSelected,
|
|
@@ -47310,36 +47310,38 @@ var MultipleChoiceOptions = function (_a) {
|
|
|
47310
47310
|
var isSelected = Array.isArray(selectedOptions)
|
|
47311
47311
|
? selectedOptions.some(function (option) { return option.value === value; })
|
|
47312
47312
|
: selectedOptions.value === value;
|
|
47313
|
+
var selectionInput = {
|
|
47314
|
+
id: "chips-option-".concat(value),
|
|
47315
|
+
checked: isSelected,
|
|
47316
|
+
onClick: function () { return onSelect(label, value); },
|
|
47317
|
+
readOnly: true,
|
|
47318
|
+
disabled: disabled,
|
|
47319
|
+
};
|
|
47313
47320
|
return (e.createElement("div", { key: value },
|
|
47314
|
-
e.createElement(ListSelectable, { inverted: true, indicator: indicator, type: "text", title: label, showDivider: index !== options.length - 1, platform: isMobile ? 'app' : 'web', checkbox:
|
|
47315
|
-
|
|
47316
|
-
|
|
47317
|
-
onClick: function () { return onSelect(label, value); },
|
|
47318
|
-
readOnly: true,
|
|
47319
|
-
disabled: disabled,
|
|
47320
|
-
indeterminate: indeterminate || false,
|
|
47321
|
-
} })));
|
|
47321
|
+
e.createElement(ListSelectable, { inverted: true, indicator: indicator, type: "text", title: label, showDivider: index !== options.length - 1, platform: isMobile ? 'app' : 'web', radio: singleSelection ? selectionInput : undefined, checkbox: singleSelection
|
|
47322
|
+
? undefined
|
|
47323
|
+
: __assign$1(__assign$1({}, selectionInput), { indeterminate: indeterminate || false }) })));
|
|
47322
47324
|
}),
|
|
47323
47325
|
e.createElement("div", { className: "ods-chips__options--footer" },
|
|
47324
47326
|
e.createElement("button", { type: "button", onClick: clearOptions, className: responsiveSecondaryBtnClasses, disabled: !isMultiArray || selectedOptions.length === 0 }, clearLabel),
|
|
47325
47327
|
e.createElement("button", { type: "button", onClick: filterOptions, className: responsivePrimaryBtnClasses }, filterLabel)))));
|
|
47326
47328
|
};
|
|
47327
47329
|
|
|
47328
|
-
var shouldDefaultToEmpty = function (defaultValue, multiChoice) { return Boolean(defaultValue) || Boolean(multiChoice); };
|
|
47330
|
+
var shouldDefaultToEmpty = function (defaultValue, multiChoice, singleSelection) { return Boolean(defaultValue) || Boolean(multiChoice) || Boolean(singleSelection); };
|
|
47329
47331
|
var useChip = function (_a) {
|
|
47330
|
-
var defaultValue = _a.defaultValue, _b = _a.multiChoice, multiChoice = _b === void 0 ? false : _b, onChange = _a.onChange, onClean = _a.onClean, onConfirm = _a.onConfirm, onClose = _a.onClose, onClick = _a.onClick,
|
|
47332
|
+
var defaultValue = _a.defaultValue, _b = _a.multiChoice, multiChoice = _b === void 0 ? false : _b, _c = _a.singleSelection, singleSelection = _c === void 0 ? false : _c, onChange = _a.onChange, onClean = _a.onClean, onConfirm = _a.onConfirm, onClose = _a.onClose, onClick = _a.onClick, _d = _a.options, options = _d === void 0 ? [] : _d, selectedValue = _a.selectedValue;
|
|
47331
47333
|
var wrapperRef = e.useRef(null);
|
|
47332
|
-
var
|
|
47333
|
-
var
|
|
47334
|
-
var
|
|
47335
|
-
return shouldDefaultToEmpty(defaultValue, multiChoice)
|
|
47334
|
+
var _e = e.useState(0), counter = _e[0], setCounter = _e[1];
|
|
47335
|
+
var _f = e.useState(false), selectionIsOpen = _f[0], setSelectionIsOpen = _f[1];
|
|
47336
|
+
var _g = e.useState(function () {
|
|
47337
|
+
return shouldDefaultToEmpty(defaultValue, multiChoice, singleSelection)
|
|
47336
47338
|
? []
|
|
47337
47339
|
: { label: '', value: '' };
|
|
47338
|
-
}), selectedOptions =
|
|
47340
|
+
}), selectedOptions = _g[0], setSelectedOptions = _g[1];
|
|
47339
47341
|
e.useEffect(function () {
|
|
47340
47342
|
if (selectedValue && selectedValue !== selectedOptions) {
|
|
47341
47343
|
setSelectedOptions(selectedValue);
|
|
47342
|
-
if (multiChoice && Array.isArray(selectedValue)) {
|
|
47344
|
+
if (multiChoice && !singleSelection && Array.isArray(selectedValue)) {
|
|
47343
47345
|
setCounter(selectedValue.length);
|
|
47344
47346
|
}
|
|
47345
47347
|
}
|
|
@@ -47368,6 +47370,21 @@ var useChip = function (_a) {
|
|
|
47368
47370
|
}
|
|
47369
47371
|
}, [options.length, onClick]);
|
|
47370
47372
|
var handleSelectOption = e.useCallback(function (labelProp, value) {
|
|
47373
|
+
if (singleSelection) {
|
|
47374
|
+
setSelectedOptions(function (prev) {
|
|
47375
|
+
var previous = Array.isArray(prev) ? prev : [];
|
|
47376
|
+
var isSameOption = previous.some(function (option) { return option.value === value; });
|
|
47377
|
+
var matchedOption = options.find(function (option) { return option.value === value; });
|
|
47378
|
+
var next = isSameOption
|
|
47379
|
+
? []
|
|
47380
|
+
: [matchedOption !== null && matchedOption !== void 0 ? matchedOption : { label: labelProp, value: value }];
|
|
47381
|
+
if (onChange) {
|
|
47382
|
+
onChange(next);
|
|
47383
|
+
}
|
|
47384
|
+
return next;
|
|
47385
|
+
});
|
|
47386
|
+
return;
|
|
47387
|
+
}
|
|
47371
47388
|
if (!multiChoice) {
|
|
47372
47389
|
var nextSelection = { label: labelProp, value: value };
|
|
47373
47390
|
setSelectedOptions(nextSelection);
|
|
@@ -47395,7 +47412,7 @@ var useChip = function (_a) {
|
|
|
47395
47412
|
}
|
|
47396
47413
|
return copyOptions;
|
|
47397
47414
|
});
|
|
47398
|
-
}, [multiChoice, onChange, options]);
|
|
47415
|
+
}, [multiChoice, onChange, options, singleSelection]);
|
|
47399
47416
|
var clearOptions = e.useCallback(function () {
|
|
47400
47417
|
setSelectedOptions([]);
|
|
47401
47418
|
setCounter(0);
|
|
@@ -47439,10 +47456,11 @@ var useChip = function (_a) {
|
|
|
47439
47456
|
};
|
|
47440
47457
|
|
|
47441
47458
|
var Chips = function (_a) {
|
|
47442
|
-
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 =
|
|
47443
|
-
var
|
|
47459
|
+
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.singleSelection, singleSelection = _d === void 0 ? false : _d, _e = _a.clearLabel, clearLabel = _e === void 0 ? 'Limpar' : _e, _f = _a.filterLabel, filterLabel = _f === void 0 ? 'Filtrar' : _f, initialCounter = _a.initialCounter, actived = _a.actived, selectedValue = _a.selectedValue, onClick = _a.onClick, onChange = _a.onChange, onClose = _a.onClose, onConfirm = _a.onConfirm, onClean = _a.onClean, headerOptions = _a.headerOptions, _g = _a.selectAllOptions, selectAllOptions = _g === void 0 ? false : _g;
|
|
47460
|
+
var _h = useChip({
|
|
47444
47461
|
defaultValue: defaultValue,
|
|
47445
47462
|
multiChoice: multiChoice,
|
|
47463
|
+
singleSelection: singleSelection,
|
|
47446
47464
|
onChange: onChange,
|
|
47447
47465
|
onClean: onClean,
|
|
47448
47466
|
onConfirm: onConfirm,
|
|
@@ -47450,7 +47468,7 @@ var Chips = function (_a) {
|
|
|
47450
47468
|
onClick: onClick,
|
|
47451
47469
|
options: options,
|
|
47452
47470
|
selectedValue: selectedValue,
|
|
47453
|
-
}), clearOptions =
|
|
47471
|
+
}), clearOptions = _h.clearOptions, counter = _h.counter, filterOptions = _h.filterOptions, handleClickChips = _h.handleClickChips, handleContextMenuOpenChange = _h.handleContextMenuOpenChange, handleSelectOption = _h.handleSelectOption, selectedOptions = _h.selectedOptions, selectionIsOpen = _h.selectionIsOpen, wrapperRef = _h.wrapperRef;
|
|
47454
47472
|
var displayValue = function () {
|
|
47455
47473
|
if (!Array.isArray(selectedOptions)) {
|
|
47456
47474
|
return selectedOptions.value ? selectedOptions.label : label;
|
|
@@ -47458,7 +47476,7 @@ var Chips = function (_a) {
|
|
|
47458
47476
|
return label;
|
|
47459
47477
|
};
|
|
47460
47478
|
var contextualMenuItems = e.useMemo(function () {
|
|
47461
|
-
return multiChoice
|
|
47479
|
+
return multiChoice || singleSelection
|
|
47462
47480
|
? []
|
|
47463
47481
|
: options.map(function (_a) {
|
|
47464
47482
|
var optionLabel = _a.label, value = _a.value, indicator = _a.indicator, optionDisabled = _a.disabled, tag = _a.tag;
|
|
@@ -47472,7 +47490,7 @@ var Chips = function (_a) {
|
|
|
47472
47490
|
type: 'neutral',
|
|
47473
47491
|
});
|
|
47474
47492
|
});
|
|
47475
|
-
}, [multiChoice, options]);
|
|
47493
|
+
}, [multiChoice, singleSelection, options]);
|
|
47476
47494
|
var handleContextualMenuSelect = function (value) {
|
|
47477
47495
|
var option = options.find(function (item) { return item.value === value; });
|
|
47478
47496
|
if (option) {
|
|
@@ -47485,8 +47503,8 @@ var Chips = function (_a) {
|
|
|
47485
47503
|
var hasOptions = options && (options === null || options === void 0 ? void 0 : options.length) > 0;
|
|
47486
47504
|
var shouldRenderOptions = selectionIsOpen && hasOptions;
|
|
47487
47505
|
var renderOptions = function () {
|
|
47488
|
-
if (multiChoice) {
|
|
47489
|
-
return (e.createElement(MultipleChoiceOptions, { options: options, onSelect: handleSelectOption, selectedOptions: selectedOptions, clearLabel: clearLabel, filterLabel: filterLabel, multiChoice: multiChoice, clearOptions: clearOptions, filterOptions: filterOptions, headerOptions: headerOptions, selectionIsOpen: selectionIsOpen, handleContextMenuOpenChange: handleContextMenuOpenChange, selectAllOptions: selectAllOptions }));
|
|
47506
|
+
if (multiChoice || singleSelection) {
|
|
47507
|
+
return (e.createElement(MultipleChoiceOptions, { options: options, onSelect: handleSelectOption, selectedOptions: selectedOptions, clearLabel: clearLabel, filterLabel: filterLabel, multiChoice: multiChoice, singleSelection: singleSelection, clearOptions: clearOptions, filterOptions: filterOptions, headerOptions: headerOptions, selectionIsOpen: selectionIsOpen, handleContextMenuOpenChange: handleContextMenuOpenChange, selectAllOptions: selectAllOptions }));
|
|
47490
47508
|
}
|
|
47491
47509
|
return (e.createElement(ContextualMenu, { items: contextualMenuItems, open: selectionIsOpen, onOpenChange: handleContextMenuOpenChange, onSelect: handleContextualMenuSelect, selectedValue: contextualMenuSelectedValue, className: "ods-chips__contextual-menu" }));
|
|
47492
47510
|
};
|