@useblu/ocean-react 1.53.0 → 1.54.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/CHANGELOG.md +12 -0
- package/Chips/Chips.d.ts +12 -6
- package/Chips/Chips.d.ts.map +1 -1
- package/Chips/Options.d.ts +9 -5
- package/Chips/Options.d.ts.map +1 -1
- package/index.es.js +69 -22
- package/index.es.js.map +1 -1
- package/index.js +69 -22
- package/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.54.1](https://github.com/ocean-ds/ocean-web/compare/v1.54.0...v1.54.1) (2024-03-26)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- adjust optins columns ([#1093](https://github.com/ocean-ds/ocean-web/issues/1093)) ([b49ed7c](https://github.com/ocean-ds/ocean-web/commit/b49ed7cc28408a1cce4a2f6366b7c8799bff563e))
|
|
11
|
+
|
|
12
|
+
# [1.54.0](https://github.com/ocean-ds/ocean-web/compare/v1.53.0...v1.54.0) (2024-03-25)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- add multi choice options on chips ([#1092](https://github.com/ocean-ds/ocean-web/issues/1092)) ([fc239e5](https://github.com/ocean-ds/ocean-web/commit/fc239e5e66b556c2c1580aab1735077e378e17c7))
|
|
17
|
+
|
|
6
18
|
# [1.53.0](https://github.com/ocean-ds/ocean-web/compare/v1.52.2...v1.53.0) (2024-03-21)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/Chips/Chips.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
export declare type ChipValue = {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
2
6
|
interface IChips {
|
|
3
7
|
label: string;
|
|
4
|
-
counter?: string | number;
|
|
5
8
|
icon?: React.ReactNode;
|
|
6
9
|
disabled?: boolean;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
multiChoice?: boolean;
|
|
11
|
+
options?: ChipValue[];
|
|
12
|
+
defaultValue?: ChipValue;
|
|
13
|
+
clearLabel?: string;
|
|
14
|
+
filterLabel?: string;
|
|
15
|
+
initialCounter?: number;
|
|
11
16
|
onClick?: () => void;
|
|
12
|
-
onChange?: (value:
|
|
17
|
+
onChange?: (value: ChipValue[] | ChipValue) => void;
|
|
18
|
+
onClose?: () => void;
|
|
13
19
|
}
|
|
14
20
|
declare const Chips: React.FunctionComponent<IChips>;
|
|
15
21
|
export default Chips;
|
package/Chips/Chips.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chips.d.ts","sourceRoot":"","sources":["../../src/Chips/Chips.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAMjD,
|
|
1
|
+
{"version":3,"file":"Chips.d.ts","sourceRoot":"","sources":["../../src/Chips/Chips.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAMjD,oBAAY,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,KAAK,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,QAAA,MAAM,KAAK,EAAE,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAiJ1C,CAAC;AAIF,eAAe,KAAK,CAAC"}
|
package/Chips/Options.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ChipValue } from './Chips';
|
|
2
3
|
interface IOptions {
|
|
3
|
-
options: Array<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
options: Array<ChipValue>;
|
|
5
|
+
selectedOptions?: ChipValue[];
|
|
6
|
+
clearLabel: string;
|
|
7
|
+
filterLabel: string;
|
|
8
|
+
multiChoice: boolean;
|
|
9
|
+
onSelect: (label: string, value: string) => void;
|
|
10
|
+
filterOptions: () => void;
|
|
11
|
+
clearOptions: () => void;
|
|
8
12
|
}
|
|
9
13
|
declare const Options: React.FunctionComponent<IOptions>;
|
|
10
14
|
export default Options;
|
package/Chips/Options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Options.d.ts","sourceRoot":"","sources":["../../src/Chips/Options.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Options.d.ts","sourceRoot":"","sources":["../../src/Chips/Options.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,UAAU,QAAQ;IAChB,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1B,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED,QAAA,MAAM,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CA4D9C,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/index.es.js
CHANGED
|
@@ -46421,27 +46421,35 @@ var CardListItem = function (_a) {
|
|
|
46421
46421
|
};
|
|
46422
46422
|
|
|
46423
46423
|
var Options = function (_a) {
|
|
46424
|
-
var options = _a.options, onSelect = _a.onSelect;
|
|
46425
|
-
|
|
46426
|
-
|
|
46427
|
-
|
|
46428
|
-
|
|
46424
|
+
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;
|
|
46425
|
+
var columns = multiChoice ? Math.ceil(10 / 5) : 1;
|
|
46426
|
+
return (e.createElement("div", { className: "ods-chips__options", "data-testid": "ods-chips-option" },
|
|
46427
|
+
e.createElement("div", { className: classNames('ods-chips__options--content', "ods-chips__options--content--columns-".concat(columns)) }, options.map(function (_a) {
|
|
46428
|
+
var label = _a.label, value = _a.value;
|
|
46429
|
+
return (e.createElement("button", { key: label, type: "button", value: value, onClick: function () { return onSelect(label, value); }, className: "ods-chips__options--option" },
|
|
46430
|
+
multiChoice && (e.createElement(Checkbox, { checked: !!selectedOptions.find(function (option) { return option.value === value; }), readOnly: true })),
|
|
46431
|
+
label));
|
|
46432
|
+
})),
|
|
46433
|
+
multiChoice && (e.createElement("div", { className: "ods-chips__options--footer" },
|
|
46434
|
+
e.createElement("button", { type: "button", onClick: clearOptions, className: "ods-btn ods-btn--sm ods-btn--text" }, clearLabel),
|
|
46435
|
+
e.createElement("button", { type: "button", onClick: filterOptions, className: "ods-btn ods-btn--sm ods-btn--primary" }, filterLabel)))));
|
|
46429
46436
|
};
|
|
46430
46437
|
|
|
46431
46438
|
var Chips = function (_a) {
|
|
46432
|
-
var label = _a.label,
|
|
46439
|
+
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;
|
|
46433
46440
|
var wrapperRef = useRef(null);
|
|
46434
|
-
var
|
|
46435
|
-
var
|
|
46436
|
-
|
|
46437
|
-
|
|
46438
|
-
|
|
46439
|
-
|
|
46440
|
-
|
|
46441
|
-
if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
|
|
46442
|
-
setSelectionIsOpen(false);
|
|
46443
|
-
}
|
|
46441
|
+
var _f = e.useState(0), counter = _f[0], setCounter = _f[1];
|
|
46442
|
+
var _g = e.useState(false), selectionIsOpen = _g[0], setSelectionIsOpen = _g[1];
|
|
46443
|
+
var _h = e.useState(defaultValue || multiChoice ? [] : { label: '', value: '' }), selectedOptions = _h[0], setSelectedOptions = _h[1];
|
|
46444
|
+
function handleClickOutside(event) {
|
|
46445
|
+
var target = event.target;
|
|
46446
|
+
if (wrapperRef.current && !wrapperRef.current.contains(target)) {
|
|
46447
|
+
setSelectionIsOpen(false);
|
|
46444
46448
|
}
|
|
46449
|
+
if (onClose)
|
|
46450
|
+
onClose();
|
|
46451
|
+
}
|
|
46452
|
+
useEffect(function () {
|
|
46445
46453
|
document.addEventListener('mousedown', handleClickOutside);
|
|
46446
46454
|
return function () {
|
|
46447
46455
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
@@ -46456,23 +46464,62 @@ var Chips = function (_a) {
|
|
|
46456
46464
|
}
|
|
46457
46465
|
};
|
|
46458
46466
|
var handleSelectOption = function (labelProp, value) {
|
|
46459
|
-
|
|
46467
|
+
if (!multiChoice) {
|
|
46468
|
+
setSelectedOptions({ label: labelProp, value: value });
|
|
46469
|
+
setSelectionIsOpen(false);
|
|
46470
|
+
if (onChange) {
|
|
46471
|
+
onChange({ label: labelProp, value: value });
|
|
46472
|
+
}
|
|
46473
|
+
return;
|
|
46474
|
+
}
|
|
46475
|
+
if (Array.isArray(selectedOptions)) {
|
|
46476
|
+
var copyOptions = __spreadArray$1([], selectedOptions, true);
|
|
46477
|
+
if (selectedOptions.find(function (option) { return option.value === value; })) {
|
|
46478
|
+
copyOptions = copyOptions.filter(function (option) { return option.value !== value; });
|
|
46479
|
+
}
|
|
46480
|
+
else {
|
|
46481
|
+
copyOptions.push({ label: labelProp, value: value });
|
|
46482
|
+
}
|
|
46483
|
+
setCounter(copyOptions.length);
|
|
46484
|
+
setSelectedOptions(copyOptions);
|
|
46485
|
+
if (onChange) {
|
|
46486
|
+
onChange(copyOptions);
|
|
46487
|
+
}
|
|
46488
|
+
}
|
|
46489
|
+
};
|
|
46490
|
+
var displayValue = function () {
|
|
46491
|
+
if (!Array.isArray(selectedOptions)) {
|
|
46492
|
+
return selectedOptions.value ? selectedOptions.label : label;
|
|
46493
|
+
}
|
|
46494
|
+
return label;
|
|
46495
|
+
};
|
|
46496
|
+
var clearOptions = function () {
|
|
46497
|
+
setSelectedOptions([]);
|
|
46498
|
+
setCounter(0);
|
|
46460
46499
|
setSelectionIsOpen(false);
|
|
46461
46500
|
if (onChange) {
|
|
46462
|
-
onChange(
|
|
46501
|
+
onChange([]);
|
|
46463
46502
|
}
|
|
46464
46503
|
};
|
|
46504
|
+
var filterOptions = function () {
|
|
46505
|
+
setSelectionIsOpen(false);
|
|
46506
|
+
if (onClose)
|
|
46507
|
+
onClose();
|
|
46508
|
+
};
|
|
46465
46509
|
return (e.createElement("div", { className: "ods-chips", ref: wrapperRef },
|
|
46466
46510
|
e.createElement("button", { type: "button", onClick: handleClickChips, disabled: disabled, className: classNames('ods-chips__button', {
|
|
46467
46511
|
'ods-chips__button--disabled': disabled,
|
|
46468
|
-
'ods-chips__button--active': selectionIsOpen ||
|
|
46512
|
+
'ods-chips__button--active': selectionIsOpen ||
|
|
46513
|
+
(Array.isArray(selectedOptions)
|
|
46514
|
+
? selectedOptions.length > 0
|
|
46515
|
+
: selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.value)
|
|
46469
46516
|
}) },
|
|
46470
46517
|
icon || undefined,
|
|
46471
|
-
e.createElement("p", { className: "ods-chips__label" },
|
|
46472
|
-
counter && (e.createElement(Badge, { color: "brand", className: "ods-chips__badge" }, counter)),
|
|
46518
|
+
e.createElement("p", { className: "ods-chips__label" }, displayValue()),
|
|
46519
|
+
(counter > 0 || initialCounter) && (e.createElement(Badge, { color: "brand", className: "ods-chips__badge" }, initialCounter !== null && initialCounter !== void 0 ? initialCounter : counter)),
|
|
46473
46520
|
options && (options === null || options === void 0 ? void 0 : options.length) > 0 && !selectionIsOpen && e.createElement(J, null),
|
|
46474
46521
|
options && (options === null || options === void 0 ? void 0 : options.length) > 0 && selectionIsOpen && e.createElement(re, null)),
|
|
46475
|
-
selectionIsOpen && options && (e.createElement(Options, { options: options, onSelect: handleSelectOption }))));
|
|
46522
|
+
selectionIsOpen && options && (e.createElement(Options, { options: options, onSelect: handleSelectOption, selectedOptions: Array.isArray(selectedOptions) ? selectedOptions : undefined, clearLabel: clearLabel, filterLabel: filterLabel, multiChoice: multiChoice, clearOptions: clearOptions, filterOptions: filterOptions }))));
|
|
46476
46523
|
};
|
|
46477
46524
|
Chips.displayName = 'Chips';
|
|
46478
46525
|
|